* src/SDCCval.h: fixed bug #1739860 - sdcc does not work correctly on some
[fw/sdcc] / src / SDCCval.h
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 /* double to unsigned long conversion */
30 /*
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
34  */
35 #if defined(__APPLE__) && defined(__i386__)
36 #define double2ul(val)  (((val) < 0) ? (unsigned long) -((long) -(val)) : (unsigned long) (val))
37 #else
38 #define double2ul(val)  ((unsigned long) (val))
39 #endif
40
41 /* value wrapper */
42 typedef struct value
43   {
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 */
50
51   }
52 value;
53
54 typedef struct literalList
55 {
56     double    literalValue;
57     unsigned  count;
58     struct literalList *next;
59 } literalList;
60
61
62 enum
63   {
64     INIT_NODE,
65     INIT_DEEP,
66     INIT_HOLE
67   };
68
69 /* initializer lists use this structure */
70 typedef struct initList
71   {
72     int type;
73     int lineno;
74     char *filename;
75     union
76       {
77         struct ast *node;
78         struct initList *deep;
79       }
80     init;
81
82     struct initList *next;
83   }
84 initList;
85
86 /* return values from checkConstantRange */
87 typedef enum
88   {
89     CCR_OK,           /* evaluate at runtime */
90     CCR_OVL,
91     CCR_ALWAYS_FALSE,
92     CCR_ALWAYS_TRUE
93   }
94 CCR_RESULT;
95
96 #define  IS_VARG(x)             (x->vArgs)
97
98 /* forward definitions for the symbol table related functions */
99 void initValue ();
100 value *newValue ();
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 *);
112
113 /* convert a fixed16x16 type to double */
114 double doubleFromFixed16x16(TYPE_TARGET_ULONG value);
115
116 /* convert a double type to fixed16x16 */
117 TYPE_TARGET_ULONG fixed16x16FromDouble(double value);
118
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);
152 #endif