comparison lwasm/pass1.c @ 43:18b49cf10ae9

Added an instruction reduction immediately after instruction parsing to minimize memory footprint and expression complexity
author lost@l-w.ca
date Mon, 04 Apr 2011 17:55:08 -0600
parents d96037ea0b80
children bd8b3fbd1e28
comparison
equal deleted inserted replaced
42:31adb7c09b4e 43:18b49cf10ae9
275 // no parse func means operand doesn't matter 275 // no parse func means operand doesn't matter
276 if (instab[opnum].parse) 276 if (instab[opnum].parse)
277 { 277 {
278 if (as -> instruct == 0 || instab[opnum].flags & lwasm_insn_struct) 278 if (as -> instruct == 0 || instab[opnum].flags & lwasm_insn_struct)
279 { 279 {
280 struct line_expr_s *le;
281
280 cl -> len = -1; 282 cl -> len = -1;
281 // call parse function 283 // call parse function
282 (instab[opnum].parse)(as, cl, &p1); 284 (instab[opnum].parse)(as, cl, &p1);
283 285
284 if (*p1 && !isspace(*p1)) 286 if (*p1 && !isspace(*p1))
285 { 287 {
286 // flag bad operand error 288 // flag bad operand error
287 lwasm_register_error(as, cl, "Bad operand (%s)", p1); 289 lwasm_register_error(as, cl, "Bad operand (%s)", p1);
288 } 290 }
291
292 /* do a reduction on the line expressions to avoid carrying excessive expression baggage if not needed */
293 as -> cl = cl;
294
295 // simplify address
296 lwasm_reduce_expr(as, cl -> addr);
297
298 // simplify each expression
299 for (le = cl -> exprs; le; le = le -> next)
300 lwasm_reduce_expr(as, le -> expr);
301
302 /* try resolving the instruction as well */
303 if (cl -> insn >= 0 && instab[cl -> insn].resolve)
304 {
305 (instab[cl -> insn].resolve)(as, cl, 0);
306 }
307
289 } 308 }
290 else if (as -> instruct == 1) 309 else if (as -> instruct == 1)
291 { 310 {
292 lwasm_register_error(as, cl, "Bad operand (%s)", p1); 311 lwasm_register_error(as, cl, "Bad operand (%s)", p1);
293 } 312 }