Rewrite/cleanup of the complete expression flags handling.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3056 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2001-2003 Ullrich von Bassewitz */
|
/* (C) 2001-2004 Ullrich von Bassewitz */
|
||||||
/* R<>merstrasse 52 */
|
/* R<>merstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@musoftware.de */
|
||||||
@@ -132,23 +132,23 @@ static void ParseByteArg (StrBuf* T, unsigned Arg)
|
|||||||
ConsumeComma ();
|
ConsumeComma ();
|
||||||
|
|
||||||
/* Evaluate the expression */
|
/* Evaluate the expression */
|
||||||
ConstSubExpr (hie1, &Expr);
|
ConstAbsIntExpr (hie1, &Expr);
|
||||||
|
|
||||||
/* 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.ConstVal < 0 || Expr.ConstVal > 0xFF) {
|
if (Expr.Val < 0 || Expr.Val > 0xFF) {
|
||||||
AsmRangeError (Arg);
|
AsmRangeError (Arg);
|
||||||
Expr.ConstVal = 0;
|
Expr.Val = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Expr.ConstVal < -128 || Expr.ConstVal > 127) {
|
if (Expr.Val < -128 || Expr.Val > 127) {
|
||||||
AsmRangeError (Arg);
|
AsmRangeError (Arg);
|
||||||
Expr.ConstVal = 0;
|
Expr.Val = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert into a hex number */
|
/* Convert into a hex number */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02lX", Expr.ConstVal & 0xFF);
|
xsprintf (Buf, sizeof (Buf), "$%02lX", Expr.Val & 0xFF);
|
||||||
|
|
||||||
/* Add the number to the target buffer */
|
/* Add the number to the target buffer */
|
||||||
SB_AppendStr (T, Buf);
|
SB_AppendStr (T, Buf);
|
||||||
@@ -166,23 +166,23 @@ static void ParseWordArg (StrBuf* T, unsigned Arg)
|
|||||||
ConsumeComma ();
|
ConsumeComma ();
|
||||||
|
|
||||||
/* Evaluate the expression */
|
/* Evaluate the expression */
|
||||||
ConstSubExpr (hie1, &Expr);
|
ConstAbsIntExpr (hie1, &Expr);
|
||||||
|
|
||||||
/* 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.ConstVal < 0 || Expr.ConstVal > 0xFFFF) {
|
if (Expr.Val < 0 || Expr.Val > 0xFFFF) {
|
||||||
AsmRangeError (Arg);
|
AsmRangeError (Arg);
|
||||||
Expr.ConstVal = 0;
|
Expr.Val = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Expr.ConstVal < -32768 || Expr.ConstVal > 32767) {
|
if (Expr.Val < -32768 || Expr.Val > 32767) {
|
||||||
AsmRangeError (Arg);
|
AsmRangeError (Arg);
|
||||||
Expr.ConstVal = 0;
|
Expr.Val = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert into a hex number */
|
/* Convert into a hex number */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%04lX", Expr.ConstVal & 0xFFFF);
|
xsprintf (Buf, sizeof (Buf), "$%04lX", Expr.Val & 0xFFFF);
|
||||||
|
|
||||||
/* Add the number to the target buffer */
|
/* Add the number to the target buffer */
|
||||||
SB_AppendStr (T, Buf);
|
SB_AppendStr (T, Buf);
|
||||||
@@ -200,10 +200,10 @@ static void ParseLongArg (StrBuf* T, unsigned Arg attribute ((unused)))
|
|||||||
ConsumeComma ();
|
ConsumeComma ();
|
||||||
|
|
||||||
/* Evaluate the expression */
|
/* Evaluate the expression */
|
||||||
ConstSubExpr (hie1, &Expr);
|
ConstAbsIntExpr (hie1, &Expr);
|
||||||
|
|
||||||
/* Convert into a hex number */
|
/* Convert into a hex number */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%08lX", Expr.ConstVal & 0xFFFFFFFF);
|
xsprintf (Buf, sizeof (Buf), "$%08lX", Expr.Val & 0xFFFFFFFF);
|
||||||
|
|
||||||
/* Add the number to the target buffer */
|
/* Add the number to the target buffer */
|
||||||
SB_AppendStr (T, Buf);
|
SB_AppendStr (T, Buf);
|
||||||
@@ -265,7 +265,7 @@ static void ParseLVarArg (StrBuf* T, unsigned Arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate the current offset from SP */
|
/* Calculate the current offset from SP */
|
||||||
Offs = Sym->V.Offs - oursp;
|
Offs = Sym->V.Offs - StackPtr;
|
||||||
|
|
||||||
/* Output the offset */
|
/* Output the offset */
|
||||||
xsprintf (Buf, sizeof (Buf), (Offs > 0xFF)? "$%04X" : "$%02X", Offs);
|
xsprintf (Buf, sizeof (Buf), (Offs > 0xFF)? "$%04X" : "$%02X", Offs);
|
||||||
@@ -300,8 +300,8 @@ static void ParseStrArg (StrBuf* T, unsigned Arg attribute ((unused)))
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ConstSubExpr (hie1, InitExprDesc (&Expr));
|
ConstAbsIntExpr (hie1, &Expr);
|
||||||
xsprintf (Buf, sizeof (Buf), "%ld", Expr.ConstVal);
|
xsprintf (Buf, sizeof (Buf), "%ld", Expr.Val);
|
||||||
SB_AppendStr (T, Buf);
|
SB_AppendStr (T, Buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,15 +52,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Assignment (ExprDesc* lval)
|
void Assignment (ExprDesc* Expr)
|
||||||
/* Parse an assignment */
|
/* Parse an assignment */
|
||||||
{
|
{
|
||||||
ExprDesc lval2;
|
ExprDesc lval2;
|
||||||
type* ltype = lval->Type;
|
type* ltype = Expr->Type;
|
||||||
|
|
||||||
|
|
||||||
/* We must have an lvalue for an assignment */
|
/* We must have an lvalue for an assignment */
|
||||||
if (ED_IsRVal (lval)) {
|
if (ED_IsRVal (Expr)) {
|
||||||
Error ("Invalid lvalue in assignment");
|
Error ("Invalid lvalue in assignment");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,9 +94,9 @@ void Assignment (ExprDesc* lval)
|
|||||||
default: stype = ltype; UseReg = 0; break;
|
default: stype = ltype; UseReg = 0; break;
|
||||||
}
|
}
|
||||||
if (UseReg) {
|
if (UseReg) {
|
||||||
PushAddr (lval);
|
PushAddr (Expr);
|
||||||
} else {
|
} else {
|
||||||
ExprLoad (CF_NONE, lval);
|
ExprLoad (CF_NONE, Expr);
|
||||||
g_push (CF_PTR | CF_UNSIGNED, 0);
|
g_push (CF_PTR | CF_UNSIGNED, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ void Assignment (ExprDesc* lval)
|
|||||||
ExprLoad (CF_FORCECHAR, &lval2);
|
ExprLoad (CF_FORCECHAR, &lval2);
|
||||||
|
|
||||||
/* Store it into the new location */
|
/* Store it into the new location */
|
||||||
Store (lval, stype);
|
Store (Expr, stype);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ void Assignment (ExprDesc* lval)
|
|||||||
*/
|
*/
|
||||||
if (UseReg) {
|
if (UseReg) {
|
||||||
/* Do the store */
|
/* Do the store */
|
||||||
Store (lval, stype);
|
Store (Expr, stype);
|
||||||
} else {
|
} else {
|
||||||
/* Print a diagnostic */
|
/* Print a diagnostic */
|
||||||
Error ("Structs of this size are not supported");
|
Error ("Structs of this size are not supported");
|
||||||
@@ -159,7 +159,7 @@ void Assignment (ExprDesc* lval)
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Get the address on stack if needed */
|
/* Get the address on stack if needed */
|
||||||
PushAddr (lval);
|
PushAddr (Expr);
|
||||||
|
|
||||||
/* Read the expression on the right side of the '=' */
|
/* Read the expression on the right side of the '=' */
|
||||||
hie1 (&lval2);
|
hie1 (&lval2);
|
||||||
@@ -171,12 +171,12 @@ void Assignment (ExprDesc* lval)
|
|||||||
ExprLoad (CF_NONE, &lval2);
|
ExprLoad (CF_NONE, &lval2);
|
||||||
|
|
||||||
/* Generate a store instruction */
|
/* Generate a store instruction */
|
||||||
Store (lval, 0);
|
Store (Expr, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Value is still in primary and not an lvalue */
|
/* Value is still in primary and not an lvalue */
|
||||||
lval->Flags = E_MEXPR | E_RVAL;
|
ED_MakeRValExpr (Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Compiler relative stack pointer */
|
/* Compiler relative stack pointer */
|
||||||
int oursp = 0;
|
int StackPtr = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -291,7 +291,7 @@ unsigned sizeofarg (unsigned flags)
|
|||||||
int pop (unsigned flags)
|
int pop (unsigned flags)
|
||||||
/* Pop an argument of the given size */
|
/* Pop an argument of the given size */
|
||||||
{
|
{
|
||||||
return oursp += sizeofarg (flags);
|
return StackPtr += sizeofarg (flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ int pop (unsigned flags)
|
|||||||
int push (unsigned flags)
|
int push (unsigned flags)
|
||||||
/* Push an argument of the given size */
|
/* Push an argument of the given size */
|
||||||
{
|
{
|
||||||
return oursp -= sizeofarg (flags);
|
return StackPtr -= sizeofarg (flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -464,7 +464,7 @@ void g_leave (void)
|
|||||||
/* Function epilogue */
|
/* Function epilogue */
|
||||||
{
|
{
|
||||||
/* How many bytes of locals do we have to drop? */
|
/* How many bytes of locals do we have to drop? */
|
||||||
int k = -oursp;
|
int k = -StackPtr;
|
||||||
|
|
||||||
/* If we didn't have a variable argument list, don't call leave */
|
/* If we didn't have a variable argument list, don't call leave */
|
||||||
if (funcargs >= 0) {
|
if (funcargs >= 0) {
|
||||||
@@ -509,7 +509,7 @@ void g_swap_regvars (int StackOffs, int RegOffs, unsigned Bytes)
|
|||||||
/* Swap a register variable with a location on the stack */
|
/* Swap a register variable with a location on the stack */
|
||||||
{
|
{
|
||||||
/* Calculate the actual stack offset and check it */
|
/* Calculate the actual stack offset and check it */
|
||||||
StackOffs -= oursp;
|
StackOffs -= StackPtr;
|
||||||
CheckLocalOffs (StackOffs);
|
CheckLocalOffs (StackOffs);
|
||||||
|
|
||||||
/* Generate code */
|
/* Generate code */
|
||||||
@@ -577,7 +577,7 @@ void g_save_regvars (int RegOffs, unsigned Bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We pushed stuff, correct the stack pointer */
|
/* We pushed stuff, correct the stack pointer */
|
||||||
oursp -= Bytes;
|
StackPtr -= Bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -586,7 +586,7 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes)
|
|||||||
/* Restore register variables */
|
/* Restore register variables */
|
||||||
{
|
{
|
||||||
/* Calculate the actual stack offset and check it */
|
/* Calculate the actual stack offset and check it */
|
||||||
StackOffs -= oursp;
|
StackOffs -= StackPtr;
|
||||||
CheckLocalOffs (StackOffs);
|
CheckLocalOffs (StackOffs);
|
||||||
|
|
||||||
/* Don't loop for up to two bytes */
|
/* Don't loop for up to two bytes */
|
||||||
@@ -807,7 +807,7 @@ void g_getstatic (unsigned flags, unsigned long label, long offs)
|
|||||||
void g_getlocal (unsigned flags, int offs)
|
void g_getlocal (unsigned flags, int offs)
|
||||||
/* Fetch specified local object (local var). */
|
/* Fetch specified local object (local var). */
|
||||||
{
|
{
|
||||||
offs -= oursp;
|
offs -= StackPtr;
|
||||||
CheckLocalOffs (offs);
|
CheckLocalOffs (offs);
|
||||||
switch (flags & CF_TYPE) {
|
switch (flags & CF_TYPE) {
|
||||||
|
|
||||||
@@ -912,7 +912,7 @@ void g_leasp (int offs)
|
|||||||
/* Fetch the address of the specified symbol into the primary register */
|
/* Fetch the address of the specified symbol into the primary register */
|
||||||
{
|
{
|
||||||
/* Calculate the offset relative to sp */
|
/* Calculate the offset relative to sp */
|
||||||
offs -= oursp;
|
offs -= StackPtr;
|
||||||
|
|
||||||
/* For value 0 we do direct code */
|
/* For value 0 we do direct code */
|
||||||
if (offs == 0) {
|
if (offs == 0) {
|
||||||
@@ -953,13 +953,13 @@ void g_leavariadic (int Offs)
|
|||||||
unsigned ArgSizeOffs;
|
unsigned ArgSizeOffs;
|
||||||
|
|
||||||
/* Calculate the offset relative to sp */
|
/* Calculate the offset relative to sp */
|
||||||
Offs -= oursp;
|
Offs -= StackPtr;
|
||||||
|
|
||||||
/* Get the offset of the parameter which is stored at sp+0 on function
|
/* Get the offset of the parameter which is stored at sp+0 on function
|
||||||
* entry and check if this offset is reachable with a byte offset.
|
* entry and check if this offset is reachable with a byte offset.
|
||||||
*/
|
*/
|
||||||
CHECK (oursp <= 0);
|
CHECK (StackPtr <= 0);
|
||||||
ArgSizeOffs = -oursp;
|
ArgSizeOffs = -StackPtr;
|
||||||
CheckLocalOffs (ArgSizeOffs);
|
CheckLocalOffs (ArgSizeOffs);
|
||||||
|
|
||||||
/* Get the size of all parameters. */
|
/* Get the size of all parameters. */
|
||||||
@@ -1033,7 +1033,7 @@ void g_putstatic (unsigned flags, unsigned long label, long offs)
|
|||||||
void g_putlocal (unsigned Flags, int Offs, long Val)
|
void g_putlocal (unsigned Flags, int Offs, long Val)
|
||||||
/* Put data into local object. */
|
/* Put data into local object. */
|
||||||
{
|
{
|
||||||
Offs -= oursp;
|
Offs -= StackPtr;
|
||||||
CheckLocalOffs (Offs);
|
CheckLocalOffs (Offs);
|
||||||
switch (Flags & CF_TYPE) {
|
switch (Flags & CF_TYPE) {
|
||||||
|
|
||||||
@@ -1552,7 +1552,7 @@ void g_addlocal (unsigned flags, int offs)
|
|||||||
unsigned L;
|
unsigned L;
|
||||||
|
|
||||||
/* Correct the offset and check it */
|
/* Correct the offset and check it */
|
||||||
offs -= oursp;
|
offs -= StackPtr;
|
||||||
CheckLocalOffs (offs);
|
CheckLocalOffs (offs);
|
||||||
|
|
||||||
switch (flags & CF_TYPE) {
|
switch (flags & CF_TYPE) {
|
||||||
@@ -1759,7 +1759,7 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val)
|
|||||||
/* Emit += for a local variable */
|
/* Emit += for a local variable */
|
||||||
{
|
{
|
||||||
/* Calculate the true offset, check it, load it into Y */
|
/* Calculate the true offset, check it, load it into Y */
|
||||||
offs -= oursp;
|
offs -= StackPtr;
|
||||||
CheckLocalOffs (offs);
|
CheckLocalOffs (offs);
|
||||||
|
|
||||||
/* Check the size and determine operation */
|
/* Check the size and determine operation */
|
||||||
@@ -1990,7 +1990,7 @@ void g_subeqlocal (unsigned flags, int offs, unsigned long val)
|
|||||||
/* Emit -= for a local variable */
|
/* Emit -= for a local variable */
|
||||||
{
|
{
|
||||||
/* Calculate the true offset, check it, load it into Y */
|
/* Calculate the true offset, check it, load it into Y */
|
||||||
offs -= oursp;
|
offs -= StackPtr;
|
||||||
CheckLocalOffs (offs);
|
CheckLocalOffs (offs);
|
||||||
|
|
||||||
/* Check the size and determine operation */
|
/* Check the size and determine operation */
|
||||||
@@ -2113,7 +2113,7 @@ void g_addaddr_local (unsigned flags attribute ((unused)), int offs)
|
|||||||
unsigned L = 0;
|
unsigned L = 0;
|
||||||
|
|
||||||
/* Add the offset */
|
/* Add the offset */
|
||||||
offs -= oursp;
|
offs -= StackPtr;
|
||||||
if (offs != 0) {
|
if (offs != 0) {
|
||||||
/* We cannot address more then 256 bytes of locals anyway */
|
/* We cannot address more then 256 bytes of locals anyway */
|
||||||
L = GetLocalLabel();
|
L = GetLocalLabel();
|
||||||
@@ -2438,7 +2438,7 @@ void g_call (unsigned Flags, const char* Label, unsigned ArgSize)
|
|||||||
ldyconst (ArgSize);
|
ldyconst (ArgSize);
|
||||||
}
|
}
|
||||||
AddCodeLine ("jsr _%s", Label);
|
AddCodeLine ("jsr _%s", Label);
|
||||||
oursp += ArgSize; /* callee pops args */
|
StackPtr += ArgSize; /* callee pops args */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2455,7 +2455,7 @@ void g_callind (unsigned Flags, unsigned ArgSize, int Offs)
|
|||||||
AddCodeLine ("jsr callax");
|
AddCodeLine ("jsr callax");
|
||||||
} else {
|
} else {
|
||||||
/* The address is on stack, offset is on Val */
|
/* The address is on stack, offset is on Val */
|
||||||
Offs -= oursp;
|
Offs -= StackPtr;
|
||||||
CheckLocalOffs (Offs);
|
CheckLocalOffs (Offs);
|
||||||
AddCodeLine ("pha");
|
AddCodeLine ("pha");
|
||||||
AddCodeLine ("ldy #$%02X", Offs);
|
AddCodeLine ("ldy #$%02X", Offs);
|
||||||
@@ -2469,7 +2469,7 @@ void g_callind (unsigned Flags, unsigned ArgSize, int Offs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Callee pops args */
|
/* Callee pops args */
|
||||||
oursp += ArgSize;
|
StackPtr += ArgSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Compiler relative stackpointer */
|
/* Compiler relative stackpointer */
|
||||||
extern int oursp;
|
extern int StackPtr;
|
||||||
|
|
||||||
/* Forward */
|
/* Forward */
|
||||||
struct StrBuf;
|
struct StrBuf;
|
||||||
|
|||||||
@@ -269,8 +269,8 @@ static void ParseEnumDecl (void)
|
|||||||
if (CurTok.Tok == TOK_ASSIGN) {
|
if (CurTok.Tok == TOK_ASSIGN) {
|
||||||
ExprDesc lval;
|
ExprDesc lval;
|
||||||
NextToken ();
|
NextToken ();
|
||||||
ConstExpr (&lval);
|
ConstAbsIntExpr (hie1, &lval);
|
||||||
EnumVal = lval.ConstVal;
|
EnumVal = lval.Val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add an entry to the symbol table */
|
/* Add an entry to the symbol table */
|
||||||
@@ -1046,16 +1046,16 @@ static void Decl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
/* 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 lval;
|
||||||
ConstExpr (&lval);
|
ConstAbsIntExpr (hie1, &lval);
|
||||||
if (lval.ConstVal <= 0) {
|
if (lval.Val <= 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.ConstVal = 1;
|
lval.Val = 1;
|
||||||
}
|
}
|
||||||
Size = lval.ConstVal;
|
Size = lval.Val;
|
||||||
}
|
}
|
||||||
ConsumeRBrack ();
|
ConsumeRBrack ();
|
||||||
|
|
||||||
@@ -1222,7 +1222,7 @@ static unsigned ParseScalarInit (type* T)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the expression and convert it to the target type */
|
/* Get the expression and convert it to the target type */
|
||||||
ConstExpr (&ED);
|
ConstExpr (hie1, &ED);
|
||||||
TypeConversion (&ED, T);
|
TypeConversion (&ED, T);
|
||||||
|
|
||||||
/* Output the data */
|
/* Output the data */
|
||||||
@@ -1245,11 +1245,7 @@ static unsigned ParsePointerInit (type* T)
|
|||||||
|
|
||||||
/* Expression */
|
/* Expression */
|
||||||
ExprDesc ED;
|
ExprDesc ED;
|
||||||
ConstExpr (&ED);
|
ConstExpr (hie1, &ED);
|
||||||
if ((ED.Flags & E_MCTYPE) == E_TCONST) {
|
|
||||||
/* Make the const value the correct size */
|
|
||||||
ED.ConstVal &= 0xFFFF;
|
|
||||||
}
|
|
||||||
TypeConversion (&ED, T);
|
TypeConversion (&ED, T);
|
||||||
|
|
||||||
/* Output the data */
|
/* Output the data */
|
||||||
@@ -1419,7 +1415,7 @@ static unsigned ParseVoidInit (void)
|
|||||||
* Return the number of bytes initialized.
|
* Return the number of bytes initialized.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ExprDesc lval;
|
ExprDesc Expr;
|
||||||
unsigned Size;
|
unsigned Size;
|
||||||
|
|
||||||
/* Opening brace */
|
/* Opening brace */
|
||||||
@@ -1428,16 +1424,16 @@ static unsigned ParseVoidInit (void)
|
|||||||
/* Allow an arbitrary list of values */
|
/* Allow an arbitrary list of values */
|
||||||
Size = 0;
|
Size = 0;
|
||||||
do {
|
do {
|
||||||
ConstExpr (&lval);
|
ConstExpr (hie1, &Expr);
|
||||||
switch (UnqualifiedType (lval.Type[0])) {
|
switch (UnqualifiedType (Expr.Type[0])) {
|
||||||
|
|
||||||
case T_SCHAR:
|
case T_SCHAR:
|
||||||
case T_UCHAR:
|
case T_UCHAR:
|
||||||
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
if (ED_IsConstAbsInt (&Expr)) {
|
||||||
/* Make it byte sized */
|
/* Make it byte sized */
|
||||||
lval.ConstVal &= 0xFF;
|
Expr.Val &= 0xFF;
|
||||||
}
|
}
|
||||||
DefineData (&lval);
|
DefineData (&Expr);
|
||||||
Size += SIZEOF_CHAR;
|
Size += SIZEOF_CHAR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1447,17 +1443,21 @@ static unsigned ParseVoidInit (void)
|
|||||||
case T_UINT:
|
case T_UINT:
|
||||||
case T_PTR:
|
case T_PTR:
|
||||||
case T_ARRAY:
|
case T_ARRAY:
|
||||||
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
if (ED_IsConstAbsInt (&Expr)) {
|
||||||
/* Make it word sized */
|
/* Make it word sized */
|
||||||
lval.ConstVal &= 0xFFFF;
|
Expr.Val &= 0xFFFF;
|
||||||
}
|
}
|
||||||
DefineData (&lval);
|
DefineData (&Expr);
|
||||||
Size += SIZEOF_INT;
|
Size += SIZEOF_INT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_LONG:
|
case T_LONG:
|
||||||
case T_ULONG:
|
case T_ULONG:
|
||||||
DefineData (&lval);
|
if (ED_IsConstAbsInt (&Expr)) {
|
||||||
|
/* Make it dword sized */
|
||||||
|
Expr.Val &= 0xFFFFFFFF;
|
||||||
|
}
|
||||||
|
DefineData (&Expr);
|
||||||
Size += SIZEOF_LONG;
|
Size += SIZEOF_LONG;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|||||||
1581
src/cc65/expr.c
1581
src/cc65/expr.c
File diff suppressed because it is too large
Load Diff
@@ -18,68 +18,60 @@
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* code */
|
/* code */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PushAddr (ExprDesc* lval);
|
void PushAddr (const ExprDesc* Expr);
|
||||||
/* If the expression contains an address that was somehow evaluated,
|
/* If the expression contains an address that was somehow evaluated,
|
||||||
* push this address on the stack. This is a helper function for all
|
* push this address on the stack. This is a helper function for all
|
||||||
* sorts of implicit or explicit assignment functions where the lvalue
|
* sorts of implicit or explicit assignment functions where the lvalue
|
||||||
* must be saved if it's not constant, before evaluating the rhs.
|
* must be saved if it's not constant, before evaluating the rhs.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ConstSubExpr (void (*F) (ExprDesc*), ExprDesc* Expr);
|
void ExprLoad (unsigned flags, ExprDesc* Expr);
|
||||||
/* Will evaluate an expression via the given function. If the result is not
|
|
||||||
* a constant, a diagnostic will be printed, and the value is replaced by
|
|
||||||
* a constant one to make sure there are no internal errors that result
|
|
||||||
* from this input error.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void CheckBoolExpr (ExprDesc* lval);
|
|
||||||
/* Check if the given expression is a boolean expression, output a diagnostic
|
|
||||||
* if not.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void ExprLoad (unsigned flags, ExprDesc *lval);
|
|
||||||
/* Put the result of an expression into the primary register */
|
/* Put the result of an expression into the primary register */
|
||||||
|
|
||||||
void Store (ExprDesc* lval, const type* StoreType);
|
void Store (ExprDesc* Expr, const type* StoreType);
|
||||||
/* Store the primary register into the location denoted by lval. If StoreType
|
/* Store the primary register into the location denoted by lval. If StoreType
|
||||||
* is given, use this type when storing instead of lval->Type. If StoreType
|
* is given, use this type when storing instead of lval->Type. If StoreType
|
||||||
* is NULL, use lval->Type instead.
|
* is NULL, use lval->Type instead.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void hie0 (ExprDesc *lval);
|
void hie0 (ExprDesc* Expr);
|
||||||
/* Parse comma operator. */
|
/* Parse comma operator. */
|
||||||
|
|
||||||
int evalexpr (unsigned flags, void (*f) (ExprDesc*), ExprDesc* lval);
|
int evalexpr (unsigned flags, void (*Func) (ExprDesc*), ExprDesc* Expr);
|
||||||
/* Will evaluate an expression via the given function. If the result is a
|
/* Will evaluate an expression via the given function. If the result is a
|
||||||
* constant, 0 is returned and the value is put in the lval struct. If the
|
* constant, 0 is returned and the value is put in the lval struct. If the
|
||||||
* result is not constant, ExprLoad is called to bring the value into the
|
* result is not constant, ExprLoad is called to bring the value into the
|
||||||
* primary register and 1 is returned.
|
* primary register and 1 is returned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void expr (void (*Func) (ExprDesc*), ExprDesc *Expr);
|
void Expression0 (ExprDesc* Expr);
|
||||||
/* Expression parser; func is either hie0 or hie1. */
|
/* Evaluate an expression via hie0 and put the result into the primary register */
|
||||||
|
|
||||||
void expression1 (ExprDesc* lval);
|
void ConstExpr (void (*Func) (ExprDesc*), ExprDesc* Expr);
|
||||||
/* Evaluate an expression on level 1 (no comma operator) and put it into
|
/* Will evaluate an expression via the given function. If the result is not
|
||||||
* the primary register
|
* a constant of some sort, a diagnostic will be printed, and the value is
|
||||||
|
* replaced by a constant one to make sure there are no internal errors that
|
||||||
|
* result from this input error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void expression0 (ExprDesc* lval);
|
void BoolExpr (void (*Func) (ExprDesc*), ExprDesc* Expr);
|
||||||
/* Evaluate an expression via hie0 and put it into the primary register */
|
/* Will evaluate an expression via the given function. If the result is not
|
||||||
|
* something that may be evaluated in a boolean context, a diagnostic will be
|
||||||
|
* printed, and the value is replaced by a constant one to make sure there
|
||||||
|
* are no internal errors that result from this input error.
|
||||||
|
*/
|
||||||
|
|
||||||
void ConstExpr (ExprDesc* lval);
|
void ConstAbsIntExpr (void (*Func) (ExprDesc*), ExprDesc* Expr);
|
||||||
/* Get a constant value */
|
/* Will evaluate an expression via the given function. If the result is not
|
||||||
|
* a constant numeric integer value, a diagnostic will be printed, and the
|
||||||
void ConstIntExpr (ExprDesc* Val);
|
* value is replaced by a constant one to make sure there are no internal
|
||||||
/* Get a constant int value */
|
* errors that result from this input error.
|
||||||
|
*/
|
||||||
void intexpr (ExprDesc* lval);
|
|
||||||
/* Get an integer expression */
|
|
||||||
|
|
||||||
void hie10 (ExprDesc* lval);
|
void hie10 (ExprDesc* lval);
|
||||||
/* Handle ++, --, !, unary - etc. */
|
/* Handle ++, --, !, unary - etc. */
|
||||||
|
|||||||
@@ -46,20 +46,137 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ExprDesc* ED_MakeConstInt (ExprDesc* Expr, long Value)
|
ExprDesc* ED_Init (ExprDesc* Expr)
|
||||||
|
/* Initialize an ExprDesc */
|
||||||
|
{
|
||||||
|
Expr->Sym = 0;
|
||||||
|
Expr->Type = 0;
|
||||||
|
Expr->Val = 0;
|
||||||
|
Expr->Flags = 0;
|
||||||
|
Expr->Test = 0;
|
||||||
|
Expr->Name = 0;
|
||||||
|
return Expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type)
|
||||||
|
/* Make Expr an absolute const with the given value and type. */
|
||||||
|
{
|
||||||
|
Expr->Sym = 0;
|
||||||
|
Expr->Type = Type;
|
||||||
|
Expr->Val = Value;
|
||||||
|
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
||||||
|
Expr->Test = 0;
|
||||||
|
Expr->Name = 0;
|
||||||
|
return Expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long Value)
|
||||||
/* Make Expr a constant integer expression with the given value */
|
/* Make Expr a constant integer expression with the given value */
|
||||||
{
|
{
|
||||||
Expr->Flags = E_MCONST | E_RVAL;
|
Expr->Sym = 0;
|
||||||
Expr->Type = type_int;
|
Expr->Type = type_int;
|
||||||
Expr->ConstVal = Value;
|
Expr->Val = Value;
|
||||||
|
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
||||||
|
Expr->Test = 0;
|
||||||
|
Expr->Name = 0;
|
||||||
return Expr;
|
return Expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ExprDesc* ED_MakeRValExpr (ExprDesc* Expr)
|
||||||
|
/* Convert Expr into a rvalue which is in the primary register without an
|
||||||
|
* offset.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
Expr->Sym = 0;
|
||||||
|
Expr->Val = 0; /* No offset */
|
||||||
|
Expr->Flags = (Expr->Flags & ~(E_MASK_LOC|E_MASK_RTYPE)) | (E_LOC_EXPR|E_RTYPE_RVAL);
|
||||||
|
Expr->Test = 0;
|
||||||
|
Expr->Name = 0;
|
||||||
|
return Expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ExprDesc* ED_MakeLValExpr (ExprDesc* Expr)
|
||||||
|
/* Convert Expr into a lvalue which is in the primary register without an
|
||||||
|
* offset.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
Expr->Sym = 0;
|
||||||
|
Expr->Val = 0; /* No offset */
|
||||||
|
Expr->Flags = (Expr->Flags & ~(E_MASK_LOC|E_MASK_RTYPE)) | (E_LOC_EXPR|E_RTYPE_LVAL);
|
||||||
|
Expr->Test = 0;
|
||||||
|
Expr->Name = 0;
|
||||||
|
return Expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int ED_IsConst (const ExprDesc* Expr)
|
||||||
|
/* Return true if the expression denotes a constant of some sort. This can be a
|
||||||
|
* numeric constant, the address of a global variable (maybe with offset) or
|
||||||
|
* similar.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
return ED_IsRVal (Expr) && (Expr->Flags & E_LOC_CONST) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int ED_IsConstAbs (const ExprDesc* Expr)
|
||||||
|
/* Return true if the expression denotes a constant absolute value. This can be
|
||||||
|
* a numeric constant, cast to any type.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
return ED_IsConst (Expr) && ED_IsLocAbs (Expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int ED_IsConstAbsInt (const ExprDesc* Expr)
|
||||||
|
/* Return true if the expression is a constant (numeric) integer. */
|
||||||
|
{
|
||||||
|
return (Expr->Flags & (E_MASK_LOC|E_MASK_RTYPE)) == (E_LOC_ABS|E_RTYPE_RVAL) &&
|
||||||
|
IsClassInt (Expr->Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int ED_IsNullPtr (const ExprDesc* Expr)
|
||||||
|
/* 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) &&
|
||||||
|
Expr->Val == 0 &&
|
||||||
|
IsClassInt (Expr->Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int ED_IsBool (const ExprDesc* Expr)
|
||||||
|
/* Return true of the expression can be treated as a boolean, that is, it can
|
||||||
|
* be an operand to a compare operation.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* Either ints, floats, or pointers can be used in a boolean context */
|
||||||
|
return IsClassInt (Expr->Type) ||
|
||||||
|
IsClassFloat (Expr->Type) ||
|
||||||
|
IsClassPtr (Expr->Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrintExprDesc (FILE* F, ExprDesc* E)
|
void PrintExprDesc (FILE* F, ExprDesc* E)
|
||||||
/* Print an ExprDesc */
|
/* Print an ExprDesc */
|
||||||
{
|
{
|
||||||
|
unsigned Flags;
|
||||||
|
char Sep;
|
||||||
|
|
||||||
fprintf (F, "Symbol: %s\n", E->Sym? E->Sym->Name : "(none)");
|
fprintf (F, "Symbol: %s\n", E->Sym? E->Sym->Name : "(none)");
|
||||||
if (E->Type) {
|
if (E->Type) {
|
||||||
fprintf (F, "Type: ");
|
fprintf (F, "Type: ");
|
||||||
@@ -70,33 +187,64 @@ 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->ConstVal);
|
fprintf (F, "Value: 0x%08lX\n", E->Val);
|
||||||
fprintf (F, "Flags: ");
|
|
||||||
switch (E->Flags & E_MCTYPE) {
|
Flags = E->Flags;
|
||||||
case E_TCONST: fprintf (F, "E_TCONST "); break;
|
Sep = '(';
|
||||||
case E_TGLAB: fprintf (F, "E_TGLAB "); break;
|
fprintf (F, "Flags: 0x%04X ", Flags);
|
||||||
case E_TLIT: fprintf (F, "E_TLIT "); break;
|
if (Flags & E_LOC_ABS) {
|
||||||
case E_TLOFFS: fprintf (F, "E_TLOFFS "); break;
|
fprintf (F, "%cE_LOC_ABS", Sep);
|
||||||
case E_TLLAB: fprintf (F, "E_TLLAB "); break;
|
Flags &= ~E_LOC_ABS;
|
||||||
case E_TREGISTER: fprintf (F, "E_TREGISTER "); break;
|
Sep = ',';
|
||||||
default: fprintf (F, "0x%02X ", E->Flags & E_MCTYPE); break;
|
|
||||||
}
|
}
|
||||||
if ((E->Flags & E_MREG) == E_MREG) {
|
if (Flags & E_LOC_GLOBAL) {
|
||||||
fprintf (F, "E_MREG ");
|
fprintf (F, "%cE_LOC_GLOBAL", Sep);
|
||||||
} else if ((E->Flags & E_MEOFFS) == E_MEOFFS) {
|
Flags &= ~E_LOC_GLOBAL;
|
||||||
fprintf (F, "E_MEOFFS ");
|
Sep = ',';
|
||||||
} else if ((E->Flags & E_MEXPR) == E_MEXPR) {
|
|
||||||
fprintf (F, "E_MEXPR ");
|
|
||||||
}
|
}
|
||||||
if ((E->Flags & E_MGLOBAL) == E_MGLOBAL) {
|
if (Flags & E_LOC_STATIC) {
|
||||||
fprintf (F, "E_MGLOBAL ");
|
fprintf (F, "%cE_LOC_STATIC", Sep);
|
||||||
|
Flags &= ~E_LOC_STATIC;
|
||||||
|
Sep = ',';
|
||||||
}
|
}
|
||||||
if ((E->Flags & E_MLOCAL) == E_MLOCAL) {
|
if (Flags & E_LOC_REGISTER) {
|
||||||
fprintf (F, "E_MLOCAL ");
|
fprintf (F, "%cE_LOC_REGISTER", Sep);
|
||||||
|
Flags &= ~E_LOC_REGISTER;
|
||||||
|
Sep = ',';
|
||||||
}
|
}
|
||||||
if ((E->Flags & E_MCONST) == E_MCONST) {
|
if (Flags & E_LOC_STACK) {
|
||||||
fprintf (F, "E_MCONST ");
|
fprintf (F, "%cE_LOC_STACK", Sep);
|
||||||
|
Flags &= ~E_LOC_STACK;
|
||||||
|
Sep = ',';
|
||||||
}
|
}
|
||||||
|
if (Flags & E_LOC_PRIMARY) {
|
||||||
|
fprintf (F, "%cE_LOC_PRIMARY", Sep);
|
||||||
|
Flags &= ~E_LOC_PRIMARY;
|
||||||
|
Sep = ',';
|
||||||
|
}
|
||||||
|
if (Flags & E_LOC_EXPR) {
|
||||||
|
fprintf (F, "%cE_LOC_EXPR", Sep);
|
||||||
|
Flags &= ~E_LOC_EXPR;
|
||||||
|
Sep = ',';
|
||||||
|
}
|
||||||
|
if (Flags & E_LOC_LITERAL) {
|
||||||
|
fprintf (F, "%cE_LOC_LITERAL", Sep);
|
||||||
|
Flags &= ~E_LOC_LITERAL;
|
||||||
|
Sep = ',';
|
||||||
|
}
|
||||||
|
if (Flags & E_RTYPE_LVAL) {
|
||||||
|
fprintf (F, "%cE_RTYPE_LVAL", Sep);
|
||||||
|
Flags &= ~E_RTYPE_LVAL;
|
||||||
|
Sep = ',';
|
||||||
|
}
|
||||||
|
if (Flags) {
|
||||||
|
fprintf (F, "%c,0x%04X", Sep, Flags);
|
||||||
|
Sep = ',';
|
||||||
|
}
|
||||||
|
if (Sep != '(') {
|
||||||
|
fputc (')', F);
|
||||||
|
}
|
||||||
|
fputc ('\n', F);
|
||||||
|
|
||||||
fprintf (F, "\nTest: ");
|
fprintf (F, "\nTest: ");
|
||||||
if (E->Test & E_CC) {
|
if (E->Test & E_CC) {
|
||||||
|
|||||||
@@ -55,37 +55,41 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Defines for the flags field of the expression descriptor */
|
/* Defines for the flags field of the expression descriptor */
|
||||||
#define E_MREG 0x0110U /* Special: Expression is primary register */
|
enum {
|
||||||
#define E_MGLOBAL 0x0080U /* Reference to static variable */
|
/* Location: Where is the value we're talking about? */
|
||||||
#define E_MLOCAL 0x0040U /* Reference to local variable (stack offset) */
|
E_MASK_LOC = 0x00FF,
|
||||||
#define E_MCONST 0x0020U /* Constant value */
|
E_LOC_ABS = 0x0001, /* Absolute: numeric address or const */
|
||||||
#define E_MEXPR 0x0010U /* Result is in primary register */
|
E_LOC_GLOBAL = 0x0002, /* Global variable */
|
||||||
#define E_MEOFFS 0x0011U /* Base is in primary register, const offset */
|
E_LOC_STATIC = 0x0004, /* Static variable */
|
||||||
|
E_LOC_REGISTER = 0x0008, /* Register variable */
|
||||||
|
E_LOC_STACK = 0x0010, /* Value on the stack */
|
||||||
|
E_LOC_PRIMARY = 0x0020, /* The primary register */
|
||||||
|
E_LOC_EXPR = 0x0040, /* An expression in the primary register */
|
||||||
|
E_LOC_LITERAL = 0x0080, /* Literal in the literal pool */
|
||||||
|
|
||||||
#define E_MCTYPE 0x0007U /* Type of a constant */
|
/* Constant location of some sort (only if rval) */
|
||||||
#define E_TCONST 0x0000U /* Constant */
|
E_LOC_CONST = E_LOC_ABS | E_LOC_GLOBAL | E_LOC_STATIC |
|
||||||
#define E_TGLAB 0x0001U /* Global label */
|
E_LOC_REGISTER | E_LOC_LITERAL,
|
||||||
#define E_TLIT 0x0002U /* Literal of some kind */
|
|
||||||
#define E_TLOFFS 0x0003U /* Constant stack offset */
|
|
||||||
#define E_TLLAB 0x0004U /* Local label */
|
|
||||||
#define E_TREGISTER 0x0005U /* Register variable */
|
|
||||||
|
|
||||||
#define E_RVAL 0x0000U /* Expression node is a value */
|
/* Reference? */
|
||||||
#define E_LVAL 0x1000U /* Expression node is a reference */
|
E_MASK_RTYPE = 0x8000,
|
||||||
|
E_RTYPE_RVAL = 0x0000,
|
||||||
|
E_RTYPE_LVAL = 0x8000
|
||||||
|
};
|
||||||
|
|
||||||
/* Defines for the test field of the expression descriptor */
|
/* Defines for the test field of the expression descriptor */
|
||||||
#define E_CC 0x0001U /* expr has set cond codes apropos result value */
|
#define E_CC 0x0001U /* Condition codes are set */
|
||||||
#define E_FORCETEST 0x0002U /* if expr has NOT set CC, force a test */
|
#define E_FORCETEST 0x0002U /* Force test to set condition codes */
|
||||||
|
|
||||||
/* Describe the result of an expression */
|
/* Describe the result of an expression */
|
||||||
typedef struct ExprDesc ExprDesc;
|
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 ConstVal;/* Value if expression constant */
|
long Val; /* Value if expression constant */
|
||||||
unsigned short Flags;
|
unsigned short Flags;
|
||||||
unsigned short Test; /* */
|
unsigned short Test; /* */
|
||||||
unsigned long Name; /* Name or label number */
|
unsigned long Name; /* Name or label number */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -96,73 +100,137 @@ struct ExprDesc {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
ExprDesc* ED_Init (ExprDesc* Expr);
|
||||||
INLINE ExprDesc* InitExprDesc (ExprDesc* Expr)
|
|
||||||
/* Initialize an ExprDesc */
|
/* Initialize an ExprDesc */
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE int ED_GetLoc (const ExprDesc* Expr)
|
||||||
|
/* Return the location flags from the expression */
|
||||||
{
|
{
|
||||||
return memset (Expr, 0, sizeof (*Expr));
|
return (Expr->Flags & E_MASK_LOC);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define InitExprDesc(E) memset ((E), 0, sizeof (*(E)))
|
# define ED_GetLoc(Expr) ((Expr)->Flags & E_MASK_LOC)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE int ED_IsLocAbs (const ExprDesc* Expr)
|
||||||
|
/* Return true if the expression is an absolute value */
|
||||||
|
{
|
||||||
|
return (Expr->Flags & E_MASK_LOC) == E_LOC_ABS;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define ED_IsLocAbs(Expr) (((Expr)->Flags & E_MASK_LOC) == E_LOC_ABS)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE int ED_IsLocStack (const ExprDesc* Expr)
|
||||||
|
/* Return true if the expression is located on the stack */
|
||||||
|
{
|
||||||
|
return (Expr->Flags & E_MASK_LOC) == E_LOC_STACK;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define ED_IsLocStack(Expr) (((Expr)->Flags & E_MASK_LOC) == E_LOC_STACK)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE int ED_IsLocExpr (const ExprDesc* Expr)
|
||||||
|
/* Return true if the expression is an expression in the primary */
|
||||||
|
{
|
||||||
|
return (Expr->Flags & E_MASK_LOC) == E_LOC_EXPR;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define ED_IsLocExpr(Expr) (((Expr)->Flags & E_MASK_LOC) == E_LOC_EXPR)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE int ED_IsLocConst (const ExprDesc* Expr)
|
||||||
|
/* Return true if the expression is a constant location of some sort */
|
||||||
|
{
|
||||||
|
return (Expr->Flags & E_LOC_CONST) != 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define ED_IsLocConst(Expr) (((Expr)->Flags & E_LOC_CONST) != 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE int ED_IsLVal (const ExprDesc* Expr)
|
INLINE int ED_IsLVal (const ExprDesc* Expr)
|
||||||
/* Return true if the expression is a reference */
|
/* Return true if the expression is a reference */
|
||||||
{
|
{
|
||||||
return (Expr->Flags & E_LVAL) != 0;
|
return (Expr->Flags & E_MASK_RTYPE) == E_RTYPE_LVAL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define ED_IsLVal(Expr) (((Expr)->Flags & E_LVAL) != 0)
|
# define ED_IsLVal(Expr) (((Expr)->Flags & E_MASK_RTYPE) == E_RTYPE_LVAL)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE int ED_IsRVal (const ExprDesc* Expr)
|
INLINE int ED_IsRVal (const ExprDesc* Expr)
|
||||||
/* Return true if the expression is a rvalue */
|
/* Return true if the expression is a rvalue */
|
||||||
{
|
{
|
||||||
return (Expr->Flags & E_LVAL) == 0;
|
return (Expr->Flags & E_MASK_RTYPE) == E_RTYPE_RVAL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define ED_IsRVal(Expr) (((Expr)->Flags & E_LVAL) == 0)
|
# define ED_IsRVal(Expr) (((Expr)->Flags & E_MASK_RTYPE) == E_RTYPE_RVAL)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE int ED_SetValType (ExprDesc* Expr, int Ref)
|
INLINE void ED_MakeLVal (ExprDesc* Expr)
|
||||||
/* Set the reference flag for an expression and return it (the flag) */
|
/* Make the expression a lvalue. */
|
||||||
{
|
{
|
||||||
Expr->Flags = Ref? (Expr->Flags | E_LVAL) : (Expr->Flags & ~E_LVAL);
|
Expr->Flags |= E_RTYPE_LVAL;
|
||||||
return Ref;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* Beware: Just one occurance of R below, since it may have side effects! */
|
# define ED_MakeLVal(Expr) do { (Expr)->Flags |= R_RTYPE_LVAL; } while (0)
|
||||||
# define ED_SetValType(E, R) \
|
|
||||||
(((E)->Flags = (R)? ((E)->Flags | E_LVAL) : ((E)->Flags & ~E_LVAL)), \
|
|
||||||
ED_IsLVal (E))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE int ED_MakeLVal (ExprDesc* Expr)
|
INLINE void ED_MakeRVal (ExprDesc* Expr)
|
||||||
/* Make the expression a lvalue and return true */
|
/* Make the expression a rvalue. */
|
||||||
{
|
{
|
||||||
return ED_SetValType (Expr, 1);
|
Expr->Flags &= ~E_RTYPE_LVAL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define ED_MakeLVal(Expr) ED_SetValType (Expr, 1)
|
# define ED_MakeRVal(Expr) do { (Expr)->Flags &= ~E_RTYPE_LVAL; } while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type);
|
||||||
INLINE int ED_MakeRVal (ExprDesc* Expr)
|
/* Make Expr an absolute const with the given value and type. */
|
||||||
/* Make the expression a rvalue and return false */
|
|
||||||
{
|
|
||||||
return ED_SetValType (Expr, 0);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define ED_MakeRVal(Expr) ED_SetValType (Expr, 0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ExprDesc* ED_MakeConstInt (ExprDesc* Expr, long Value);
|
ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long Value);
|
||||||
/* Make Expr a constant integer expression with the given value */
|
/* Make Expr a constant integer expression with the given value */
|
||||||
|
|
||||||
|
ExprDesc* ED_MakeRValExpr (ExprDesc* Expr);
|
||||||
|
/* Convert Expr into a rvalue which is in the primary register without an
|
||||||
|
* offset.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ExprDesc* ED_MakeLValExpr (ExprDesc* Expr);
|
||||||
|
/* Convert Expr into a lvalue which is in the primary register without an
|
||||||
|
* offset.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int ED_IsConst (const ExprDesc* Expr);
|
||||||
|
/* Return true if the expression denotes a constant of some sort. This can be a
|
||||||
|
* numeric constant, the address of a global variable (maybe with offset) or
|
||||||
|
* similar.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int ED_IsConstAbs (const ExprDesc* Expr);
|
||||||
|
/* Return true if the expression denotes a constant absolute value. This can be
|
||||||
|
* a numeric constant, cast to any type.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int ED_IsConstAbsInt (const ExprDesc* Expr);
|
||||||
|
/* Return true if the expression is a constant (numeric) integer. */
|
||||||
|
|
||||||
|
int ED_IsNullPtr (const ExprDesc* Expr);
|
||||||
|
/* Return true if the given expression is a NULL pointer constant */
|
||||||
|
|
||||||
|
int ED_IsBool (const ExprDesc* Expr);
|
||||||
|
/* Return true of the expression can be treated as a boolean, that is, it can
|
||||||
|
* be an operand to a compare operation.
|
||||||
|
*/
|
||||||
|
|
||||||
void PrintExprDesc (FILE* F, ExprDesc* Expr);
|
void PrintExprDesc (FILE* F, ExprDesc* Expr);
|
||||||
/* Print an ExprDesc */
|
/* Print an ExprDesc */
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ int F_ReserveLocalSpace (Function* F, unsigned Size)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
F->Reserved += Size;
|
F->Reserved += Size;
|
||||||
return oursp - F->Reserved;
|
return StackPtr - F->Reserved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ void F_AllocLocalSpace (Function* F)
|
|||||||
g_space (F->Reserved);
|
g_space (F->Reserved);
|
||||||
|
|
||||||
/* Correct the stack pointer */
|
/* Correct the stack pointer */
|
||||||
oursp -= F->Reserved;
|
StackPtr -= F->Reserved;
|
||||||
|
|
||||||
/* Nothing more reserved */
|
/* Nothing more reserved */
|
||||||
F->Reserved = 0;
|
F->Reserved = 0;
|
||||||
@@ -408,7 +408,7 @@ void NewFunc (SymEntry* Func)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Setup the stack */
|
/* Setup the stack */
|
||||||
oursp = 0;
|
StackPtr = 0;
|
||||||
|
|
||||||
/* Walk through the parameter list and allocate register variable space
|
/* Walk through the parameter list and allocate register variable space
|
||||||
* for parameters declared as register. Generate code to swap the contents
|
* for parameters declared as register. Generate code to swap the contents
|
||||||
@@ -450,7 +450,7 @@ void NewFunc (SymEntry* Func)
|
|||||||
/* Remember the current stack pointer. All variables allocated elsewhere
|
/* Remember the current stack pointer. All variables allocated elsewhere
|
||||||
* must be dropped when doing a return from an inner block.
|
* must be dropped when doing a return from an inner block.
|
||||||
*/
|
*/
|
||||||
CurrentFunc->TopLevelSP = oursp;
|
CurrentFunc->TopLevelSP = StackPtr;
|
||||||
|
|
||||||
/* Now process statements in this block */
|
/* Now process statements in this block */
|
||||||
HadReturn = 0;
|
HadReturn = 0;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ static unsigned ParseRegisterDecl (Declaration* Decl, unsigned* SC, int Reg)
|
|||||||
/* Check for an optional initialization */
|
/* Check for an optional initialization */
|
||||||
if (CurTok.Tok == TOK_ASSIGN) {
|
if (CurTok.Tok == TOK_ASSIGN) {
|
||||||
|
|
||||||
ExprDesc lval;
|
ExprDesc Expr;
|
||||||
|
|
||||||
/* Skip the '=' */
|
/* Skip the '=' */
|
||||||
NextToken ();
|
NextToken ();
|
||||||
@@ -111,13 +111,13 @@ static unsigned ParseRegisterDecl (Declaration* Decl, unsigned* SC, int Reg)
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Parse the expression */
|
/* Parse the expression */
|
||||||
hie1 (InitExprDesc (&lval));
|
hie1 (&Expr);
|
||||||
|
|
||||||
/* Convert it to the target type */
|
/* Convert it to the target type */
|
||||||
TypeConversion (&lval, Decl->Type);
|
TypeConversion (&Expr, Decl->Type);
|
||||||
|
|
||||||
/* Load the value into the primary */
|
/* Load the value into the primary */
|
||||||
ExprLoad (CF_NONE, &lval);
|
ExprLoad (CF_NONE, &Expr);
|
||||||
|
|
||||||
/* Store the value into the variable */
|
/* Store the value into the variable */
|
||||||
g_putstatic (CF_REGVAR | TypeOf (Decl->Type), Reg, 0);
|
g_putstatic (CF_REGVAR | TypeOf (Decl->Type), Reg, 0);
|
||||||
@@ -161,7 +161,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
|||||||
/* Check for an optional initialization */
|
/* Check for an optional initialization */
|
||||||
if (CurTok.Tok == TOK_ASSIGN) {
|
if (CurTok.Tok == TOK_ASSIGN) {
|
||||||
|
|
||||||
ExprDesc lval;
|
ExprDesc Expr;
|
||||||
|
|
||||||
/* Skip the '=' */
|
/* Skip the '=' */
|
||||||
NextToken ();
|
NextToken ();
|
||||||
@@ -207,23 +207,23 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
|||||||
Flags = (Size == SIZEOF_CHAR)? CF_FORCECHAR : CF_NONE;
|
Flags = (Size == SIZEOF_CHAR)? CF_FORCECHAR : CF_NONE;
|
||||||
|
|
||||||
/* Parse the expression */
|
/* Parse the expression */
|
||||||
hie1 (InitExprDesc (&lval));
|
hie1 (&Expr);
|
||||||
|
|
||||||
/* Convert it to the target type */
|
/* Convert it to the target type */
|
||||||
TypeConversion (&lval, Decl->Type);
|
TypeConversion (&Expr, Decl->Type);
|
||||||
|
|
||||||
/* If the value is not const, load it into the primary.
|
/* If the value is not const, load it into the primary.
|
||||||
* Otherwise pass the information to the code generator.
|
* Otherwise pass the information to the code generator.
|
||||||
*/
|
*/
|
||||||
if (ED_IsLVal (&lval) || lval.Flags != E_MCONST) {
|
if (ED_IsConstAbsInt (&Expr)) {
|
||||||
ExprLoad (CF_NONE, &lval);
|
|
||||||
ED_MakeRVal (&lval);
|
|
||||||
} else {
|
|
||||||
Flags |= CF_CONST;
|
Flags |= CF_CONST;
|
||||||
|
} else {
|
||||||
|
ExprLoad (CF_NONE, &Expr);
|
||||||
|
ED_MakeRVal (&Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Push the value */
|
/* Push the value */
|
||||||
g_push (Flags | TypeOf (Decl->Type), lval.ConstVal);
|
g_push (Flags | TypeOf (Decl->Type), Expr.Val);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
|||||||
*SC |= SC_REF;
|
*SC |= SC_REF;
|
||||||
|
|
||||||
/* Variable is located at the current SP */
|
/* Variable is located at the current SP */
|
||||||
SymData = oursp;
|
SymData = StackPtr;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Non-initialized local variable. Just keep track of
|
/* Non-initialized local variable. Just keep track of
|
||||||
@@ -258,7 +258,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
|||||||
/* Allow assignments */
|
/* Allow assignments */
|
||||||
if (CurTok.Tok == TOK_ASSIGN) {
|
if (CurTok.Tok == TOK_ASSIGN) {
|
||||||
|
|
||||||
ExprDesc lval;
|
ExprDesc Expr;
|
||||||
|
|
||||||
/* Skip the '=' */
|
/* Skip the '=' */
|
||||||
NextToken ();
|
NextToken ();
|
||||||
@@ -283,13 +283,13 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Parse the expression */
|
/* Parse the expression */
|
||||||
hie1 (InitExprDesc (&lval));
|
hie1 (&Expr);
|
||||||
|
|
||||||
/* Convert it to the target type */
|
/* Convert it to the target type */
|
||||||
TypeConversion (&lval, Decl->Type);
|
TypeConversion (&Expr, Decl->Type);
|
||||||
|
|
||||||
/* Load the value into the primary */
|
/* Load the value into the primary */
|
||||||
ExprLoad (CF_NONE, &lval);
|
ExprLoad (CF_NONE, &Expr);
|
||||||
|
|
||||||
/* Store the value into the variable */
|
/* Store the value into the variable */
|
||||||
g_putstatic (TypeOf (Decl->Type), SymData, 0);
|
g_putstatic (TypeOf (Decl->Type), SymData, 0);
|
||||||
@@ -447,7 +447,7 @@ void DeclareLocals (void)
|
|||||||
/* Declare local variables and types. */
|
/* Declare local variables and types. */
|
||||||
{
|
{
|
||||||
/* Remember the current stack pointer */
|
/* Remember the current stack pointer */
|
||||||
int InitialStack = oursp;
|
int InitialStack = StackPtr;
|
||||||
|
|
||||||
/* Loop until we don't find any more variables */
|
/* Loop until we don't find any more variables */
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -501,7 +501,7 @@ void DeclareLocals (void)
|
|||||||
/* In case we've allocated local variables in this block, emit a call to
|
/* In case we've allocated local variables in this block, emit a call to
|
||||||
* the stack checking routine if stack checks are enabled.
|
* the stack checking routine if stack checks are enabled.
|
||||||
*/
|
*/
|
||||||
if (IS_Get (&CheckStack) && InitialStack != oursp) {
|
if (IS_Get (&CheckStack) && InitialStack != StackPtr) {
|
||||||
g_cstackcheck ();
|
g_cstackcheck ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ OBJS = anonname.o \
|
|||||||
error.o \
|
error.o \
|
||||||
expr.o \
|
expr.o \
|
||||||
exprdesc.o \
|
exprdesc.o \
|
||||||
exprheap.o \
|
|
||||||
exprnode.o \
|
exprnode.o \
|
||||||
funcdesc.o \
|
funcdesc.o \
|
||||||
function.o \
|
function.o \
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ OBJS = anonname.obj \
|
|||||||
error.obj \
|
error.obj \
|
||||||
expr.obj \
|
expr.obj \
|
||||||
exprdesc.obj \
|
exprdesc.obj \
|
||||||
exprheap.obj \
|
|
||||||
exprnode.obj \
|
exprnode.obj \
|
||||||
funcdesc.obj \
|
funcdesc.obj \
|
||||||
function.obj \
|
function.obj \
|
||||||
|
|||||||
@@ -804,7 +804,7 @@ static int DoIf (int Skip)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Call the expression parser */
|
/* Call the expression parser */
|
||||||
ConstExpr (&lval);
|
ConstExpr (hie1, &lval);
|
||||||
|
|
||||||
/* 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.ConstVal != 0);
|
return PushIf (Skip, 1, lval.Val != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||||
/* R<>merstrasse 52 */
|
/* R<>merstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@@ -117,23 +117,21 @@ static unsigned ParseArg (type* Type, ExprDesc* Arg)
|
|||||||
unsigned Flags = CF_FORCECHAR;
|
unsigned Flags = CF_FORCECHAR;
|
||||||
|
|
||||||
/* Read the expression we're going to pass to the function */
|
/* Read the expression we're going to pass to the function */
|
||||||
hie1 (InitExprDesc (Arg));
|
hie1 (Arg);
|
||||||
|
|
||||||
/* Convert this expression to the expected type */
|
/* Convert this expression to the expected type */
|
||||||
TypeConversion (Arg, Type);
|
TypeConversion (Arg, Type);
|
||||||
|
|
||||||
/* If the value is not a constant, load it into the primary */
|
/* If the value is a constant, set the flag, otherwise load it into the
|
||||||
if (ED_IsLVal (Arg) || Arg->Flags != E_MCONST) {
|
* primary register.
|
||||||
|
*/
|
||||||
|
if (ED_IsConstAbsInt (Arg)) {
|
||||||
|
/* Remember that we have a constant value */
|
||||||
|
Flags |= CF_CONST;
|
||||||
|
} else {
|
||||||
/* Load into the primary */
|
/* Load into the primary */
|
||||||
ExprLoad (CF_NONE, Arg);
|
ExprLoad (CF_NONE, Arg);
|
||||||
ED_MakeRVal (Arg);
|
ED_MakeRVal (Arg);
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
/* Remember that we have a constant value */
|
|
||||||
Flags |= CF_CONST;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use the type of the argument for the push */
|
/* Use the type of the argument for the push */
|
||||||
@@ -164,7 +162,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)),
|
|||||||
|
|
||||||
/* Argument #1 */
|
/* Argument #1 */
|
||||||
Flags = ParseArg (Arg1Type, &Arg);
|
Flags = ParseArg (Arg1Type, &Arg);
|
||||||
g_push (Flags, Arg.ConstVal);
|
g_push (Flags, Arg.Val);
|
||||||
ParamSize += SizeOf (Arg1Type);
|
ParamSize += SizeOf (Arg1Type);
|
||||||
ConsumeComma ();
|
ConsumeComma ();
|
||||||
|
|
||||||
@@ -172,12 +170,12 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)),
|
|||||||
* function if it is a constant zero.
|
* function if it is a constant zero.
|
||||||
*/
|
*/
|
||||||
Flags = ParseArg (Arg2Type, &Arg);
|
Flags = ParseArg (Arg2Type, &Arg);
|
||||||
if ((Flags & CF_CONST) != 0 && Arg.ConstVal == 0) {
|
if ((Flags & CF_CONST) != 0 && Arg.Val == 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 (Flags, Arg.ConstVal);
|
g_push (Flags, Arg.Val);
|
||||||
ParamSize += SizeOf (Arg2Type);
|
ParamSize += SizeOf (Arg2Type);
|
||||||
}
|
}
|
||||||
ConsumeComma ();
|
ConsumeComma ();
|
||||||
@@ -189,7 +187,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)),
|
|||||||
*/
|
*/
|
||||||
Flags = ParseArg (Arg3Type, &Arg);
|
Flags = ParseArg (Arg3Type, &Arg);
|
||||||
if (Flags & CF_CONST) {
|
if (Flags & CF_CONST) {
|
||||||
if (Arg.ConstVal == 0) {
|
if (Arg.Val == 0) {
|
||||||
Warning ("Call to memset has no effect");
|
Warning ("Call to memset has no effect");
|
||||||
}
|
}
|
||||||
ExprLoad (CF_FORCECHAR, &Arg);
|
ExprLoad (CF_FORCECHAR, &Arg);
|
||||||
@@ -217,7 +215,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)),
|
|||||||
ParamType[1] = GetDefaultChar () | T_QUAL_CONST;
|
ParamType[1] = GetDefaultChar () | T_QUAL_CONST;
|
||||||
|
|
||||||
/* Fetch the parameter and convert it to the type needed */
|
/* Fetch the parameter and convert it to the type needed */
|
||||||
hie1 (InitExprDesc (&Param));
|
hie1 (&Param);
|
||||||
TypeConversion (&Param, ParamType);
|
TypeConversion (&Param, ParamType);
|
||||||
|
|
||||||
/* Check if the parameter is a constant array of some type, or a numeric
|
/* Check if the parameter is a constant array of some type, or a numeric
|
||||||
@@ -225,33 +223,33 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)),
|
|||||||
*/
|
*/
|
||||||
CodeFlags = 0;
|
CodeFlags = 0;
|
||||||
ParamName = Param.Name;
|
ParamName = Param.Name;
|
||||||
if ((IsTypeArray (Param.Type) && (Param.Flags & E_MCONST) != 0) ||
|
if ((ED_IsLocConst (&Param) && IsTypeArray (Param.Type)) ||
|
||||||
(IsTypePtr (Param.Type) && Param.Flags == (E_MCONST | E_TCONST))) {
|
(ED_IsLocAbs (&Param) && IsTypePtr (Param.Type))) {
|
||||||
|
|
||||||
/* Check which type of constant it is */
|
/* Check which type of constant it is */
|
||||||
switch (Param.Flags & E_MCTYPE) {
|
switch (ED_GetLoc (&Param)) {
|
||||||
|
|
||||||
case E_TCONST:
|
case E_LOC_ABS:
|
||||||
/* Numerical address */
|
/* Numerical address */
|
||||||
CodeFlags |= CF_CONST | CF_ABSOLUTE;
|
CodeFlags |= CF_CONST | CF_ABSOLUTE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_TREGISTER:
|
case E_LOC_GLOBAL:
|
||||||
/* Register variable */
|
|
||||||
CodeFlags |= CF_CONST | CF_REGVAR;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case E_TGLAB:
|
|
||||||
/* Global label */
|
/* Global label */
|
||||||
CodeFlags |= CF_CONST | CF_EXTERNAL;
|
CodeFlags |= CF_CONST | CF_EXTERNAL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_TLLAB:
|
case E_LOC_STATIC:
|
||||||
/* Local symbol */
|
/* Local symbol */
|
||||||
CodeFlags |= CF_CONST | CF_STATIC;
|
CodeFlags |= CF_CONST | CF_STATIC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_TLIT:
|
case E_LOC_REGISTER:
|
||||||
|
/* Register variable */
|
||||||
|
CodeFlags |= CF_CONST | CF_REGVAR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case E_LOC_LITERAL:
|
||||||
/* A literal of some kind. If string literals are read only,
|
/* A literal of some kind. If string literals are read only,
|
||||||
* we can calculate the length of the string and remove it
|
* we can calculate the length of the string and remove it
|
||||||
* from the literal pool. Otherwise we have to calculate the
|
* from the literal pool. Otherwise we have to calculate the
|
||||||
@@ -260,8 +258,8 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)),
|
|||||||
if (!WriteableStrings) {
|
if (!WriteableStrings) {
|
||||||
/* String literals are const */
|
/* String literals are const */
|
||||||
ExprDesc Length;
|
ExprDesc Length;
|
||||||
ED_MakeConstInt (&Length, strlen (GetLiteral (Param.ConstVal)));
|
ED_MakeConstAbsInt (&Length, strlen (GetLiteral (Param.Val)));
|
||||||
ResetLiteralPoolOffs (Param.ConstVal);
|
ResetLiteralPoolOffs (Param.Val);
|
||||||
ExprLoad (CF_NONE, &Length);
|
ExprLoad (CF_NONE, &Length);
|
||||||
goto ExitPoint;
|
goto ExitPoint;
|
||||||
} else {
|
} else {
|
||||||
@@ -282,7 +280,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)),
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate the strlen code */
|
/* Generate the strlen code */
|
||||||
g_strlen (CodeFlags, ParamName, Param.ConstVal);
|
g_strlen (CodeFlags, ParamName, Param.Val);
|
||||||
|
|
||||||
ExitPoint:
|
ExitPoint:
|
||||||
/* We expect the closing brace */
|
/* We expect the closing brace */
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||||
/* R<>merstra<72>e 52 */
|
/* R<>merstra<72>e 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@@ -201,7 +201,7 @@ static void DoStatement (void)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Add the loop to the loop stack */
|
/* Add the loop to the loop stack */
|
||||||
AddLoop (oursp, BreakLabel, ContinueLabel);
|
AddLoop (StackPtr, BreakLabel, ContinueLabel);
|
||||||
|
|
||||||
/* Define the loop label */
|
/* Define the loop label */
|
||||||
g_defcodelabel (LoopLabel);
|
g_defcodelabel (LoopLabel);
|
||||||
@@ -241,7 +241,7 @@ static void WhileStatement (void)
|
|||||||
/* Add the loop to the loop stack. In case of a while loop, the loop head
|
/* Add the loop to the loop stack. In case of a while loop, the loop head
|
||||||
* label is used for continue statements.
|
* label is used for continue statements.
|
||||||
*/
|
*/
|
||||||
AddLoop (oursp, BreakLabel, LoopLabel);
|
AddLoop (StackPtr, BreakLabel, LoopLabel);
|
||||||
|
|
||||||
/* Define the head label */
|
/* Define the head label */
|
||||||
g_defcodelabel (LoopLabel);
|
g_defcodelabel (LoopLabel);
|
||||||
@@ -283,7 +283,7 @@ static void ReturnStatement (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Evaluate the return expression */
|
/* Evaluate the return expression */
|
||||||
hie0 (InitExprDesc (&Expr));
|
hie0 (&Expr);
|
||||||
|
|
||||||
/* Ignore the return expression if the function returns void */
|
/* Ignore the return expression if the function returns void */
|
||||||
if (!F_HasVoidReturn (CurrentFunc)) {
|
if (!F_HasVoidReturn (CurrentFunc)) {
|
||||||
@@ -300,7 +300,7 @@ static void ReturnStatement (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup the stack in case we're inside a block with locals */
|
/* Cleanup the stack in case we're inside a block with locals */
|
||||||
g_space (oursp - F_GetTopLevelSP (CurrentFunc));
|
g_space (StackPtr - F_GetTopLevelSP (CurrentFunc));
|
||||||
|
|
||||||
/* Output a jump to the function exit code */
|
/* Output a jump to the function exit code */
|
||||||
g_jump (F_GetRetLab (CurrentFunc));
|
g_jump (F_GetRetLab (CurrentFunc));
|
||||||
@@ -327,7 +327,7 @@ static void BreakStatement (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Correct the stack pointer if needed */
|
/* Correct the stack pointer if needed */
|
||||||
g_space (oursp - L->StackPtr);
|
g_space (StackPtr - L->StackPtr);
|
||||||
|
|
||||||
/* Jump to the exit label of the loop */
|
/* Jump to the exit label of the loop */
|
||||||
g_jump (L->BreakLabel);
|
g_jump (L->BreakLabel);
|
||||||
@@ -362,7 +362,7 @@ static void ContinueStatement (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Correct the stackpointer if needed */
|
/* Correct the stackpointer if needed */
|
||||||
g_space (oursp - L->StackPtr);
|
g_space (StackPtr - L->StackPtr);
|
||||||
|
|
||||||
/* Jump to next loop iteration */
|
/* Jump to next loop iteration */
|
||||||
g_jump (L->ContinueLabel);
|
g_jump (L->ContinueLabel);
|
||||||
@@ -392,14 +392,14 @@ static void ForStatement (void)
|
|||||||
/* Add the loop to the loop stack. A continue jumps to the start of the
|
/* Add the loop to the loop stack. A continue jumps to the start of the
|
||||||
* the increment condition.
|
* the increment condition.
|
||||||
*/
|
*/
|
||||||
AddLoop (oursp, BreakLabel, IncLabel);
|
AddLoop (StackPtr, BreakLabel, IncLabel);
|
||||||
|
|
||||||
/* Skip the opening paren */
|
/* Skip the opening paren */
|
||||||
ConsumeLParen ();
|
ConsumeLParen ();
|
||||||
|
|
||||||
/* Parse the initializer expression */
|
/* Parse the initializer expression */
|
||||||
if (CurTok.Tok != TOK_SEMI) {
|
if (CurTok.Tok != TOK_SEMI) {
|
||||||
expression0 (&lval1);
|
Expression0 (&lval1);
|
||||||
}
|
}
|
||||||
ConsumeSemi ();
|
ConsumeSemi ();
|
||||||
|
|
||||||
@@ -424,7 +424,7 @@ static void ForStatement (void)
|
|||||||
/* Parse the increment expression */
|
/* Parse the increment expression */
|
||||||
HaveIncExpr = (CurTok.Tok != TOK_RPAREN);
|
HaveIncExpr = (CurTok.Tok != TOK_RPAREN);
|
||||||
if (HaveIncExpr) {
|
if (HaveIncExpr) {
|
||||||
expression0 (&lval3);
|
Expression0 (&lval3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Jump to the test */
|
/* Jump to the test */
|
||||||
@@ -471,7 +471,7 @@ static int CompoundStatement (void)
|
|||||||
int GotBreak;
|
int GotBreak;
|
||||||
|
|
||||||
/* Remember the stack at block entry */
|
/* Remember the stack at block entry */
|
||||||
int OldStack = oursp;
|
int OldStack = StackPtr;
|
||||||
|
|
||||||
/* Enter a new lexical level */
|
/* Enter a new lexical level */
|
||||||
EnterBlockLevel ();
|
EnterBlockLevel ();
|
||||||
@@ -491,9 +491,9 @@ static int CompoundStatement (void)
|
|||||||
|
|
||||||
/* Clean up the stack. */
|
/* Clean up the stack. */
|
||||||
if (!GotBreak) {
|
if (!GotBreak) {
|
||||||
g_space (oursp - OldStack);
|
g_space (StackPtr - OldStack);
|
||||||
}
|
}
|
||||||
oursp = OldStack;
|
StackPtr = OldStack;
|
||||||
|
|
||||||
/* Emit references to imports/exports for this block */
|
/* Emit references to imports/exports for this block */
|
||||||
EmitExternals ();
|
EmitExternals ();
|
||||||
@@ -590,7 +590,7 @@ int Statement (int* PendingToken)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
/* Actual statement */
|
/* Actual statement */
|
||||||
expression0 (&lval);
|
Expression0 (&lval);
|
||||||
CheckSemi (PendingToken);
|
CheckSemi (PendingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@@ -81,9 +81,17 @@ void SwitchStatement (void)
|
|||||||
/* Eat the "switch" token */
|
/* Eat the "switch" token */
|
||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Read the switch expression */
|
/* Read the switch expression and load it into the primary. It must have
|
||||||
|
* integer type.
|
||||||
|
*/
|
||||||
ConsumeLParen ();
|
ConsumeLParen ();
|
||||||
intexpr (&SwitchExpr);
|
Expression0 (&SwitchExpr);
|
||||||
|
if (!IsClassInt (SwitchExpr.Type)) {
|
||||||
|
Error ("Switch quantity is not an integer");
|
||||||
|
/* To avoid any compiler errors, make the expression a valid int */
|
||||||
|
ED_MakeConstAbsInt (&SwitchExpr, 1);
|
||||||
|
}
|
||||||
|
/* Load the expression into the primary register */
|
||||||
ConsumeRParen ();
|
ConsumeRParen ();
|
||||||
|
|
||||||
/* Add a jump to the switch code. This jump is usually unnecessary,
|
/* Add a jump to the switch code. This jump is usually unnecessary,
|
||||||
@@ -117,7 +125,7 @@ void SwitchStatement (void)
|
|||||||
ExitLabel = GetLocalLabel ();
|
ExitLabel = GetLocalLabel ();
|
||||||
|
|
||||||
/* Create a loop so we may use break. */
|
/* Create a loop so we may use break. */
|
||||||
AddLoop (oursp, ExitLabel, 0);
|
AddLoop (StackPtr, ExitLabel, 0);
|
||||||
|
|
||||||
/* Create the collection for the case node tree */
|
/* Create the collection for the case node tree */
|
||||||
Nodes = NewCollection ();
|
Nodes = NewCollection ();
|
||||||
@@ -137,13 +145,10 @@ void SwitchStatement (void)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Read the selector expression */
|
/* Read the selector expression */
|
||||||
ConstExpr (&CaseExpr);
|
ConstAbsIntExpr (hie1, &CaseExpr);
|
||||||
if (!IsClassInt (CaseExpr.Type)) {
|
|
||||||
Error ("Switch quantity not an integer");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check the range of the expression */
|
/* Check the range of the expression */
|
||||||
Val = CaseExpr.ConstVal;
|
Val = CaseExpr.Val;
|
||||||
switch (SwitchExprType) {
|
switch (SwitchExprType) {
|
||||||
|
|
||||||
case T_SCHAR:
|
case T_SCHAR:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2000-2003 Ullrich von Bassewitz */
|
/* (C) 2000-2004 Ullrich von Bassewitz */
|
||||||
/* R<>merstrasse 52 */
|
/* R<>merstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@@ -672,7 +672,7 @@ SymEntry* AddLocalSym (const char* Name, const type* Type, unsigned Flags, int O
|
|||||||
Entry->V.Offs = Offs;
|
Entry->V.Offs = Offs;
|
||||||
} else if ((Flags & SC_REGISTER) == SC_REGISTER) {
|
} else if ((Flags & SC_REGISTER) == SC_REGISTER) {
|
||||||
Entry->V.R.RegOffs = Offs;
|
Entry->V.R.RegOffs = Offs;
|
||||||
Entry->V.R.SaveOffs = oursp; /* ### Cleaner! */
|
Entry->V.R.SaveOffs = StackPtr; /* ### Cleaner! */
|
||||||
} else if ((Flags & SC_STATIC) == SC_STATIC) {
|
} else if ((Flags & SC_STATIC) == SC_STATIC) {
|
||||||
/* Generate the assembler name from the label number */
|
/* Generate the assembler name from the label number */
|
||||||
Entry->V.Label = Offs;
|
Entry->V.Label = Offs;
|
||||||
|
|||||||
@@ -53,26 +53,23 @@ unsigned Test (unsigned Label, int Invert)
|
|||||||
* defined above. If the jump is always true, a warning is output.
|
* defined above. If the jump is always true, a warning is output.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ExprDesc lval;
|
ExprDesc Expr;
|
||||||
unsigned Result;
|
unsigned Result;
|
||||||
|
|
||||||
/* Evaluate the expression */
|
/* Read a boolean expression */
|
||||||
expr (hie0, InitExprDesc (&lval));
|
BoolExpr (hie0, &Expr);
|
||||||
|
|
||||||
/* Check for a boolean expression */
|
|
||||||
CheckBoolExpr (&lval);
|
|
||||||
|
|
||||||
/* Check for a constant expression */
|
/* Check for a constant expression */
|
||||||
if (ED_IsRVal (&lval) && lval.Flags == E_MCONST) {
|
if (ED_IsConstAbs (&Expr)) {
|
||||||
|
|
||||||
/* Result is constant, so we know the outcome */
|
/* Result is constant, so we know the outcome */
|
||||||
Result = (lval.ConstVal != 0);
|
Result = (Expr.Val != 0);
|
||||||
|
|
||||||
/* Constant rvalue */
|
/* Constant rvalue */
|
||||||
if (!Invert && lval.ConstVal == 0) {
|
if (!Invert && Expr.Val == 0) {
|
||||||
g_jump (Label);
|
g_jump (Label);
|
||||||
Warning ("Unreachable code");
|
Warning ("Unreachable code");
|
||||||
} else if (Invert && lval.ConstVal != 0) {
|
} else if (Invert && Expr.Val != 0) {
|
||||||
g_jump (Label);
|
g_jump (Label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,12 +79,12 @@ unsigned Test (unsigned Label, int Invert)
|
|||||||
Result = TESTEXPR_UNKNOWN;
|
Result = TESTEXPR_UNKNOWN;
|
||||||
|
|
||||||
/* If the expr hasn't set condition codes, set the force-test flag */
|
/* If the expr hasn't set condition codes, set the force-test flag */
|
||||||
if ((lval.Test & E_CC) == 0) {
|
if ((Expr.Test & E_CC) == 0) {
|
||||||
lval.Test |= E_FORCETEST;
|
Expr.Test |= E_FORCETEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load the value into the primary register */
|
/* Load the value into the primary register */
|
||||||
ExprLoad (CF_FORCECHAR, &lval);
|
ExprLoad (CF_FORCECHAR, &Expr);
|
||||||
|
|
||||||
/* Generate the jump */
|
/* Generate the jump */
|
||||||
if (Invert) {
|
if (Invert) {
|
||||||
|
|||||||
@@ -118,13 +118,13 @@ static void DoConversion (ExprDesc* Expr, type* NewType)
|
|||||||
g_typecast (TypeOf (NewType), TypeOf (OldType));
|
g_typecast (TypeOf (NewType), TypeOf (OldType));
|
||||||
|
|
||||||
/* Value is now in primary and an rvalue */
|
/* Value is now in primary and an rvalue */
|
||||||
Expr->Flags = E_MEXPR | E_RVAL;
|
ED_MakeRValExpr (Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* We have an rvalue. Check for a constant. */
|
/* We have an rvalue. Check for a constant. */
|
||||||
if (Expr->Flags == E_MCONST) {
|
if (ED_IsLocAbs (Expr)) {
|
||||||
|
|
||||||
/* A cast of a constant to an integer. Be sure to handle sign
|
/* A cast of a constant to an integer. Be sure to handle sign
|
||||||
* extension correctly.
|
* extension correctly.
|
||||||
@@ -141,13 +141,13 @@ static void DoConversion (ExprDesc* Expr, type* NewType)
|
|||||||
if (NewBits <= OldBits) {
|
if (NewBits <= OldBits) {
|
||||||
|
|
||||||
/* Cut the value to the new size */
|
/* Cut the value to the new size */
|
||||||
Expr->ConstVal &= (0xFFFFFFFFUL >> (32 - NewBits));
|
Expr->Val &= (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->ConstVal & (0x01UL << (NewBits-1))) {
|
if (Expr->Val & (0x01UL << (NewBits-1))) {
|
||||||
/* Beware: Use the safe shift routine here. */
|
/* Beware: Use the safe shift routine here. */
|
||||||
Expr->ConstVal |= shl_l (~0UL, NewBits);
|
Expr->Val |= shl_l (~0UL, NewBits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,8 +166,8 @@ static void DoConversion (ExprDesc* Expr, type* NewType)
|
|||||||
/* Emit typecast code. */
|
/* Emit typecast code. */
|
||||||
g_typecast (TypeOf (NewType) | CF_FORCECHAR, TypeOf (OldType));
|
g_typecast (TypeOf (NewType) | CF_FORCECHAR, TypeOf (OldType));
|
||||||
|
|
||||||
/* Value is now a rvalie in the primary */
|
/* Value is now a rvalue in the primary */
|
||||||
Expr->Flags = E_MEXPR | E_RVAL;
|
ED_MakeRValExpr (Expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,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 (Expr->Flags != E_MCONST || Expr->ConstVal != 0) {
|
if (!ED_IsConstAbsInt (Expr) || Expr->Val != 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)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user