1 /*----------------------------------------------------------------------
2 SDCCval.h - value wrapper related header information
3 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1997)
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding!
22 -------------------------------------------------------------------------*/
29 /* double to unsigned long conversion */
31 * See ISO/IEC 9899, chapter 6.3.1.4 Real floating and integer:
32 * If the value of the integral part cannot be represented by the integer type, the behavior is undefined.
33 * This shows up on Mac OS X i386 platform which useus SSE unit instead of the x87 FPU for floating-point operations
36 * on Mac OS X ppc (long) 2147483648.0 equals to 2147483647, so we explicitely convert it to 0x80000000
37 * on other known platforms (long) 2147483648.0 equals to -2147483648
39 #define double2ul(val) (((val) < 0) ? (((val) < -2147483647.0) ? 0x80000000UL : (unsigned long) -((long) -(val))) : (unsigned long) (val))
44 char name[SDCC_NAME_MAX + 1]; /* operand accessing this value */
45 sym_link *type; /* start of type chain */
46 sym_link *etype; /* end of type chain */
47 symbol *sym; /* Original Symbol */
48 struct value *next; /* used in initializer list */
49 unsigned vArgs:1; /* arg list ended with variable arg */
54 typedef struct literalList
58 struct literalList *next;
68 /* initializer lists use this structure */
69 typedef struct initList
77 struct initList *deep;
81 struct initList *next;
85 /* return values from checkConstantRange */
88 CCR_OK, /* evaluate at runtime */
95 #define IS_VARG(x) (x->vArgs)
97 /* forward definitions for the symbol table related functions */
98 value *newValue (void);
99 value *constVal (const char *);
100 value *constCharVal (unsigned char);
101 value *reverseVal (value *);
102 value *reverseValWithType (value *);
103 value *copyValue (value *);
104 value *copyValueChain (value *);
105 value *strVal (const char *);
106 value *charVal (const char *);
107 value *symbolVal (symbol *);
108 void printVal (value *);
109 double floatFromVal (value *);
110 unsigned long ulFromVal (value *);
112 /* convert a fixed16x16 type to double */
113 double doubleFromFixed16x16(TYPE_TARGET_ULONG value);
115 /* convert a double type to fixed16x16 */
116 TYPE_TARGET_ULONG fixed16x16FromDouble(double value);
118 CCR_RESULT checkConstantRange (sym_link *var, sym_link *lit, int op, bool exchangeOps);
119 value *array2Ptr (value *);
120 value *valUnaryPM (value *);
121 value *valComplement (value *);
122 value *valNot (value *);
123 value *valMult (value *, value *);
124 value *valDiv (value *, value *);
125 value *valMod (value *, value *);
126 value *valPlus (value *, value *);
127 value *valMinus (value *, value *);
128 value *valShift (value *, value *, int);
129 value *valCompare (value *, value *, int);
130 value *valBitwise (value *, value *, int);
131 value *valLogicAndOr (value *, value *, int);
132 value *valCastLiteral (sym_link *, double);
133 value *valueFromLit (double);
134 initList *newiList (int, void *);
135 initList *revinit (initList *);
136 initList *copyIlist (initList *);
137 double list2int (initList *);
138 value *list2val (initList *);
139 struct ast *list2expr (initList *);
140 void resolveIvalSym (initList *, sym_link *);
141 value *valFromType (sym_link *);
142 value *constFloatVal (const char *);
143 value *constFixed16x16Val (const char *);
144 int getNelements (sym_link *, initList *);
145 value *valForArray (struct ast *);
146 value *valForStructElem (struct ast *, struct ast *);
147 value *valForCastAggr (struct ast *, sym_link *, struct ast *, int);
148 value *valForCastArr (struct ast * , sym_link *);
149 bool convertIListToConstList(initList *src, literalList **lList);
150 literalList *copyLiteralList(literalList *src);