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
35 #if defined(__APPLE__) && defined(__i386__)
36 #define double2ul(val) (((val) < 0) ? (unsigned long) -((long) -(val)) : (unsigned long) (val))
38 #define double2ul(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;
69 /* initializer lists use this structure */
70 typedef struct initList
78 struct initList *deep;
82 struct initList *next;
86 /* return values from checkConstantRange */
89 CCR_OK, /* evaluate at runtime */
96 #define IS_VARG(x) (x->vArgs)
98 /* forward definitions for the symbol table related functions */
101 value *constVal (const char *);
102 value *reverseVal (value *);
103 value *reverseValWithType (value *);
104 value *copyValue (value *);
105 value *copyValueChain (value *);
106 value *strVal (const char *);
107 value *charVal (const char *);
108 value *symbolVal (symbol *);
109 void printVal (value *);
110 double floatFromVal (value *);
111 unsigned long ulFromVal (value *);
113 /* convert a fixed16x16 type to double */
114 double doubleFromFixed16x16(TYPE_TARGET_ULONG value);
116 /* convert a double type to fixed16x16 */
117 TYPE_TARGET_ULONG fixed16x16FromDouble(double value);
119 CCR_RESULT checkConstantRange (sym_link *var, sym_link *lit, int op, bool exchangeOps);
120 value *array2Ptr (value *);
121 value *valUnaryPM (value *);
122 value *valComplement (value *);
123 value *valNot (value *);
124 value *valMult (value *, value *);
125 value *valDiv (value *, value *);
126 value *valMod (value *, value *);
127 value *valPlus (value *, value *);
128 value *valMinus (value *, value *);
129 value *valShift (value *, value *, int);
130 value *valCompare (value *, value *, int);
131 value *valBitwise (value *, value *, int);
132 value *valLogicAndOr (value *, value *, int);
133 value *valCastLiteral (sym_link *, double);
134 value *valueFromLit (double);
135 initList *newiList (int, void *);
136 initList *revinit (initList *);
137 initList *copyIlist (initList *);
138 double list2int (initList *);
139 value *list2val (initList *);
140 struct ast *list2expr (initList *);
141 void resolveIvalSym (initList *, sym_link *);
142 value *valFromType (sym_link *);
143 value *constFloatVal (char *);
144 value *constFixed16x16Val (char *);
145 int getNelements (sym_link *, initList *);
146 value *valForArray (struct ast *);
147 value *valForStructElem (struct ast *, struct ast *);
148 value *valForCastAggr (struct ast *, sym_link *, struct ast *, int);
149 value *valForCastArr (struct ast * , sym_link *);
150 bool convertIListToConstList(initList *src, literalList **lList);
151 literalList *copyLiteralList(literalList *src);