* src/SDCC.y, src/SDCCast.c, src/SDCCcse.c, src/SDCCglue.c, src/SDCCicode.c,
[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 #define double2ul(val)  (((val) < 0) ? (unsigned long) -((long) -(val)) : (unsigned long) (val))
31
32 /* value wrapper */
33 typedef struct value
34   {
35     char name[SDCC_NAME_MAX + 1]; /* operand accessing this value     */
36     sym_link *type;               /* start of type chain              */
37     sym_link *etype;              /* end of type chain                */
38     symbol *sym;                  /* Original Symbol                  */
39     struct value *next;           /* used in initializer list         */
40     unsigned vArgs:1;             /* arg list ended with variable arg */
41
42   }
43 value;
44
45 typedef struct literalList
46 {
47     double    literalValue;
48     unsigned  count;
49     struct literalList *next;
50 } literalList;
51
52
53 enum
54   {
55     INIT_NODE,
56     INIT_DEEP,
57     INIT_HOLE
58   };
59
60 /* initializer lists use this structure */
61 typedef struct initList
62   {
63     int type;
64     int lineno;
65     char *filename;
66     union
67       {
68         struct ast *node;
69         struct initList *deep;
70       }
71     init;
72
73     struct initList *next;
74   }
75 initList;
76
77 /* return values from checkConstantRange */
78 typedef enum
79   {
80     CCR_OK,           /* evaluate at runtime */
81     CCR_OVL,
82     CCR_ALWAYS_FALSE,
83     CCR_ALWAYS_TRUE
84   }
85 CCR_RESULT;
86
87 #define  IS_VARG(x)             (x->vArgs)
88
89 /* forward definitions for the symbol table related functions */
90 void initValue ();
91 value *newValue ();
92 value *constVal (const char *);
93 value *reverseVal (value *);
94 value *reverseValWithType (value *);
95 value *copyValue (value *);
96 value *copyValueChain (value *);
97 value *strVal (const char *);
98 value *charVal (const char *);
99 value *symbolVal (symbol *);
100 void printVal (value *);
101 double floatFromVal (value *);
102 unsigned long ulFromVal (value *);
103
104 /* convert a fixed16x16 type to double */
105 double doubleFromFixed16x16(TYPE_TARGET_ULONG value);
106
107 /* convert a double type to fixed16x16 */
108 TYPE_TARGET_ULONG fixed16x16FromDouble(double value);
109
110 CCR_RESULT checkConstantRange (sym_link *var, sym_link *lit, int op, bool exchangeOps);
111 value *array2Ptr (value *);
112 value *valUnaryPM (value *);
113 value *valComplement (value *);
114 value *valNot (value *);
115 value *valMult (value *, value *);
116 value *valDiv (value *, value *);
117 value *valMod (value *, value *);
118 value *valPlus (value *, value *);
119 value *valMinus (value *, value *);
120 value *valShift (value *, value *, int);
121 value *valCompare (value *, value *, int);
122 value *valBitwise (value *, value *, int);
123 value *valLogicAndOr (value *, value *, int);
124 value *valCastLiteral (sym_link *, double);
125 value *valueFromLit (double);
126 initList *newiList (int, void *);
127 initList *revinit (initList *);
128 initList *copyIlist (initList *);
129 double list2int (initList *);
130 value *list2val (initList *);
131 struct ast *list2expr (initList *);
132 void resolveIvalSym (initList *, sym_link *);
133 value *valFromType (sym_link *);
134 value *constFloatVal (char *);
135 value *constFixed16x16Val (char *);
136 int getNelements (sym_link *, initList *);
137 value *valForArray (struct ast *);
138 value *valForStructElem (struct ast *, struct ast *);
139 value *valForCastAggr (struct ast *, sym_link *, struct ast *, int);
140 value *valForCastArr (struct ast * , sym_link *);
141 bool convertIListToConstList(initList *src, literalList **lList);
142 literalList *copyLiteralList(literalList *src);
143 #endif