annotate lwasm/lwasm.h @ 261:c79b3c88adbc 2.x

Added --depend option to generate a list of dependencies
author lost
date Sat, 26 Dec 2009 08:24:35 +0000
parents e27279180a73
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
1 /*
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
2 lwasm.h
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
3 Copyright © 2008 William Astle
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
5 This file is part of LWASM.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
6
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
8 terms of the GNU General Public License as published by the Free Software
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
10 version.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
11
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
15 more details.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
16
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
17 You should have received a copy of the GNU General Public License along with
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
19
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
20 Contains the main defs used by the assembler
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
21 */
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
22
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24 #ifndef __lwasm_h_seen__
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
25 #define __lwasm_h_seen__
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 57
diff changeset
27 #include <stdio.h>
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
28 #include "expr.h"
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
29
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30 #define OUTPUT_DECB 0 // DECB multirecord format
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
31 #define OUTPUT_RAW 1 // raw sequence of bytes
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
32 #define OUTPUT_OBJ 2 // proprietary object file format
46
b962cee20bf4 Ported output modules forward from old version
lost
parents: 44
diff changeset
33 #define OUTPUT_RAWREL 3 // raw bytes where ORG causes a SEEK in the file
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
34 #define OUTPUT_OS9 4 // os9 module target
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
35
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
36 // structure for tracking sections
86
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
37 typedef struct section_reloc_list_s section_reloc_list_t;
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
38 struct section_reloc_list_s
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
39 {
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
40 int offset; // offset into section
204
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 198
diff changeset
41 int relocsize; // size of relocation in bytes
86
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
42 lwasm_expr_stack_t *expr; // value definition
91
718998b673ee Added incomplete references to object output and added support for section base terms in expression handler
lost
parents: 90
diff changeset
43 int context; // symbol context (for local syms)
86
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
44 section_reloc_list_t *next; // next relocation
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
45 };
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
46
90
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
47 typedef struct export_list_s export_list_t;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
48 struct export_list_s
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
49 {
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
50 int offset; // offset of symbol
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
51 char *sym; // name of symbol
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
52 export_list_t *next; // next export
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
53 };
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
54
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
55 #define SECTION_BSS 1 // the section contains no actual code - just uninit vars
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
56 typedef struct sectiontab_s sectiontab_t;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
57 struct sectiontab_s
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
58 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
59 char *name; // name of the section
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
60 int offset; // current offset in the section
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
61 int flags; // section flags
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
62 sectiontab_t *next; // next section
86
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
63 // the following are used during code output
85
918be0c02239 Started adding object target output
lost
parents: 82
diff changeset
64 unsigned char *obytes; // output bytes
918be0c02239 Started adding object target output
lost
parents: 82
diff changeset
65 int oblen; // how many bytes output so far?
918be0c02239 Started adding object target output
lost
parents: 82
diff changeset
66 int obsize; // how big is output buffer so far?
86
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
67 section_reloc_list_t *rl; // relocation list
90
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
68 export_list_t *exports; // export list for the section
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
69 };
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
70
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
71 // structure for tracking macros
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
72 typedef struct macrotab_s macrotab_t;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
73 struct macrotab_s
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
74 {
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
75 char *name;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
76 char **lines;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
77 int numlines;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
78 macrotab_t *next;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
79 };
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
80
254
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
81 // structure for tracking structs
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
82 struct struct_sym_e;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
83
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
84 typedef struct structtab_s structtab_t;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
85 struct structtab_s
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
86 {
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
87 char *name;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
88 int size;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
89 struct struct_sym_e *fields;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
90 structtab_t *next;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
91 };
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
92
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
93 struct struct_sym_e
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
94 {
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
95 char *name;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
96 int size;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
97 structtab_t *substruct;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
98 struct struct_sym_e *next;
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
99 };
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
100
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
101 // structure for tracking errors
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
102 typedef struct lwasm_error_s lwasm_error_t;
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
103 struct lwasm_error_s
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
104 {
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
105 char *mess; // the actual error message
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
106 lwasm_error_t *next; // ptr to next error
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
107 };
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
108
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
109 // structure for keeping track of lines
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
110 // it also as space for 4 expressions which is enough for all known
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
111 // instructions and addressing modes
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
112 // on pass 1, the expressions are parsed, on pass 2 they are re-evaluated
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
113 // to determine constancy
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
114 typedef struct lwasm_line_s lwasm_line_t;
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
115 struct lwasm_line_s {
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
116 char *text; // the actual text of the line
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
117 int lineno; // line number within the file
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
118 char *filename; // file name reference
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
119 lwasm_line_t *next; // next line
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
120 lwasm_line_t *prev; // previous line
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
121 lwasm_error_t *err; // error messages
28
c0ff62e5ad39 Added register list mode handler
lost
parents: 27
diff changeset
122 int fsize; // forced size (0 = no forced size)
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
123 char *sym; // scratch area to record the presence of a symbol
42
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 38
diff changeset
124 unsigned char *bytes; // actual bytes emitted
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 38
diff changeset
125 int codelen; // number of bytes emitted
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 38
diff changeset
126 int codesize; // the size of the code buffer
44
2330b88f9600 Added simple output listing
lost
parents: 42
diff changeset
127 int codeaddr; // address the code goes at
46
b962cee20bf4 Ported output modules forward from old version
lost
parents: 44
diff changeset
128 int nocodelen; // for "RMB" type instructions
49
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 46
diff changeset
129 int addrset; // set if this instruction sets the assembly address
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 46
diff changeset
130 int symaddr; // set if this instruction sets a symbol addr with EQU or the like
67
d5fe306f1ab1 Fixed numerous bugs in macro handling
lost
parents: 64
diff changeset
131 int badop; // bad operation - ignore it
91
718998b673ee Added incomplete references to object output and added support for section base terms in expression handler
lost
parents: 90
diff changeset
132 int context; // the symbol context for this line
190
563adfccb645 Added 'sym=expr' opcode handling
lost
parents: 160
diff changeset
133 int forceglobal; // force a "global" symbol definition if constant
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
134
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
135 // the following are used for obj format - for external references, inter-section
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
136 // references, and intrasection relocations
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
137 int relocoff; // offset into insn where relocation value goes
204
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 198
diff changeset
138 int reloc8bit; // size of relocation (0 = 16 bit, 1 = 8 bit)
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
139 lwasm_expr_stack_t *exprs[4]; // non-constant expression values
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
140 int exprvals[4]; // constant expression values
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
141 char *exprends[4]; // pointer to character after end of expression
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
142 int inmod; // in an os9 module
85
918be0c02239 Started adding object target output
lost
parents: 82
diff changeset
143
918be0c02239 Started adding object target output
lost
parents: 82
diff changeset
144 sectiontab_t *sect; // which section is the line in?
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
145 };
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
146
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
147 // for keeping track of symbols
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 74
diff changeset
148 #define SYMBOL_SET 1 // the symbol was used for "SET"
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 74
diff changeset
149 #define SYMBOL_COMPLEX 2 // register symbol as a complex symbol (from l -> expr)
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
150 #define SYMBOL_FORCE 4 // force resetting the symbol value if it already exists on pass 2
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 74
diff changeset
151 #define SYMBOL_NORM 0 // no flags
82
03be43ae19cf Added EXTERN directive
lost
parents: 78
diff changeset
152 #define SYMBOL_EXTERN 8 // the symbol is an external reference
190
563adfccb645 Added 'sym=expr' opcode handling
lost
parents: 160
diff changeset
153 #define SYMBOL_GLOBAL 16 // force global if non-complex symbol
254
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
154 #define SYMBOL_NOCHECK 32 // don't check characters for validity
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
155 typedef struct lwasm_symbol_ent_s lwasm_symbol_ent_t;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
156 struct lwasm_symbol_ent_s
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
157 {
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 74
diff changeset
158 char *sym; // the symbol
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 74
diff changeset
159 int context; // the context number of the symbol (-1 for global)
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 74
diff changeset
160 int value; // the value of the symbol
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 74
diff changeset
161 int flags; // flags for the symbol
82
03be43ae19cf Added EXTERN directive
lost
parents: 78
diff changeset
162 char *externalname; // for external references that are aliased locally
75
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 74
diff changeset
163 sectiontab_t *sect; // the section the symbol exists in; NULL for none
92eb93bffa28 Rejigged symbol system to be able to handle non-constant references
lost
parents: 74
diff changeset
164 lwasm_expr_stack_t *expr; // expression for a symbol that is not constant NULL for const
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
165 lwasm_symbol_ent_t *next; // next symbol in the table
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
166 lwasm_symbol_ent_t *prev; // previous symbol in the table
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
167 };
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
168
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
169 // keep track of current assembler state
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
170 typedef struct {
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
171 int dpval; // current dp value (setdp)
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
172 int addr; // current address
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
173 int context; // context counter (for local symbols)
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
174 int errorcount; // error count
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
175 int passnum; // which pass are we on?
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
176 int execaddr; // execution address for the program (END ....)
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
177 int pragmas; // what pragmas are in effect?
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
178
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
179 lwasm_line_t *lineshead; // first line of source code
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
180 lwasm_line_t *linestail; // last line of source code
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
181
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
182 lwasm_symbol_ent_t *symhead; // first entry in symbol table
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
183 lwasm_symbol_ent_t *symtail; // last entry in symbol table
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
184
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
185 macrotab_t *macros; // macro table
254
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
186 structtab_t *structs; // structure table
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
187 structtab_t *cstruct; // address within the current structure def
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
188
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
189 const char *infile; // input file
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
190 const char *outfile; // output file
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
191 const char *listfile; // output listing file
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
192 int outformat; // output format type
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
193 char **filelist; // files that have been read
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
194 int filelistlen; // number of files in the list
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 49
diff changeset
195
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 49
diff changeset
196 int endseen; // set to true if "end" has been seen
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
197 int skipcond; // skipping a condition?
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
198 int skipcount; // how many?
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
199 int skipmacro; // skipping a macro?
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
200 int inmacro; // are we currently in a macro?
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
201 int macroex; // current depth of macro expansion
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
202 int nextcontext; // next context number
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
203 int skiplines; // number of lines to skip
254
c7a41b4c89b3 Added struct support to LWASM
lost
parents: 243
diff changeset
204 int instruct; // are we currently in a structure def?
261
c79b3c88adbc Added --depend option to generate a list of dependencies
lost
parents: 257
diff changeset
205 int deptrack; // are we doing dependency tracking?
c79b3c88adbc Added --depend option to generate a list of dependencies
lost
parents: 257
diff changeset
206
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
207 // items used only for the "object" target
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
208 sectiontab_t *sections; // pointer to section table
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 67
diff changeset
209 sectiontab_t *csect; // current section - NULL if not in one
230
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 229
diff changeset
210
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 229
diff changeset
211 // only 6809 ops?
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
212 int no6309;
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
213
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
214 // for os9 mode
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
215 int inmod; // in a module?
238
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
216 unsigned char crc[3]; // running crc count
243
f9f01a499525 Added zero-width external references
lost
parents: 238
diff changeset
217
f9f01a499525 Added zero-width external references
lost
parents: 238
diff changeset
218 int nextdeps; // number forced external deps
f9f01a499525 Added zero-width external references
lost
parents: 238
diff changeset
219 char **extdeps; // external dependencies
257
e27279180a73 Added support for include path to LWASM
lost
parents: 254
diff changeset
220
e27279180a73 Added support for include path to LWASM
lost
parents: 254
diff changeset
221 char **includedirs; // include path
e27279180a73 Added support for include path to LWASM
lost
parents: 254
diff changeset
222 int nincludedirs; // number of entries in include path
261
c79b3c88adbc Added --depend option to generate a list of dependencies
lost
parents: 257
diff changeset
223
c79b3c88adbc Added --depend option to generate a list of dependencies
lost
parents: 257
diff changeset
224 int nincfiles; // number of included files
c79b3c88adbc Added --depend option to generate a list of dependencies
lost
parents: 257
diff changeset
225 char **incfiles; // included files
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
226 } asmstate_t;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
227
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 101
diff changeset
228 // do not rewrite XXX,r to ,r if XXX evaluates to 0
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
229 #define PRAGMA_NOINDEX0TONONE 1
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 101
diff changeset
230 // any undefined symbols are considered external
160
b061350c17e4 Added cescapes pragma and a few other compatibility pseudo ops
lost
parents: 151
diff changeset
231 #define PRAGMA_UNDEFEXTERN 2
b061350c17e4 Added cescapes pragma and a few other compatibility pseudo ops
lost
parents: 151
diff changeset
232 // allow C-style escapes in fcc, fcs, and fcn directives
b061350c17e4 Added cescapes pragma and a few other compatibility pseudo ops
lost
parents: 151
diff changeset
233 #define PRAGMA_CESCAPES 4
198
6ddc861a07d4 Allow export to import undefined symbols
lost
parents: 190
diff changeset
234 // allow "export <undefsym>" to import the symbol
6ddc861a07d4 Allow export to import undefined symbols
lost
parents: 190
diff changeset
235 #define PRAGMA_IMPORTUNDEFEXPORT 8
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
236 // don't have $ as a local symbol
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
237 #define PRAGMA_DOLLARNOTLOCAL 16
198
6ddc861a07d4 Allow export to import undefined symbols
lost
parents: 190
diff changeset
238
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
239 #ifndef __lwasm_c_seen__
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
240 #define __lwasm_E__ extern
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
241 #else
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
242 #define __lwasm_E__
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
243 #endif
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
244
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
245 __lwasm_E__ int debug_level;
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
246
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
247 __lwasm_E__ int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...);
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
248 __lwasm_E__ void debug_message(int level, const char *fmt, ...);
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
249
27
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
250 __lwasm_E__ void lwasm_emit(asmstate_t *as, lwasm_line_t *l, int b);
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
251 __lwasm_E__ void lwasm_emitop(asmstate_t *as, lwasm_line_t *l, int o);
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
252 __lwasm_E__ int lwasm_lookupreg2(const char *reglist, char **str);
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 28
diff changeset
253 __lwasm_E__ int lwasm_lookupreg3(const char *rlist, const char **str);
27
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
254
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
255 __lwasm_E__ lwasm_expr_stack_t *lwasm_evaluate_expr(asmstate_t *as, lwasm_line_t *l, const char *inp, const char **outp, int flags);
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
256
55
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
257
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
258 // return next context number and update it
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
259 __lwasm_E__ int lwasm_next_context(asmstate_t *as);
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
260
55
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
261 // also throw an error on expression eval failure
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 75
diff changeset
262 // return 0 on ok, -1 on error, 1 if a complex expression was returned
55
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
263 #define EXPR_NOFLAG 0
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 75
diff changeset
264 #define EXPR_PASS1CONST 1 // no forward references on pass 1
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
265 #define EXPR_SECTCONST 2 // resolve symbols local to section
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
266 #define EXPR_REEVAL 4 // re-evaluate the expression
55
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
267 __lwasm_E__ int lwasm_expr_result(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val);
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
268 __lwasm_E__ int lwasm_expr_result2(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val, int slot);
55
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
269
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
270 #undef __lwasm_E__
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
271
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
272
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
273 #ifndef __symbol_c_seen__
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
274 #define __lwasm_E__ extern
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
275 #else
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
276 #define __lwasm_E__
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
277 #endif
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
278
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
279 __lwasm_E__ int lwasm_register_symbol(asmstate_t *as, lwasm_line_t *l, char *sym, int val, int flags);
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
280 __lwasm_E__ lwasm_symbol_ent_t *lwasm_find_symbol(asmstate_t *as, char *sym, int scontext);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
281 __lwasm_E__ int lwasm_set_symbol(asmstate_t *as, char *sym, int scontext, int val);
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 57
diff changeset
282 __lwasm_E__ void lwasm_list_symbols(asmstate_t *as, FILE *f);
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
283 #undef __lwasm_E__
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
284
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
285
229
59a138df0401 Fixed additional parsing problems with pseudo ops
lost
parents: 204
diff changeset
286 #define skip_operand(p) do { char **p2 = (char **)(p); for ( ; **p2; (*p2)++ ) ; } while (0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
287
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
288 #endif //__lwasm_h_seen__