1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-18 07:29:36 +00:00

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
This commit is contained in:
uz 2009-09-08 19:48:22 +00:00
parent 7d60d32aee
commit 0c20177fce
4 changed files with 62 additions and 7 deletions

View File

@ -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 */
{

View File

@ -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.
*/

View File

@ -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);

View File

@ -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