comparison lwasm/lwasm.h @ 375:71f507f404f1

Add "testmode" pragma Add a pragma to allow testing more easily. Thanks to Erik G <erik@6809.org> for the patch.
author William Astle <lost@l-w.ca>
date Mon, 13 Jul 2015 20:35:16 -0600
parents 8e25147c2aa8
children 35d4213e6657
comparison
equal deleted inserted replaced
374:8e25147c2aa8 375:71f507f404f1
75 FLAG_NONE = 0 75 FLAG_NONE = 0
76 }; 76 };
77 77
78 enum lwasm_pragmas_e 78 enum lwasm_pragmas_e
79 { 79 {
80 PRAGMA_NONE = 0, // no pragmas in effect 80 PRAGMA_NONE = 0, // no pragmas in effect
81 PRAGMA_DOLLARNOTLOCAL = 0x0001, // dollar sign does not make a symbol local 81 PRAGMA_DOLLARNOTLOCAL = 1 << 0, // dollar sign does not make a symbol local
82 PRAGMA_NOINDEX0TONONE = 0x0002, // do not change implicit 0,R to ,R 82 PRAGMA_NOINDEX0TONONE = 1 << 1, // do not change implicit 0,R to ,R
83 PRAGMA_UNDEFEXTERN = 0x0004, // undefined symbols are considered to be external 83 PRAGMA_UNDEFEXTERN = 1 << 2, // undefined symbols are considered to be external
84 PRAGMA_CESCAPES = 0x0008, // allow C style escapes in fcc, fcs, fcn, etc. 84 PRAGMA_CESCAPES = 1 << 3, // allow C style escapes in fcc, fcs, fcn, etc.
85 PRAGMA_IMPORTUNDEFEXPORT = 0x0010, // imports symbol if undefined upon export 85 PRAGMA_IMPORTUNDEFEXPORT = 1 << 4, // imports symbol if undefined upon export
86 PRAGMA_PCASPCR = 0x0020, // treats ,PC as ,PCR instead of constant offset 86 PRAGMA_PCASPCR = 1 << 5, // treats ,PC as ,PCR instead of constant offset
87 PRAGMA_SHADOW = 0x0040, // allow macros to shadow builtin operations 87 PRAGMA_SHADOW = 1 << 6, // allow macros to shadow builtin operations
88 PRAGMA_NOLIST = 0x0080, // don't show line in listing 88 PRAGMA_NOLIST = 1 << 7, // don't show line in listing
89 PRAGMA_AUTOBRANCHLENGTH = 0x0100, // automatically select proper length for relative branches 89 PRAGMA_AUTOBRANCHLENGTH = 1 << 8, // automatically select proper length for relative branches
90 PRAGMA_EXPORT = 0x0200, // export symbols by default, unless local 90 PRAGMA_EXPORT = 1 << 9, // export symbols by default, unless local
91 PRAGMA_SYMBOLNOCASE = 0x400, // symbols defined under this pragma are matched case insensitively 91 PRAGMA_SYMBOLNOCASE = 1 << 10, // symbols defined under this pragma are matched case insensitively
92 PRAGMA_CONDUNDEFZERO = 0x800, // treat undefined symbols as zero in conditionals during pass 1 92 PRAGMA_CONDUNDEFZERO = 1 << 11, // treat undefined symbols as zero in conditionals during pass 1
93 PRAGMA_6800COMPAT = 0x1000, // enable 6800 compatibility opcodes 93 PRAGMA_6800COMPAT = 1 << 12, // enable 6800 compatibility opcodes
94 PRAGMA_FORWARDREFMAX = 0x2000, // force incomplete references on pass 1 to maximum mode 94 PRAGMA_FORWARDREFMAX = 1 << 13, // force incomplete references on pass 1 to maximum mode
95 PRAGMA_6809 = 0x4000 // 6809/6309 assembly mode 95 PRAGMA_6809 = 1 << 14, // 6809/6309 assembly mode
96 PRAGMA_TESTMODE = 1 << 15 // enable test mode (for internal unit testing)
96 }; 97 };
97 98
98 enum 99 enum
99 { 100 {
100 section_flag_bss = 1, // BSS section 101 section_flag_bss = 1, // BSS section
122 unsigned char *obytes; // output buffer 123 unsigned char *obytes; // output buffer
123 reloctab_t *reloctab; // table of relocations 124 reloctab_t *reloctab; // table of relocations
124 sectiontab_t *next; 125 sectiontab_t *next;
125 }; 126 };
126 127
128 typedef enum
129 {
130 TF_EMIT = 1,
131 TF_ERROR = 2
132 } lwasm_testflags_t;
133
127 typedef enum 134 typedef enum
128 { 135 {
129 E_6309_INVALID, 136 E_6309_INVALID = 1,
130 E_6809_INVALID, 137 E_6809_INVALID = 2,
131 E_ALIGNMENT_INVALID, 138 E_ALIGNMENT_INVALID = 3,
132 E_BITNUMBER_UNRESOLVED, 139 E_BITNUMBER_UNRESOLVED = 4,
133 E_BITNUMBER_INVALID, 140 E_BITNUMBER_INVALID = 5,
134 E_BYTE_OVERFLOW, 141 E_BYTE_OVERFLOW = 6,
135 E_CONDITION_P1, 142 E_CONDITION_P1 = 7,
136 E_DIRECTIVE_OS9_ONLY, 143 E_DIRECTIVE_OS9_ONLY = 8,
137 E_DIV0, 144 E_DIV0 = 9,
138 E_EXEC_ADDRESS, 145 E_EXEC_ADDRESS = 10,
139 E_FILL_INVALID, 146 E_FILL_INVALID = 11,
140 E_IMMEDIATE_INVALID, 147 E_IMMEDIATE_INVALID = 12,
141 E_IMMEDIATE_UNRESOLVED, 148 E_IMMEDIATE_UNRESOLVED = 13,
142 E_EXPRESSION_BAD, 149 E_EXPRESSION_BAD = 14,
143 E_EXPRESSION_NOT_CONST, 150 E_EXPRESSION_NOT_CONST = 15,
144 E_EXPRESSION_NOT_RESOLVED, 151 E_EXPRESSION_NOT_RESOLVED = 16,
145 E_FILE_OPEN, 152 E_FILE_OPEN = 17,
146 E_FILENAME_MISSING, 153 E_FILENAME_MISSING = 18,
147 E_INSTRUCTION_FAILED, 154 E_INSTRUCTION_FAILED = 19,
148 E_INSTRUCTION_SECTION, 155 E_INSTRUCTION_SECTION = 20,
149 E_LINE_ADDRESS, 156 E_LINE_ADDRESS = 21,
150 E_LINED_ADDRESS, 157 E_LINED_ADDRESS = 22,
151 E_MACRO_DUPE, 158 E_MACRO_DUPE = 23,
152 E_MACRO_ENDM, 159 E_MACRO_ENDM = 24,
153 E_MACRO_NONAME, 160 E_MACRO_NONAME = 25,
154 E_MACRO_RECURSE, 161 E_MACRO_RECURSE = 26,
155 E_MODULE_IN, 162 E_MODULE_IN = 27,
156 E_MODULE_NOTIN, 163 E_MODULE_NOTIN = 28,
157 E_NEGATIVE_BLOCKSIZE, 164 E_NEGATIVE_BLOCKSIZE = 29,
158 E_NEGATIVE_RESERVATION, 165 E_NEGATIVE_RESERVATION = 30,
159 E_NW_8, 166 E_NW_8 = 31,
160 E_OPCODE_BAD, 167 E_OPCODE_BAD = 32,
161 E_OPERAND_BAD, 168 E_OPERAND_BAD = 33,
162 E_OBJTARGET_ONLY, 169 E_OBJTARGET_ONLY = 34,
163 E_PADDING_BAD, 170 E_PADDING_BAD = 35,
164 E_PRAGMA_UNRECOGNIZED, 171 E_PRAGMA_UNRECOGNIZED = 36,
165 E_REGISTER_BAD, 172 E_REGISTER_BAD = 37,
166 E_SECTION_END, 173 E_SECTION_END = 38,
167 E_SECTION_EXTDEP, 174 E_SECTION_EXTDEP = 39,
168 E_SECTION_FLAG, 175 E_SECTION_FLAG = 40,
169 E_SECTION_NAME, 176 E_SECTION_NAME = 41,
170 E_SECTION_TARGET, 177 E_SECTION_TARGET = 42,
171 E_SETDP_INVALID, 178 E_SETDP_INVALID = 43,
172 E_SETDP_NOT_CONST, 179 E_SETDP_NOT_CONST = 44,
173 E_STRING_BAD, 180 E_STRING_BAD = 45,
174 E_STRUCT_DUPE, 181 E_STRUCT_DUPE = 46,
175 E_STRUCT_NONAME, 182 E_STRUCT_NONAME = 47,
176 E_STRUCT_NOSYMBOL, 183 E_STRUCT_NOSYMBOL = 48,
177 E_STRUCT_RECURSE, 184 E_STRUCT_RECURSE = 49,
178 E_SYMBOL_BAD, 185 E_SYMBOL_BAD = 50,
179 E_SYMBOL_DUPE, 186 E_SYMBOL_DUPE = 51,
180 E_SYMBOL_MISSING, 187 E_SYMBOL_MISSING = 52,
181 E_SYMBOL_UNDEFINED, 188 E_SYMBOL_UNDEFINED = 53,
182 E_SYMBOL_UNDEFINED_EXPORT, 189 E_SYMBOL_UNDEFINED_EXPORT = 54,
183 E_UNKNOWN_OPERATION, 190 E_UNKNOWN_OPERATION = 55,
184 E_USER_SPECIFIED, 191 E_USER_SPECIFIED = 56,
185 192
186 /* warnings must be 1000 or greater */ 193 /* warnings must be 1000 or greater */
187 194
188 W_DUPLICATE_SECTION = 1000, 195 W_DUPLICATE_SECTION = 1000,
189 W_ENDSTRUCT_WITHOUT = 1001, 196 W_ENDSTRUCT_WITHOUT = 1001,
190 W_NOT_SUPPORTED = 1002, 197 W_NOT_SUPPORTED = 1002,
191 W_USER_SPECIFIED = 1003 198 W_USER_SPECIFIED = 1003
192 } lwasm_errorcode_t; 199 } lwasm_errorcode_t;
193 200
194 typedef struct lwasm_error_s lwasm_error_t; 201 typedef struct lwasm_error_s lwasm_error_t;
195 struct lwasm_error_s 202 struct lwasm_error_s
196 { 203 {
240 int outputl; // size of output 247 int outputl; // size of output
241 int outputbl; // size of output buffer 248 int outputbl; // size of output buffer
242 int dpval; // direct page value 249 int dpval; // direct page value
243 lwasm_error_t *err; // list of errors 250 lwasm_error_t *err; // list of errors
244 lwasm_error_t *warn; // list of errors 251 lwasm_error_t *warn; // list of errors
252 lwasm_errorcode_t err_testmode; // error code in testmode
245 line_t *prev; // previous line 253 line_t *prev; // previous line
246 line_t *next; // next line 254 line_t *next; // next line
247 int inmod; // inside a module? 255 int inmod; // inside a module?
248 sectiontab_t *csect; // which section are we in? 256 sectiontab_t *csect; // which section are we in?
249 struct line_expr_s *exprs; // expressions used during parsing 257 struct line_expr_s *exprs; // expressions used during parsing
338 FILE *debug_file; // FILE * to output debug messages to 346 FILE *debug_file; // FILE * to output debug messages to
339 int flags; // assembly flags 347 int flags; // assembly flags
340 int pragmas; // pragmas currently in effect 348 int pragmas; // pragmas currently in effect
341 int errorcount; // number of errors encountered 349 int errorcount; // number of errors encountered
342 int warningcount; // number of warnings issued 350 int warningcount; // number of warnings issued
351 int testmode_errorcount; // number of errors in testmode
343 int inmacro; // are we in a macro? 352 int inmacro; // are we in a macro?
344 int instruct; // are w in a structure? 353 int instruct; // are w in a structure?
345 int skipcond; // skipping a condition? 354 int skipcond; // skipping a condition?
346 int skipcount; // depth of "skipping" 355 int skipcount; // depth of "skipping"
347 int skipmacro; // are we skipping in a macro? 356 int skipmacro; // are we skipping in a macro?
388 }; 397 };
389 398
390 struct symtabe *register_symbol(asmstate_t *as, line_t *cl, char *sym, lw_expr_t value, int flags); 399 struct symtabe *register_symbol(asmstate_t *as, line_t *cl, char *sym, lw_expr_t value, int flags);
391 struct symtabe *lookup_symbol(asmstate_t *as, line_t *cl, char *sym); 400 struct symtabe *lookup_symbol(asmstate_t *as, line_t *cl, char *sym);
392 401
402 void lwasm_parse_testmode_comment(line_t *cl, lwasm_testflags_t *flags, lwasm_errorcode_t *err, int *len, char **buf);
403 void lwasm_error_testmode(line_t *cl, const char* msg, int fatal);
404
393 void lwasm_register_error(asmstate_t *as, line_t *cl, lwasm_errorcode_t err); 405 void lwasm_register_error(asmstate_t *as, line_t *cl, lwasm_errorcode_t err);
394 void lwasm_register_error2(asmstate_t *as, line_t *cl, lwasm_errorcode_t err, const char* fmt, ...); 406 void lwasm_register_error2(asmstate_t *as, line_t *cl, lwasm_errorcode_t err, const char* fmt, ...);
395 407
396 int lwasm_next_context(asmstate_t *as); 408 int lwasm_next_context(asmstate_t *as);
397 void lwasm_emit(line_t *cl, int byte); 409 void lwasm_emit(line_t *cl, int byte);