Use 'ao-dbg' instead of 's51' to communicate with TeleMetrum
[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 value;
52
53 typedef struct literalList
54 {
55     double    literalValue;
56     unsigned  count;
57     struct literalList *next;
58 } literalList;
59
60 enum
61   {
62     INIT_NODE,
63     INIT_DEEP,
64     INIT_HOLE
65   };
66
67 /* initializer lists use this structure */
68 typedef struct initList
69   {
70     int type;
71     int lineno;
72     char *filename;
73     union
74       {
75         struct ast *node;
76         struct initList *deep;
77       }
78     init;
79
80     struct initList *next;
81   }
82 initList;
83
84 /* return values from checkConstantRange */
85 typedef enum
86   {
87     CCR_OK,           /* evaluate at runtime */
88     CCR_OVL,
89     CCR_ALWAYS_FALSE,
90     CCR_ALWAYS_TRUE
91   }
92 CCR_RESULT;
93
94 #define  IS_VARG(x)             (x->vArgs)
95
96 /* forward definitions for the symbol table related functions */
97 value *newValue (void);
98 value *constVal (const char *);
99 value *constCharVal (unsigned char);
100 value *reverseVal (value *);
101 value *reverseValWithType (value *);
102 value *copyValue (value *);
103 value *copyValueChain (value *);
104 value *strVal (const char *);
105 value *charVal (const char *);
106 value *symbolVal (symbol *);
107 void printVal (value *);
108 double floatFromVal (value *);
109 unsigned long ulFromVal (value *);
110
111 /* convert a fixed16x16 type to double */
112 double doubleFromFixed16x16(TYPE_TARGET_ULONG value);
113
114 /* convert a double type to fixed16x16 */
115 TYPE_TARGET_ULONG fixed16x16FromDouble(double value);
116
117 CCR_RESULT checkConstantRange (sym_link *var, sym_link *lit, int op, bool exchangeOps);
118 value *array2Ptr (value *);
119 value *valUnaryPM (value *);
120 value *valComplement (value *);
121 value *valNot (value *);
122 value *valMult (value *, value *);
123 value *valDiv (value *, value *);
124 value *valMod (value *, value *);
125 value *valPlus (value *, value *);
126 value *valMinus (value *, value *);
127 value *valShift (value *, value *, int);
128 value *valCompare (value *, value *, int);
129 value *valBitwise (value *, value *, int);
130 value *valLogicAndOr (value *, value *, int);
131 value *valCastLiteral (sym_link *, double);
132 value *valueFromLit (double);
133 initList *newiList (int, void *);
134 initList *revinit (initList *);
135 initList *copyIlist (initList *);
136 double list2int (initList *);
137 value *list2val (initList *);
138 struct ast *list2expr (initList *);
139 void resolveIvalSym (initList *, sym_link *);
140 value *valFromType (sym_link *);
141 value *constFloatVal (const char *);
142 value *constFixed16x16Val (const char *);
143 int getNelements (sym_link *, initList *);
144 value *valForArray (struct ast *);
145 value *valForStructElem (struct ast *, struct ast *);
146 value *valForCastAggr (struct ast *, sym_link *, struct ast *, int);
147 value *valForCastArr (struct ast * , sym_link *);
148 bool convertIListToConstList(initList *src, literalList **lList, int size);
149 literalList *copyLiteralList(literalList *src);
150 #endif