comparison lwasm/pass1.c @ 389:fbb7bfed8076

Added in structure support and fixed up some warts in the listing code (by adding more warts)
author lost@l-w.ca
date Wed, 14 Jul 2010 22:33:55 -0600
parents cf8c92d70eb1
children acaafc70044b
comparison
equal deleted inserted replaced
388:8991eb507d2d 389:fbb7bfed8076
28 #include <lw_string.h> 28 #include <lw_string.h>
29 29
30 #include "lwasm.h" 30 #include "lwasm.h"
31 #include "instab.h" 31 #include "instab.h"
32 #include "input.h" 32 #include "input.h"
33
34 extern int expand_macro(asmstate_t *as, line_t *l, char **p, char *opc);
35 extern int expand_struct(asmstate_t *as, line_t *l, char **p, char *opc);
33 36
34 /* 37 /*
35 pass 1: parse the lines 38 pass 1: parse the lines
36 39
37 line format: 40 line format:
89 cl -> inmod = as -> inmod; 92 cl -> inmod = as -> inmod;
90 cl -> csect = as -> csect; 93 cl -> csect = as -> csect;
91 cl -> pragmas = as -> pragmas; 94 cl -> pragmas = as -> pragmas;
92 cl -> context = as -> context; 95 cl -> context = as -> context;
93 cl -> ltext = lw_strdup(line); 96 cl -> ltext = lw_strdup(line);
97 cl -> soff = -1;
98 cl -> dshow = -1;
99 cl -> dsize = 0;
100 cl -> dptr = NULL;
94 as -> cl = cl; 101 as -> cl = cl;
95 if (!as -> line_tail) 102 if (!as -> line_tail)
96 { 103 {
97 as -> line_head = cl; 104 as -> line_head = cl;
98 cl -> addr = lw_expr_build(lw_expr_type_int, 0); 105 cl -> addr = lw_expr_build(lw_expr_type_int, 0);
224 // if skipping a condition and the operation code doesn't 231 // if skipping a condition and the operation code doesn't
225 // operate within a condition (not a conditional) 232 // operate within a condition (not a conditional)
226 // do nothing 233 // do nothing
227 if (as -> skipcond && !(instab[opnum].flags & lwasm_insn_cond)) 234 if (as -> skipcond && !(instab[opnum].flags & lwasm_insn_cond))
228 goto linedone; 235 goto linedone;
229 236
230 if (instab[opnum].opcode == NULL) 237 if (instab[opnum].opcode == NULL)
231 { 238 {
232 cl -> insn = -1; 239 cl -> insn = -1;
233 if (*tok != ';' && *tok != '*') 240 if (*tok != ';' && *tok != '*')
234 { 241 {
235 // bad opcode; check for macro here 242 // bad opcode; check for macro here
236 if (expand_macro(as, cl, &p1, sym) != 0) 243 if (expand_macro(as, cl, &p1, sym) != 0)
237 { 244 {
238 // macro expansion failed 245 // macro expansion failed
239 lwasm_register_error(as, cl, "Bad opcode"); 246 if (expand_struct(as, cl, &p1, sym) != 0)
247 {
248 // structure expansion failed
249 lwasm_register_error(as, cl, "Bad opcode");
250 }
240 } 251 }
241 } 252 }
242 } 253 }
243 else 254 else
244 { 255 {
245 cl -> insn = opnum; 256 cl -> insn = opnum;
246 // no parse func means operand doesn't matter 257 // no parse func means operand doesn't matter
247 if (instab[opnum].parse) 258 if (instab[opnum].parse)
248 { 259 {
249 cl -> len = -1; 260 if (as -> instruct == 0 || instab[opnum].flags & lwasm_insn_struct)
250 // call parse function 261 {
251 (instab[opnum].parse)(as, cl, &p1); 262 cl -> len = -1;
263 // call parse function
264 (instab[opnum].parse)(as, cl, &p1);
252 265
253 if (*p1 && !isspace(*p1)) 266 if (*p1 && !isspace(*p1))
267 {
268 // flag bad operand error
269 lwasm_register_error(as, cl, "Bad operand (%s)", p1);
270 }
271 }
272 else if (as -> instruct == 1)
254 { 273 {
255 // flag bad operand error
256 lwasm_register_error(as, cl, "Bad operand (%s)", p1); 274 lwasm_register_error(as, cl, "Bad operand (%s)", p1);
257 } 275 }
258 } 276 }
259 } 277 }
260 } 278 }