Imported Upstream version 2.9.0
[debian/cc1111] / debugger / mcs51 / symtab.h
1 /*-------------------------------------------------------------------------
2   symtab.h - Header file for symbol table for sdcdb ( debugger )
3         Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
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
24 #ifndef  SYMTAB_H
25 #define  SYMTAB_H
26
27 #define MAX_NEST_LEVEL  256
28 #define SDCC_NAME_MAX    64
29
30 typedef struct structdef {
31     char           *tag      ;  /* tag part of structure      */
32     unsigned char  level     ;  /* Nesting level         */
33     struct symbol  *fields   ;  /* pointer to fields     */
34     unsigned       size      ;  /* sizeof the table in bytes  */
35     char           *sname    ;  /* scope name */
36     char           scopetype ;  /* scope type 'G' or 'F' */
37 } structdef ;
38
39 /* noun definitions */
40 enum  { V_INT   =  0,
41         V_FLOAT     ,
42         V_CHAR      ,
43         V_VOID      ,
44         V_STRUCT    ,
45         V_LABEL     ,
46         V_BIT       ,
47         V_SBIT      };
48
49 /* storage class    */
50 enum  { S_FIXED  =  0,
51         S_AUTO       ,
52         S_REGISTER   ,
53         S_CONSTANT   ,
54         S_SFR        ,
55         S_SBIT       ,
56         S_CODE       ,
57         S_XDATA      ,
58         S_DATA       ,
59         S_IDATA      ,
60         S_PDATA      ,
61         S_LITERAL    ,
62         S_STACK      ,
63         S_XSTACK     ,
64         S_BIT        };
65
66 /* specifier is the last in the type-chain */
67 typedef struct specifier {
68     unsigned    noun        ;  /* CHAR INT STRUCTURE LABEL   */
69     unsigned    sclass      ;  /* REGISTER,AUTO,FIX,CONSTANT */
70     unsigned    _long : 1   ;  /* 1=long            */
71     unsigned    _short: 1       ;       /* 1=short int    */
72     unsigned _unsigned: 1   ;  /* 1=unsigned, 0=signed       */
73     unsigned   _static: 1   ;  /* 1=static keyword found     */
74     unsigned   _extern: 1   ;  /* 1=extern found             */
75     unsigned   _absadr: 1   ;  /* absolute address specfied  */
76     unsigned   _reent : 1   ;  /* function is reentrant      */
77     unsigned   _intrtn: 1   ;  /* this is an interrupt routin*/
78     unsigned   _rbank : 1   ;  /* seperate register bank     */
79     unsigned   _volatile : 1;  /* is marked as volatile      */
80     unsigned   _const:1     ;  /* is a constant              */
81     unsigned   _critical:1  ;  /* critical function          */
82     unsigned   _typedef :1  ;  /* is typedefed               */
83     unsigned   _IntNo       ;  /* 1=Interrupt svc routine    */
84     short      _regbank     ;  /* register bank 2b used      */
85     unsigned   _addr        ;  /* address of symbol          */
86     unsigned   _stack       ;  /* stack offset for stacked v */
87     unsigned   _bitStart    ;  /* bit start position         */
88     int        _bitLength   ;  /* bit length                 */
89
90     struct structdef *v_struct; /* structure pointer      */
91 } specifier ;
92
93 /* types of declarators */
94 enum {  POINTER   = 0,       /* pointer to near data */
95         FPOINTER     ,       /* pointer to far data  */
96         CPOINTER     ,       /* pointer to code space */
97         GPOINTER     ,       /* _generic pointer     */
98         PPOINTER     ,       /* paged area pointer   */
99         IPOINTER     ,       /* pointer to upper 128 bytes */
100         UPOINTER     ,       /* unknown pointer used only when parsing */
101         ARRAY        ,
102         FUNCTION     };
103
104 typedef struct declarator {
105     short    dcl_type;     /* POINTER,ARRAY or FUNCTION  */
106     short    num_elem;     /* # of elems if type==array  */
107     short    ptr_const :1;   /* pointer is constant        */
108     short    ptr_volatile:1; /* pointer is volatile        */
109     struct link *tspec;     /* pointer type specifier      */
110 } declarator ;
111
112 #define DECLARATOR   0
113 #define SPECIFIER    1
114
115 typedef struct link {
116     unsigned class : 1      ;  /* DECLARATOR or SPECIFIER    */
117     unsigned tdef  : 1      ;  /* current link created by    */
118     /* typedef if this flag is set*/
119     union {
120         specifier      s     ;  /* if CLASS == SPECIFIER      */
121         declarator     d     ;  /* if CLASS == DECLARATOR     */
122     } select ;
123
124     struct link    *next    ;  /* next element on the chain  */
125 } link ;
126
127 typedef struct symbol {
128     char     *name               ;
129
130     short    size               ;
131     short    level              ;  /* declration lev,fld offset */
132     short    block              ;  /* sequential block # of defintion */
133     short    isonstack          ;  /* is the variable on stack */
134     unsigned isfunc        :1   ;  /* is a functions           */
135     unsigned offset             ;  /* offset from top if struct */
136     unsigned addr               ;  /* address if the symbol */
137     unsigned eaddr              ;  /* end address for functions */
138     char     addr_type          ;  /* which address space   */
139     link     *type              ;  /* start of type chain        */
140     link     *etype             ;  /* end of type chain          */
141     char     scopetype         ;  /* 'G' global, 'F' - file, 'L' local */
142     char     *sname             ;  /* if 'F' or 'L' then scope name */
143     char     *rname             ;  /* real name i.e. mangled beyond recognition */
144     char     addrspace          ;  /* address space designator      */
145     struct symbol *next         ;
146 } symbol ;
147
148 /* size's in bytes  */
149 #define CHARSIZE    1
150 #define SHORTSIZE   1
151 #define INTSIZE     2
152 #define LONGSIZE    4
153 #define PTRSIZE     1
154 #define FPTRSIZE    2
155 #define GPTRSIZE    3
156 #define BITSIZE     1
157 #define FLOATSIZE   4
158 #define MAXBASESIZE 4
159
160 /* Easy Access Macros */
161 #define DCL_TYPE(l)      l->select.d.dcl_type
162 #define DCL_ELEM(l)      l->select.d.num_elem
163 #define DCL_PTR_CONST(l) l->select.d.ptr_const
164 #define DCL_PTR_VOLATILE(l) l->select.d.ptr_volatile
165 #define DCL_TSPEC(l)     l->select.d.tspec
166 #define SPEC_NOUN(x)     x->select.s.noun
167 #define SPEC_LONG(x)     x->select.s._long
168 #define SPEC_SHORT(x)    x->select.s._short
169 #define SPEC_USIGN(x)    x->select.s._unsigned
170 #define SPEC_SCLS(x)     x->select.s.sclass
171 #define SPEC_OCLS(x)     x->select.s.oclass
172 #define SPEC_STAT(x)     x->select.s._static
173 #define SPEC_EXTR(x)     x->select.s._extern
174 #define SPEC_CODE(x)     x->select.s._codesg
175 #define SPEC_RENT(x)     x->select.s._reent
176 #define SPEC_INTN(x)     x->select.s._IntNo
177 #define SPEC_ABSA(x)     x->select.s._absadr
178 #define SPEC_BANK(x)     x->select.s._regbank
179 #define SPEC_ADDR(x)     x->select.s._addr
180 #define SPEC_STAK(x)     x->select.s._stack
181 #define SPEC_CVAL(x)     x->select.s.const_val
182 #define SPEC_BSTR(x)     x->select.s._bitStart
183 #define SPEC_BLEN(x)     x->select.s._bitLength
184 #define SPEC_BNKF(x)     x->select.s._rbank
185 #define SPEC_INTRTN(x)   x->select.s._intrtn
186 #define SPEC_CRTCL(x)    x->select.s._critical
187 #define SPEC_VOLATILE(x) x->select.s._volatile
188 #define SPEC_CONST(x)    x->select.s._const
189 #define SPEC_STRUCT(x)   x->select.s.v_struct
190 #define SPEC_TYPEDEF(x)  x->select.s._typedef
191
192 /* type check macros */
193 #define IS_DECL(x)       ( x && x->class == DECLARATOR      )
194 #define IS_SPEC(x)       ( x && x->class == SPECIFIER  )
195 #define IS_ARRAY(x)      (IS_DECL(x) && DCL_TYPE(x) == ARRAY)
196 #define IS_PTR(x)        (IS_DECL(x) && (DCL_TYPE(x) == POINTER    ||    \
197                                      DCL_TYPE(x) == FPOINTER   ||    \
198                                      DCL_TYPE(x) == GPOINTER   ||    \
199                                      DCL_TYPE(x) == IPOINTER   ||    \
200                                      DCL_TYPE(x) == PPOINTER   ||    \
201                                      DCL_TYPE(x) == CPOINTER   ||    \
202                                      DCL_TYPE(x) == UPOINTER  ))
203 #define IS_PTR_CONST(x)  (IS_PTR(x) && DCL_PTR_CONST(x))
204 #define IS_FARPTR(x)     (IS_DECL(x) && DCL_TYPE(x) == FPOINTER)
205 #define IS_GENPTR(x)     (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
206 #define IS_FUNC(x)       (IS_DECL(x) && DCL_TYPE(x) == FUNCTION)
207 #define IS_LONG(x)       (IS_SPEC(x) && x->select.s._long)
208 #define IS_SHORT(x)      (IS_SPEC(x) && x->select.s._short)
209 #define IS_TYPEDEF(x)    (IS_SPEC(x) && x->select.s._typedef)
210 #define IS_CONSTANT(x)   (IS_SPEC(x) && (x->select.s.sclass == S_CONSTANT ||\
211                                         x->select.s._const == 1))
212 #define IS_STRUCT(x)     (IS_SPEC(x) && x->select.s.noun == V_STRUCT)
213 #define IS_ABSOLUTE(x)   (IS_SPEC(x) && x->select.s._absadr )
214 #define IS_REGISTER(x)   (IS_SPEC(x) && SPEC_SCLS(x) == S_REGISTER)
215 #define IS_RENT(x)       (IS_SPEC(x) && x->select.s._reent )
216 #define IS_STATIC(x)     (IS_SPEC(x) && SPEC_STAT(x))
217 #define IS_INT(x)        (IS_SPEC(x) && x->select.s.noun == V_INT)
218 #define IS_VOID(x)       (IS_SPEC(x) && x->select.s.noun == V_VOID)
219 #define IS_CHAR(x)       (IS_SPEC(x) && x->select.s.noun == V_CHAR)
220 #define IS_EXTERN(x)     (IS_SPEC(x) && x->select.s._extern)
221 #define IS_VOLATILE(x)   (IS_SPEC(x) && x->select.s._volatile )
222 #define IS_INTEGRAL(x)   (IS_SPEC(x) && (x->select.s.noun == V_INT ||  \
223                                        x->select.s.noun == V_CHAR || \
224                                        x->select.s.noun == V_BIT ||  \
225                                        x->select.s.noun == V_SBIT ))
226 #define IS_BITFIELD(x)   (IS_SPEC(x) && (x->select.s.noun == V_BIT))
227 #define IS_BITVAR(x)     (IS_SPEC(x) && (x->select.s.noun  == V_BIT ||   \
228                                      x->select.s.noun == V_SBIT ))
229 #define IS_FLOAT(x)      (IS_SPEC(x) && x->select.s.noun == V_FLOAT)
230 #define IS_ARITHMETIC(x) (IS_INTEGRAL(x) || IS_FLOAT(x))
231 #define IS_AGGREGATE(x)  (IS_ARRAY(x) || IS_STRUCT(x))
232 #define IS_LITERAL(x)    (IS_SPEC(x)  && x->select.s.sclass == S_LITERAL)
233 #define IS_ISR(x)        (IS_SPEC(x)  && SPEC_INTRTN(x))
234
235
236 symbol *parseSymbol (char *, char **, int);
237 structdef *parseStruct (char *);
238 void parseFunc (char *);
239 module *parseModule (char *, bool);
240 void parseLnkRec (char *);
241 symbol *symLookup (char *,context *);
242 DEFSETFUNC(moduleWithName);
243 DEFSETFUNC(moduleWithCName);
244 DEFSETFUNC(moduleWithAsmName);
245 unsigned int getSize (link *);
246
247 #endif