1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-29 10:29:30 +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

@ -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) static Type* promoteint (Type* lhst, Type* rhst)
/* In an expression with two ints, return the type of the result */ /* In an expression with two ints, return the type of the result */
{ {

View File

@ -26,6 +26,11 @@
void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr); void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr);
/* Call an expression function with checks. */ /* 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); 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
@ -41,7 +46,7 @@ void Store (ExprDesc* Expr, const Type* StoreType);
int evalexpr (unsigned flags, void (*Func) (ExprDesc*), ExprDesc* Expr); 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 Expr struct. If the
* result is not constant, LoadExpr is called to bring the value into the * result is not constant, LoadExpr is called to bring the value into the
* primary register and 1 is returned. * 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) const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
/* Return the assembler label name of the given expression. Beware: This /* 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 * function may use a static buffer, so the name may get "lost" on the second

View File

@ -45,6 +45,7 @@
#include "inline.h" #include "inline.h"
/* cc65 */ /* cc65 */
#include "asmcode.h"
#include "datatype.h" #include "datatype.h"
@ -82,7 +83,10 @@ enum {
/* Test */ /* Test */
E_NEED_TEST = 0x0400, /* Expression needs a test to set cc */ 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 */ /* Describe the result of an expression */
@ -95,8 +99,13 @@ struct ExprDesc {
long IVal; /* Integer value if expression constant */ long IVal; /* Integer value if expression constant */
Double FVal; /* Floating point value */ Double FVal; /* Floating point value */
/* Bit field stuff */
unsigned BitOffs; /* Bit offset for bit fields */ unsigned BitOffs; /* Bit offset for bit fields */
unsigned BitWidth; /* Bit width 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) # define ED_MarkAsUntested(Expr) do { (Expr)->Flags &= ~E_CC_SET; } while (0)
#endif #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); const char* ED_GetLabelName (const ExprDesc* Expr, long Offs);
/* Return the assembler label name of the given expression. Beware: This /* 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 * function may use a static buffer, so the name may get "lost" on the second