1 /*----------------------------------------------------------------------
2   SDCCval.h - value wrapper related header information
3   Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1997)
4 
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
8   later version.
9 
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.
14 
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.
18 
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 -------------------------------------------------------------------------*/
23 #ifndef SDCCVAL_H
24 #define SDCCVAL_H
25 
26 #include "SDCCsymt.h"
27 
28 
29 /* value wrapper */
30 typedef struct value
31 {
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 */
38 }
39 value;
40 
41 typedef struct literalList
42 {
43   double literalValue;
44   unsigned count;
45   struct literalList *next;
46 } literalList;
47 
48 enum
49 {
50   INIT_NODE,
51   INIT_DEEP,
52   INIT_HOLE
53 };
54 
55 /* initializer lists use this structure */
56 typedef struct initList
57 {
58   int type;
59   int lineno;
60   char *filename;
61   struct designation *designation;
62   union
63   {
64     struct ast *node;
65     struct initList *deep;
66   }
67   init;
68 
69   struct initList *next;
70 }
71 initList;
72 
73 enum
74   {
75     DESIGNATOR_STRUCT,
76     DESIGNATOR_ARRAY
77   };
78 
79 /* designated initializers */
80 typedef struct designation
81   {
82     int type;
83     int lineno;
84     char *filename;
85     union
86       {
87         struct symbol *tag;             /* tag part of structure          */
88         int elemno;                     /* array element (constant expr)  */
89       }
90     designator;
91 
92     struct designation *next;           /* next part of nested designator */
93   }
94 designation;
95 
96 /* return values from checkConstantRange */
97 typedef enum
98 {
99   CCR_OK,                       /* evaluate at runtime */
100   CCR_OVL,
101   CCR_ALWAYS_FALSE,
102   CCR_ALWAYS_TRUE
103 }
104 CCR_RESULT;
105 
106 #define  IS_VARG(x)             (x->vArgs)
107 
108 /* forward definitions for the symbol table related functions */
109 value *newValue (void);
110 value *constVal (const char *);
111 value *constIntVal (const char *);
112 value *constCharacterVal (unsigned long v, char type);
113 value *constCharVal (unsigned char v);
114 value *constBoolVal (bool v);
115 value *reverseVal (value *);
116 value *reverseValWithType (value *);
117 value *copyValue (value *);
118 value *copyValueChain (value *);
119 value *strVal (const char *);
120 value *rawStrVal (const char *, size_t size);
121 value *charVal (const char *);
122 value *symbolVal (symbol *);
123 void printVal (value *);
124 double floatFromVal (value *);
125 unsigned long ulFromVal (value *);
126 unsigned long long ullFromVal (value *);
127 
128 /* convert a fixed16x16 type to double */
129 double doubleFromFixed16x16 (TYPE_TARGET_ULONG value);
130 
131 /* convert a double type to fixed16x16 */
132 TYPE_TARGET_ULONG fixed16x16FromDouble (double value);
133 
134 CCR_RESULT checkConstantRange (sym_link * var, sym_link * lit, int op, bool exchangeOps);
135 value *array2Ptr (value *);
136 value *valUnaryPM (value *);
137 value *valComplement (value *);
138 value *valNot (value *);
139 value *valMult (value *, value *);
140 value *valDiv (value *, value *);
141 value *valMod (value *, value *);
142 value *valPlus (value *, value *);
143 value *valMinus (value *, value *);
144 value *valShift (value *, value *, int);
145 value *valCompare (value *, value *, int);
146 value *valBitwise (value *, value *, int);
147 value *valLogicAndOr (value *, value *, int);
148 value *valCastLiteral (sym_link *, double, TYPE_TARGET_ULONGLONG);
149 value *valueFromLit (double);
150 initList *newiList (int, void *);
151 initList *revinit (initList *);
152 initList *copyIlist (initList *);
153 double list2int (initList *);
154 value *list2val (initList *, int);
155 struct ast *list2expr (initList *);
156 void resolveIvalSym (initList *, sym_link *);
157 designation *newDesignation(int, void *);
158 designation *revDesignation (designation *);
159 designation *copyDesignation (designation *);
160 initList *reorderIlist (sym_link *, initList *);
161 value *valFromType (sym_link *);
162 value *constFloatVal (const char *);
163 value *constFixed16x16Val (const char *);
164 int getNelements (sym_link *, initList *);
165 value *valForArray (struct ast *);
166 value *valForStructElem (struct ast *, struct ast *);
167 value *valForCastAggr (struct ast *, sym_link *, struct ast *, int);
168 value *valForCastArr (struct ast *, sym_link *);
169 bool convertIListToConstList (initList * src, literalList ** lList, int size);
170 literalList *copyLiteralList (literalList * src);
171 unsigned long double2ul (double val);
172 unsigned char byteOfVal (value *, int);
173 int csdOfVal (int *topbit, int *nonzero, unsigned long long *csd_add, unsigned long long *csd_sub, value *val);
174 int isEqualVal (value *, int);
175 TYPE_TARGET_ULONGLONG ullFromLit (sym_link * lit);
176 value * valRecastLitVal (sym_link * dtype, value * val);
177 
178 #endif
179