mirror of
https://github.com/cc65/cc65.git
synced 2024-12-28 22:30:12 +00:00
Renamed ExprDesc.Val to ExprDesc.IVal. Added an FVal field for a floating
point constant. git-svn-id: svn://svn.cc65.org/cc65/trunk@3107 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
eb388aa237
commit
9fc71c5e93
@ -137,19 +137,19 @@ static void ParseByteArg (StrBuf* T, unsigned Arg)
|
|||||||
|
|
||||||
/* Check the range but allow negative values if the type is signed */
|
/* Check the range but allow negative values if the type is signed */
|
||||||
if (IsSignUnsigned (Expr.Type)) {
|
if (IsSignUnsigned (Expr.Type)) {
|
||||||
if (Expr.Val < 0 || Expr.Val > 0xFF) {
|
if (Expr.IVal < 0 || Expr.IVal > 0xFF) {
|
||||||
AsmRangeError (Arg);
|
AsmRangeError (Arg);
|
||||||
Expr.Val = 0;
|
Expr.IVal = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Expr.Val < -128 || Expr.Val > 127) {
|
if (Expr.IVal < -128 || Expr.IVal > 127) {
|
||||||
AsmRangeError (Arg);
|
AsmRangeError (Arg);
|
||||||
Expr.Val = 0;
|
Expr.IVal = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert into a hex number */
|
/* Convert into a hex number */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02lX", Expr.Val & 0xFF);
|
xsprintf (Buf, sizeof (Buf), "$%02lX", Expr.IVal & 0xFF);
|
||||||
|
|
||||||
/* Add the number to the target buffer */
|
/* Add the number to the target buffer */
|
||||||
SB_AppendStr (T, Buf);
|
SB_AppendStr (T, Buf);
|
||||||
@ -171,19 +171,19 @@ static void ParseWordArg (StrBuf* T, unsigned Arg)
|
|||||||
|
|
||||||
/* Check the range but allow negative values if the type is signed */
|
/* Check the range but allow negative values if the type is signed */
|
||||||
if (IsSignUnsigned (Expr.Type)) {
|
if (IsSignUnsigned (Expr.Type)) {
|
||||||
if (Expr.Val < 0 || Expr.Val > 0xFFFF) {
|
if (Expr.IVal < 0 || Expr.IVal > 0xFFFF) {
|
||||||
AsmRangeError (Arg);
|
AsmRangeError (Arg);
|
||||||
Expr.Val = 0;
|
Expr.IVal = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Expr.Val < -32768 || Expr.Val > 32767) {
|
if (Expr.IVal < -32768 || Expr.IVal > 32767) {
|
||||||
AsmRangeError (Arg);
|
AsmRangeError (Arg);
|
||||||
Expr.Val = 0;
|
Expr.IVal = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert into a hex number */
|
/* Convert into a hex number */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%04lX", Expr.Val & 0xFFFF);
|
xsprintf (Buf, sizeof (Buf), "$%04lX", Expr.IVal & 0xFFFF);
|
||||||
|
|
||||||
/* Add the number to the target buffer */
|
/* Add the number to the target buffer */
|
||||||
SB_AppendStr (T, Buf);
|
SB_AppendStr (T, Buf);
|
||||||
@ -204,7 +204,7 @@ static void ParseLongArg (StrBuf* T, unsigned Arg attribute ((unused)))
|
|||||||
ConstAbsIntExpr (hie1, &Expr);
|
ConstAbsIntExpr (hie1, &Expr);
|
||||||
|
|
||||||
/* Convert into a hex number */
|
/* Convert into a hex number */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%08lX", Expr.Val & 0xFFFFFFFF);
|
xsprintf (Buf, sizeof (Buf), "$%08lX", Expr.IVal & 0xFFFFFFFF);
|
||||||
|
|
||||||
/* Add the number to the target buffer */
|
/* Add the number to the target buffer */
|
||||||
SB_AppendStr (T, Buf);
|
SB_AppendStr (T, Buf);
|
||||||
@ -302,7 +302,7 @@ static void ParseStrArg (StrBuf* T, unsigned Arg attribute ((unused)))
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
ConstAbsIntExpr (hie1, &Expr);
|
ConstAbsIntExpr (hie1, &Expr);
|
||||||
xsprintf (Buf, sizeof (Buf), "%ld", Expr.Val);
|
xsprintf (Buf, sizeof (Buf), "%ld", Expr.IVal);
|
||||||
SB_AppendStr (T, Buf);
|
SB_AppendStr (T, Buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ static void AddEncodeToDeclaration (Declaration* D, type T, unsigned long Val)
|
|||||||
D->Index += DECODE_SIZE;
|
D->Index += DECODE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void ParseStorageClass (DeclSpec* D, unsigned DefStorage)
|
static void ParseStorageClass (DeclSpec* D, unsigned DefStorage)
|
||||||
/* Parse a storage class */
|
/* Parse a storage class */
|
||||||
@ -267,10 +267,10 @@ static void ParseEnumDecl (void)
|
|||||||
|
|
||||||
/* Check for an assigned value */
|
/* Check for an assigned value */
|
||||||
if (CurTok.Tok == TOK_ASSIGN) {
|
if (CurTok.Tok == TOK_ASSIGN) {
|
||||||
ExprDesc lval;
|
ExprDesc Expr;
|
||||||
NextToken ();
|
NextToken ();
|
||||||
ConstAbsIntExpr (hie1, &lval);
|
ConstAbsIntExpr (hie1, &Expr);
|
||||||
EnumVal = lval.Val;
|
EnumVal = Expr.IVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add an entry to the symbol table */
|
/* Add an entry to the symbol table */
|
||||||
@ -281,7 +281,7 @@ static void ParseEnumDecl (void)
|
|||||||
break;
|
break;
|
||||||
NextToken ();
|
NextToken ();
|
||||||
}
|
}
|
||||||
ConsumeRCurly ();
|
ConsumeRCurly ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1045,17 +1045,17 @@ static void Decl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
/* Read the size if it is given */
|
/* Read the size if it is given */
|
||||||
if (CurTok.Tok != TOK_RBRACK) {
|
if (CurTok.Tok != TOK_RBRACK) {
|
||||||
ExprDesc lval;
|
ExprDesc Expr;
|
||||||
ConstAbsIntExpr (hie1, &lval);
|
ConstAbsIntExpr (hie1, &Expr);
|
||||||
if (lval.Val <= 0) {
|
if (Expr.IVal <= 0) {
|
||||||
if (D->Ident[0] != '\0') {
|
if (D->Ident[0] != '\0') {
|
||||||
Error ("Size of array `%s' is invalid", D->Ident);
|
Error ("Size of array `%s' is invalid", D->Ident);
|
||||||
} else {
|
} else {
|
||||||
Error ("Size of array is invalid");
|
Error ("Size of array is invalid");
|
||||||
}
|
}
|
||||||
lval.Val = 1;
|
Expr.IVal = 1;
|
||||||
}
|
}
|
||||||
Size = lval.Val;
|
Size = Expr.IVal;
|
||||||
}
|
}
|
||||||
ConsumeRBrack ();
|
ConsumeRBrack ();
|
||||||
|
|
||||||
@ -1431,7 +1431,7 @@ static unsigned ParseVoidInit (void)
|
|||||||
case T_UCHAR:
|
case T_UCHAR:
|
||||||
if (ED_IsConstAbsInt (&Expr)) {
|
if (ED_IsConstAbsInt (&Expr)) {
|
||||||
/* Make it byte sized */
|
/* Make it byte sized */
|
||||||
Expr.Val &= 0xFF;
|
Expr.IVal &= 0xFF;
|
||||||
}
|
}
|
||||||
DefineData (&Expr);
|
DefineData (&Expr);
|
||||||
Size += SIZEOF_CHAR;
|
Size += SIZEOF_CHAR;
|
||||||
@ -1445,7 +1445,7 @@ static unsigned ParseVoidInit (void)
|
|||||||
case T_ARRAY:
|
case T_ARRAY:
|
||||||
if (ED_IsConstAbsInt (&Expr)) {
|
if (ED_IsConstAbsInt (&Expr)) {
|
||||||
/* Make it word sized */
|
/* Make it word sized */
|
||||||
Expr.Val &= 0xFFFF;
|
Expr.IVal &= 0xFFFF;
|
||||||
}
|
}
|
||||||
DefineData (&Expr);
|
DefineData (&Expr);
|
||||||
Size += SIZEOF_INT;
|
Size += SIZEOF_INT;
|
||||||
@ -1455,7 +1455,7 @@ static unsigned ParseVoidInit (void)
|
|||||||
case T_ULONG:
|
case T_ULONG:
|
||||||
if (ED_IsConstAbsInt (&Expr)) {
|
if (ED_IsConstAbsInt (&Expr)) {
|
||||||
/* Make it dword sized */
|
/* Make it dword sized */
|
||||||
Expr.Val &= 0xFFFFFFFF;
|
Expr.IVal &= 0xFFFFFFFF;
|
||||||
}
|
}
|
||||||
DefineData (&Expr);
|
DefineData (&Expr);
|
||||||
Size += SIZEOF_LONG;
|
Size += SIZEOF_LONG;
|
||||||
@ -1527,7 +1527,7 @@ static unsigned ParseInitInternal (type* T, int AllowFlexibleMembers)
|
|||||||
unsigned ParseInit (type* T)
|
unsigned ParseInit (type* T)
|
||||||
/* Parse initialization of variables. Return the number of data bytes. */
|
/* Parse initialization of variables. Return the number of data bytes. */
|
||||||
{
|
{
|
||||||
/* Parse the initialization */
|
/* Parse the initialization */
|
||||||
unsigned Size = ParseInitInternal (T, !ANSI);
|
unsigned Size = ParseInitInternal (T, !ANSI);
|
||||||
|
|
||||||
/* The initialization may not generate code on global level, because code
|
/* The initialization may not generate code on global level, because code
|
||||||
|
204
src/cc65/expr.c
204
src/cc65/expr.c
@ -195,18 +195,18 @@ void DefineData (ExprDesc* Expr)
|
|||||||
|
|
||||||
case E_LOC_ABS:
|
case E_LOC_ABS:
|
||||||
/* Absolute: numeric address or const */
|
/* Absolute: numeric address or const */
|
||||||
g_defdata (TypeOf (Expr->Type) | CF_CONST, Expr->Val, 0);
|
g_defdata (TypeOf (Expr->Type) | CF_CONST, Expr->IVal, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_GLOBAL:
|
case E_LOC_GLOBAL:
|
||||||
/* Global variable */
|
/* Global variable */
|
||||||
g_defdata (CF_EXTERNAL, Expr->Name, Expr->Val);
|
g_defdata (CF_EXTERNAL, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STATIC:
|
case E_LOC_STATIC:
|
||||||
case E_LOC_LITERAL:
|
case E_LOC_LITERAL:
|
||||||
/* Static variable or literal in the literal pool */
|
/* Static variable or literal in the literal pool */
|
||||||
g_defdata (CF_STATIC, Expr->Name, Expr->Val);
|
g_defdata (CF_STATIC, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_REGISTER:
|
case E_LOC_REGISTER:
|
||||||
@ -216,7 +216,7 @@ void DefineData (ExprDesc* Expr)
|
|||||||
if (IS_Get (&AllowRegVarAddr) == 0) {
|
if (IS_Get (&AllowRegVarAddr) == 0) {
|
||||||
Error ("Cannot take the address of a register variable");
|
Error ("Cannot take the address of a register variable");
|
||||||
}
|
}
|
||||||
g_defdata (CF_REGVAR, Expr->Name, Expr->Val);
|
g_defdata (CF_REGVAR, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -233,18 +233,18 @@ static void LoadConstant (unsigned Flags, ExprDesc* Expr)
|
|||||||
|
|
||||||
case E_LOC_ABS:
|
case E_LOC_ABS:
|
||||||
/* Number constant */
|
/* Number constant */
|
||||||
g_getimmed (Flags | TypeOf (Expr->Type) | CF_CONST, Expr->Val, 0);
|
g_getimmed (Flags | TypeOf (Expr->Type) | CF_CONST, Expr->IVal, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_GLOBAL:
|
case E_LOC_GLOBAL:
|
||||||
/* Global symbol, load address */
|
/* Global symbol, load address */
|
||||||
g_getimmed ((Flags | CF_EXTERNAL) & ~CF_CONST, Expr->Name, Expr->Val);
|
g_getimmed ((Flags | CF_EXTERNAL) & ~CF_CONST, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STATIC:
|
case E_LOC_STATIC:
|
||||||
case E_LOC_LITERAL:
|
case E_LOC_LITERAL:
|
||||||
/* Static symbol or literal, load address */
|
/* Static symbol or literal, load address */
|
||||||
g_getimmed ((Flags | CF_STATIC) & ~CF_CONST, Expr->Name, Expr->Val);
|
g_getimmed ((Flags | CF_STATIC) & ~CF_CONST, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_REGISTER:
|
case E_LOC_REGISTER:
|
||||||
@ -254,10 +254,10 @@ static void LoadConstant (unsigned Flags, ExprDesc* Expr)
|
|||||||
if (IS_Get (&AllowRegVarAddr) == 0) {
|
if (IS_Get (&AllowRegVarAddr) == 0) {
|
||||||
Error ("Cannot take the address of a register variable");
|
Error ("Cannot take the address of a register variable");
|
||||||
}
|
}
|
||||||
g_getimmed ((Flags | CF_REGVAR) & ~CF_CONST, Expr->Name, Expr->Val);
|
g_getimmed ((Flags | CF_REGVAR) & ~CF_CONST, Expr->Name, Expr->IVal);
|
||||||
|
|
||||||
case E_LOC_STACK:
|
case E_LOC_STACK:
|
||||||
g_leasp (Expr->Val);
|
g_leasp (Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -392,28 +392,28 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr)
|
|||||||
|
|
||||||
case E_LOC_ABS:
|
case E_LOC_ABS:
|
||||||
/* Absolute: numeric address or const */
|
/* Absolute: numeric address or const */
|
||||||
g_getstatic (Flags | CF_ABSOLUTE, Expr->Val, 0);
|
g_getstatic (Flags | CF_ABSOLUTE, Expr->IVal, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_GLOBAL:
|
case E_LOC_GLOBAL:
|
||||||
/* Global variable */
|
/* Global variable */
|
||||||
g_getstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->Val);
|
g_getstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STATIC:
|
case E_LOC_STATIC:
|
||||||
case E_LOC_LITERAL:
|
case E_LOC_LITERAL:
|
||||||
/* Static variable or literal in the literal pool */
|
/* Static variable or literal in the literal pool */
|
||||||
g_getstatic (Flags | CF_STATIC, Expr->Name, Expr->Val);
|
g_getstatic (Flags | CF_STATIC, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_REGISTER:
|
case E_LOC_REGISTER:
|
||||||
/* Register variable */
|
/* Register variable */
|
||||||
g_getstatic (Flags | CF_REGVAR, Expr->Name, Expr->Val);
|
g_getstatic (Flags | CF_REGVAR, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STACK:
|
case E_LOC_STACK:
|
||||||
/* Value on the stack */
|
/* Value on the stack */
|
||||||
g_getlocal (Flags, Expr->Val);
|
g_getlocal (Flags, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_PRIMARY:
|
case E_LOC_PRIMARY:
|
||||||
@ -425,7 +425,7 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr)
|
|||||||
|
|
||||||
case E_LOC_EXPR:
|
case E_LOC_EXPR:
|
||||||
/* Reference to address in primary with offset in Expr */
|
/* Reference to address in primary with offset in Expr */
|
||||||
g_getind (Flags, Expr->Val);
|
g_getind (Flags, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -438,12 +438,12 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr)
|
|||||||
} else {
|
} else {
|
||||||
/* An rvalue */
|
/* An rvalue */
|
||||||
if (ED_IsLocExpr (Expr)) {
|
if (ED_IsLocExpr (Expr)) {
|
||||||
if (Expr->Val != 0) {
|
if (Expr->IVal != 0) {
|
||||||
/* We have an expression in the primary plus a constant
|
/* We have an expression in the primary plus a constant
|
||||||
* offset. Adjust the value in the primary accordingly.
|
* offset. Adjust the value in the primary accordingly.
|
||||||
*/
|
*/
|
||||||
Flags |= TypeOf (Expr->Type);
|
Flags |= TypeOf (Expr->Type);
|
||||||
g_inc (Flags | CF_CONST, Expr->Val);
|
g_inc (Flags | CF_CONST, Expr->IVal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Constant of some sort, load it into the primary */
|
/* Constant of some sort, load it into the primary */
|
||||||
@ -593,10 +593,10 @@ static unsigned FunctionParamList (FuncDesc* Func)
|
|||||||
}
|
}
|
||||||
FrameOffs -= ArgSize;
|
FrameOffs -= ArgSize;
|
||||||
/* Store */
|
/* Store */
|
||||||
g_putlocal (Flags | CF_NOKEEP, FrameOffs, Expr.Val);
|
g_putlocal (Flags | CF_NOKEEP, FrameOffs, Expr.IVal);
|
||||||
} else {
|
} else {
|
||||||
/* Push the argument */
|
/* Push the argument */
|
||||||
g_push (Flags, Expr.Val);
|
g_push (Flags, Expr.IVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate total parameter size */
|
/* Calculate total parameter size */
|
||||||
@ -768,7 +768,7 @@ static void Primary (ExprDesc* E)
|
|||||||
if (CurTok.Tok == TOK_ICONST || CurTok.Tok == TOK_CCONST) {
|
if (CurTok.Tok == TOK_ICONST || CurTok.Tok == TOK_CCONST) {
|
||||||
E->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
E->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
||||||
E->Type = CurTok.Type;
|
E->Type = CurTok.Type;
|
||||||
E->Val = CurTok.IVal;
|
E->IVal = CurTok.IVal;
|
||||||
NextToken ();
|
NextToken ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -834,7 +834,7 @@ static void Primary (ExprDesc* E)
|
|||||||
if ((Sym->Flags & SC_CONST) == SC_CONST) {
|
if ((Sym->Flags & SC_CONST) == SC_CONST) {
|
||||||
/* Enum or some other numeric constant */
|
/* Enum or some other numeric constant */
|
||||||
E->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
E->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
||||||
E->Val = Sym->V.ConstVal;
|
E->IVal = Sym->V.ConstVal;
|
||||||
} else if ((Sym->Flags & SC_FUNC) == SC_FUNC) {
|
} else if ((Sym->Flags & SC_FUNC) == SC_FUNC) {
|
||||||
/* Function */
|
/* Function */
|
||||||
E->Flags = E_LOC_GLOBAL | E_RTYPE_LVAL;
|
E->Flags = E_LOC_GLOBAL | E_RTYPE_LVAL;
|
||||||
@ -851,7 +851,7 @@ static void Primary (ExprDesc* E)
|
|||||||
} else {
|
} else {
|
||||||
/* Normal parameter */
|
/* Normal parameter */
|
||||||
E->Flags = E_LOC_STACK | E_RTYPE_LVAL;
|
E->Flags = E_LOC_STACK | E_RTYPE_LVAL;
|
||||||
E->Val = Sym->V.Offs;
|
E->IVal = Sym->V.Offs;
|
||||||
}
|
}
|
||||||
} else if ((Sym->Flags & SC_REGISTER) == SC_REGISTER) {
|
} else if ((Sym->Flags & SC_REGISTER) == SC_REGISTER) {
|
||||||
/* Register variable, zero page based */
|
/* Register variable, zero page based */
|
||||||
@ -915,7 +915,7 @@ static void Primary (ExprDesc* E)
|
|||||||
/* String literal */
|
/* String literal */
|
||||||
E->Type = GetCharArrayType (GetLiteralPoolOffs () - CurTok.IVal);
|
E->Type = GetCharArrayType (GetLiteralPoolOffs () - CurTok.IVal);
|
||||||
E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL;
|
E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL;
|
||||||
E->Val = CurTok.IVal;
|
E->IVal = CurTok.IVal;
|
||||||
E->Name = LiteralPoolLabel;
|
E->Name = LiteralPoolLabel;
|
||||||
NextToken ();
|
NextToken ();
|
||||||
break;
|
break;
|
||||||
@ -1052,7 +1052,7 @@ static void ArrayRef (ExprDesc* Expr)
|
|||||||
/* Lhs is pointer/array. Scale the subscript value according to
|
/* Lhs is pointer/array. Scale the subscript value according to
|
||||||
* the element size.
|
* the element size.
|
||||||
*/
|
*/
|
||||||
SubScript.Val *= CheckedSizeOf (ElementType);
|
SubScript.IVal *= CheckedSizeOf (ElementType);
|
||||||
|
|
||||||
/* Remove the address load code */
|
/* Remove the address load code */
|
||||||
RemoveCode (Mark1);
|
RemoveCode (Mark1);
|
||||||
@ -1064,7 +1064,7 @@ static void ArrayRef (ExprDesc* Expr)
|
|||||||
if (IsTypeArray (Expr->Type)) {
|
if (IsTypeArray (Expr->Type)) {
|
||||||
|
|
||||||
/* Adjust the offset */
|
/* Adjust the offset */
|
||||||
Expr->Val += SubScript.Val;
|
Expr->IVal += SubScript.IVal;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -1077,7 +1077,7 @@ static void ArrayRef (ExprDesc* Expr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Use the offset */
|
/* Use the offset */
|
||||||
Expr->Val = SubScript.Val;
|
Expr->IVal = SubScript.IVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -1089,7 +1089,7 @@ static void ArrayRef (ExprDesc* Expr)
|
|||||||
* we will ignore the true type of the subscript here and
|
* we will ignore the true type of the subscript here and
|
||||||
* use always an int. #### Use offset but beware of ExprLoad!
|
* use always an int. #### Use offset but beware of ExprLoad!
|
||||||
*/
|
*/
|
||||||
g_inc (CF_INT | CF_CONST, SubScript.Val);
|
g_inc (CF_INT | CF_CONST, SubScript.IVal);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1170,29 +1170,29 @@ static void ArrayRef (ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Add the variable */
|
/* Add the variable */
|
||||||
if (ED_IsLocStack (&SubScript)) {
|
if (ED_IsLocStack (&SubScript)) {
|
||||||
g_addlocal (Flags, SubScript.Val);
|
g_addlocal (Flags, SubScript.IVal);
|
||||||
} else {
|
} else {
|
||||||
Flags |= GlobalModeFlags (SubScript.Flags);
|
Flags |= GlobalModeFlags (SubScript.Flags);
|
||||||
g_addstatic (Flags, SubScript.Name, SubScript.Val);
|
g_addstatic (Flags, SubScript.Name, SubScript.IVal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ED_IsLocAbs (Expr)) {
|
if (ED_IsLocAbs (Expr)) {
|
||||||
/* Constant numeric address. Just add it */
|
/* Constant numeric address. Just add it */
|
||||||
g_inc (CF_INT, Expr->Val);
|
g_inc (CF_INT, Expr->IVal);
|
||||||
} else if (ED_IsLocStack (Expr)) {
|
} else if (ED_IsLocStack (Expr)) {
|
||||||
/* Base address is a local variable address */
|
/* Base address is a local variable address */
|
||||||
if (IsTypeArray (Expr->Type)) {
|
if (IsTypeArray (Expr->Type)) {
|
||||||
g_addaddr_local (CF_INT, Expr->Val);
|
g_addaddr_local (CF_INT, Expr->IVal);
|
||||||
} else {
|
} else {
|
||||||
g_addlocal (CF_PTR, Expr->Val);
|
g_addlocal (CF_PTR, Expr->IVal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Base address is a static variable address */
|
/* Base address is a static variable address */
|
||||||
unsigned Flags = CF_INT | GlobalModeFlags (Expr->Flags);
|
unsigned Flags = CF_INT | GlobalModeFlags (Expr->Flags);
|
||||||
if (IsTypeArray (Expr->Type)) {
|
if (IsTypeArray (Expr->Type)) {
|
||||||
g_addaddr_static (Flags, Expr->Name, Expr->Val);
|
g_addaddr_static (Flags, Expr->Name, Expr->IVal);
|
||||||
} else {
|
} else {
|
||||||
g_addstatic (Flags, Expr->Name, Expr->Val);
|
g_addstatic (Flags, Expr->Name, Expr->IVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1262,7 +1262,7 @@ static void StructRef (ExprDesc* Expr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the struct field offset */
|
/* Set the struct field offset */
|
||||||
Expr->Val += Field->V.Offs;
|
Expr->IVal += Field->V.Offs;
|
||||||
|
|
||||||
/* The type is now the type of the field */
|
/* The type is now the type of the field */
|
||||||
Expr->Type = Field->Type;
|
Expr->Type = Field->Type;
|
||||||
@ -1362,28 +1362,28 @@ void Store (ExprDesc* Expr, const type* StoreType)
|
|||||||
|
|
||||||
case E_LOC_ABS:
|
case E_LOC_ABS:
|
||||||
/* Absolute: numeric address or const */
|
/* Absolute: numeric address or const */
|
||||||
g_putstatic (Flags | CF_ABSOLUTE, Expr->Val, 0);
|
g_putstatic (Flags | CF_ABSOLUTE, Expr->IVal, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_GLOBAL:
|
case E_LOC_GLOBAL:
|
||||||
/* Global variable */
|
/* Global variable */
|
||||||
g_putstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->Val);
|
g_putstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STATIC:
|
case E_LOC_STATIC:
|
||||||
case E_LOC_LITERAL:
|
case E_LOC_LITERAL:
|
||||||
/* Static variable or literal in the literal pool */
|
/* Static variable or literal in the literal pool */
|
||||||
g_putstatic (Flags | CF_STATIC, Expr->Name, Expr->Val);
|
g_putstatic (Flags | CF_STATIC, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_REGISTER:
|
case E_LOC_REGISTER:
|
||||||
/* Register variable */
|
/* Register variable */
|
||||||
g_putstatic (Flags | CF_REGVAR, Expr->Name, Expr->Val);
|
g_putstatic (Flags | CF_REGVAR, Expr->Name, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STACK:
|
case E_LOC_STACK:
|
||||||
/* Value on the stack */
|
/* Value on the stack */
|
||||||
g_putlocal (Flags, Expr->Val, 0);
|
g_putlocal (Flags, Expr->IVal, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_PRIMARY:
|
case E_LOC_PRIMARY:
|
||||||
@ -1393,7 +1393,7 @@ void Store (ExprDesc* Expr, const type* StoreType)
|
|||||||
|
|
||||||
case E_LOC_EXPR:
|
case E_LOC_EXPR:
|
||||||
/* An expression in the primary register */
|
/* An expression in the primary register */
|
||||||
g_putind (Flags, Expr->Val);
|
g_putind (Flags, Expr->IVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1433,28 +1433,28 @@ static void PreInc (ExprDesc* Expr)
|
|||||||
|
|
||||||
case E_LOC_ABS:
|
case E_LOC_ABS:
|
||||||
/* Absolute: numeric address or const */
|
/* Absolute: numeric address or const */
|
||||||
g_addeqstatic (Flags | CF_ABSOLUTE, Expr->Val, 0, Val);
|
g_addeqstatic (Flags | CF_ABSOLUTE, Expr->IVal, 0, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_GLOBAL:
|
case E_LOC_GLOBAL:
|
||||||
/* Global variable */
|
/* Global variable */
|
||||||
g_addeqstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->Val, Val);
|
g_addeqstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STATIC:
|
case E_LOC_STATIC:
|
||||||
case E_LOC_LITERAL:
|
case E_LOC_LITERAL:
|
||||||
/* Static variable or literal in the literal pool */
|
/* Static variable or literal in the literal pool */
|
||||||
g_addeqstatic (Flags | CF_STATIC, Expr->Name, Expr->Val, Val);
|
g_addeqstatic (Flags | CF_STATIC, Expr->Name, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_REGISTER:
|
case E_LOC_REGISTER:
|
||||||
/* Register variable */
|
/* Register variable */
|
||||||
g_addeqstatic (Flags | CF_REGVAR, Expr->Name, Expr->Val, Val);
|
g_addeqstatic (Flags | CF_REGVAR, Expr->Name, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STACK:
|
case E_LOC_STACK:
|
||||||
/* Value on the stack */
|
/* Value on the stack */
|
||||||
g_addeqlocal (Flags, Expr->Val, Val);
|
g_addeqlocal (Flags, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_PRIMARY:
|
case E_LOC_PRIMARY:
|
||||||
@ -1464,7 +1464,7 @@ static void PreInc (ExprDesc* Expr)
|
|||||||
|
|
||||||
case E_LOC_EXPR:
|
case E_LOC_EXPR:
|
||||||
/* An expression in the primary register */
|
/* An expression in the primary register */
|
||||||
g_addeqind (Flags, Expr->Val, Val);
|
g_addeqind (Flags, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1475,7 +1475,7 @@ static void PreInc (ExprDesc* Expr)
|
|||||||
ED_MakeRValExpr (Expr);
|
ED_MakeRValExpr (Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void PreDec (ExprDesc* Expr)
|
static void PreDec (ExprDesc* Expr)
|
||||||
/* Handle the predecrement operators */
|
/* Handle the predecrement operators */
|
||||||
@ -1504,28 +1504,28 @@ static void PreDec (ExprDesc* Expr)
|
|||||||
|
|
||||||
case E_LOC_ABS:
|
case E_LOC_ABS:
|
||||||
/* Absolute: numeric address or const */
|
/* Absolute: numeric address or const */
|
||||||
g_subeqstatic (Flags | CF_ABSOLUTE, Expr->Val, 0, Val);
|
g_subeqstatic (Flags | CF_ABSOLUTE, Expr->IVal, 0, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_GLOBAL:
|
case E_LOC_GLOBAL:
|
||||||
/* Global variable */
|
/* Global variable */
|
||||||
g_subeqstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->Val, Val);
|
g_subeqstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STATIC:
|
case E_LOC_STATIC:
|
||||||
case E_LOC_LITERAL:
|
case E_LOC_LITERAL:
|
||||||
/* Static variable or literal in the literal pool */
|
/* Static variable or literal in the literal pool */
|
||||||
g_subeqstatic (Flags | CF_STATIC, Expr->Name, Expr->Val, Val);
|
g_subeqstatic (Flags | CF_STATIC, Expr->Name, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_REGISTER:
|
case E_LOC_REGISTER:
|
||||||
/* Register variable */
|
/* Register variable */
|
||||||
g_subeqstatic (Flags | CF_REGVAR, Expr->Name, Expr->Val, Val);
|
g_subeqstatic (Flags | CF_REGVAR, Expr->Name, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STACK:
|
case E_LOC_STACK:
|
||||||
/* Value on the stack */
|
/* Value on the stack */
|
||||||
g_subeqlocal (Flags, Expr->Val, Val);
|
g_subeqlocal (Flags, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_PRIMARY:
|
case E_LOC_PRIMARY:
|
||||||
@ -1535,7 +1535,7 @@ static void PreDec (ExprDesc* Expr)
|
|||||||
|
|
||||||
case E_LOC_EXPR:
|
case E_LOC_EXPR:
|
||||||
/* An expression in the primary register */
|
/* An expression in the primary register */
|
||||||
g_subeqind (Flags, Expr->Val, Val);
|
g_subeqind (Flags, Expr->IVal, Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1547,7 +1547,7 @@ static void PreDec (ExprDesc* Expr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void PostIncDec (ExprDesc* Expr, void (*inc) (unsigned, unsigned long))
|
static void PostIncDec (ExprDesc* Expr, void (*inc) (unsigned, unsigned long))
|
||||||
/* Handle i-- and i++ */
|
/* Handle i-- and i++ */
|
||||||
{
|
{
|
||||||
@ -1612,9 +1612,9 @@ static void UnaryOp (ExprDesc* Expr)
|
|||||||
if (ED_IsConstAbs (Expr)) {
|
if (ED_IsConstAbs (Expr)) {
|
||||||
/* Value is constant */
|
/* Value is constant */
|
||||||
switch (Tok) {
|
switch (Tok) {
|
||||||
case TOK_MINUS: Expr->Val = -Expr->Val; break;
|
case TOK_MINUS: Expr->IVal = -Expr->IVal; break;
|
||||||
case TOK_PLUS: break;
|
case TOK_PLUS: break;
|
||||||
case TOK_COMP: Expr->Val = ~Expr->Val; break;
|
case TOK_COMP: Expr->IVal = ~Expr->IVal; break;
|
||||||
default: Internal ("Unexpected token: %d", Tok);
|
default: Internal ("Unexpected token: %d", Tok);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1664,7 +1664,7 @@ void hie10 (ExprDesc* Expr)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
if (evalexpr (CF_NONE, hie10, Expr) == 0) {
|
if (evalexpr (CF_NONE, hie10, Expr) == 0) {
|
||||||
/* Constant expression */
|
/* Constant expression */
|
||||||
Expr->Val = !Expr->Val;
|
Expr->IVal = !Expr->IVal;
|
||||||
} else {
|
} else {
|
||||||
g_bneg (TypeOf (Expr->Type));
|
g_bneg (TypeOf (Expr->Type));
|
||||||
ED_MakeRValExpr (Expr);
|
ED_MakeRValExpr (Expr);
|
||||||
@ -1797,7 +1797,7 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */
|
|||||||
if (ED_IsConstAbs (Expr)) {
|
if (ED_IsConstAbs (Expr)) {
|
||||||
/* Constant value */
|
/* Constant value */
|
||||||
Mark2 = GetCodePos ();
|
Mark2 = GetCodePos ();
|
||||||
g_push (ltype | CF_CONST, Expr->Val);
|
g_push (ltype | CF_CONST, Expr->IVal);
|
||||||
} else {
|
} else {
|
||||||
/* Value not constant */
|
/* Value not constant */
|
||||||
ExprLoad (CF_NONE, Expr);
|
ExprLoad (CF_NONE, Expr);
|
||||||
@ -1821,7 +1821,7 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */
|
|||||||
pop (ltype);
|
pop (ltype);
|
||||||
|
|
||||||
/* Evaluate the result */
|
/* Evaluate the result */
|
||||||
Expr->Val = kcalc (Tok, Expr->Val, Expr2.Val);
|
Expr->IVal = kcalc (Tok, Expr->IVal, Expr2.IVal);
|
||||||
|
|
||||||
/* Get the type of the result */
|
/* Get the type of the result */
|
||||||
Expr->Type = promoteint (Expr->Type, Expr2.Type);
|
Expr->Type = promoteint (Expr->Type, Expr2.Type);
|
||||||
@ -1838,9 +1838,9 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */
|
|||||||
/* Second value is constant - check for div */
|
/* Second value is constant - check for div */
|
||||||
type |= CF_CONST;
|
type |= CF_CONST;
|
||||||
rtype |= CF_CONST;
|
rtype |= CF_CONST;
|
||||||
if (Tok == TOK_DIV && Expr2.Val == 0) {
|
if (Tok == TOK_DIV && Expr2.IVal == 0) {
|
||||||
Error ("Division by zero");
|
Error ("Division by zero");
|
||||||
} else if (Tok == TOK_MOD && Expr2.Val == 0) {
|
} else if (Tok == TOK_MOD && Expr2.IVal == 0) {
|
||||||
Error ("Modulo operation with zero");
|
Error ("Modulo operation with zero");
|
||||||
}
|
}
|
||||||
if ((Gen->Flags & GEN_NOPUSH) != 0) {
|
if ((Gen->Flags & GEN_NOPUSH) != 0) {
|
||||||
@ -1855,7 +1855,7 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */
|
|||||||
Expr->Type = promoteint (Expr->Type, Expr2.Type);
|
Expr->Type = promoteint (Expr->Type, Expr2.Type);
|
||||||
|
|
||||||
/* Generate code */
|
/* Generate code */
|
||||||
Gen->Func (type, Expr2.Val);
|
Gen->Func (type, Expr2.IVal);
|
||||||
|
|
||||||
/* We have a rvalue in the primary now */
|
/* We have a rvalue in the primary now */
|
||||||
ED_MakeRValExpr (Expr);
|
ED_MakeRValExpr (Expr);
|
||||||
@ -1893,7 +1893,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
if (ED_IsConstAbs (Expr)) {
|
if (ED_IsConstAbs (Expr)) {
|
||||||
/* Constant value */
|
/* Constant value */
|
||||||
Mark2 = GetCodePos ();
|
Mark2 = GetCodePos ();
|
||||||
g_push (ltype | CF_CONST, Expr->Val);
|
g_push (ltype | CF_CONST, Expr->IVal);
|
||||||
} else {
|
} else {
|
||||||
/* Value not constant */
|
/* Value not constant */
|
||||||
ExprLoad (CF_NONE, Expr);
|
ExprLoad (CF_NONE, Expr);
|
||||||
@ -1933,7 +1933,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
pop (ltype);
|
pop (ltype);
|
||||||
|
|
||||||
/* Evaluate the result */
|
/* Evaluate the result */
|
||||||
Expr->Val = kcalc (tok, Expr->Val, Expr2.Val);
|
Expr->IVal = kcalc (tok, Expr->IVal, Expr2.IVal);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -1971,7 +1971,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate code */
|
/* Generate code */
|
||||||
Gen->Func (flags, Expr2.Val);
|
Gen->Func (flags, Expr2.IVal);
|
||||||
|
|
||||||
/* The result is an rvalue in the primary */
|
/* The result is an rvalue in the primary */
|
||||||
ED_MakeRValExpr (Expr);
|
ED_MakeRValExpr (Expr);
|
||||||
@ -2036,16 +2036,16 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
/* Both expressions are constants. Check for pointer arithmetic */
|
/* Both expressions are constants. Check for pointer arithmetic */
|
||||||
if (IsClassPtr (lhst) && IsClassInt (rhst)) {
|
if (IsClassPtr (lhst) && IsClassInt (rhst)) {
|
||||||
/* Left is pointer, right is int, must scale rhs */
|
/* Left is pointer, right is int, must scale rhs */
|
||||||
Expr->Val += Expr2.Val * CheckedPSizeOf (lhst);
|
Expr->IVal += Expr2.IVal * CheckedPSizeOf (lhst);
|
||||||
/* Result type is a pointer */
|
/* Result type is a pointer */
|
||||||
} else if (IsClassInt (lhst) && IsClassPtr (rhst)) {
|
} else if (IsClassInt (lhst) && IsClassPtr (rhst)) {
|
||||||
/* Left is int, right is pointer, must scale lhs */
|
/* Left is int, right is pointer, must scale lhs */
|
||||||
Expr->Val = Expr->Val * CheckedPSizeOf (rhst) + Expr2.Val;
|
Expr->IVal = Expr->IVal * CheckedPSizeOf (rhst) + Expr2.IVal;
|
||||||
/* Result type is a pointer */
|
/* Result type is a pointer */
|
||||||
Expr->Type = Expr2.Type;
|
Expr->Type = Expr2.Type;
|
||||||
} else if (IsClassInt (lhst) && IsClassInt (rhst)) {
|
} else if (IsClassInt (lhst) && IsClassInt (rhst)) {
|
||||||
/* Integer addition */
|
/* Integer addition */
|
||||||
Expr->Val += Expr2.Val;
|
Expr->IVal += Expr2.IVal;
|
||||||
typeadjust (Expr, &Expr2, 1);
|
typeadjust (Expr, &Expr2, 1);
|
||||||
} else {
|
} else {
|
||||||
/* OOPS */
|
/* OOPS */
|
||||||
@ -2085,10 +2085,10 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
/* Generate the code for the add */
|
/* Generate the code for the add */
|
||||||
if (ED_GetLoc (Expr) == E_LOC_ABS) {
|
if (ED_GetLoc (Expr) == E_LOC_ABS) {
|
||||||
/* Numeric constant */
|
/* Numeric constant */
|
||||||
g_inc (flags, Expr->Val);
|
g_inc (flags, Expr->IVal);
|
||||||
} else {
|
} else {
|
||||||
/* Constant address */
|
/* Constant address */
|
||||||
g_addaddr_static (flags, Expr->Name, Expr->Val);
|
g_addaddr_static (flags, Expr->Name, Expr->IVal);
|
||||||
}
|
}
|
||||||
} else if (IsClassInt (lhst) && IsClassPtr (rhst)) {
|
} else if (IsClassInt (lhst) && IsClassPtr (rhst)) {
|
||||||
|
|
||||||
@ -2105,16 +2105,16 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
*/
|
*/
|
||||||
if (ED_IsLocAbs (Expr)) {
|
if (ED_IsLocAbs (Expr)) {
|
||||||
/* Numeric constant, scale lhs */
|
/* Numeric constant, scale lhs */
|
||||||
Expr->Val *= ScaleFactor;
|
Expr->IVal *= ScaleFactor;
|
||||||
/* Generate the code for the add */
|
/* Generate the code for the add */
|
||||||
g_inc (flags, Expr->Val);
|
g_inc (flags, Expr->IVal);
|
||||||
} else if (ScaleFactor == 1) {
|
} else if (ScaleFactor == 1) {
|
||||||
/* Constant address but no need to scale */
|
/* Constant address but no need to scale */
|
||||||
g_addaddr_static (flags, Expr->Name, Expr->Val);
|
g_addaddr_static (flags, Expr->Name, Expr->IVal);
|
||||||
} else {
|
} else {
|
||||||
/* Constant address that must be scaled */
|
/* Constant address that must be scaled */
|
||||||
g_push (TypeOf (Expr2.Type), 0); /* rhs --> stack */
|
g_push (TypeOf (Expr2.Type), 0); /* rhs --> stack */
|
||||||
g_getimmed (flags, Expr->Name, Expr->Val);
|
g_getimmed (flags, Expr->Name, Expr->IVal);
|
||||||
g_scale (CF_PTR, ScaleFactor);
|
g_scale (CF_PTR, ScaleFactor);
|
||||||
g_add (CF_PTR, 0);
|
g_add (CF_PTR, 0);
|
||||||
}
|
}
|
||||||
@ -2124,10 +2124,10 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
/* Generate the code for the add */
|
/* Generate the code for the add */
|
||||||
if (ED_IsLocAbs (Expr)) {
|
if (ED_IsLocAbs (Expr)) {
|
||||||
/* Numeric constant */
|
/* Numeric constant */
|
||||||
g_inc (flags, Expr->Val);
|
g_inc (flags, Expr->IVal);
|
||||||
} else {
|
} else {
|
||||||
/* Constant address */
|
/* Constant address */
|
||||||
g_addaddr_static (flags, Expr->Name, Expr->Val);
|
g_addaddr_static (flags, Expr->Name, Expr->IVal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* OOPS */
|
/* OOPS */
|
||||||
@ -2158,7 +2158,7 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
/* Check for pointer arithmetic */
|
/* Check for pointer arithmetic */
|
||||||
if (IsClassPtr (lhst) && IsClassInt (rhst)) {
|
if (IsClassPtr (lhst) && IsClassInt (rhst)) {
|
||||||
/* Left is pointer, right is int, must scale rhs */
|
/* Left is pointer, right is int, must scale rhs */
|
||||||
Expr2.Val *= CheckedPSizeOf (lhst);
|
Expr2.IVal *= CheckedPSizeOf (lhst);
|
||||||
/* Operate on pointers, result type is a pointer */
|
/* Operate on pointers, result type is a pointer */
|
||||||
flags = CF_PTR;
|
flags = CF_PTR;
|
||||||
} else if (IsClassInt (lhst) && IsClassPtr (rhst)) {
|
} else if (IsClassInt (lhst) && IsClassPtr (rhst)) {
|
||||||
@ -2176,7 +2176,7 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate code for the add */
|
/* Generate code for the add */
|
||||||
g_inc (flags | CF_CONST, Expr2.Val);
|
g_inc (flags | CF_CONST, Expr2.IVal);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -2274,14 +2274,14 @@ static void parsesub (ExprDesc* Expr)
|
|||||||
/* Check for pointer arithmetic */
|
/* Check for pointer arithmetic */
|
||||||
if (IsClassPtr (lhst) && IsClassInt (rhst)) {
|
if (IsClassPtr (lhst) && IsClassInt (rhst)) {
|
||||||
/* Left is pointer, right is int, must scale rhs */
|
/* Left is pointer, right is int, must scale rhs */
|
||||||
Expr->Val -= Expr2.Val * CheckedPSizeOf (lhst);
|
Expr->IVal -= Expr2.IVal * CheckedPSizeOf (lhst);
|
||||||
/* Operate on pointers, result type is a pointer */
|
/* Operate on pointers, result type is a pointer */
|
||||||
} else if (IsClassPtr (lhst) && IsClassPtr (rhst)) {
|
} else if (IsClassPtr (lhst) && IsClassPtr (rhst)) {
|
||||||
/* Left is pointer, right is pointer, must scale result */
|
/* Left is pointer, right is pointer, must scale result */
|
||||||
if (TypeCmp (Indirect (lhst), Indirect (rhst)) < TC_QUAL_DIFF) {
|
if (TypeCmp (Indirect (lhst), Indirect (rhst)) < TC_QUAL_DIFF) {
|
||||||
Error ("Incompatible pointer types");
|
Error ("Incompatible pointer types");
|
||||||
} else {
|
} else {
|
||||||
Expr->Val = (Expr->Val - Expr2.Val) /
|
Expr->IVal = (Expr->IVal - Expr2.IVal) /
|
||||||
CheckedPSizeOf (lhst);
|
CheckedPSizeOf (lhst);
|
||||||
}
|
}
|
||||||
/* Operate on pointers, result type is an integer */
|
/* Operate on pointers, result type is an integer */
|
||||||
@ -2289,7 +2289,7 @@ static void parsesub (ExprDesc* Expr)
|
|||||||
} else if (IsClassInt (lhst) && IsClassInt (rhst)) {
|
} else if (IsClassInt (lhst) && IsClassInt (rhst)) {
|
||||||
/* Integer subtraction */
|
/* Integer subtraction */
|
||||||
typeadjust (Expr, &Expr2, 1);
|
typeadjust (Expr, &Expr2, 1);
|
||||||
Expr->Val -= Expr2.Val;
|
Expr->IVal -= Expr2.IVal;
|
||||||
} else {
|
} else {
|
||||||
/* OOPS */
|
/* OOPS */
|
||||||
Error ("Invalid operands for binary operator `-'");
|
Error ("Invalid operands for binary operator `-'");
|
||||||
@ -2308,7 +2308,7 @@ static void parsesub (ExprDesc* Expr)
|
|||||||
|
|
||||||
if (IsClassPtr (lhst) && IsClassInt (rhst)) {
|
if (IsClassPtr (lhst) && IsClassInt (rhst)) {
|
||||||
/* Left is pointer, right is int, must scale rhs */
|
/* Left is pointer, right is int, must scale rhs */
|
||||||
Expr2.Val *= CheckedPSizeOf (lhst);
|
Expr2.IVal *= CheckedPSizeOf (lhst);
|
||||||
/* Operate on pointers, result type is a pointer */
|
/* Operate on pointers, result type is a pointer */
|
||||||
flags = CF_PTR;
|
flags = CF_PTR;
|
||||||
} else if (IsClassPtr (lhst) && IsClassPtr (rhst)) {
|
} else if (IsClassPtr (lhst) && IsClassPtr (rhst)) {
|
||||||
@ -2330,7 +2330,7 @@ static void parsesub (ExprDesc* Expr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Do the subtraction */
|
/* Do the subtraction */
|
||||||
g_dec (flags | CF_CONST, Expr2.Val);
|
g_dec (flags | CF_CONST, Expr2.IVal);
|
||||||
|
|
||||||
/* If this was a pointer subtraction, we must scale the result */
|
/* If this was a pointer subtraction, we must scale the result */
|
||||||
if (rscale != 1) {
|
if (rscale != 1) {
|
||||||
@ -2512,7 +2512,7 @@ static void hieAndPP (ExprDesc* Expr)
|
|||||||
ConstAbsIntExpr (hie2, &Expr2);
|
ConstAbsIntExpr (hie2, &Expr2);
|
||||||
|
|
||||||
/* Combine the two */
|
/* Combine the two */
|
||||||
Expr->Val = (Expr->Val && Expr2.Val);
|
Expr->IVal = (Expr->IVal && Expr2.IVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2535,7 +2535,7 @@ static void hieOrPP (ExprDesc *Expr)
|
|||||||
ConstAbsIntExpr (hieAndPP, &Expr2);
|
ConstAbsIntExpr (hieAndPP, &Expr2);
|
||||||
|
|
||||||
/* Combine the two */
|
/* Combine the two */
|
||||||
Expr->Val = (Expr->Val || Expr2.Val);
|
Expr->IVal = (Expr->IVal || Expr2.IVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2852,7 +2852,7 @@ static void opeq (const GenDesc* Gen, ExprDesc* Expr)
|
|||||||
}
|
}
|
||||||
if (MustScale) {
|
if (MustScale) {
|
||||||
/* lhs is a pointer, scale rhs */
|
/* lhs is a pointer, scale rhs */
|
||||||
Expr2.Val *= CheckedSizeOf (Expr->Type+1);
|
Expr2.IVal *= CheckedSizeOf (Expr->Type+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the lhs is character sized, the operation may be later done
|
/* If the lhs is character sized, the operation may be later done
|
||||||
@ -2864,11 +2864,11 @@ static void opeq (const GenDesc* Gen, ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Special handling for add and sub - some sort of a hack, but short code */
|
/* Special handling for add and sub - some sort of a hack, but short code */
|
||||||
if (Gen->Func == g_add) {
|
if (Gen->Func == g_add) {
|
||||||
g_inc (flags | CF_CONST, Expr2.Val);
|
g_inc (flags | CF_CONST, Expr2.IVal);
|
||||||
} else if (Gen->Func == g_sub) {
|
} else if (Gen->Func == g_sub) {
|
||||||
g_dec (flags | CF_CONST, Expr2.Val);
|
g_dec (flags | CF_CONST, Expr2.IVal);
|
||||||
} else {
|
} else {
|
||||||
Gen->Func (flags | CF_CONST, Expr2.Val);
|
Gen->Func (flags | CF_CONST, Expr2.IVal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* rhs is not constant and already in the primary register */
|
/* rhs is not constant and already in the primary register */
|
||||||
@ -2938,7 +2938,7 @@ static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
|
|||||||
if (ED_IsConstAbs (&Expr2)) {
|
if (ED_IsConstAbs (&Expr2)) {
|
||||||
/* The resulting value is a constant. Scale it. */
|
/* The resulting value is a constant. Scale it. */
|
||||||
if (MustScale) {
|
if (MustScale) {
|
||||||
Expr2.Val *= CheckedSizeOf (Indirect (Expr->Type));
|
Expr2.IVal *= CheckedSizeOf (Indirect (Expr->Type));
|
||||||
}
|
}
|
||||||
rflags |= CF_CONST;
|
rflags |= CF_CONST;
|
||||||
lflags |= CF_CONST;
|
lflags |= CF_CONST;
|
||||||
@ -2965,9 +2965,9 @@ static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
|
|||||||
/* Absolute: numeric address or const */
|
/* Absolute: numeric address or const */
|
||||||
lflags |= CF_ABSOLUTE;
|
lflags |= CF_ABSOLUTE;
|
||||||
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
||||||
g_addeqstatic (lflags, Expr->Name, Expr->Val, Expr2.Val);
|
g_addeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
|
||||||
} else {
|
} else {
|
||||||
g_subeqstatic (lflags, Expr->Name, Expr->Val, Expr2.Val);
|
g_subeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2975,9 +2975,9 @@ static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
|
|||||||
/* Global variable */
|
/* Global variable */
|
||||||
lflags |= CF_EXTERNAL;
|
lflags |= CF_EXTERNAL;
|
||||||
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
||||||
g_addeqstatic (lflags, Expr->Name, Expr->Val, Expr2.Val);
|
g_addeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
|
||||||
} else {
|
} else {
|
||||||
g_subeqstatic (lflags, Expr->Name, Expr->Val, Expr2.Val);
|
g_subeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2986,9 +2986,9 @@ static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
|
|||||||
/* Static variable or literal in the literal pool */
|
/* Static variable or literal in the literal pool */
|
||||||
lflags |= CF_STATIC;
|
lflags |= CF_STATIC;
|
||||||
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
||||||
g_addeqstatic (lflags, Expr->Name, Expr->Val, Expr2.Val);
|
g_addeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
|
||||||
} else {
|
} else {
|
||||||
g_subeqstatic (lflags, Expr->Name, Expr->Val, Expr2.Val);
|
g_subeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2996,18 +2996,18 @@ static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
|
|||||||
/* Register variable */
|
/* Register variable */
|
||||||
lflags |= CF_REGVAR;
|
lflags |= CF_REGVAR;
|
||||||
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
||||||
g_addeqstatic (lflags, Expr->Name, Expr->Val, Expr2.Val);
|
g_addeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
|
||||||
} else {
|
} else {
|
||||||
g_subeqstatic (lflags, Expr->Name, Expr->Val, Expr2.Val);
|
g_subeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_STACK:
|
case E_LOC_STACK:
|
||||||
/* Value on the stack */
|
/* Value on the stack */
|
||||||
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
if (Gen->Tok == TOK_PLUS_ASSIGN) {
|
||||||
g_addeqlocal (lflags, Expr->Val, Expr2.Val);
|
g_addeqlocal (lflags, Expr->IVal, Expr2.IVal);
|
||||||
} else {
|
} else {
|
||||||
g_subeqlocal (lflags, Expr->Val, Expr2.Val);
|
g_subeqlocal (lflags, Expr->IVal, Expr2.IVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -58,9 +58,10 @@ ExprDesc* ED_Init (ExprDesc* Expr)
|
|||||||
{
|
{
|
||||||
Expr->Sym = 0;
|
Expr->Sym = 0;
|
||||||
Expr->Type = 0;
|
Expr->Type = 0;
|
||||||
Expr->Val = 0;
|
|
||||||
Expr->Flags = 0;
|
Expr->Flags = 0;
|
||||||
Expr->Name = 0;
|
Expr->Name = 0;
|
||||||
|
Expr->IVal = 0;
|
||||||
|
Expr->FVal = 0.0;
|
||||||
return Expr;
|
return Expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
|
|||||||
static char Buf[256];
|
static char Buf[256];
|
||||||
|
|
||||||
/* Expr may have it's own offset, adjust Offs accordingly */
|
/* Expr may have it's own offset, adjust Offs accordingly */
|
||||||
Offs += Expr->Val;
|
Offs += Expr->IVal;
|
||||||
|
|
||||||
/* Generate a label depending on the location */
|
/* Generate a label depending on the location */
|
||||||
switch (ED_GetLoc (Expr)) {
|
switch (ED_GetLoc (Expr)) {
|
||||||
@ -130,7 +131,7 @@ int ED_GetStackOffs (const ExprDesc* Expr, int Offs)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PRECONDITION (ED_IsLocStack (Expr));
|
PRECONDITION (ED_IsLocStack (Expr));
|
||||||
Offs += ((int) Expr->Val) - StackPtr;
|
Offs += ((int) Expr->IVal) - StackPtr;
|
||||||
CHECK (Offs >= 0); /* Cannot handle negative stack offsets */
|
CHECK (Offs >= 0); /* Cannot handle negative stack offsets */
|
||||||
return Offs;
|
return Offs;
|
||||||
}
|
}
|
||||||
@ -142,9 +143,10 @@ ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type)
|
|||||||
{
|
{
|
||||||
Expr->Sym = 0;
|
Expr->Sym = 0;
|
||||||
Expr->Type = Type;
|
Expr->Type = Type;
|
||||||
Expr->Val = Value;
|
|
||||||
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
||||||
Expr->Name = 0;
|
Expr->Name = 0;
|
||||||
|
Expr->IVal = Value;
|
||||||
|
Expr->FVal = 0.0;
|
||||||
return Expr;
|
return Expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,9 +157,10 @@ ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long Value)
|
|||||||
{
|
{
|
||||||
Expr->Sym = 0;
|
Expr->Sym = 0;
|
||||||
Expr->Type = type_int;
|
Expr->Type = type_int;
|
||||||
Expr->Val = Value;
|
|
||||||
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
||||||
Expr->Name = 0;
|
Expr->Name = 0;
|
||||||
|
Expr->IVal = Value;
|
||||||
|
Expr->FVal = 0.0;
|
||||||
return Expr;
|
return Expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,10 +172,11 @@ ExprDesc* ED_MakeRValExpr (ExprDesc* Expr)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
Expr->Sym = 0;
|
Expr->Sym = 0;
|
||||||
Expr->Val = 0; /* No offset */
|
|
||||||
Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_NEED_TEST | E_CC_SET);
|
Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_NEED_TEST | E_CC_SET);
|
||||||
Expr->Flags |= (E_LOC_EXPR | E_RTYPE_RVAL);
|
Expr->Flags |= (E_LOC_EXPR | E_RTYPE_RVAL);
|
||||||
Expr->Name = 0;
|
Expr->Name = 0;
|
||||||
|
Expr->IVal = 0; /* No offset */
|
||||||
|
Expr->FVal = 0.0;
|
||||||
return Expr;
|
return Expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,10 +188,11 @@ ExprDesc* ED_MakeLValExpr (ExprDesc* Expr)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
Expr->Sym = 0;
|
Expr->Sym = 0;
|
||||||
Expr->Val = 0; /* No offset */
|
|
||||||
Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_NEED_TEST | E_CC_SET);
|
Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_NEED_TEST | E_CC_SET);
|
||||||
Expr->Flags |= (E_LOC_EXPR | E_RTYPE_LVAL);
|
Expr->Flags |= (E_LOC_EXPR | E_RTYPE_LVAL);
|
||||||
Expr->Name = 0;
|
Expr->Name = 0;
|
||||||
|
Expr->IVal = 0; /* No offset */
|
||||||
|
Expr->FVal = 0.0;
|
||||||
return Expr;
|
return Expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +232,7 @@ int ED_IsNullPtr (const ExprDesc* Expr)
|
|||||||
/* Return true if the given expression is a NULL pointer constant */
|
/* Return true if the given expression is a NULL pointer constant */
|
||||||
{
|
{
|
||||||
return (Expr->Flags & (E_MASK_LOC|E_MASK_RTYPE)) == (E_LOC_ABS|E_RTYPE_RVAL) &&
|
return (Expr->Flags & (E_MASK_LOC|E_MASK_RTYPE)) == (E_LOC_ABS|E_RTYPE_RVAL) &&
|
||||||
Expr->Val == 0 &&
|
Expr->IVal == 0 &&
|
||||||
IsClassInt (Expr->Type);
|
IsClassInt (Expr->Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +267,8 @@ void PrintExprDesc (FILE* F, ExprDesc* E)
|
|||||||
fprintf (F, "Type: (unknown)\n"
|
fprintf (F, "Type: (unknown)\n"
|
||||||
"Raw type: (unknown)\n");
|
"Raw type: (unknown)\n");
|
||||||
}
|
}
|
||||||
fprintf (F, "Value: 0x%08lX\n", E->Val);
|
fprintf (F, "IVal: 0x%08lX\n", E->IVal);
|
||||||
|
fprintf (F, "FVal: %f\n", E->FVal);
|
||||||
|
|
||||||
Flags = E->Flags;
|
Flags = E->Flags;
|
||||||
Sep = '(';
|
Sep = '(';
|
||||||
|
@ -86,9 +86,10 @@ typedef struct ExprDesc ExprDesc;
|
|||||||
struct ExprDesc {
|
struct ExprDesc {
|
||||||
struct SymEntry* Sym; /* Symbol table entry if known */
|
struct SymEntry* Sym; /* Symbol table entry if known */
|
||||||
type* Type; /* Type array of expression */
|
type* Type; /* Type array of expression */
|
||||||
long Val; /* Value if expression constant */
|
unsigned Flags;
|
||||||
unsigned short Flags;
|
|
||||||
unsigned long Name; /* Name or label number */
|
unsigned long Name; /* Name or label number */
|
||||||
|
long IVal; /* Integer value if expression constant */
|
||||||
|
float FVal; /* Floating point value */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Push the value */
|
/* Push the value */
|
||||||
g_push (Flags | TypeOf (Decl->Type), Expr.Val);
|
g_push (Flags | TypeOf (Decl->Type), Expr.IVal);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,8 +755,8 @@ static int PushIf (int Skip, int Invert, int Cond)
|
|||||||
|
|
||||||
static int DoIf (int Skip)
|
static int DoIf (int Skip)
|
||||||
/* Process #if directive */
|
/* Process #if directive */
|
||||||
{
|
{
|
||||||
ExprDesc lval;
|
ExprDesc Expr;
|
||||||
char* S;
|
char* S;
|
||||||
|
|
||||||
/* We're about to abuse the compiler expression parser to evaluate the
|
/* We're about to abuse the compiler expression parser to evaluate the
|
||||||
@ -804,7 +804,7 @@ static int DoIf (int Skip)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Call the expression parser */
|
/* Call the expression parser */
|
||||||
ConstExpr (hie1, &lval);
|
ConstExpr (hie1, &Expr);
|
||||||
|
|
||||||
/* End preprocessing mode */
|
/* End preprocessing mode */
|
||||||
Preprocessing = 0;
|
Preprocessing = 0;
|
||||||
@ -814,7 +814,7 @@ static int DoIf (int Skip)
|
|||||||
NextTok = sv2;
|
NextTok = sv2;
|
||||||
|
|
||||||
/* Set the #if condition according to the expression result */
|
/* Set the #if condition according to the expression result */
|
||||||
return PushIf (Skip, 1, lval.Val != 0);
|
return PushIf (Skip, 1, Expr.IVal != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,14 +205,14 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Argument #1 */
|
/* Argument #1 */
|
||||||
ParseArg (&Arg1, Arg1Type);
|
ParseArg (&Arg1, Arg1Type);
|
||||||
g_push (Arg1.Flags, Arg1.Expr.Val);
|
g_push (Arg1.Flags, Arg1.Expr.IVal);
|
||||||
Arg1.End = GetCodePos ();
|
Arg1.End = GetCodePos ();
|
||||||
ParamSize += SizeOf (Arg1Type);
|
ParamSize += SizeOf (Arg1Type);
|
||||||
ConsumeComma ();
|
ConsumeComma ();
|
||||||
|
|
||||||
/* Argument #2 */
|
/* Argument #2 */
|
||||||
ParseArg (&Arg2, Arg2Type);
|
ParseArg (&Arg2, Arg2Type);
|
||||||
g_push (Arg2.Flags, Arg2.Expr.Val);
|
g_push (Arg2.Flags, Arg2.Expr.IVal);
|
||||||
Arg2.End = GetCodePos ();
|
Arg2.End = GetCodePos ();
|
||||||
ParamSize += SizeOf (Arg2Type);
|
ParamSize += SizeOf (Arg2Type);
|
||||||
ConsumeComma ();
|
ConsumeComma ();
|
||||||
@ -230,7 +230,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
/* Emit the actual function call. This will also cleanup the stack. */
|
/* Emit the actual function call. This will also cleanup the stack. */
|
||||||
g_call (CF_FIXARGC, Func_memcpy, ParamSize);
|
g_call (CF_FIXARGC, Func_memcpy, ParamSize);
|
||||||
|
|
||||||
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val == 0) {
|
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal == 0) {
|
||||||
|
|
||||||
/* memcpy has been called with a count argument of zero */
|
/* memcpy has been called with a count argument of zero */
|
||||||
Warning ("Call to memcpy has no effect");
|
Warning ("Call to memcpy has no effect");
|
||||||
@ -252,7 +252,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
* be generated. If such a situation is detected, throw away the
|
* be generated. If such a situation is detected, throw away the
|
||||||
* generated, and emit better code.
|
* generated, and emit better code.
|
||||||
*/
|
*/
|
||||||
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
|
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||||
((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) ||
|
((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) ||
|
||||||
(ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) &&
|
(ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) &&
|
||||||
((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) ||
|
((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) ||
|
||||||
@ -268,10 +268,10 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
Label = GetLocalLabel ();
|
Label = GetLocalLabel ();
|
||||||
|
|
||||||
/* Generate memcpy code */
|
/* Generate memcpy code */
|
||||||
if (Arg3.Expr.Val <= 127) {
|
if (Arg3.Expr.IVal <= 127) {
|
||||||
|
|
||||||
AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.Val-1));
|
AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
|
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
if (Reg2) {
|
if (Reg2) {
|
||||||
AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0));
|
AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0));
|
||||||
@ -289,7 +289,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
AddCodeLine ("ldy #$00");
|
AddCodeLine ("ldy #$00");
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
|
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
if (Reg2) {
|
if (Reg2) {
|
||||||
AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0));
|
AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0));
|
||||||
@ -302,7 +302,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0));
|
AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0));
|
||||||
}
|
}
|
||||||
AddCodeLine ("iny");
|
AddCodeLine ("iny");
|
||||||
AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.Val);
|
AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.IVal);
|
||||||
AddCodeLine ("bne %s", LocalLabelName (Label));
|
AddCodeLine ("bne %s", LocalLabelName (Label));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -312,10 +312,10 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
*/
|
*/
|
||||||
*Expr = Arg1.Expr;
|
*Expr = Arg1.Expr;
|
||||||
|
|
||||||
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
|
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||||
ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) &&
|
ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) &&
|
||||||
ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) &&
|
ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) &&
|
||||||
(Arg1.Expr.Val - StackPtr) + Arg3.Expr.Val < 256) {
|
(Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) {
|
||||||
|
|
||||||
/* It is possible to just use one index register even if the stack
|
/* It is possible to just use one index register even if the stack
|
||||||
* offset is not zero, by adjusting the offset to the constant
|
* offset is not zero, by adjusting the offset to the constant
|
||||||
@ -325,7 +325,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
* address calculation could overflow in the linker.
|
* address calculation could overflow in the linker.
|
||||||
*/
|
*/
|
||||||
int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) &&
|
int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) &&
|
||||||
!(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.Val < 256);
|
!(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.IVal < 256);
|
||||||
|
|
||||||
/* Calculate the real stack offset */
|
/* Calculate the real stack offset */
|
||||||
int Offs = ED_GetStackOffs (&Arg1.Expr, 0);
|
int Offs = ED_GetStackOffs (&Arg1.Expr, 0);
|
||||||
@ -337,18 +337,18 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
Label = GetLocalLabel ();
|
Label = GetLocalLabel ();
|
||||||
|
|
||||||
/* Generate memcpy code */
|
/* Generate memcpy code */
|
||||||
if (Arg3.Expr.Val <= 127) {
|
if (Arg3.Expr.IVal <= 127) {
|
||||||
|
|
||||||
if (Offs == 0 || AllowOneIndex) {
|
if (Offs == 0 || AllowOneIndex) {
|
||||||
AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val - 1));
|
AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1));
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs));
|
AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs));
|
||||||
AddCodeLine ("sta (sp),y");
|
AddCodeLine ("sta (sp),y");
|
||||||
AddCodeLine ("dey");
|
AddCodeLine ("dey");
|
||||||
AddCodeLine ("bpl %s", LocalLabelName (Label));
|
AddCodeLine ("bpl %s", LocalLabelName (Label));
|
||||||
} else {
|
} else {
|
||||||
AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.Val-1));
|
AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
|
||||||
AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val - 1));
|
AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1));
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0));
|
AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0));
|
||||||
AddCodeLine ("sta (sp),y");
|
AddCodeLine ("sta (sp),y");
|
||||||
@ -365,7 +365,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs));
|
AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs));
|
||||||
AddCodeLine ("sta (sp),y");
|
AddCodeLine ("sta (sp),y");
|
||||||
AddCodeLine ("iny");
|
AddCodeLine ("iny");
|
||||||
AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val));
|
AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal));
|
||||||
AddCodeLine ("bne %s", LocalLabelName (Label));
|
AddCodeLine ("bne %s", LocalLabelName (Label));
|
||||||
} else {
|
} else {
|
||||||
AddCodeLine ("ldx #$00");
|
AddCodeLine ("ldx #$00");
|
||||||
@ -375,7 +375,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
AddCodeLine ("sta (sp),y");
|
AddCodeLine ("sta (sp),y");
|
||||||
AddCodeLine ("iny");
|
AddCodeLine ("iny");
|
||||||
AddCodeLine ("inx");
|
AddCodeLine ("inx");
|
||||||
AddCodeLine ("cpx #$%02X", (unsigned char) Arg3.Expr.Val);
|
AddCodeLine ("cpx #$%02X", (unsigned char) Arg3.Expr.IVal);
|
||||||
AddCodeLine ("bne %s", LocalLabelName (Label));
|
AddCodeLine ("bne %s", LocalLabelName (Label));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,9 +386,9 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
*/
|
*/
|
||||||
*Expr = Arg1.Expr;
|
*Expr = Arg1.Expr;
|
||||||
|
|
||||||
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
|
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||||
ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) &&
|
ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) &&
|
||||||
(Arg2.Expr.Val - StackPtr) + Arg3.Expr.Val < 256 &&
|
(Arg2.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256 &&
|
||||||
ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) {
|
ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) {
|
||||||
|
|
||||||
/* It is possible to just use one index register even if the stack
|
/* It is possible to just use one index register even if the stack
|
||||||
@ -399,7 +399,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
* address calculation could overflow in the linker.
|
* address calculation could overflow in the linker.
|
||||||
*/
|
*/
|
||||||
int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) &&
|
int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) &&
|
||||||
!(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.Val < 256);
|
!(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.IVal < 256);
|
||||||
|
|
||||||
/* Calculate the real stack offset */
|
/* Calculate the real stack offset */
|
||||||
int Offs = ED_GetStackOffs (&Arg2.Expr, 0);
|
int Offs = ED_GetStackOffs (&Arg2.Expr, 0);
|
||||||
@ -411,18 +411,18 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
Label = GetLocalLabel ();
|
Label = GetLocalLabel ();
|
||||||
|
|
||||||
/* Generate memcpy code */
|
/* Generate memcpy code */
|
||||||
if (Arg3.Expr.Val <= 127) {
|
if (Arg3.Expr.IVal <= 127) {
|
||||||
|
|
||||||
if (Offs == 0 || AllowOneIndex) {
|
if (Offs == 0 || AllowOneIndex) {
|
||||||
AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val - 1));
|
AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1));
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
AddCodeLine ("lda (sp),y");
|
AddCodeLine ("lda (sp),y");
|
||||||
AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs));
|
AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs));
|
||||||
AddCodeLine ("dey");
|
AddCodeLine ("dey");
|
||||||
AddCodeLine ("bpl %s", LocalLabelName (Label));
|
AddCodeLine ("bpl %s", LocalLabelName (Label));
|
||||||
} else {
|
} else {
|
||||||
AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.Val-1));
|
AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
|
||||||
AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val - 1));
|
AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1));
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
AddCodeLine ("lda (sp),y");
|
AddCodeLine ("lda (sp),y");
|
||||||
AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0));
|
AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0));
|
||||||
@ -439,7 +439,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
AddCodeLine ("lda (sp),y");
|
AddCodeLine ("lda (sp),y");
|
||||||
AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs));
|
AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs));
|
||||||
AddCodeLine ("iny");
|
AddCodeLine ("iny");
|
||||||
AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val));
|
AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal));
|
||||||
AddCodeLine ("bne %s", LocalLabelName (Label));
|
AddCodeLine ("bne %s", LocalLabelName (Label));
|
||||||
} else {
|
} else {
|
||||||
AddCodeLine ("ldx #$00");
|
AddCodeLine ("ldx #$00");
|
||||||
@ -449,7 +449,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0));
|
AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0));
|
||||||
AddCodeLine ("iny");
|
AddCodeLine ("iny");
|
||||||
AddCodeLine ("inx");
|
AddCodeLine ("inx");
|
||||||
AddCodeLine ("cpx #$%02X", (unsigned char) Arg3.Expr.Val);
|
AddCodeLine ("cpx #$%02X", (unsigned char) Arg3.Expr.IVal);
|
||||||
AddCodeLine ("bne %s", LocalLabelName (Label));
|
AddCodeLine ("bne %s", LocalLabelName (Label));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,7 +500,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Argument #1 */
|
/* Argument #1 */
|
||||||
ParseArg (&Arg1, Arg1Type);
|
ParseArg (&Arg1, Arg1Type);
|
||||||
g_push (Arg1.Flags, Arg1.Expr.Val);
|
g_push (Arg1.Flags, Arg1.Expr.IVal);
|
||||||
Arg1.End = GetCodePos ();
|
Arg1.End = GetCodePos ();
|
||||||
ParamSize += SizeOf (Arg1Type);
|
ParamSize += SizeOf (Arg1Type);
|
||||||
ConsumeComma ();
|
ConsumeComma ();
|
||||||
@ -509,12 +509,12 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
* function if it is a constant zero.
|
* function if it is a constant zero.
|
||||||
*/
|
*/
|
||||||
ParseArg (&Arg2, Arg2Type);
|
ParseArg (&Arg2, Arg2Type);
|
||||||
if ((Arg2.Flags & CF_CONST) != 0 && Arg2.Expr.Val == 0) {
|
if ((Arg2.Flags & CF_CONST) != 0 && Arg2.Expr.IVal == 0) {
|
||||||
/* Don't call memset, call bzero instead */
|
/* Don't call memset, call bzero instead */
|
||||||
MemSet = 0;
|
MemSet = 0;
|
||||||
} else {
|
} else {
|
||||||
/* Push the argument */
|
/* Push the argument */
|
||||||
g_push (Arg2.Flags, Arg2.Expr.Val);
|
g_push (Arg2.Flags, Arg2.Expr.IVal);
|
||||||
Arg2.End = GetCodePos ();
|
Arg2.End = GetCodePos ();
|
||||||
ParamSize += SizeOf (Arg2Type);
|
ParamSize += SizeOf (Arg2Type);
|
||||||
}
|
}
|
||||||
@ -533,7 +533,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
/* Emit the actual function call. This will also cleanup the stack. */
|
/* Emit the actual function call. This will also cleanup the stack. */
|
||||||
g_call (CF_FIXARGC, MemSet? Func_memset : Func__bzero, ParamSize);
|
g_call (CF_FIXARGC, MemSet? Func_memset : Func__bzero, ParamSize);
|
||||||
|
|
||||||
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val == 0) {
|
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal == 0) {
|
||||||
|
|
||||||
/* memset has been called with a count argument of zero */
|
/* memset has been called with a count argument of zero */
|
||||||
Warning ("Call to memset has no effect");
|
Warning ("Call to memset has no effect");
|
||||||
@ -559,7 +559,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
* being constant numerical values. Some checks have shown that this
|
* being constant numerical values. Some checks have shown that this
|
||||||
* covers nearly 90% of all memset calls.
|
* covers nearly 90% of all memset calls.
|
||||||
*/
|
*/
|
||||||
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
|
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||||
ED_IsConstAbsInt (&Arg2.Expr) &&
|
ED_IsConstAbsInt (&Arg2.Expr) &&
|
||||||
((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) ||
|
((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) ||
|
||||||
(ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)))) {
|
(ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)))) {
|
||||||
@ -573,10 +573,10 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
Label = GetLocalLabel ();
|
Label = GetLocalLabel ();
|
||||||
|
|
||||||
/* Generate memset code */
|
/* Generate memset code */
|
||||||
if (Arg3.Expr.Val <= 127) {
|
if (Arg3.Expr.IVal <= 127) {
|
||||||
|
|
||||||
AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.Val-1));
|
AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
|
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
if (Reg) {
|
if (Reg) {
|
||||||
AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0));
|
AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0));
|
||||||
@ -589,7 +589,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
AddCodeLine ("ldy #$00");
|
AddCodeLine ("ldy #$00");
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
|
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
if (Reg) {
|
if (Reg) {
|
||||||
AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0));
|
AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0));
|
||||||
@ -597,7 +597,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0));
|
AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0));
|
||||||
}
|
}
|
||||||
AddCodeLine ("iny");
|
AddCodeLine ("iny");
|
||||||
AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.Val);
|
AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.IVal);
|
||||||
AddCodeLine ("bne %s", LocalLabelName (Label));
|
AddCodeLine ("bne %s", LocalLabelName (Label));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -607,10 +607,10 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
*/
|
*/
|
||||||
*Expr = Arg1.Expr;
|
*Expr = Arg1.Expr;
|
||||||
|
|
||||||
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
|
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||||
ED_IsConstAbsInt (&Arg2.Expr) &&
|
ED_IsConstAbsInt (&Arg2.Expr) &&
|
||||||
ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) &&
|
ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) &&
|
||||||
(Arg1.Expr.Val - StackPtr) + Arg3.Expr.Val < 256) {
|
(Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) {
|
||||||
|
|
||||||
/* Calculate the real stack offset */
|
/* Calculate the real stack offset */
|
||||||
int Offs = ED_GetStackOffs (&Arg1.Expr, 0);
|
int Offs = ED_GetStackOffs (&Arg1.Expr, 0);
|
||||||
@ -623,11 +623,11 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Generate memset code */
|
/* Generate memset code */
|
||||||
AddCodeLine ("ldy #$%02X", (unsigned char) Offs);
|
AddCodeLine ("ldy #$%02X", (unsigned char) Offs);
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
|
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
AddCodeLine ("sta (sp),y");
|
AddCodeLine ("sta (sp),y");
|
||||||
AddCodeLine ("iny");
|
AddCodeLine ("iny");
|
||||||
AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val));
|
AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal));
|
||||||
AddCodeLine ("bne %s", LocalLabelName (Label));
|
AddCodeLine ("bne %s", LocalLabelName (Label));
|
||||||
|
|
||||||
/* memset returns the address, so the result is actually identical
|
/* memset returns the address, so the result is actually identical
|
||||||
@ -635,9 +635,9 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
*/
|
*/
|
||||||
*Expr = Arg1.Expr;
|
*Expr = Arg1.Expr;
|
||||||
|
|
||||||
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
|
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||||
ED_IsConstAbsInt (&Arg2.Expr) &&
|
ED_IsConstAbsInt (&Arg2.Expr) &&
|
||||||
(Arg2.Expr.Val != 0 || CodeSizeFactor > 200)) {
|
(Arg2.Expr.IVal != 0 || CodeSizeFactor > 200)) {
|
||||||
|
|
||||||
/* Remove all of the generated code but the load of the first
|
/* Remove all of the generated code but the load of the first
|
||||||
* argument.
|
* argument.
|
||||||
@ -650,20 +650,20 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
/* Generate code */
|
/* Generate code */
|
||||||
AddCodeLine ("sta ptr1");
|
AddCodeLine ("sta ptr1");
|
||||||
AddCodeLine ("stx ptr1+1");
|
AddCodeLine ("stx ptr1+1");
|
||||||
if (Arg3.Expr.Val <= 127) {
|
if (Arg3.Expr.IVal <= 127) {
|
||||||
AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.Val-1));
|
AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
|
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
AddCodeLine ("sta (ptr1),y");
|
AddCodeLine ("sta (ptr1),y");
|
||||||
AddCodeLine ("dey");
|
AddCodeLine ("dey");
|
||||||
AddCodeLine ("bpl %s", LocalLabelName (Label));
|
AddCodeLine ("bpl %s", LocalLabelName (Label));
|
||||||
} else {
|
} else {
|
||||||
AddCodeLine ("ldy #$00");
|
AddCodeLine ("ldy #$00");
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
|
AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
|
||||||
g_defcodelabel (Label);
|
g_defcodelabel (Label);
|
||||||
AddCodeLine ("sta (ptr1),y");
|
AddCodeLine ("sta (ptr1),y");
|
||||||
AddCodeLine ("iny");
|
AddCodeLine ("iny");
|
||||||
AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.Val);
|
AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.IVal);
|
||||||
AddCodeLine ("bne %s", LocalLabelName (Label));
|
AddCodeLine ("bne %s", LocalLabelName (Label));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -719,7 +719,7 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Argument #1 */
|
/* Argument #1 */
|
||||||
ParseArg (&Arg1, Arg1Type);
|
ParseArg (&Arg1, Arg1Type);
|
||||||
g_push (Arg1.Flags, Arg1.Expr.Val);
|
g_push (Arg1.Flags, Arg1.Expr.IVal);
|
||||||
Arg1.End = GetCodePos ();
|
Arg1.End = GetCodePos ();
|
||||||
ParamSize += SizeOf (Arg1Type);
|
ParamSize += SizeOf (Arg1Type);
|
||||||
ConsumeComma ();
|
ConsumeComma ();
|
||||||
@ -794,7 +794,7 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
* address calculation could overflow in the linker.
|
* address calculation could overflow in the linker.
|
||||||
*/
|
*/
|
||||||
int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) &&
|
int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) &&
|
||||||
!(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.Val < 256);
|
!(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.IVal < 256);
|
||||||
|
|
||||||
/* Calculate the real stack offset */
|
/* Calculate the real stack offset */
|
||||||
int Offs = ED_GetStackOffs (&Arg2.Expr, 0);
|
int Offs = ED_GetStackOffs (&Arg2.Expr, 0);
|
||||||
@ -837,7 +837,7 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
* address calculation could overflow in the linker.
|
* address calculation could overflow in the linker.
|
||||||
*/
|
*/
|
||||||
int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) &&
|
int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) &&
|
||||||
!(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.Val < 256);
|
!(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.IVal < 256);
|
||||||
|
|
||||||
/* Calculate the real stack offset */
|
/* Calculate the real stack offset */
|
||||||
int Offs = ED_GetStackOffs (&Arg1.Expr, 0);
|
int Offs = ED_GetStackOffs (&Arg1.Expr, 0);
|
||||||
@ -940,8 +940,8 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
if (ED_IsLocLiteral (&Arg) && IS_Get (&WritableStrings) == 0) {
|
if (ED_IsLocLiteral (&Arg) && IS_Get (&WritableStrings) == 0) {
|
||||||
|
|
||||||
/* Constant string literal */
|
/* Constant string literal */
|
||||||
ED_MakeConstAbs (Expr, strlen (GetLiteral (Arg.Val)), type_size_t);
|
ED_MakeConstAbs (Expr, strlen (GetLiteral (Arg.IVal)), type_size_t);
|
||||||
ResetLiteralPoolOffs (Arg.Val);
|
ResetLiteralPoolOffs (Arg.IVal);
|
||||||
|
|
||||||
/* We will inline strlen for arrays with constant addresses, if either the
|
/* We will inline strlen for arrays with constant addresses, if either the
|
||||||
* inlining was forced on the command line, or the array is smaller than
|
* inlining was forced on the command line, or the array is smaller than
|
||||||
@ -968,7 +968,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
|||||||
* completely within the reach of a byte sized index register.
|
* completely within the reach of a byte sized index register.
|
||||||
*/
|
*/
|
||||||
} else if (ED_IsLocStack (&Arg) && IsArray && IsByteIndex &&
|
} else if (ED_IsLocStack (&Arg) && IsArray && IsByteIndex &&
|
||||||
(Arg.Val - StackPtr) + ECount < 256) {
|
(Arg.IVal - StackPtr) + ECount < 256) {
|
||||||
|
|
||||||
/* Calculate the true stack offset */
|
/* Calculate the true stack offset */
|
||||||
int Offs = ED_GetStackOffs (&Arg, 0);
|
int Offs = ED_GetStackOffs (&Arg, 0);
|
||||||
|
@ -148,7 +148,7 @@ void SwitchStatement (void)
|
|||||||
ConstAbsIntExpr (hie1, &CaseExpr);
|
ConstAbsIntExpr (hie1, &CaseExpr);
|
||||||
|
|
||||||
/* Check the range of the expression */
|
/* Check the range of the expression */
|
||||||
Val = CaseExpr.Val;
|
Val = CaseExpr.IVal;
|
||||||
switch (SwitchExprType) {
|
switch (SwitchExprType) {
|
||||||
|
|
||||||
case T_SCHAR:
|
case T_SCHAR:
|
||||||
|
@ -63,13 +63,13 @@ unsigned Test (unsigned Label, int Invert)
|
|||||||
if (ED_IsConstAbs (&Expr)) {
|
if (ED_IsConstAbs (&Expr)) {
|
||||||
|
|
||||||
/* Result is constant, so we know the outcome */
|
/* Result is constant, so we know the outcome */
|
||||||
Result = (Expr.Val != 0);
|
Result = (Expr.IVal != 0);
|
||||||
|
|
||||||
/* Constant rvalue */
|
/* Constant rvalue */
|
||||||
if (!Invert && Expr.Val == 0) {
|
if (!Invert && Expr.IVal == 0) {
|
||||||
g_jump (Label);
|
g_jump (Label);
|
||||||
Warning ("Unreachable code");
|
Warning ("Unreachable code");
|
||||||
} else if (Invert && Expr.Val != 0) {
|
} else if (Invert && Expr.IVal != 0) {
|
||||||
g_jump (Label);
|
g_jump (Label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,13 +138,13 @@ static void DoConversion (ExprDesc* Expr, const type* NewType)
|
|||||||
if (NewBits <= OldBits) {
|
if (NewBits <= OldBits) {
|
||||||
|
|
||||||
/* Cut the value to the new size */
|
/* Cut the value to the new size */
|
||||||
Expr->Val &= (0xFFFFFFFFUL >> (32 - NewBits));
|
Expr->IVal &= (0xFFFFFFFFUL >> (32 - NewBits));
|
||||||
|
|
||||||
/* If the new type is signed, sign extend the value */
|
/* If the new type is signed, sign extend the value */
|
||||||
if (!IsSignUnsigned (NewType)) {
|
if (!IsSignUnsigned (NewType)) {
|
||||||
if (Expr->Val & (0x01UL << (NewBits-1))) {
|
if (Expr->IVal & (0x01UL << (NewBits-1))) {
|
||||||
/* Beware: Use the safe shift routine here. */
|
/* Beware: Use the safe shift routine here. */
|
||||||
Expr->Val |= shl_l (~0UL, NewBits);
|
Expr->IVal |= shl_l (~0UL, NewBits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ void TypeConversion (ExprDesc* Expr, type* NewType)
|
|||||||
}
|
}
|
||||||
} else if (IsClassInt (Expr->Type)) {
|
} else if (IsClassInt (Expr->Type)) {
|
||||||
/* Int to pointer assignment is valid only for constant zero */
|
/* Int to pointer assignment is valid only for constant zero */
|
||||||
if (!ED_IsConstAbsInt (Expr) || Expr->Val != 0) {
|
if (!ED_IsConstAbsInt (Expr) || Expr->IVal != 0) {
|
||||||
Warning ("Converting integer to pointer without a cast");
|
Warning ("Converting integer to pointer without a cast");
|
||||||
}
|
}
|
||||||
} else if (IsTypeFuncPtr (NewType) && IsTypeFunc(Expr->Type)) {
|
} else if (IsTypeFuncPtr (NewType) && IsTypeFunc(Expr->Type)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user