struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / asxxsrc / asdata.c
blob76e0fefa7ab65d6f468910ebd3a42075cb94fce9
1 /* asdata.c */
3 /*
4 * Copyright (C) 1989-2021 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Alan R. Baldwin
21 * 721 Berkeley St.
22 * Kent, Ohio 44240
24 * With enhancements from
26 * John L. Hartman (JLH)
27 * jhartman@compuserve.com
29 * Bill McKinnon (BM)
30 * w_mckinnon@conknet.com
32 * Mike McCarty
33 * mike dot mccarty at sbcglobal dot net
36 #include "asxxxx.h"
38 /*)Module asdata.c
40 * The module asdata.c contains the global constants,
41 * structures, and variables used in the assembler.
44 int aserr; /* ASxxxx error counter
46 jmp_buf jump_env; /* compiler dependent structure
47 * used by setjmp() and longjmp()
51 * The asmf structure contains the information
52 * pertaining to an assembler source file/macro.
54 * The Parameters:
55 * next is a pointer to the next object in the linked list
56 * objtyp specifies the object type - T_ASM, T_INCL, T_MACRO
57 * line is the saved line number of the parent object
58 * fp is the source FILE handle
59 * afp is the file path length (excludes the files name.ext)
60 * afn[] is the assembler/include file path/name.ext
62 * struct asmf
63 * {
64 * struct asmf *next; Link to Next Object
65 * int objtyp; Object Type
66 * int line; Saved Line Counter
67 * int flevel; saved flevel
68 * int tlevel; saved tlevel
69 * int lnlist; saved lnlist
70 * FILE * fp; FILE Handle
71 * int afp; File Path Length
72 * char afn[FILSPC]; File Name
73 * };
75 struct asmf *asmc; /* Pointer to the current
76 * source input structure
78 struct asmf *asmp; /* The pointer to the first assembler
79 * source file structure of a linked list
81 struct asmf *asmi; /* Queued pointer to an include file
82 * source input structure
84 struct asmf *asmq; /* Queued pointer to a macro
85 * source input structure
89 * The mcrdef structure contains the
90 * information about a macro definition.
92 * When the macro is defined the definition
93 * arguments are packed into a linked list of
94 * strings beginning with bgnarg and ending with
95 * endarg. The number of args is placed in narg.
97 * When the macro is invoked the expansion
98 * argument strings are placed into a linked
99 * list of strings beginning with bgnxrg and
100 * ending with endxrg. The number of expansion
101 * arguments is placed in xarg.
103 * The Parameters:
104 * next is a pointer to the next macro definition structure
105 * name is a pointer to the macro name string
106 * bgnlst is a pointer to the first text line of the macro
107 * endlst is a pointer to the last text line of the macro
108 * type is the macro type - .macro, .irp, .irpc, or .rept
109 * rptcnt is the repeat count for the macro
110 * nest is the macro nesting counter
111 * narg is the number of macro definition arguments
112 * bgnarg is a pointer to the first definition argument string
113 * endarg is a pointer to the last definition argument string
114 * xarg is the number of expansion arguments at macro invocation
115 * bgnxrg is a pointer to the first expansion argument string
116 * endxrg is a pointer to the last expansion argument string
118 * struct mcrdef {
119 * struct mcrdef * next; link to next macro definition
120 * char * name; pointer to the macro name
121 * struct strlst * bgnlst; link to first text line of macro
122 * struct strlst * endlst; link to last text line of macro
123 * int type; macro type
124 * int rptcnt; repeat counter
125 * int nest; macro nesting counter
126 * int narg; number of macro defintion arguments
127 * struct strlst * bgnarg; link to first macro defintion argument
128 * struct strlst * endarg; link to last macro definition argument
129 * int xarg; number of macro expansion arguments
130 * struct strlst * bgnxrg; link to first macro expansion argument
131 * struct strlst * endxrg; link to last macro xpansion argument
132 * };
134 struct mcrdef * mcrlst; /* link to list of defined macros
136 struct mcrdef * mcrp; /* link to list of defined macros
140 * The memlnk structure is a linked list
141 * of memory allocations.
143 * The function new() uses the memlnk structure
144 * to create a linked list of allocated memory
145 * that can be traversed by asfree() to release
146 * the allocated memory.
148 * The function mhunk() uses the memlnk structure
149 * to create a linked list of allocated memory
150 * that can be reused.
152 * The Parameters:
153 * next is a pointer to the next memlnk structure.
154 * ptr is a pointer to the allocated memory.
156 * struct memlnk {
157 * struct memlnk * next; link to next memlnk
158 * VOID * ptr; pointer to allocated memory
159 * };
161 struct memlnk * pmcrmem;/* First Macro Memory Allocation Structure
163 struct memlnk * mcrmem; /* Macro Memory Allocation Structure
165 int mcrblk; /* new data blocks allocated
167 int incfil; /* include file nesting counter
169 int maxinc; /* maximum include file nesting encountered
171 int mcrfil; /* macro nesting counter
173 int maxmcr; /* maximum macro nesting encountered
175 int flevel; /* IF-ELSE-ENDIF flag will be non
176 * zero for false conditional case
178 int ftflevel; /* IIFF-IIFT-IIFTF FLAG
180 int tlevel; /* current conditional level
182 int lnlist; /* LIST-NLIST options
184 int ifcnd[MAXIF+1]; /* array of IF statement condition
185 * values (0 = FALSE) indexed by tlevel
187 int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
188 * values indexed by tlevel
190 char afn[FILSPC]; /* current input file specification
192 int afp; /* current input file path length
194 char afntmp[FILSPC]; /* temporary input file specification
196 int afptmp; /* temporary input file path length
198 int srcline; /* current source line number
200 int asmline; /* current assembler file line number
202 int incline; /* current include file line number
204 int mcrline; /* current macro line number
206 int radix; /* current number conversion radix:
207 * 2 (binary), 8 (octal), 10 (decimal),
208 * 16 (hexadecimal)
210 int line; /* current assembler source
211 * line number
213 int page; /* current page number
215 int lop; /* current line number on page
217 time_t curtim; /* pointer to the current time string
219 int pass; /* assembler pass number
221 int aflag; /* -a, make all symbols global flag
223 int bflag; /* -b(b), listing modes flag
225 int cflag; /* -c, disable cycle counts in listing flag
227 int fflag; /* -f(f), relocations flagged flag
229 int gflag; /* -g, make undefined symbols global flag
231 int jflag; /* -j, enable NoICE Debug Symbols
233 int lflag; /* -l, generate listing flag
235 int nflag; /* -n, don't resolve global assigned value symbols flag
237 int oflag; /* -o, generate relocatable output flag
239 int pflag; /* -p, disable listing pagination
241 int sflag; /* -s, generate symbol table flag
243 int tflag; /* -t, output diagnostic parameters from assembler
245 int uflag; /* -u, disable .list/.nlist processing flag
247 int vflag; /* -v, enable out of range signed / unsigned errors
249 int wflag; /* -w, enable wide listing format
251 int xflag; /* -x, listing radix flag
253 int yflag; /* -y, enable SDCC Debug Symbols
255 int zflag; /* -z, disable symbol case sensitivity
257 int waddrmode; /* WORD Address mode flag
259 int a_bytes; /* REL file T Line address length
261 a_uint a_mask; /* Address Mask
263 a_uint s_mask; /* Sign Mask
265 a_uint v_mask; /* Value Mask
267 a_uint laddr; /* address of current assembler line
268 * or value of .if argument
270 a_uint fuzz; /* tracks pass to pass changes in the
271 * address of symbols caused by
272 * variable length instruction formats
274 int lmode; /* listing mode
276 char *ep; /* pointer into error list
277 * array eb[NERR]
279 char eb[NERR]; /* array of generated error codes
281 char *ex[NERR]; /* array of error string pointers
283 char *ip; /* pointer into the assembler-source
284 * text line in ib[]
286 char *ib; /* assembler-source text line for processing
288 char *ic; /* assembler-source text line for listing
290 char *cp; /* pointer to assembler output
291 * array cb[]
293 char cb[NCODE]; /* array of assembler output values
295 int *cpt; /* pointer to assembler relocation type
296 * output array cbt[]
298 int cbt[NCODE]; /* array of assembler relocation types
299 * describing the data in cb[]
301 int opcycles; /* opcode execution cycles
303 char tb[NTITL]; /* Title string buffer
305 char stb[NSBTL]; /* Subtitle string buffer
307 char erb[NINPUT+4]; /* Error string buffer
310 char symtbl[] = { "Symbol Table" };
311 char aretbl[] = { "Area Table" };
313 char module[NCPS+2]; /* module name string
315 /* sdas specific */
316 int org_cnt; /* .org directive counter
318 char *optsdcc; /* sdcc compile options
320 /* end sdas specific */
323 * The mne structure is a linked list of the assembler
324 * mnemonics and directives. The list of mnemonics and
325 * directives contained in the device dependent file
326 * xxxpst.c are hashed and linked into NHASH lists in
327 * module assym.c by syminit(). The structure contains
328 * the mnemonic/directive name, a subtype which directs
329 * the evaluation of this mnemonic/directive, a flag which
330 * is used to detect the end of the mnemonic/directive
331 * list in xxxpst.c, and a value which is normally
332 * associated with the assembler mnemonic base instruction
333 * value.
335 * struct mne
337 * struct mne *m_mp; Hash link
338 * char * m_id; Mnemonic (JLH)
339 * char m_type; Mnemonic subtype
340 * char m_flag; Mnemonic flags
341 * a_uint m_valu; Value
342 * };
344 struct mne *mnehash[NHASH];
347 * The sym structure is a linked list of symbols defined
348 * in the assembler source files. The first symbol is "."
349 * defined here. The entry 'struct tsym *s_tsym'
350 * links any temporary symbols following this symbol and
351 * preceeding the next normal symbol. The structure also
352 * contains the symbol's name, type (USER or NEW), flag
353 * (global, assigned, and multiply defined), a pointer
354 * to the area structure defining where the symbol is
355 * located, a reference number assigned by outgsd() in
356 * asout.c, and the symbols address relative to the base
357 * address of the area where the symbol is located.
359 * struct sym
361 * struct sym *s_sp; Hash link
362 * struct tsym *s_tsym; Temporary symbol link
363 * char *s_id; Symbol (JLH)
364 * char s_type; Symbol subtype
365 * char s_flag; Symbol flags
366 * struct area *s_area; Area line, 0 if absolute
367 * int s_ref; Ref. number
368 * a_uint s_addr; Address
369 * sdas specific
370 * a_uint s_org; Start Address if absolute
371 * end sdas specific
372 * };
374 struct sym sym[] = {
375 { NULL, NULL, ".", S_USER, 0, NULL, 0, 0, 0 },
376 { NULL, NULL, ".__.ABS.", S_USER, S_ASG|S_GBL, NULL, 0, 0, 0 },
377 { NULL, NULL, ".__.CPU.", S_USER, S_ASG|S_LCL, NULL, 0, 0, 0 },
378 { NULL, NULL, ".__.H$L.", S_USER, S_ASG|S_LCL, NULL, 0, 0, 0 },
379 { NULL, NULL, ".__.$$$.", S_USER, S_ASG|S_LCL|S_EOL, NULL, 0, 0, 0 }
382 struct sym *symp; /* pointer to a symbol structure
384 struct sym *symhash[NHASH]; /* array of pointers to NHASH
385 * linked symbol lists
389 * The area structure contains the parameter values for a
390 * specific program or data section. The area structure
391 * is a linked list of areas. The initial default area
392 * is "_CODE" defined here, the next area structure
393 * will be linked to this structure through the structure
394 * element 'struct area *a_ap'. The structure contains the
395 * area name, area reference number ("_CODE" is 0) determined
396 * by the order of .area directives, area size determined
397 * from the total code and/or data in an area, area fuzz is
398 * a variable used to track pass to pass changes in the
399 * area size caused by variable length instruction formats,
400 * and area flags which specify the area's relocation type.
402 * struct area
404 * struct area *a_ap; Area link
405 * char * a_id; Area Name
406 * int a_ref; Reference number
407 * a_uint a_size; Area size
408 * a_uint a_fuzz; Area fuzz
409 * int a_flag; Area flags
410 * };
412 struct area area[] = {
413 {NULL, "_CODE", 0, 0, 0, A_CON|A_REL}
416 struct area *areap; /* pointer to an area structure
419 * The def structure is used by the .define assembler
420 * directive to define a substitution string for a
421 * single word. The def structure contains the
422 * string being defined, the string to substitute
423 * for the defined string, and a link to the next
424 * def structure. The defined string is a sequence
425 * of characters not containing any white space
426 * (i.e. NO SPACEs or TABs). The substitution string
427 * may contain SPACES and/or TABs.
429 * struct def
431 * struct def *d_dp; link to next define
432 * char *d_id; defined string
433 * char *d_define; string to substitute for defined string
434 * int d_dflag; (1) .defined / (0) .undefined
435 * };
437 * Pointer to a def structure
439 struct def *defp = NULL;
441 FILE *lfp; /* list output file handle
443 FILE *ofp; /* relocation output file handle
445 FILE *tfp; /* symbol table output file handle
447 char txt[NTXT]; /* T Line Values
449 char rel[NREL]; /* R Line Values
451 char *txtp = &txt[0];/* Pointer to T Line Values
453 char *relp = &rel[0];/* Pointer to R Line Values
457 * an array of character types,
458 * one per ASCII character
460 unsigned char ctype[256] = {
461 /*NUL*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
462 /*BS*/ ILL, SPACE, ILL, ILL, SPACE, ILL, ILL, ILL,
463 /*DLE*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
464 /*CAN*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
465 /*SPC*/ SPACE, ETC, ETC, ETC, LETTER, BINOP, BINOP, ETC,
466 /*(*/ ETC, ETC, BINOP, BINOP, ETC, BINOP, LETTER, BINOP,
467 /*0*/ DGT2, DGT2, DGT8, DGT8, DGT8, DGT8, DGT8, DGT8,
468 /*8*/ DGT10, DGT10, ETC, ETC, BINOP, ETC, BINOP, ETC,
469 /*@*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER,
470 /*H*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
471 /*P*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
472 /*X*/ LETTER, LETTER, LETTER, BINOP, ETC, ETC, BINOP, LETTER,
473 /*`*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER,
474 /*h*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
475 /*p*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
476 /*x*/ LETTER, LETTER, LETTER, ETC, BINOP, ETC, ETC, ETC,
477 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
478 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
479 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
480 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
481 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
482 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
483 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
484 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
485 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
486 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
487 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
488 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
489 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
490 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
491 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
492 LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER
496 * an array of characters which
497 * perform the case translation function
499 char ccase[256] = {
500 /*NUL*/ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
501 /*BS*/ '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
502 /*DLE*/ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
503 /*CAN*/ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
504 /*SPC*/ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
505 /*(*/ '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
506 /*0*/ '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
507 /*8*/ '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
508 /*@*/ '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
509 /*H*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
510 /*P*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
511 /*X*/ '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
512 /*`*/ '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
513 /*h*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
514 /*p*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
515 /*x*/ '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
516 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
517 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
518 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
519 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
520 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
521 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
522 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
523 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
524 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
525 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
526 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
527 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
528 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
529 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
530 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
531 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377'