From: uz Date: Tue, 8 Sep 2009 19:48:22 +0000 (+0000) Subject: Allow to store start and end of generated code in the ExprDesc structure. New X-Git-Tag: V2.13.0rc1~121 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0c20177fce7256c342f55166594b4693d4e3e796;p=cc65 Allow to store start and end of generated code in the ExprDesc structure. New function MarkedExprWithCheck. git-svn-id: svn://svn.cc65.org/cc65/trunk@4135 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 9dd6afe8d..7f30bb11b 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -71,7 +71,7 @@ static GenDesc GenOASGN = { TOK_OR_ASSIGN, GEN_NOPUSH, g_or }; /*****************************************************************************/ -/* Helper functions */ +/* Helper functions */ /*****************************************************************************/ @@ -97,7 +97,7 @@ static unsigned GlobalModeFlags (const ExprDesc* Expr) -void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc *Expr) +void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr) /* Call an expression function with checks. */ { /* Remember the stack pointer */ @@ -121,6 +121,20 @@ void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc *Expr) +void MarkedExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr) +/* Call an expression function with checks and record start and end of the + * generated code. + */ +{ + CodeMark Start, End; + GetCodePos (&Start); + ExprWithCheck (Func, Expr); + GetCodePos (&End); + ED_SetCodeRange (Expr, &Start, &End); +} + + + static Type* promoteint (Type* lhst, Type* rhst) /* In an expression with two ints, return the type of the result */ { diff --git a/src/cc65/expr.h b/src/cc65/expr.h index ef5762939..c98074356 100644 --- a/src/cc65/expr.h +++ b/src/cc65/expr.h @@ -23,9 +23,14 @@ -void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc *Expr); +void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr); /* Call an expression function with checks. */ +void MarkedExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr); +/* Call an expression function with checks and record start and end of the + * generated code. + */ + 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 @@ -41,7 +46,7 @@ void Store (ExprDesc* Expr, const Type* StoreType); 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 + * constant, 0 is returned and the value is put in the Expr struct. If the * result is not constant, LoadExpr is called to bring the value into the * primary register and 1 is returned. */ diff --git a/src/cc65/exprdesc.c b/src/cc65/exprdesc.c index 6726a2cf1..7881f3524 100644 --- a/src/cc65/exprdesc.c +++ b/src/cc65/exprdesc.c @@ -80,6 +80,27 @@ void ED_MakeBitField (ExprDesc* Expr, unsigned BitOffs, unsigned BitWidth) +void ED_SetCodeRange (ExprDesc* Expr, const CodeMark* Start, const CodeMark* End) +/* Set the code range for this expression */ +{ + Expr->Flags |= E_HAVE_MARKS; + Expr->Start = *Start; + Expr->End = *End; +} + + + +int ED_CodeRangeIsEmpty (const ExprDesc* Expr) +/* Return true if no code was output for this expression */ +{ + /* We must have code marks */ + PRECONDITION (Expr->Flags & E_HAVE_MARKS); + + return CodeRangeIsEmpty (&Expr->Start, &Expr->End); +} + + + const char* ED_GetLabelName (const ExprDesc* Expr, long Offs) /* Return the assembler label name of the given expression. Beware: This * function may use a static buffer, so the name may get "lost" on the second @@ -229,7 +250,7 @@ int ED_IsConstAbsInt (const ExprDesc* Expr) 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_BITFIELD)) == + return (Expr->Flags & (E_MASK_LOC|E_MASK_RTYPE|E_BITFIELD)) == (E_LOC_ABS|E_RTYPE_RVAL) && Expr->IVal == 0 && IsClassInt (Expr->Type); diff --git a/src/cc65/exprdesc.h b/src/cc65/exprdesc.h index 6091f1597..9de064952 100644 --- a/src/cc65/exprdesc.h +++ b/src/cc65/exprdesc.h @@ -45,6 +45,7 @@ #include "inline.h" /* cc65 */ +#include "asmcode.h" #include "datatype.h" @@ -82,7 +83,10 @@ enum { /* Test */ E_NEED_TEST = 0x0400, /* Expression needs a test to set cc */ - E_CC_SET = 0x0800 /* Condition codes are set */ + E_CC_SET = 0x0800, /* Condition codes are set */ + + E_HAVE_MARKS = 0x1000, /* Code marks are valid */ + }; /* Describe the result of an expression */ @@ -91,12 +95,17 @@ struct ExprDesc { struct SymEntry* Sym; /* Symbol table entry if known */ Type* Type; /* Type array of expression */ unsigned Flags; - unsigned long Name; /* Name or label number */ + unsigned long Name; /* Name or label number */ long IVal; /* Integer value if expression constant */ Double FVal; /* Floating point value */ + /* Bit field stuff */ unsigned BitOffs; /* Bit offset for bit fields */ unsigned BitWidth; /* Bit width for bit fields */ + + /* Start and end of generated code */ + CodeMark Start; + CodeMark End; }; @@ -294,6 +303,12 @@ INLINE void ED_MarkAsUntested (ExprDesc* Expr) # define ED_MarkAsUntested(Expr) do { (Expr)->Flags &= ~E_CC_SET; } while (0) #endif +void ED_SetCodeRange (ExprDesc* Expr, const CodeMark* Start, const CodeMark* End); +/* Set the code range for this expression */ + +int ED_CodeRangeIsEmpty (const ExprDesc* Expr); +/* Return true if no code was output for this expression */ + const char* ED_GetLabelName (const ExprDesc* Expr, long Offs); /* Return the assembler label name of the given expression. Beware: This * function may use a static buffer, so the name may get "lost" on the second