X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fexprdesc.h;h=f2d5ce3220e7e875e97d28029faeb8c71c2f6a56;hb=1bcd4b44f84d322871ac774dff831d6524733f21;hp=420f86b6cde75dcf78f506cadfa86992c27c125f;hpb=1ec972d0c4657942ca842d0457f0a1a8c1ebdd01;p=cc65 diff --git a/src/cc65/exprdesc.h b/src/cc65/exprdesc.h index 420f86b6c..f2d5ce322 100644 --- a/src/cc65/exprdesc.h +++ b/src/cc65/exprdesc.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2002-2004 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2002-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -41,15 +41,17 @@ #include /* common */ +#include "fp.h" #include "inline.h" /* cc65 */ +#include "asmcode.h" #include "datatype.h" /*****************************************************************************/ -/* Data */ +/* Data */ /*****************************************************************************/ @@ -72,30 +74,48 @@ enum { E_LOC_REGISTER | E_LOC_LITERAL, /* Reference? */ - E_MASK_RTYPE = 0x8000, + E_MASK_RTYPE = 0x0100, E_RTYPE_RVAL = 0x0000, - E_RTYPE_LVAL = 0x8000 + E_RTYPE_LVAL = 0x0100, + + /* Bit-field? */ + E_BITFIELD = 0x0200, + + /* Test */ + E_NEED_TEST = 0x0400, /* Expression needs a test to set cc */ + E_CC_SET = 0x0800, /* Condition codes are set */ + + E_HAVE_MARKS = 0x1000, /* Code marks are valid */ + }; -/* Defines for the test field of the expression descriptor */ -#define E_CC 0x0001U /* Condition codes are set */ -#define E_FORCETEST 0x0002U /* Force test to set condition codes */ +/* Forward */ +struct Literal; /* 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 Val; /* Value if expression constant */ - unsigned short Flags; - unsigned short Test; /* */ - unsigned long Name; /* Name or label number */ + struct SymEntry* Sym; /* Symbol table entry if known */ + Type* Type; /* Type array of expression */ + unsigned Flags; + unsigned long Name; /* Name or label number */ + long IVal; /* Integer value if expression constant */ + Double FVal; /* Floating point value */ + struct Literal* LVal; /* Literal 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; }; /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ @@ -166,7 +186,7 @@ INLINE int ED_IsLocExpr (const ExprDesc* Expr) #if defined(HAVE_INLINE) INLINE int ED_IsLocLiteral (const ExprDesc* Expr) /* Return true if the expression is a string from the literal pool */ -{ +{ return (Expr->Flags & E_MASK_LOC) == E_LOC_LITERAL; } #else @@ -210,7 +230,7 @@ INLINE void ED_MakeLVal (ExprDesc* Expr) Expr->Flags |= E_RTYPE_LVAL; } #else -# define ED_MakeLVal(Expr) do { (Expr)->Flags |= E_RTYPE_LVAL; } while (0) +# define ED_MakeLVal(Expr) do { (Expr)->Flags |= E_RTYPE_LVAL; } while (0) #endif #if defined(HAVE_INLINE) @@ -220,16 +240,91 @@ INLINE void ED_MakeRVal (ExprDesc* Expr) Expr->Flags &= ~E_RTYPE_LVAL; } #else -# define ED_MakeRVal(Expr) do { (Expr)->Flags &= ~E_RTYPE_LVAL; } while (0) +# define ED_MakeRVal(Expr) do { (Expr)->Flags &= ~E_RTYPE_LVAL; } while (0) +#endif + +#if defined(HAVE_INLINE) +INLINE int ED_IsBitField (const ExprDesc* Expr) +/* Return true if the expression is a bit field */ +{ + return (Expr->Flags & E_BITFIELD) != 0; +} +#else +# define ED_IsBitField(Expr) (((Expr)->Flags & E_BITFIELD) != 0) +#endif + +void ED_MakeBitField (ExprDesc* Expr, unsigned BitOffs, unsigned BitWidth); +/* Make this expression a bit field expression */ + +#if defined(HAVE_INLINE) +INLINE void ED_MarkForTest (ExprDesc* Expr) +/* Mark the expression for a test. */ +{ + Expr->Flags |= E_NEED_TEST; +} +#else +# define ED_MarkForTest(Expr) do { (Expr)->Flags |= E_NEED_TEST; } while (0) #endif +#if defined(HAVE_INLINE) +INLINE int ED_NeedsTest (const ExprDesc* Expr) +/* Check if the expression needs a test. */ +{ + return (Expr->Flags & E_NEED_TEST) != 0; +} +#else +# define ED_NeedsTest(Expr) (((Expr)->Flags & E_NEED_TEST) != 0) +#endif + +#if defined(HAVE_INLINE) +INLINE void ED_TestDone (ExprDesc* Expr) +/* Mark the expression as tested and condition codes set. */ +{ + Expr->Flags = (Expr->Flags & ~E_NEED_TEST) | E_CC_SET; +} +#else +# define ED_TestDone(Expr) \ + do { (Expr)->Flags = ((Expr)->Flags & ~E_NEED_TEST) | E_CC_SET; } while (0) +#endif + +#if defined(HAVE_INLINE) +INLINE int ED_IsTested (const ExprDesc* Expr) +/* Check if the expression has set the condition codes. */ +{ + return (Expr->Flags & E_CC_SET) != 0; +} +#else +# define ED_IsTested(Expr) (((Expr)->Flags & E_CC_SET) != 0) +#endif + +#if defined(HAVE_INLINE) +INLINE void ED_MarkAsUntested (ExprDesc* Expr) +/* Mark the expression as not tested (condition codes not set). */ +{ + Expr->Flags &= ~E_CC_SET; +} +#else +# 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 * call to the function. */ -ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type); +int ED_GetStackOffs (const ExprDesc* Expr, int Offs); +/* Get the stack offset of an address on the stack in Expr taking into account + * an additional offset in Offs. + */ + +ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, Type* Type); /* Make Expr an absolute const with the given value and type. */ ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long Value); @@ -251,10 +346,18 @@ int ED_IsConst (const ExprDesc* Expr); * similar. */ -int ED_IsConstAbs (const ExprDesc* Expr); +#if defined(HAVE_INLINE) +INLINE 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 (Expr->Flags & (E_MASK_LOC|E_MASK_RTYPE)) == (E_LOC_ABS|E_RTYPE_RVAL); +} +#else +# define ED_IsConstAbs(E) \ + (((E)->Flags & (E_MASK_LOC|E_MASK_RTYPE)) == (E_LOC_ABS|E_RTYPE_RVAL)) +#endif int ED_IsConstAbsInt (const ExprDesc* Expr); /* Return true if the expression is a constant (numeric) integer. */ @@ -270,7 +373,7 @@ int ED_IsBool (const ExprDesc* Expr); void PrintExprDesc (FILE* F, ExprDesc* Expr); /* Print an ExprDesc */ -type* ReplaceType (ExprDesc* Expr, const type* NewType); +Type* ReplaceType (ExprDesc* Expr, const Type* NewType); /* Replace the type of Expr by a copy of Newtype and return the old type string */