* support/regression/Makefile.in,
[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 which useus SSE unit instead of the x87 FPU for floating-point operations
34  */
35 /*
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
38  */
39 #define double2ul(val)  (((val) < 0) ? (((val) < -2147483647.0) ? 0x80000000UL : (unsigned long) -((long) -(val))) : (unsigned long) (val))
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 enum
62   {
63     INIT_NODE,
64     INIT_DEEP,
65     INIT_HOLE
66   };
67
68 /* initializer lists use this structure */
69 typedef struct initList
70   {
71     int type;
72     int lineno;
73     char *filename;
74     union
75       {
76         struct ast *node;
77         struct initList *deep;
78       }
79     init;
80
81     struct initList *next;
82   }
83 initList;
84
85 /* return values from checkConstantRange */
86 typedef enum
87   {
88     CCR_OK,           /* evaluate at runtime */
89     CCR_OVL,
90     CCR_ALWAYS_FALSE,
91     CCR_ALWAYS_TRUE
92   }
93 CCR_RESULT;
94
95 #define  IS_VARG(x)             (x->vArgs)
96
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 *);
111
112 /* convert a fixed16x16 type to double */
113 double doubleFromFixed16x16(TYPE_TARGET_ULONG value);
114
115 /* convert a double type to fixed16x16 */
116 TYPE_TARGET_ULONG fixed16x16FromDouble(double value);
117
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);
151 #endif