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