X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCval.h;h=5348ec9814b1ad8371d97178268f8123a830fe8c;hb=c18a4cebda9c0f424821db515901d7357ea233a7;hp=17c4ba4a3df5597857a05dca0383bdc2d0ede3c1;hpb=f61f15d2fcba8d632ad59335615fb1fa4bdcdf6c;p=fw%2Fsdcc diff --git a/src/SDCCval.h b/src/SDCCval.h index 17c4ba4a..5348ec98 100644 --- a/src/SDCCval.h +++ b/src/SDCCval.h @@ -20,23 +20,45 @@ You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "SDCCsymt.h" #ifndef SDCCVAL_H #define SDCCVAL_H +#include "SDCCsymt.h" + + +/* double to unsigned long conversion */ +/* + * See ISO/IEC 9899, chapter 6.3.1.4 Real floating and integer: + * If the value of the integral part cannot be represented by the integer type, the behavior is undefined. + * This shows up on Mac OS X i386 platform + */ +#if defined(__APPLE__) && defined(__i386__) +#define double2ul(val) (((val) < 0) ? (unsigned long) -((long) -(val)) : (unsigned long) (val)) +#else +#define double2ul(val) ((unsigned long) (val)) +#endif + /* value wrapper */ typedef struct value { - char name[SDCC_NAME_MAX + 1]; /* operand accessing this value */ - sym_link *type; /* start of type chain */ - sym_link *etype; /* end of type chain */ - symbol *sym; /* Original Symbol */ - struct value *next; /* used in initializer list */ - unsigned vArgs:1; /* arg list ended with variable arg */ + char name[SDCC_NAME_MAX + 1]; /* operand accessing this value */ + sym_link *type; /* start of type chain */ + sym_link *etype; /* end of type chain */ + symbol *sym; /* Original Symbol */ + struct value *next; /* used in initializer list */ + unsigned vArgs:1; /* arg list ended with variable arg */ } value; +typedef struct literalList +{ + double literalValue; + unsigned count; + struct literalList *next; +} literalList; + + enum { INIT_NODE, @@ -49,10 +71,11 @@ typedef struct initList { int type; int lineno; + char *filename; union { - struct ast *node; - struct initList *deep; + struct ast *node; + struct initList *deep; } init; @@ -60,21 +83,40 @@ typedef struct initList } initList; -#define IS_VARG(x) (x->vArgs) +/* return values from checkConstantRange */ +typedef enum + { + CCR_OK, /* evaluate at runtime */ + CCR_OVL, + CCR_ALWAYS_FALSE, + CCR_ALWAYS_TRUE + } +CCR_RESULT; + +#define IS_VARG(x) (x->vArgs) /* forward definitions for the symbol table related functions */ void initValue (); value *newValue (); -value *constVal (char *); +value *constVal (const char *); value *reverseVal (value *); value *reverseValWithType (value *); value *copyValue (value *); value *copyValueChain (value *); -value *strVal (char *); -value *charVal (char *); +value *strVal (const char *); +value *charVal (const char *); value *symbolVal (symbol *); void printVal (value *); double floatFromVal (value *); +unsigned long ulFromVal (value *); + +/* convert a fixed16x16 type to double */ +double doubleFromFixed16x16(TYPE_TARGET_ULONG value); + +/* convert a double type to fixed16x16 */ +TYPE_TARGET_ULONG fixed16x16FromDouble(double value); + +CCR_RESULT checkConstantRange (sym_link *var, sym_link *lit, int op, bool exchangeOps); value *array2Ptr (value *); value *valUnaryPM (value *); value *valComplement (value *); @@ -96,12 +138,15 @@ initList *copyIlist (initList *); double list2int (initList *); value *list2val (initList *); struct ast *list2expr (initList *); -void resolveIvalSym (initList *); +void resolveIvalSym (initList *, sym_link *); value *valFromType (sym_link *); value *constFloatVal (char *); +value *constFixed16x16Val (char *); int getNelements (sym_link *, initList *); value *valForArray (struct ast *); value *valForStructElem (struct ast *, struct ast *); value *valForCastAggr (struct ast *, sym_link *, struct ast *, int); value *valForCastArr (struct ast * , sym_link *); +bool convertIListToConstList(initList *src, literalList **lList); +literalList *copyLiteralList(literalList *src); #endif