2daf953bd34de69eaf445e15f2d548ac2766c1bf
[fw/sdcc] / as / z80 / asdata.c
1 /* asdata.c */
2
3 /*
4  * (C) Copyright 1989-1995
5  * All Rights Reserved
6  *
7  * Alan R. Baldwin
8  * 721 Berkeley St.
9  * Kent, Ohio  44240
10  */
11
12 #include <stdio.h>
13 #include <setjmp.h>
14 #include <string.h>
15
16 #include "asm.h"
17
18 /*)Module       asdata.c
19  *
20  *      The module asdata.c contains the global constants,
21  *      structures, and variables used in the assembler.
22  */
23
24 int     aserr;          /*      ASxxxx error counter
25                          */
26 jmp_buf jump_env;       /*      compiler dependent structure
27                          *      used by setjmp() and longjmp()
28                          */
29 int     inpfil;         /*      count of assembler
30                          *      input files specified
31                          */
32 int     incfil;         /*      current file handle index
33                          *      for include files
34                          */
35 int     cfile;          /*      current file handle index
36                          *      of input assembly files
37                          */
38 int     flevel;         /*      IF-ELSE-ENDIF flag will be non
39                          *      zero for false conditional case
40                          */
41 int     tlevel;         /*      current conditional level
42                          */
43 int     ifcnd[MAXIF+1]; /*      array of IF statement condition
44                          *      values (0 = FALSE) indexed by tlevel
45                          */
46 int     iflvl[MAXIF+1]; /*      array of IF-ELSE-ENDIF flevel
47                          *      values indexed by tlevel
48                          */
49
50 char    afn[FILSPC];            /*      afile temporary file name
51                                  */
52 char    srcfn[MAXFIL][FILSPC];  /*      array of source file names
53                                  */
54 int     srcline[MAXFIL];        /*      source line number
55                                  */
56 char    incfn[MAXINC][FILSPC];  /*      array of include file names
57                                  */
58 int     incline[MAXINC];        /*      include line number
59                                  */
60
61 int     radix;          /*      current number conversion radix:
62                          *      2 (binary), 8 (octal), 10 (decimal),
63                          *      16 (hexadecimal)
64                          */
65 int     line;           /*      current assembler source
66                          *      line number
67                          */
68 int     page;           /*      current page number
69                          */
70 int     lop;            /*      current line number on page
71                          */
72 int     pass;           /*      assembler pass number
73                          */
74 int     lflag;          /*      -l, generate listing flag
75                          */
76 int     gflag;          /*      -g, make undefined symbols global flag
77                          */
78 int     aflag;          /*      -a, make all symbols global flag
79                          */
80 int     oflag;          /*      -o, generate relocatable output flag
81                          */
82 int     sflag;          /*      -s, generate symbol table flag
83                          */
84 int     pflag;          /*      -p, enable listing pagination
85                          */
86 int     xflag;          /*      -x, listing radix flag
87                          */
88 int     fflag;          /*      -f(f), relocations flagged flag
89                          */
90 Addr_T  laddr;          /*      address of current assembler line
91                          *      or value of .if argument
92                          */
93 Addr_T  fuzz;           /*      tracks pass to pass changes in the
94                          *      address of symbols caused by
95                          *      variable length instruction formats
96                          */
97 int     lmode;          /*      listing mode
98                          */
99 char    *ep;            /*      pointer into error list
100                          *      array eb[NERR]
101                          */
102 char    eb[NERR];       /*      array of generated error codes
103                          */
104 char    *ip;            /*      pointer into the assembler-source
105                          *      text line in ib[]
106                          */
107 char    ib[NINPUT];     /*      assembler-source text line
108                          */
109 char    *cp;            /*      pointer to assembler output
110                          *      array cb[]
111                          */
112 char    cb[NCODE];      /*      array of assembler output values
113                          */
114 int     *cpt;           /*      pointer to assembler relocation type
115                          *      output array cbt[]
116                          */
117 int     cbt[NCODE];     /*      array of assembler relocation types
118                          *      describing the data in cb[]
119                          */
120 char    tb[NTITL];      /*      Title string buffer
121                          */
122 char    stb[NSBTL];     /*      Subtitle string buffer
123                          */
124 char    optsdcc[NINPUT];        /*      sdcc compile options 
125                          */
126
127 char    symtbl[] = { "Symbol Table" };
128 char    aretbl[] = { "Area Table" };
129
130 char    module[NCPS];   /*      module name string
131                          */
132
133 /*
134  *      The mne structure is a linked list of the assembler
135  *      mnemonics and directives.  The list of mnemonics and
136  *      directives contained in the device dependent file
137  *      xxxpst.c are hashed and linked into NHASH lists in
138  *      module assym.c by syminit().  The structure contains
139  *      the mnemonic/directive name, a subtype which directs
140  *      the evaluation of this mnemonic/directive, a flag which
141  *      is used to detect the end of the mnemonic/directive
142  *      list in xxxpst.c, and a value which is normally
143  *      associated with the assembler mnemonic base instruction
144  *      value.
145  *
146  *      struct  mne
147  *      {
148  *              struct  mne *m_mp;      Hash link
149  *              char    m_id[NCPS];     Mnemonic
150  *              char    m_type;         Mnemonic subtype
151  *              char    m_flag;         Mnemonic flags
152  *              Addr_T  m_valu;         Value
153  *      };
154  */
155 struct  mne     *mnehash[NHASH];
156
157 /*
158  *      The sym structure is a linked list of symbols defined
159  *      in the assembler source files.  The first symbol is "."
160  *      defined here.  The entry 'struct tsym *s_tsym'
161  *      links any temporary symbols following this symbol and
162  *      preceeding the next normal symbol.  The structure also
163  *      contains the symbol's name, type (USER or NEW), flag
164  *      (global, assigned, and multiply defined), a pointer
165  *      to the area structure defining where the symbol is
166  *      located, a reference number assigned by outgsd() in
167  *      asout.c, and the symbols address relative to the base
168  *      address of the area where the symbol is located.
169  *
170  *      struct  sym
171  *      {
172  *              struct  sym  *s_sp;     Hash link
173  *              struct  tsym *s_tsym;   Temporary symbol link
174  *              char    s_id[NCPS];     Symbol
175  *              char    s_type;         Symbol subtype
176  *              char    s_flag;         Symbol flags
177  *              struct  area *s_area;   Area line, 0 if absolute
178  *              int     s_ref;          Ref. number
179  *              Addr_T  s_addr;         Address
180  *      };
181  */
182 struct  sym     sym[] = {
183     { NULL,     NULL,   ".",    S_USER, S_END,  NULL,   0, }
184 };
185
186 struct  sym     *symp;          /*      pointer to a symbol structure
187                                  */
188 struct  sym *symhash[NHASH];    /*      array of pointers to NHASH
189                                  *      linked symbol lists
190                                  */
191
192 /*
193  *      The area structure contains the parameter values for a
194  *      specific program or data section.  The area structure
195  *      is a linked list of areas.  The initial default area
196  *      is "_CODE" defined here, the next area structure
197  *      will be linked to this structure through the structure
198  *      element 'struct area *a_ep'.  The structure contains the
199  *      area name, area reference number ("_CODE" is 0) determined
200  *      by the order of .area directives, area size determined
201  *      from the total code and/or data in an area, area fuzz is
202  *      an variable used to track pass to pass changes in the
203  *      area size caused by variable length instruction formats,
204  *      and area flags which specify the area's relocation type.
205  *
206  *      struct  area
207  *      {
208  *              struct  area *a_ap;     Area link
209  *              char    a_id[NCPS];     Area Name
210  *              int     a_ref;          Reference number
211  *              Addr_T  a_size;         Area size
212  *              Addr_T  a_fuzz;         Area fuzz
213  *              int     a_flag;         Area flags
214  *      };
215  */
216 struct  area    area[] = {
217     { NULL,     "_CODE",        0,      0,      0,      A_CON|A_REL }
218 };
219
220 struct  area    *areap; /*      pointer to an area structure
221                          */
222
223 FILE    *lfp;           /*      list output file handle
224                          */
225 FILE    *ofp;           /*      relocation output file handle
226                          */
227 FILE    *tfp;           /*      symbol table output file handle
228                          */
229 FILE    *sfp[MAXFIL];   /*      array of assembler-source file handles
230                          */
231 FILE    *ifp[MAXINC];   /*      array of include-file file handles
232                          */
233
234 /*
235  *      array of character types, one per
236  *      ASCII character
237  */
238 unsigned char   ctype[128] = {
239 /*NUL*/ ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,
240 /*BS*/  ILL,    SPACE,  ILL,    ILL,    SPACE,  ILL,    ILL,    ILL,
241 /*DLE*/ ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,
242 /*CAN*/ ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,
243 /*SPC*/ SPACE,  ETC,    ETC,    ETC,    LETTER, BINOP,  BINOP,  ETC,
244 /*(*/   ETC,    ETC,    BINOP,  BINOP,  ETC,    BINOP,  LETTER, BINOP,
245 /*0*/   DGT2,   DGT2,   DGT8,   DGT8,   DGT8,   DGT8,   DGT8,   DGT8,
246 /*8*/   DGT10,  DGT10,  ETC,    ETC,    BINOP,  ETC,    BINOP,  ETC,
247 /*@*/   ETC,    LTR16,  LTR16,  LTR16,  LTR16,  LTR16,  LTR16,  LETTER,
248 /*H*/   LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
249 /*P*/   LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
250 /*X*/   LETTER, LETTER, LETTER, ETC,    ETC,    ETC,    BINOP,  LETTER,
251 /*`*/   ETC,    LTR16,  LTR16,  LTR16,  LTR16,  LTR16,  LTR16,  LETTER,
252 /*h*/   LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
253 /*p*/   LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
254 /*x*/   LETTER, LETTER, LETTER, ETC,    BINOP,  ETC,    ETC,    ETC
255 };
256
257 /*
258  *      an array of characters which
259  *      perform the case translation function
260  */
261 #if     CASE_SENSITIVE
262 #else
263 char    ccase[128] = {
264 /*NUL*/ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
265 /*BS*/  '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
266 /*DLE*/ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
267 /*CAN*/ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
268 /*SPC*/ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
269 /*(*/   '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
270 /*0*/   '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
271 /*8*/   '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
272 /*@*/   '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
273 /*H*/   '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
274 /*P*/   '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
275 /*X*/   '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
276 /*`*/   '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
277 /*h*/   '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
278 /*p*/   '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
279 /*x*/   '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177'
280 };      
281 #endif