mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +00:00
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:
parent
c39022729d
commit
8d8162eb23
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2001-2003 Ullrich von Bassewitz */
|
||||
/* (C) 2001-2004 Ullrich von Bassewitz */
|
||||
/* Römerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@musoftware.de */
|
||||
@ -132,23 +132,23 @@ static void ParseByteArg (StrBuf* T, unsigned Arg)
|
||||
ConsumeComma ();
|
||||
|
||||
/* Evaluate the expression */
|
||||
ConstSubExpr (hie1, &Expr);
|
||||
ConstAbsIntExpr (hie1, &Expr);
|
||||
|
||||
/* Check the range but allow negative values if the type is signed */
|
||||
if (IsSignUnsigned (Expr.Type)) {
|
||||
if (Expr.ConstVal < 0 || Expr.ConstVal > 0xFF) {
|
||||
if (Expr.Val < 0 || Expr.Val > 0xFF) {
|
||||
AsmRangeError (Arg);
|
||||
Expr.ConstVal = 0;
|
||||
Expr.Val = 0;
|
||||
}
|
||||
} else {
|
||||
if (Expr.ConstVal < -128 || Expr.ConstVal > 127) {
|
||||
if (Expr.Val < -128 || Expr.Val > 127) {
|
||||
AsmRangeError (Arg);
|
||||
Expr.ConstVal = 0;
|
||||
Expr.Val = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
SB_AppendStr (T, Buf);
|
||||
@ -166,23 +166,23 @@ static void ParseWordArg (StrBuf* T, unsigned Arg)
|
||||
ConsumeComma ();
|
||||
|
||||
/* Evaluate the expression */
|
||||
ConstSubExpr (hie1, &Expr);
|
||||
ConstAbsIntExpr (hie1, &Expr);
|
||||
|
||||
/* Check the range but allow negative values if the type is signed */
|
||||
if (IsSignUnsigned (Expr.Type)) {
|
||||
if (Expr.ConstVal < 0 || Expr.ConstVal > 0xFFFF) {
|
||||
if (Expr.Val < 0 || Expr.Val > 0xFFFF) {
|
||||
AsmRangeError (Arg);
|
||||
Expr.ConstVal = 0;
|
||||
Expr.Val = 0;
|
||||
}
|
||||
} else {
|
||||
if (Expr.ConstVal < -32768 || Expr.ConstVal > 32767) {
|
||||
if (Expr.Val < -32768 || Expr.Val > 32767) {
|
||||
AsmRangeError (Arg);
|
||||
Expr.ConstVal = 0;
|
||||
Expr.Val = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
SB_AppendStr (T, Buf);
|
||||
@ -200,10 +200,10 @@ static void ParseLongArg (StrBuf* T, unsigned Arg attribute ((unused)))
|
||||
ConsumeComma ();
|
||||
|
||||
/* Evaluate the expression */
|
||||
ConstSubExpr (hie1, &Expr);
|
||||
ConstAbsIntExpr (hie1, &Expr);
|
||||
|
||||
/* 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 */
|
||||
SB_AppendStr (T, Buf);
|
||||
@ -265,7 +265,7 @@ static void ParseLVarArg (StrBuf* T, unsigned Arg)
|
||||
}
|
||||
|
||||
/* Calculate the current offset from SP */
|
||||
Offs = Sym->V.Offs - oursp;
|
||||
Offs = Sym->V.Offs - StackPtr;
|
||||
|
||||
/* Output the offset */
|
||||
xsprintf (Buf, sizeof (Buf), (Offs > 0xFF)? "$%04X" : "$%02X", Offs);
|
||||
@ -300,8 +300,8 @@ static void ParseStrArg (StrBuf* T, unsigned Arg attribute ((unused)))
|
||||
break;
|
||||
|
||||
default:
|
||||
ConstSubExpr (hie1, InitExprDesc (&Expr));
|
||||
xsprintf (Buf, sizeof (Buf), "%ld", Expr.ConstVal);
|
||||
ConstAbsIntExpr (hie1, &Expr);
|
||||
xsprintf (Buf, sizeof (Buf), "%ld", Expr.Val);
|
||||
SB_AppendStr (T, Buf);
|
||||
break;
|
||||
}
|
||||
|
@ -52,15 +52,15 @@
|
||||
|
||||
|
||||
|
||||
void Assignment (ExprDesc* lval)
|
||||
void Assignment (ExprDesc* Expr)
|
||||
/* Parse an assignment */
|
||||
{
|
||||
ExprDesc lval2;
|
||||
type* ltype = lval->Type;
|
||||
type* ltype = Expr->Type;
|
||||
|
||||
|
||||
/* We must have an lvalue for an assignment */
|
||||
if (ED_IsRVal (lval)) {
|
||||
if (ED_IsRVal (Expr)) {
|
||||
Error ("Invalid lvalue in assignment");
|
||||
}
|
||||
|
||||
@ -94,9 +94,9 @@ void Assignment (ExprDesc* lval)
|
||||
default: stype = ltype; UseReg = 0; break;
|
||||
}
|
||||
if (UseReg) {
|
||||
PushAddr (lval);
|
||||
PushAddr (Expr);
|
||||
} else {
|
||||
ExprLoad (CF_NONE, lval);
|
||||
ExprLoad (CF_NONE, Expr);
|
||||
g_push (CF_PTR | CF_UNSIGNED, 0);
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ void Assignment (ExprDesc* lval)
|
||||
ExprLoad (CF_FORCECHAR, &lval2);
|
||||
|
||||
/* Store it into the new location */
|
||||
Store (lval, stype);
|
||||
Store (Expr, stype);
|
||||
|
||||
} else {
|
||||
|
||||
@ -146,7 +146,7 @@ void Assignment (ExprDesc* lval)
|
||||
*/
|
||||
if (UseReg) {
|
||||
/* Do the store */
|
||||
Store (lval, stype);
|
||||
Store (Expr, stype);
|
||||
} else {
|
||||
/* Print a diagnostic */
|
||||
Error ("Structs of this size are not supported");
|
||||
@ -159,7 +159,7 @@ void Assignment (ExprDesc* lval)
|
||||
} else {
|
||||
|
||||
/* Get the address on stack if needed */
|
||||
PushAddr (lval);
|
||||
PushAddr (Expr);
|
||||
|
||||
/* Read the expression on the right side of the '=' */
|
||||
hie1 (&lval2);
|
||||
@ -171,12 +171,12 @@ void Assignment (ExprDesc* lval)
|
||||
ExprLoad (CF_NONE, &lval2);
|
||||
|
||||
/* Generate a store instruction */
|
||||
Store (lval, 0);
|
||||
Store (Expr, 0);
|
||||
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
int oursp = 0;
|
||||
int StackPtr = 0;
|
||||
|
||||
|
||||
|
||||
@ -291,7 +291,7 @@ unsigned sizeofarg (unsigned flags)
|
||||
int pop (unsigned flags)
|
||||
/* 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)
|
||||
/* 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 */
|
||||
{
|
||||
/* 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 (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 */
|
||||
{
|
||||
/* Calculate the actual stack offset and check it */
|
||||
StackOffs -= oursp;
|
||||
StackOffs -= StackPtr;
|
||||
CheckLocalOffs (StackOffs);
|
||||
|
||||
/* Generate code */
|
||||
@ -577,7 +577,7 @@ void g_save_regvars (int RegOffs, unsigned Bytes)
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
{
|
||||
/* Calculate the actual stack offset and check it */
|
||||
StackOffs -= oursp;
|
||||
StackOffs -= StackPtr;
|
||||
CheckLocalOffs (StackOffs);
|
||||
|
||||
/* 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)
|
||||
/* Fetch specified local object (local var). */
|
||||
{
|
||||
offs -= oursp;
|
||||
offs -= StackPtr;
|
||||
CheckLocalOffs (offs);
|
||||
switch (flags & CF_TYPE) {
|
||||
|
||||
@ -912,7 +912,7 @@ void g_leasp (int offs)
|
||||
/* Fetch the address of the specified symbol into the primary register */
|
||||
{
|
||||
/* Calculate the offset relative to sp */
|
||||
offs -= oursp;
|
||||
offs -= StackPtr;
|
||||
|
||||
/* For value 0 we do direct code */
|
||||
if (offs == 0) {
|
||||
@ -953,13 +953,13 @@ void g_leavariadic (int Offs)
|
||||
unsigned ArgSizeOffs;
|
||||
|
||||
/* Calculate the offset relative to sp */
|
||||
Offs -= oursp;
|
||||
Offs -= StackPtr;
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
CHECK (oursp <= 0);
|
||||
ArgSizeOffs = -oursp;
|
||||
CHECK (StackPtr <= 0);
|
||||
ArgSizeOffs = -StackPtr;
|
||||
CheckLocalOffs (ArgSizeOffs);
|
||||
|
||||
/* 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)
|
||||
/* Put data into local object. */
|
||||
{
|
||||
Offs -= oursp;
|
||||
Offs -= StackPtr;
|
||||
CheckLocalOffs (Offs);
|
||||
switch (Flags & CF_TYPE) {
|
||||
|
||||
@ -1552,7 +1552,7 @@ void g_addlocal (unsigned flags, int offs)
|
||||
unsigned L;
|
||||
|
||||
/* Correct the offset and check it */
|
||||
offs -= oursp;
|
||||
offs -= StackPtr;
|
||||
CheckLocalOffs (offs);
|
||||
|
||||
switch (flags & CF_TYPE) {
|
||||
@ -1759,7 +1759,7 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val)
|
||||
/* Emit += for a local variable */
|
||||
{
|
||||
/* Calculate the true offset, check it, load it into Y */
|
||||
offs -= oursp;
|
||||
offs -= StackPtr;
|
||||
CheckLocalOffs (offs);
|
||||
|
||||
/* 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 */
|
||||
{
|
||||
/* Calculate the true offset, check it, load it into Y */
|
||||
offs -= oursp;
|
||||
offs -= StackPtr;
|
||||
CheckLocalOffs (offs);
|
||||
|
||||
/* Check the size and determine operation */
|
||||
@ -2113,7 +2113,7 @@ void g_addaddr_local (unsigned flags attribute ((unused)), int offs)
|
||||
unsigned L = 0;
|
||||
|
||||
/* Add the offset */
|
||||
offs -= oursp;
|
||||
offs -= StackPtr;
|
||||
if (offs != 0) {
|
||||
/* We cannot address more then 256 bytes of locals anyway */
|
||||
L = GetLocalLabel();
|
||||
@ -2438,7 +2438,7 @@ void g_call (unsigned Flags, const char* Label, unsigned ArgSize)
|
||||
ldyconst (ArgSize);
|
||||
}
|
||||
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");
|
||||
} else {
|
||||
/* The address is on stack, offset is on Val */
|
||||
Offs -= oursp;
|
||||
Offs -= StackPtr;
|
||||
CheckLocalOffs (Offs);
|
||||
AddCodeLine ("pha");
|
||||
AddCodeLine ("ldy #$%02X", Offs);
|
||||
@ -2469,7 +2469,7 @@ void g_callind (unsigned Flags, unsigned ArgSize, int Offs)
|
||||
}
|
||||
|
||||
/* Callee pops args */
|
||||
oursp += ArgSize;
|
||||
StackPtr += ArgSize;
|
||||
}
|
||||
|
||||
|
||||
|
@ -86,7 +86,7 @@
|
||||
|
||||
|
||||
/* Compiler relative stackpointer */
|
||||
extern int oursp;
|
||||
extern int StackPtr;
|
||||
|
||||
/* Forward */
|
||||
struct StrBuf;
|
||||
|
@ -269,8 +269,8 @@ static void ParseEnumDecl (void)
|
||||
if (CurTok.Tok == TOK_ASSIGN) {
|
||||
ExprDesc lval;
|
||||
NextToken ();
|
||||
ConstExpr (&lval);
|
||||
EnumVal = lval.ConstVal;
|
||||
ConstAbsIntExpr (hie1, &lval);
|
||||
EnumVal = lval.Val;
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
if (CurTok.Tok != TOK_RBRACK) {
|
||||
ExprDesc lval;
|
||||
ConstExpr (&lval);
|
||||
if (lval.ConstVal <= 0) {
|
||||
ConstAbsIntExpr (hie1, &lval);
|
||||
if (lval.Val <= 0) {
|
||||
if (D->Ident[0] != '\0') {
|
||||
Error ("Size of array `%s' is invalid", D->Ident);
|
||||
} else {
|
||||
Error ("Size of array is invalid");
|
||||
}
|
||||
lval.ConstVal = 1;
|
||||
lval.Val = 1;
|
||||
}
|
||||
Size = lval.ConstVal;
|
||||
Size = lval.Val;
|
||||
}
|
||||
ConsumeRBrack ();
|
||||
|
||||
@ -1222,7 +1222,7 @@ static unsigned ParseScalarInit (type* T)
|
||||
}
|
||||
|
||||
/* Get the expression and convert it to the target type */
|
||||
ConstExpr (&ED);
|
||||
ConstExpr (hie1, &ED);
|
||||
TypeConversion (&ED, T);
|
||||
|
||||
/* Output the data */
|
||||
@ -1245,11 +1245,7 @@ static unsigned ParsePointerInit (type* T)
|
||||
|
||||
/* Expression */
|
||||
ExprDesc ED;
|
||||
ConstExpr (&ED);
|
||||
if ((ED.Flags & E_MCTYPE) == E_TCONST) {
|
||||
/* Make the const value the correct size */
|
||||
ED.ConstVal &= 0xFFFF;
|
||||
}
|
||||
ConstExpr (hie1, &ED);
|
||||
TypeConversion (&ED, T);
|
||||
|
||||
/* Output the data */
|
||||
@ -1419,7 +1415,7 @@ static unsigned ParseVoidInit (void)
|
||||
* Return the number of bytes initialized.
|
||||
*/
|
||||
{
|
||||
ExprDesc lval;
|
||||
ExprDesc Expr;
|
||||
unsigned Size;
|
||||
|
||||
/* Opening brace */
|
||||
@ -1428,16 +1424,16 @@ static unsigned ParseVoidInit (void)
|
||||
/* Allow an arbitrary list of values */
|
||||
Size = 0;
|
||||
do {
|
||||
ConstExpr (&lval);
|
||||
switch (UnqualifiedType (lval.Type[0])) {
|
||||
ConstExpr (hie1, &Expr);
|
||||
switch (UnqualifiedType (Expr.Type[0])) {
|
||||
|
||||
case T_SCHAR:
|
||||
case T_UCHAR:
|
||||
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
||||
if (ED_IsConstAbsInt (&Expr)) {
|
||||
/* Make it byte sized */
|
||||
lval.ConstVal &= 0xFF;
|
||||
Expr.Val &= 0xFF;
|
||||
}
|
||||
DefineData (&lval);
|
||||
DefineData (&Expr);
|
||||
Size += SIZEOF_CHAR;
|
||||
break;
|
||||
|
||||
@ -1447,17 +1443,21 @@ static unsigned ParseVoidInit (void)
|
||||
case T_UINT:
|
||||
case T_PTR:
|
||||
case T_ARRAY:
|
||||
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
||||
if (ED_IsConstAbsInt (&Expr)) {
|
||||
/* Make it word sized */
|
||||
lval.ConstVal &= 0xFFFF;
|
||||
Expr.Val &= 0xFFFF;
|
||||
}
|
||||
DefineData (&lval);
|
||||
DefineData (&Expr);
|
||||
Size += SIZEOF_INT;
|
||||
break;
|
||||
|
||||
case T_LONG:
|
||||
case T_ULONG:
|
||||
DefineData (&lval);
|
||||
if (ED_IsConstAbsInt (&Expr)) {
|
||||
/* Make it dword sized */
|
||||
Expr.Val &= 0xFFFFFFFF;
|
||||
}
|
||||
DefineData (&Expr);
|
||||
Size += SIZEOF_LONG;
|
||||
break;
|
||||
|
||||
@ -1527,7 +1527,7 @@ static unsigned ParseInitInternal (type* T, int AllowFlexibleMembers)
|
||||
unsigned ParseInit (type* T)
|
||||
/* Parse initialization of variables. Return the number of data bytes. */
|
||||
{
|
||||
/* Parse the initialization */
|
||||
/* Parse the initialization */
|
||||
unsigned Size = ParseInitInternal (T, !ANSI);
|
||||
|
||||
/* 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,
|
||||
* push this address on the stack. This is a helper function for all
|
||||
* sorts of implicit or explicit assignment functions where the lvalue
|
||||
* must be saved if it's not constant, before evaluating the rhs.
|
||||
*/
|
||||
|
||||
void ConstSubExpr (void (*F) (ExprDesc*), 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);
|
||||
void ExprLoad (unsigned flags, ExprDesc* Expr);
|
||||
/* 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
|
||||
* is given, use this type when storing instead of lval->Type. If StoreType
|
||||
* is NULL, use lval->Type instead.
|
||||
*/
|
||||
|
||||
void hie0 (ExprDesc *lval);
|
||||
void hie0 (ExprDesc* Expr);
|
||||
/* 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
|
||||
* 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
|
||||
* primary register and 1 is returned.
|
||||
*/
|
||||
|
||||
void expr (void (*Func) (ExprDesc*), ExprDesc *Expr);
|
||||
/* Expression parser; func is either hie0 or hie1. */
|
||||
void Expression0 (ExprDesc* Expr);
|
||||
/* Evaluate an expression via hie0 and put the result into the primary register */
|
||||
|
||||
void expression1 (ExprDesc* lval);
|
||||
/* Evaluate an expression on level 1 (no comma operator) and put it into
|
||||
* the primary register
|
||||
void ConstExpr (void (*Func) (ExprDesc*), ExprDesc* Expr);
|
||||
/* Will evaluate an expression via the given function. If the result is not
|
||||
* 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);
|
||||
/* Evaluate an expression via hie0 and put it into the primary register */
|
||||
void BoolExpr (void (*Func) (ExprDesc*), ExprDesc* Expr);
|
||||
/* 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);
|
||||
/* Get a constant value */
|
||||
|
||||
void ConstIntExpr (ExprDesc* Val);
|
||||
/* Get a constant int value */
|
||||
|
||||
void intexpr (ExprDesc* lval);
|
||||
/* Get an integer expression */
|
||||
void ConstAbsIntExpr (void (*Func) (ExprDesc*), ExprDesc* Expr);
|
||||
/* 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
|
||||
* value is replaced by a constant one to make sure there are no internal
|
||||
* errors that result from this input error.
|
||||
*/
|
||||
|
||||
void hie10 (ExprDesc* lval);
|
||||
/* 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 */
|
||||
{
|
||||
Expr->Flags = E_MCONST | E_RVAL;
|
||||
Expr->Type = type_int;
|
||||
Expr->ConstVal = Value;
|
||||
Expr->Sym = 0;
|
||||
Expr->Type = type_int;
|
||||
Expr->Val = Value;
|
||||
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
|
||||
Expr->Test = 0;
|
||||
Expr->Name = 0;
|
||||
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)
|
||||
/* Print an ExprDesc */
|
||||
{
|
||||
unsigned Flags;
|
||||
char Sep;
|
||||
|
||||
fprintf (F, "Symbol: %s\n", E->Sym? E->Sym->Name : "(none)");
|
||||
if (E->Type) {
|
||||
fprintf (F, "Type: ");
|
||||
@ -70,33 +187,64 @@ void PrintExprDesc (FILE* F, ExprDesc* E)
|
||||
fprintf (F, "Type: (unknown)\n"
|
||||
"Raw type: (unknown)\n");
|
||||
}
|
||||
fprintf (F, "Value: 0x%08lX\n", E->ConstVal);
|
||||
fprintf (F, "Flags: ");
|
||||
switch (E->Flags & E_MCTYPE) {
|
||||
case E_TCONST: fprintf (F, "E_TCONST "); break;
|
||||
case E_TGLAB: fprintf (F, "E_TGLAB "); break;
|
||||
case E_TLIT: fprintf (F, "E_TLIT "); break;
|
||||
case E_TLOFFS: fprintf (F, "E_TLOFFS "); break;
|
||||
case E_TLLAB: fprintf (F, "E_TLLAB "); break;
|
||||
case E_TREGISTER: fprintf (F, "E_TREGISTER "); break;
|
||||
default: fprintf (F, "0x%02X ", E->Flags & E_MCTYPE); break;
|
||||
fprintf (F, "Value: 0x%08lX\n", E->Val);
|
||||
|
||||
Flags = E->Flags;
|
||||
Sep = '(';
|
||||
fprintf (F, "Flags: 0x%04X ", Flags);
|
||||
if (Flags & E_LOC_ABS) {
|
||||
fprintf (F, "%cE_LOC_ABS", Sep);
|
||||
Flags &= ~E_LOC_ABS;
|
||||
Sep = ',';
|
||||
}
|
||||
if ((E->Flags & E_MREG) == E_MREG) {
|
||||
fprintf (F, "E_MREG ");
|
||||
} else if ((E->Flags & E_MEOFFS) == E_MEOFFS) {
|
||||
fprintf (F, "E_MEOFFS ");
|
||||
} else if ((E->Flags & E_MEXPR) == E_MEXPR) {
|
||||
fprintf (F, "E_MEXPR ");
|
||||
if (Flags & E_LOC_GLOBAL) {
|
||||
fprintf (F, "%cE_LOC_GLOBAL", Sep);
|
||||
Flags &= ~E_LOC_GLOBAL;
|
||||
Sep = ',';
|
||||
}
|
||||
if ((E->Flags & E_MGLOBAL) == E_MGLOBAL) {
|
||||
fprintf (F, "E_MGLOBAL ");
|
||||
if (Flags & E_LOC_STATIC) {
|
||||
fprintf (F, "%cE_LOC_STATIC", Sep);
|
||||
Flags &= ~E_LOC_STATIC;
|
||||
Sep = ',';
|
||||
}
|
||||
if ((E->Flags & E_MLOCAL) == E_MLOCAL) {
|
||||
fprintf (F, "E_MLOCAL ");
|
||||
if (Flags & E_LOC_REGISTER) {
|
||||
fprintf (F, "%cE_LOC_REGISTER", Sep);
|
||||
Flags &= ~E_LOC_REGISTER;
|
||||
Sep = ',';
|
||||
}
|
||||
if ((E->Flags & E_MCONST) == E_MCONST) {
|
||||
fprintf (F, "E_MCONST ");
|
||||
if (Flags & E_LOC_STACK) {
|
||||
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: ");
|
||||
if (E->Test & E_CC) {
|
||||
|
@ -55,37 +55,41 @@
|
||||
|
||||
|
||||
/* Defines for the flags field of the expression descriptor */
|
||||
#define E_MREG 0x0110U /* Special: Expression is primary register */
|
||||
#define E_MGLOBAL 0x0080U /* Reference to static variable */
|
||||
#define E_MLOCAL 0x0040U /* Reference to local variable (stack offset) */
|
||||
#define E_MCONST 0x0020U /* Constant value */
|
||||
#define E_MEXPR 0x0010U /* Result is in primary register */
|
||||
#define E_MEOFFS 0x0011U /* Base is in primary register, const offset */
|
||||
enum {
|
||||
/* Location: Where is the value we're talking about? */
|
||||
E_MASK_LOC = 0x00FF,
|
||||
E_LOC_ABS = 0x0001, /* Absolute: numeric address or const */
|
||||
E_LOC_GLOBAL = 0x0002, /* Global variable */
|
||||
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 */
|
||||
#define E_TCONST 0x0000U /* Constant */
|
||||
#define E_TGLAB 0x0001U /* Global label */
|
||||
#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 */
|
||||
/* Constant location of some sort (only if rval) */
|
||||
E_LOC_CONST = E_LOC_ABS | E_LOC_GLOBAL | E_LOC_STATIC |
|
||||
E_LOC_REGISTER | E_LOC_LITERAL,
|
||||
|
||||
#define E_RVAL 0x0000U /* Expression node is a value */
|
||||
#define E_LVAL 0x1000U /* Expression node is a reference */
|
||||
/* Reference? */
|
||||
E_MASK_RTYPE = 0x8000,
|
||||
E_RTYPE_RVAL = 0x0000,
|
||||
E_RTYPE_LVAL = 0x8000
|
||||
};
|
||||
|
||||
/* Defines for the test field of the expression descriptor */
|
||||
#define E_CC 0x0001U /* expr has set cond codes apropos result value */
|
||||
#define E_FORCETEST 0x0002U /* if expr has NOT set CC, force a test */
|
||||
#define E_CC 0x0001U /* Condition codes are set */
|
||||
#define E_FORCETEST 0x0002U /* Force test to set condition codes */
|
||||
|
||||
/* Describe the result of an expression */
|
||||
typedef struct ExprDesc ExprDesc;
|
||||
struct ExprDesc {
|
||||
struct SymEntry* Sym; /* Symbol table entry if known */
|
||||
type* Type; /* Type array of expression */
|
||||
long ConstVal;/* Value if expression constant */
|
||||
struct SymEntry* Sym; /* Symbol table entry if known */
|
||||
type* Type; /* Type array of expression */
|
||||
long Val; /* Value if expression constant */
|
||||
unsigned short Flags;
|
||||
unsigned short Test; /* */
|
||||
unsigned long Name; /* Name or label number */
|
||||
unsigned short Test; /* */
|
||||
unsigned long Name; /* Name or label number */
|
||||
};
|
||||
|
||||
|
||||
@ -96,73 +100,137 @@ struct ExprDesc {
|
||||
|
||||
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE ExprDesc* InitExprDesc (ExprDesc* Expr)
|
||||
ExprDesc* ED_Init (ExprDesc* Expr);
|
||||
/* 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
|
||||
# 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
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int ED_IsLVal (const ExprDesc* Expr)
|
||||
/* Return true if the expression is a reference */
|
||||
{
|
||||
return (Expr->Flags & E_LVAL) != 0;
|
||||
return (Expr->Flags & E_MASK_RTYPE) == E_RTYPE_LVAL;
|
||||
}
|
||||
#else
|
||||
# define ED_IsLVal(Expr) (((Expr)->Flags & E_LVAL) != 0)
|
||||
# define ED_IsLVal(Expr) (((Expr)->Flags & E_MASK_RTYPE) == E_RTYPE_LVAL)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int ED_IsRVal (const ExprDesc* Expr)
|
||||
/* Return true if the expression is a rvalue */
|
||||
{
|
||||
return (Expr->Flags & E_LVAL) == 0;
|
||||
return (Expr->Flags & E_MASK_RTYPE) == E_RTYPE_RVAL;
|
||||
}
|
||||
#else
|
||||
# define ED_IsRVal(Expr) (((Expr)->Flags & E_LVAL) == 0)
|
||||
# define ED_IsRVal(Expr) (((Expr)->Flags & E_MASK_RTYPE) == E_RTYPE_RVAL)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int ED_SetValType (ExprDesc* Expr, int Ref)
|
||||
/* Set the reference flag for an expression and return it (the flag) */
|
||||
INLINE void ED_MakeLVal (ExprDesc* Expr)
|
||||
/* Make the expression a lvalue. */
|
||||
{
|
||||
Expr->Flags = Ref? (Expr->Flags | E_LVAL) : (Expr->Flags & ~E_LVAL);
|
||||
return Ref;
|
||||
Expr->Flags |= E_RTYPE_LVAL;
|
||||
}
|
||||
#else
|
||||
/* Beware: Just one occurance of R below, since it may have side effects! */
|
||||
# define ED_SetValType(E, R) \
|
||||
(((E)->Flags = (R)? ((E)->Flags | E_LVAL) : ((E)->Flags & ~E_LVAL)), \
|
||||
ED_IsLVal (E))
|
||||
# define ED_MakeLVal(Expr) do { (Expr)->Flags |= R_RTYPE_LVAL; } while (0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int ED_MakeLVal (ExprDesc* Expr)
|
||||
/* Make the expression a lvalue and return true */
|
||||
INLINE void ED_MakeRVal (ExprDesc* Expr)
|
||||
/* Make the expression a rvalue. */
|
||||
{
|
||||
return ED_SetValType (Expr, 1);
|
||||
Expr->Flags &= ~E_RTYPE_LVAL;
|
||||
}
|
||||
#else
|
||||
# define ED_MakeLVal(Expr) ED_SetValType (Expr, 1)
|
||||
# define ED_MakeRVal(Expr) do { (Expr)->Flags &= ~E_RTYPE_LVAL; } while (0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int ED_MakeRVal (ExprDesc* Expr)
|
||||
/* 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_MakeConstAbs (ExprDesc* Expr, long Value, type* Type);
|
||||
/* Make Expr an absolute const with the given value and type. */
|
||||
|
||||
ExprDesc* ED_MakeConstInt (ExprDesc* Expr, long Value);
|
||||
ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long 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);
|
||||
/* Print an ExprDesc */
|
||||
|
||||
|
@ -197,7 +197,7 @@ int F_ReserveLocalSpace (Function* F, unsigned 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);
|
||||
|
||||
/* Correct the stack pointer */
|
||||
oursp -= F->Reserved;
|
||||
StackPtr -= F->Reserved;
|
||||
|
||||
/* Nothing more reserved */
|
||||
F->Reserved = 0;
|
||||
@ -408,7 +408,7 @@ void NewFunc (SymEntry* Func)
|
||||
}
|
||||
|
||||
/* Setup the stack */
|
||||
oursp = 0;
|
||||
StackPtr = 0;
|
||||
|
||||
/* Walk through the parameter list and allocate register variable space
|
||||
* 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
|
||||
* must be dropped when doing a return from an inner block.
|
||||
*/
|
||||
CurrentFunc->TopLevelSP = oursp;
|
||||
CurrentFunc->TopLevelSP = StackPtr;
|
||||
|
||||
/* Now process statements in this block */
|
||||
HadReturn = 0;
|
||||
|
@ -78,7 +78,7 @@ static unsigned ParseRegisterDecl (Declaration* Decl, unsigned* SC, int Reg)
|
||||
/* Check for an optional initialization */
|
||||
if (CurTok.Tok == TOK_ASSIGN) {
|
||||
|
||||
ExprDesc lval;
|
||||
ExprDesc Expr;
|
||||
|
||||
/* Skip the '=' */
|
||||
NextToken ();
|
||||
@ -111,13 +111,13 @@ static unsigned ParseRegisterDecl (Declaration* Decl, unsigned* SC, int Reg)
|
||||
} else {
|
||||
|
||||
/* Parse the expression */
|
||||
hie1 (InitExprDesc (&lval));
|
||||
hie1 (&Expr);
|
||||
|
||||
/* Convert it to the target type */
|
||||
TypeConversion (&lval, Decl->Type);
|
||||
TypeConversion (&Expr, Decl->Type);
|
||||
|
||||
/* Load the value into the primary */
|
||||
ExprLoad (CF_NONE, &lval);
|
||||
ExprLoad (CF_NONE, &Expr);
|
||||
|
||||
/* Store the value into the variable */
|
||||
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 */
|
||||
if (CurTok.Tok == TOK_ASSIGN) {
|
||||
|
||||
ExprDesc lval;
|
||||
ExprDesc Expr;
|
||||
|
||||
/* Skip the '=' */
|
||||
NextToken ();
|
||||
@ -207,23 +207,23 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
||||
Flags = (Size == SIZEOF_CHAR)? CF_FORCECHAR : CF_NONE;
|
||||
|
||||
/* Parse the expression */
|
||||
hie1 (InitExprDesc (&lval));
|
||||
hie1 (&Expr);
|
||||
|
||||
/* 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.
|
||||
* Otherwise pass the information to the code generator.
|
||||
*/
|
||||
if (ED_IsLVal (&lval) || lval.Flags != E_MCONST) {
|
||||
ExprLoad (CF_NONE, &lval);
|
||||
ED_MakeRVal (&lval);
|
||||
} else {
|
||||
*/
|
||||
if (ED_IsConstAbsInt (&Expr)) {
|
||||
Flags |= CF_CONST;
|
||||
} else {
|
||||
ExprLoad (CF_NONE, &Expr);
|
||||
ED_MakeRVal (&Expr);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Variable is located at the current SP */
|
||||
SymData = oursp;
|
||||
SymData = StackPtr;
|
||||
|
||||
} else {
|
||||
/* Non-initialized local variable. Just keep track of
|
||||
@ -258,7 +258,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
||||
/* Allow assignments */
|
||||
if (CurTok.Tok == TOK_ASSIGN) {
|
||||
|
||||
ExprDesc lval;
|
||||
ExprDesc Expr;
|
||||
|
||||
/* Skip the '=' */
|
||||
NextToken ();
|
||||
@ -283,13 +283,13 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
||||
} else {
|
||||
|
||||
/* Parse the expression */
|
||||
hie1 (InitExprDesc (&lval));
|
||||
hie1 (&Expr);
|
||||
|
||||
/* Convert it to the target type */
|
||||
TypeConversion (&lval, Decl->Type);
|
||||
TypeConversion (&Expr, Decl->Type);
|
||||
|
||||
/* Load the value into the primary */
|
||||
ExprLoad (CF_NONE, &lval);
|
||||
ExprLoad (CF_NONE, &Expr);
|
||||
|
||||
/* Store the value into the variable */
|
||||
g_putstatic (TypeOf (Decl->Type), SymData, 0);
|
||||
@ -447,7 +447,7 @@ void DeclareLocals (void)
|
||||
/* Declare local variables and types. */
|
||||
{
|
||||
/* Remember the current stack pointer */
|
||||
int InitialStack = oursp;
|
||||
int InitialStack = StackPtr;
|
||||
|
||||
/* Loop until we don't find any more variables */
|
||||
while (1) {
|
||||
@ -501,7 +501,7 @@ void DeclareLocals (void)
|
||||
/* In case we've allocated local variables in this block, emit a call to
|
||||
* the stack checking routine if stack checks are enabled.
|
||||
*/
|
||||
if (IS_Get (&CheckStack) && InitialStack != oursp) {
|
||||
if (IS_Get (&CheckStack) && InitialStack != StackPtr) {
|
||||
g_cstackcheck ();
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,6 @@ OBJS = anonname.o \
|
||||
error.o \
|
||||
expr.o \
|
||||
exprdesc.o \
|
||||
exprheap.o \
|
||||
exprnode.o \
|
||||
funcdesc.o \
|
||||
function.o \
|
||||
|
@ -90,7 +90,6 @@ OBJS = anonname.obj \
|
||||
error.obj \
|
||||
expr.obj \
|
||||
exprdesc.obj \
|
||||
exprheap.obj \
|
||||
exprnode.obj \
|
||||
funcdesc.obj \
|
||||
function.obj \
|
||||
|
@ -804,7 +804,7 @@ static int DoIf (int Skip)
|
||||
NextToken ();
|
||||
|
||||
/* Call the expression parser */
|
||||
ConstExpr (&lval);
|
||||
ConstExpr (hie1, &lval);
|
||||
|
||||
/* End preprocessing mode */
|
||||
Preprocessing = 0;
|
||||
@ -814,7 +814,7 @@ static int DoIf (int Skip)
|
||||
NextTok = sv2;
|
||||
|
||||
/* 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 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -117,23 +117,21 @@ static unsigned ParseArg (type* Type, ExprDesc* Arg)
|
||||
unsigned Flags = CF_FORCECHAR;
|
||||
|
||||
/* Read the expression we're going to pass to the function */
|
||||
hie1 (InitExprDesc (Arg));
|
||||
hie1 (Arg);
|
||||
|
||||
/* Convert this expression to the expected type */
|
||||
TypeConversion (Arg, Type);
|
||||
|
||||
/* If the value is not a constant, load it into the primary */
|
||||
if (ED_IsLVal (Arg) || Arg->Flags != E_MCONST) {
|
||||
|
||||
/* If the value is a constant, set the flag, otherwise load it into the
|
||||
* primary register.
|
||||
*/
|
||||
if (ED_IsConstAbsInt (Arg)) {
|
||||
/* Remember that we have a constant value */
|
||||
Flags |= CF_CONST;
|
||||
} else {
|
||||
/* Load into the primary */
|
||||
ExprLoad (CF_NONE, Arg);
|
||||
ED_MakeRVal (Arg);
|
||||
|
||||
} else {
|
||||
|
||||
/* Remember that we have a constant value */
|
||||
Flags |= CF_CONST;
|
||||
|
||||
}
|
||||
|
||||
/* Use the type of the argument for the push */
|
||||
@ -164,7 +162,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)),
|
||||
|
||||
/* Argument #1 */
|
||||
Flags = ParseArg (Arg1Type, &Arg);
|
||||
g_push (Flags, Arg.ConstVal);
|
||||
g_push (Flags, Arg.Val);
|
||||
ParamSize += SizeOf (Arg1Type);
|
||||
ConsumeComma ();
|
||||
|
||||
@ -172,12 +170,12 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)),
|
||||
* function if it is a constant zero.
|
||||
*/
|
||||
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 */
|
||||
MemSet = 0;
|
||||
} else {
|
||||
/* Push the argument */
|
||||
g_push (Flags, Arg.ConstVal);
|
||||
g_push (Flags, Arg.Val);
|
||||
ParamSize += SizeOf (Arg2Type);
|
||||
}
|
||||
ConsumeComma ();
|
||||
@ -189,7 +187,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)),
|
||||
*/
|
||||
Flags = ParseArg (Arg3Type, &Arg);
|
||||
if (Flags & CF_CONST) {
|
||||
if (Arg.ConstVal == 0) {
|
||||
if (Arg.Val == 0) {
|
||||
Warning ("Call to memset has no effect");
|
||||
}
|
||||
ExprLoad (CF_FORCECHAR, &Arg);
|
||||
@ -217,7 +215,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)),
|
||||
ParamType[1] = GetDefaultChar () | T_QUAL_CONST;
|
||||
|
||||
/* Fetch the parameter and convert it to the type needed */
|
||||
hie1 (InitExprDesc (&Param));
|
||||
hie1 (&Param);
|
||||
TypeConversion (&Param, ParamType);
|
||||
|
||||
/* 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;
|
||||
ParamName = Param.Name;
|
||||
if ((IsTypeArray (Param.Type) && (Param.Flags & E_MCONST) != 0) ||
|
||||
(IsTypePtr (Param.Type) && Param.Flags == (E_MCONST | E_TCONST))) {
|
||||
if ((ED_IsLocConst (&Param) && IsTypeArray (Param.Type)) ||
|
||||
(ED_IsLocAbs (&Param) && IsTypePtr (Param.Type))) {
|
||||
|
||||
/* 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 */
|
||||
CodeFlags |= CF_CONST | CF_ABSOLUTE;
|
||||
break;
|
||||
|
||||
case E_TREGISTER:
|
||||
/* Register variable */
|
||||
CodeFlags |= CF_CONST | CF_REGVAR;
|
||||
break;
|
||||
|
||||
case E_TGLAB:
|
||||
case E_LOC_GLOBAL:
|
||||
/* Global label */
|
||||
CodeFlags |= CF_CONST | CF_EXTERNAL;
|
||||
break;
|
||||
|
||||
case E_TLLAB:
|
||||
case E_LOC_STATIC:
|
||||
/* Local symbol */
|
||||
CodeFlags |= CF_CONST | CF_STATIC;
|
||||
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,
|
||||
* we can calculate the length of the string and remove it
|
||||
* from the literal pool. Otherwise we have to calculate the
|
||||
@ -260,8 +258,8 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)),
|
||||
if (!WriteableStrings) {
|
||||
/* String literals are const */
|
||||
ExprDesc Length;
|
||||
ED_MakeConstInt (&Length, strlen (GetLiteral (Param.ConstVal)));
|
||||
ResetLiteralPoolOffs (Param.ConstVal);
|
||||
ED_MakeConstAbsInt (&Length, strlen (GetLiteral (Param.Val)));
|
||||
ResetLiteralPoolOffs (Param.Val);
|
||||
ExprLoad (CF_NONE, &Length);
|
||||
goto ExitPoint;
|
||||
} else {
|
||||
@ -282,7 +280,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)),
|
||||
}
|
||||
|
||||
/* Generate the strlen code */
|
||||
g_strlen (CodeFlags, ParamName, Param.ConstVal);
|
||||
g_strlen (CodeFlags, ParamName, Param.Val);
|
||||
|
||||
ExitPoint:
|
||||
/* We expect the closing brace */
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||
/* Römerstraße 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -201,7 +201,7 @@ static void DoStatement (void)
|
||||
NextToken ();
|
||||
|
||||
/* Add the loop to the loop stack */
|
||||
AddLoop (oursp, BreakLabel, ContinueLabel);
|
||||
AddLoop (StackPtr, BreakLabel, ContinueLabel);
|
||||
|
||||
/* Define the loop label */
|
||||
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
|
||||
* label is used for continue statements.
|
||||
*/
|
||||
AddLoop (oursp, BreakLabel, LoopLabel);
|
||||
AddLoop (StackPtr, BreakLabel, LoopLabel);
|
||||
|
||||
/* Define the head label */
|
||||
g_defcodelabel (LoopLabel);
|
||||
@ -283,7 +283,7 @@ static void ReturnStatement (void)
|
||||
}
|
||||
|
||||
/* Evaluate the return expression */
|
||||
hie0 (InitExprDesc (&Expr));
|
||||
hie0 (&Expr);
|
||||
|
||||
/* Ignore the return expression if the function returns void */
|
||||
if (!F_HasVoidReturn (CurrentFunc)) {
|
||||
@ -300,7 +300,7 @@ static void ReturnStatement (void)
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
g_jump (F_GetRetLab (CurrentFunc));
|
||||
@ -327,7 +327,7 @@ static void BreakStatement (void)
|
||||
}
|
||||
|
||||
/* Correct the stack pointer if needed */
|
||||
g_space (oursp - L->StackPtr);
|
||||
g_space (StackPtr - L->StackPtr);
|
||||
|
||||
/* Jump to the exit label of the loop */
|
||||
g_jump (L->BreakLabel);
|
||||
@ -362,7 +362,7 @@ static void ContinueStatement (void)
|
||||
}
|
||||
|
||||
/* Correct the stackpointer if needed */
|
||||
g_space (oursp - L->StackPtr);
|
||||
g_space (StackPtr - L->StackPtr);
|
||||
|
||||
/* Jump to next loop iteration */
|
||||
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
|
||||
* the increment condition.
|
||||
*/
|
||||
AddLoop (oursp, BreakLabel, IncLabel);
|
||||
AddLoop (StackPtr, BreakLabel, IncLabel);
|
||||
|
||||
/* Skip the opening paren */
|
||||
ConsumeLParen ();
|
||||
|
||||
/* Parse the initializer expression */
|
||||
if (CurTok.Tok != TOK_SEMI) {
|
||||
expression0 (&lval1);
|
||||
Expression0 (&lval1);
|
||||
}
|
||||
ConsumeSemi ();
|
||||
|
||||
@ -424,7 +424,7 @@ static void ForStatement (void)
|
||||
/* Parse the increment expression */
|
||||
HaveIncExpr = (CurTok.Tok != TOK_RPAREN);
|
||||
if (HaveIncExpr) {
|
||||
expression0 (&lval3);
|
||||
Expression0 (&lval3);
|
||||
}
|
||||
|
||||
/* Jump to the test */
|
||||
@ -471,7 +471,7 @@ static int CompoundStatement (void)
|
||||
int GotBreak;
|
||||
|
||||
/* Remember the stack at block entry */
|
||||
int OldStack = oursp;
|
||||
int OldStack = StackPtr;
|
||||
|
||||
/* Enter a new lexical level */
|
||||
EnterBlockLevel ();
|
||||
@ -491,9 +491,9 @@ static int CompoundStatement (void)
|
||||
|
||||
/* Clean up the stack. */
|
||||
if (!GotBreak) {
|
||||
g_space (oursp - OldStack);
|
||||
g_space (StackPtr - OldStack);
|
||||
}
|
||||
oursp = OldStack;
|
||||
StackPtr = OldStack;
|
||||
|
||||
/* Emit references to imports/exports for this block */
|
||||
EmitExternals ();
|
||||
@ -590,7 +590,7 @@ int Statement (int* PendingToken)
|
||||
|
||||
default:
|
||||
/* Actual statement */
|
||||
expression0 (&lval);
|
||||
Expression0 (&lval);
|
||||
CheckSemi (PendingToken);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -81,9 +81,17 @@ void SwitchStatement (void)
|
||||
/* Eat the "switch" token */
|
||||
NextToken ();
|
||||
|
||||
/* Read the switch expression */
|
||||
/* Read the switch expression and load it into the primary. It must have
|
||||
* integer type.
|
||||
*/
|
||||
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 ();
|
||||
|
||||
/* Add a jump to the switch code. This jump is usually unnecessary,
|
||||
@ -117,7 +125,7 @@ void SwitchStatement (void)
|
||||
ExitLabel = GetLocalLabel ();
|
||||
|
||||
/* Create a loop so we may use break. */
|
||||
AddLoop (oursp, ExitLabel, 0);
|
||||
AddLoop (StackPtr, ExitLabel, 0);
|
||||
|
||||
/* Create the collection for the case node tree */
|
||||
Nodes = NewCollection ();
|
||||
@ -137,13 +145,10 @@ void SwitchStatement (void)
|
||||
NextToken ();
|
||||
|
||||
/* Read the selector expression */
|
||||
ConstExpr (&CaseExpr);
|
||||
if (!IsClassInt (CaseExpr.Type)) {
|
||||
Error ("Switch quantity not an integer");
|
||||
}
|
||||
ConstAbsIntExpr (hie1, &CaseExpr);
|
||||
|
||||
/* Check the range of the expression */
|
||||
Val = CaseExpr.ConstVal;
|
||||
Val = CaseExpr.Val;
|
||||
switch (SwitchExprType) {
|
||||
|
||||
case T_SCHAR:
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2000-2003 Ullrich von Bassewitz */
|
||||
/* (C) 2000-2004 Ullrich von Bassewitz */
|
||||
/* Römerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -672,7 +672,7 @@ SymEntry* AddLocalSym (const char* Name, const type* Type, unsigned Flags, int O
|
||||
Entry->V.Offs = Offs;
|
||||
} else if ((Flags & SC_REGISTER) == SC_REGISTER) {
|
||||
Entry->V.R.RegOffs = Offs;
|
||||
Entry->V.R.SaveOffs = oursp; /* ### Cleaner! */
|
||||
Entry->V.R.SaveOffs = StackPtr; /* ### Cleaner! */
|
||||
} else if ((Flags & SC_STATIC) == SC_STATIC) {
|
||||
/* Generate the assembler name from the label number */
|
||||
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.
|
||||
*/
|
||||
{
|
||||
ExprDesc lval;
|
||||
ExprDesc Expr;
|
||||
unsigned Result;
|
||||
|
||||
/* Evaluate the expression */
|
||||
expr (hie0, InitExprDesc (&lval));
|
||||
|
||||
/* Check for a boolean expression */
|
||||
CheckBoolExpr (&lval);
|
||||
/* Read a boolean expression */
|
||||
BoolExpr (hie0, &Expr);
|
||||
|
||||
/* 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 = (lval.ConstVal != 0);
|
||||
Result = (Expr.Val != 0);
|
||||
|
||||
/* Constant rvalue */
|
||||
if (!Invert && lval.ConstVal == 0) {
|
||||
if (!Invert && Expr.Val == 0) {
|
||||
g_jump (Label);
|
||||
Warning ("Unreachable code");
|
||||
} else if (Invert && lval.ConstVal != 0) {
|
||||
} else if (Invert && Expr.Val != 0) {
|
||||
g_jump (Label);
|
||||
}
|
||||
|
||||
@ -82,12 +79,12 @@ unsigned Test (unsigned Label, int Invert)
|
||||
Result = TESTEXPR_UNKNOWN;
|
||||
|
||||
/* If the expr hasn't set condition codes, set the force-test flag */
|
||||
if ((lval.Test & E_CC) == 0) {
|
||||
lval.Test |= E_FORCETEST;
|
||||
if ((Expr.Test & E_CC) == 0) {
|
||||
Expr.Test |= E_FORCETEST;
|
||||
}
|
||||
|
||||
/* Load the value into the primary register */
|
||||
ExprLoad (CF_FORCECHAR, &lval);
|
||||
ExprLoad (CF_FORCECHAR, &Expr);
|
||||
|
||||
/* Generate the jump */
|
||||
if (Invert) {
|
||||
|
@ -118,13 +118,13 @@ static void DoConversion (ExprDesc* Expr, type* NewType)
|
||||
g_typecast (TypeOf (NewType), TypeOf (OldType));
|
||||
|
||||
/* Value is now in primary and an rvalue */
|
||||
Expr->Flags = E_MEXPR | E_RVAL;
|
||||
ED_MakeRValExpr (Expr);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/* 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
|
||||
* extension correctly.
|
||||
@ -141,13 +141,13 @@ static void DoConversion (ExprDesc* Expr, type* NewType)
|
||||
if (NewBits <= OldBits) {
|
||||
|
||||
/* 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 (!IsSignUnsigned (NewType)) {
|
||||
if (Expr->ConstVal & (0x01UL << (NewBits-1))) {
|
||||
if (Expr->Val & (0x01UL << (NewBits-1))) {
|
||||
/* 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. */
|
||||
g_typecast (TypeOf (NewType) | CF_FORCECHAR, TypeOf (OldType));
|
||||
|
||||
/* Value is now a rvalie in the primary */
|
||||
Expr->Flags = E_MEXPR | E_RVAL;
|
||||
/* Value is now a rvalue in the primary */
|
||||
ED_MakeRValExpr (Expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -237,7 +237,7 @@ void TypeConversion (ExprDesc* Expr, type* NewType)
|
||||
}
|
||||
} else if (IsClassInt (Expr->Type)) {
|
||||
/* 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");
|
||||
}
|
||||
} else if (IsTypeFuncPtr (NewType) && IsTypeFunc(Expr->Type)) {
|
||||
|
Loading…
Reference in New Issue
Block a user