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 -------------------------------------------------------------------------*/
32 char name
[SDCC_NAME_MAX
+ 1]; /* operand accessing this value */
33 sym_link
*type
; /* start of type chain */
34 sym_link
*etype
; /* end of type chain */
35 symbol
*sym
; /* Original Symbol */
36 struct value
*next
; /* used in initializer list */
37 unsigned vArgs
:1; /* arg list ended with variable arg */
41 typedef struct literalList
45 unsigned long long ull
;
50 struct literalList
*next
;
60 /* initializer lists use this structure */
61 typedef struct initList
66 bool isempty
; // C23 empty initializer
67 struct designation
*designation
;
71 struct initList
*deep
;
75 struct initList
*next
;
85 /* designated initializers */
86 typedef struct designation
93 struct symbol
*tag
; /* tag part of structure */
94 int elemno
; /* array element (constant expr) */
98 struct designation
*next
; /* next part of nested designator */
102 /* return values from checkConstantRange */
105 CCR_OK
, /* evaluate at runtime */
112 #define IS_VARG(x) (x->vArgs)
114 /* forward definitions for the symbol table related functions */
115 value
*newValue (void);
116 value
*constVal (const char *);
117 value
*constIntVal (const char *);
118 value
*constCharacterVal (unsigned long v
, char type
);
119 value
*constCharVal (unsigned char v
);
120 value
*constBoolVal (bool v
, bool reduceType
);
121 value
*constNullptrVal (void);
122 value
*reverseVal (value
*);
123 value
*reverseValWithType (value
*);
124 value
*copyValue (value
*);
125 value
*copyValueChain (value
*);
126 value
*strVal (const char *);
127 value
*rawStrVal (const char *, size_t size
);
128 value
*charVal (const char *);
129 value
*symbolVal (symbol
*);
130 void printVal (value
*);
131 double floatFromVal (value
*);
132 unsigned long ulFromVal (const value
*);
133 unsigned long long ullFromVal (const value
*);
135 /* convert a fixed16x16 type to double */
136 double doubleFromFixed16x16 (TYPE_TARGET_ULONG value
);
138 /* convert a double type to fixed16x16 */
139 TYPE_TARGET_ULONG
fixed16x16FromDouble (double value
);
141 CCR_RESULT
checkConstantRange (sym_link
* var
, sym_link
* lit
, int op
, bool exchangeOps
);
142 value
*array2Ptr (value
*);
143 value
*valUnaryPM (value
*, bool reduceType
);
144 value
*valComplement (value
*, bool reduceType
);
145 value
*valNot (value
*, bool reduceType
);
146 value
*valMult (value
*, value
*, bool reduceType
);
147 value
*valDiv (value
*, value
*, bool reduceType
);
148 value
*valMod (value
*, value
*, bool reduceType
);
149 value
*valZeroResultFromOp (sym_link
* type1
, sym_link
* type2
, int op
, bool reduceType
);
150 value
*valPlus (value
*, value
*, bool reduceType
);
151 value
*valMinus (value
*, value
*, bool reduceType
);
152 value
*valShift (value
*, value
*, int, bool reduceType
);
153 value
*valCompare (value
*, value
*, int, bool reduceType
);
154 value
*valBitwise (value
*, value
*, int, bool reduceType
);
155 value
*valLogicAndOr (value
*, value
*, int, bool reduceType
);
156 value
*valCastLiteral (sym_link
*, double, TYPE_TARGET_ULONGLONG
);
157 value
*valueFromLit (double);
158 initList
*newiList (int, void *);
159 initList
*revinit (initList
*);
160 initList
*copyIlist (initList
*);
161 double list2int (initList
*);
162 value
*list2val (initList
*, int);
163 struct ast
*list2expr (initList
*);
164 void resolveIvalSym (initList
*, sym_link
*);
165 designation
*newDesignation(int, void *);
166 designation
*revDesignation (designation
*);
167 designation
*copyDesignation (designation
*);
168 initList
*reorderIlist (sym_link
*, initList
*);
169 value
*valFromType (sym_link
*);
170 value
*constFloatVal (const char *);
171 value
*constFixed16x16Val (const char *);
172 int getNelements (sym_link
*, initList
*);
173 value
*valForArray (struct ast
*);
174 value
*valForStructElem (struct ast
*, struct ast
*);
175 value
*valForCastAggr (struct ast
*, sym_link
*, struct ast
*, int);
176 value
*valForCastArr (struct ast
*, sym_link
*);
177 bool convertIListToConstList (initList
* src
, literalList
** lList
, int size
);
178 literalList
*copyLiteralList (literalList
* src
);
179 unsigned long double2ul (double val
);
180 unsigned char byteOfVal (value
*, int);
181 int csdOfVal (int *topbit
, int *nonzero
, unsigned long long *csd_add
, unsigned long long *csd_sub
, value
*val
, unsigned long long mask
);
182 int isEqualVal (value
*, int);
183 TYPE_TARGET_ULONGLONG
ullFromLit (sym_link
* lit
);
184 value
* valRecastLitVal (sym_link
* dtype
, value
* val
);