Mercurial > hg-old > index.cgi
annotate src/lwasm.h @ 74:c8c772ef5df9
Checkpointing object target implementation
author | lost |
---|---|
date | Thu, 08 Jan 2009 01:18:40 +0000 |
parents | d5fe306f1ab1 |
children | 92eb93bffa28 |
rev | line source |
---|---|
0 | 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 | 22 |
23 | |
24 #ifndef __lwasm_h_seen__ | |
25 #define __lwasm_h_seen__ | |
26 | |
58 | 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 | 30 #define OUTPUT_DECB 0 // DECB multirecord format |
31 #define OUTPUT_RAW 1 // raw sequence of bytes | |
21 | 32 #define OUTPUT_OBJ 2 // proprietary object file format |
46 | 33 #define OUTPUT_RAWREL 3 // raw bytes where ORG causes a SEEK in the file |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
34 |
74 | 35 // structure for tracking sections |
36 #define SECTION_BSS 1 // the section contains no actual code - just uninit vars | |
37 typedef struct sectiontab_s sectiontab_t; | |
38 struct sectiontab_s | |
39 { | |
40 char *name; // name of the section | |
41 int offset; // current offset in the section | |
42 int flags; // section flags | |
43 sectiontab_t *next; // next section | |
44 }; | |
45 | |
57 | 46 // structure for tracking macros |
47 typedef struct macrotab_s macrotab_t; | |
48 struct macrotab_s | |
49 { | |
50 char *name; | |
51 char **lines; | |
52 int numlines; | |
53 macrotab_t *next; | |
54 }; | |
55 | |
26 | 56 // structure for tracking errors |
57 typedef struct lwasm_error_s lwasm_error_t; | |
58 struct lwasm_error_s | |
59 { | |
60 char *mess; // the actual error message | |
61 lwasm_error_t *next; // ptr to next error | |
62 }; | |
63 | |
21 | 64 // structure for keeping track of lines |
65 typedef struct lwasm_line_s lwasm_line_t; | |
66 struct lwasm_line_s { | |
67 char *text; // the actual text of the line | |
68 int lineno; // line number within the file | |
69 char *filename; // file name reference | |
70 lwasm_line_t *next; // next line | |
71 lwasm_line_t *prev; // previous line | |
26 | 72 lwasm_error_t *err; // error messages |
28 | 73 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
|
74 char *sym; // scratch area to record the presence of a symbol |
42 | 75 unsigned char *bytes; // actual bytes emitted |
76 int codelen; // number of bytes emitted | |
77 int codesize; // the size of the code buffer | |
44 | 78 int codeaddr; // address the code goes at |
46 | 79 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
|
80 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
|
81 int symaddr; // set if this instruction sets a symbol addr with EQU or the like |
67 | 82 int badop; // bad operation - ignore it |
74 | 83 |
84 // the following are used for obj format - for external references, inter-section | |
85 // references, and intrasection relocations | |
86 int relocoff; // offset into insn where relocation value goes | |
87 // the incomplete reference expression | |
88 struct lwasm_expr_strack_t *expr; | |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
89 }; |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
90 |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
91 // for keeping track of symbols |
63
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
58
diff
changeset
|
92 #define SYMBOL_SET 1 // the symbol was used for "SET" |
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
58
diff
changeset
|
93 #define SYMBOL_NORM 0 // no flags |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
94 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
|
95 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
|
96 { |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
97 char *sym; // the symbol |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
98 int context; // the context number of the symbol (-1 for global) |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
99 int value; // the value of the symbol |
63
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
58
diff
changeset
|
100 int flags; // flags for the symbol |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
101 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
|
102 lwasm_symbol_ent_t *prev; // previous symbol in the table |
21 | 103 }; |
0 | 104 |
105 // keep track of current assembler state | |
106 typedef struct { | |
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
4
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 int passnum; // which pass are we on? |
21 | 112 int execaddr; // execution address for the program (END ....) |
113 int pragmas; // what pragmas are in effect? | |
114 | |
115 lwasm_line_t *lineshead; // first line of source code | |
116 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
|
117 |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
118 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
|
119 lwasm_symbol_ent_t *symtail; // last entry in symbol table |
57 | 120 |
121 macrotab_t *macros; // macro table | |
21 | 122 |
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
4
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 int outformat; // output format type |
21 | 127 char **filelist; // files that have been read |
128 int filelistlen; // number of files in the list | |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
49
diff
changeset
|
129 |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
49
diff
changeset
|
130 int endseen; // set to true if "end" has been seen |
57 | 131 int skipcond; // skipping a condition? |
132 int skipcount; // how many? | |
133 int skipmacro; // skipping a macro? | |
134 int inmacro; // are we currently in a macro? | |
135 int macroex; // current depth of macro expansion | |
136 int nextcontext; // next context number | |
137 int skiplines; // number of lines to skip | |
74 | 138 |
139 // items used only for the "object" target | |
140 sectiontab_t *sections; // pointer to section table | |
141 sectiontab_t *csect; // current section - NULL if not in one | |
0 | 142 } asmstate_t; |
143 | |
144 #define PRAGMA_NOINDEX0TONONE 1 | |
145 | |
26 | 146 #ifndef __lwasm_c_seen__ |
147 #define __lwasm_E__ extern | |
148 #else | |
149 #define __lwasm_E__ | |
150 #endif | |
151 | |
38 | 152 __lwasm_E__ int debug_level; |
153 | |
26 | 154 __lwasm_E__ int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...); |
38 | 155 __lwasm_E__ void debug_message(int level, const char *fmt, ...); |
26 | 156 |
27
f736579569b4
Added handlers for inherent and register to register instructions
lost
parents:
26
diff
changeset
|
157 __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
|
158 __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
|
159 __lwasm_E__ int lwasm_lookupreg2(const char *reglist, char **str); |
32 | 160 __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
|
161 |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
162 __lwasm_E__ lwasm_expr_stack_t *lwasm_evaluate_expr(asmstate_t *as, lwasm_line_t *l, const char *inp, const char **outp); |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
163 |
55 | 164 |
57 | 165 // return next context number and update it |
166 __lwasm_E__ int lwasm_next_context(asmstate_t *as); | |
167 | |
55 | 168 // also throw an error on expression eval failure |
169 // return 0 on ok, -1 on error | |
170 #define EXPR_NOFLAG 0 | |
171 #define EXPR_PASS1CONST 1 | |
172 #define EXPR_PASS2CONST 2 | |
173 #define EXPR_BYTE 4 | |
174 __lwasm_E__ int lwasm_expr_result(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val); | |
175 | |
26 | 176 #undef __lwasm_E__ |
177 | |
178 | |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
179 #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
|
180 #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
|
181 #else |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
182 #define __lwasm_E__ |
0 | 183 #endif |
184 | |
64 | 185 __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
|
186 __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
|
187 __lwasm_E__ int lwasm_set_symbol(asmstate_t *as, char *sym, int scontext, int val); |
58 | 188 __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
|
189 #undef __lwasm_E__ |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
190 |
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
32
diff
changeset
|
191 |
0 | 192 |
193 #endif //__lwasm_h_seen__ |