Mercurial > hg > index.cgi
comparison lwasm/insn_gen.c @ 370:8764142b3192
Convert internal error/warning handling framework to a new unified system
Replace the ad hoc error and warning handling with a new system that
codifies the errors with specific codes. This makes it possible in the
future for error numbers to be used for testing and other purposes. It also
makes sure the error strings themselves are consistent.
Thanks to Erik G <erik@6809.org> for the patch.
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 22 Jun 2015 18:49:38 -0600 |
parents | 433dbc18fb41 |
children | 8e25147c2aa8 |
comparison
equal
deleted
inserted
replaced
369:682524a1f32f | 370:8764142b3192 |
---|---|
41 int v1, tv; | 41 int v1, tv; |
42 lw_expr_t s; | 42 lw_expr_t s; |
43 | 43 |
44 if (!**p) | 44 if (!**p) |
45 { | 45 { |
46 lwasm_register_error(as, l, "Bad operand"); | 46 lwasm_register_error(as, l, E_OPERAND_BAD); |
47 return; | 47 return; |
48 } | 48 } |
49 | 49 |
50 optr2 = *p; | 50 optr2 = *p; |
51 while (*optr2 && !isspace(*optr2) && *optr2 != ',') optr2++ | 51 while (*optr2 && !isspace(*optr2) && *optr2 != ',') optr2++ |
91 l -> minlen = OPLEN(instab[l -> insn].ops[0]) + 1 + elen; | 91 l -> minlen = OPLEN(instab[l -> insn].ops[0]) + 1 + elen; |
92 l -> maxlen = OPLEN(instab[l -> insn].ops[2]) + 2 + elen; | 92 l -> maxlen = OPLEN(instab[l -> insn].ops[2]) + 2 + elen; |
93 s = lwasm_parse_expr(as, p); | 93 s = lwasm_parse_expr(as, p); |
94 if (!s) | 94 if (!s) |
95 { | 95 { |
96 lwasm_register_error(as, l, "Bad operand"); | 96 lwasm_register_error(as, l, E_OPERAND_BAD); |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
100 lwasm_save_expr(l, 0, s); | 100 lwasm_save_expr(l, 0, s); |
101 | 101 |
274 int i; | 274 int i; |
275 i = lw_expr_intval(e); | 275 i = lw_expr_intval(e); |
276 if (l -> lint == 1) | 276 if (l -> lint == 1) |
277 { | 277 { |
278 if (i < -128 || i > 127) | 278 if (i < -128 || i > 127) |
279 lwasm_register_error(as, l, "Byte overflow"); | 279 lwasm_register_error(as, l, E_BYTE_OVERFLOW); |
280 } | 280 } |
281 lwasm_emitexpr(l, e, l -> lint); | 281 lwasm_emitexpr(l, e, l -> lint); |
282 } | 282 } |
283 return; | 283 return; |
284 } | 284 } |
292 // the various insn_gen? functions have an immediate mode of ? bits | 292 // the various insn_gen? functions have an immediate mode of ? bits |
293 PARSEFUNC(insn_parse_gen0) | 293 PARSEFUNC(insn_parse_gen0) |
294 { | 294 { |
295 if (**p == '#') | 295 if (**p == '#') |
296 { | 296 { |
297 lwasm_register_error(as, l, "Immediate mode not allowed"); | 297 lwasm_register_error(as, l, E_IMMEDIATE_INVALID); |
298 return; | 298 return; |
299 } | 299 } |
300 | 300 |
301 // handle non-immediate | 301 // handle non-immediate |
302 insn_parse_gen_aux(as, l, p, 0); | 302 insn_parse_gen_aux(as, l, p, 0); |
326 as -> exprwidth = 8; | 326 as -> exprwidth = 8; |
327 e = lwasm_parse_expr(as, p); | 327 e = lwasm_parse_expr(as, p); |
328 as -> exprwidth = 16; | 328 as -> exprwidth = 16; |
329 if (!e) | 329 if (!e) |
330 { | 330 { |
331 lwasm_register_error(as, l, "Bad operand"); | 331 lwasm_register_error(as, l, E_OPERAND_BAD); |
332 return; | 332 return; |
333 } | 333 } |
334 l -> len = OPLEN(instab[l -> insn].ops[3]) + 1; | 334 l -> len = OPLEN(instab[l -> insn].ops[3]) + 1; |
335 l -> lint2 = 3; | 335 l -> lint2 = 3; |
336 lwasm_save_expr(l, 0, e); | 336 lwasm_save_expr(l, 0, e); |
375 { | 375 { |
376 int i; | 376 int i; |
377 i = lw_expr_intval(e); | 377 i = lw_expr_intval(e); |
378 if (i < -128 || i > 255) | 378 if (i < -128 || i > 255) |
379 { | 379 { |
380 lwasm_register_error(as, l, "Byte overflow"); | 380 lwasm_register_error(as, l, E_BYTE_OVERFLOW); |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 lwasm_emitop(l, instab[l -> insn].ops[3]); | 384 lwasm_emitop(l, instab[l -> insn].ops[3]); |
385 lwasm_emitexpr(l, e, 1); | 385 lwasm_emitexpr(l, e, 1); |
397 | 397 |
398 (*p)++; | 398 (*p)++; |
399 e = lwasm_parse_expr(as, p); | 399 e = lwasm_parse_expr(as, p); |
400 if (!e) | 400 if (!e) |
401 { | 401 { |
402 lwasm_register_error(as, l, "Bad operand"); | 402 lwasm_register_error(as, l, E_OPERAND_BAD); |
403 return; | 403 return; |
404 } | 404 } |
405 l -> len = OPLEN(instab[l -> insn].ops[3]) + 2; | 405 l -> len = OPLEN(instab[l -> insn].ops[3]) + 2; |
406 l -> lint2 = 3; | 406 l -> lint2 = 3; |
407 lwasm_save_expr(l, 0, e); | 407 lwasm_save_expr(l, 0, e); |
458 | 458 |
459 (*p)++; | 459 (*p)++; |
460 e = lwasm_parse_expr(as, p); | 460 e = lwasm_parse_expr(as, p); |
461 if (!e) | 461 if (!e) |
462 { | 462 { |
463 lwasm_register_error(as, l, "Bad operand"); | 463 lwasm_register_error(as, l, E_OPERAND_BAD); |
464 return; | 464 return; |
465 } | 465 } |
466 l -> len = OPLEN(instab[l -> insn].ops[3]) + 4; | 466 l -> len = OPLEN(instab[l -> insn].ops[3]) + 4; |
467 l -> lint2 = 3; | 467 l -> lint2 = 3; |
468 lwasm_save_expr(l, 0, e); | 468 lwasm_save_expr(l, 0, e); |
522 as -> exprwidth = 8; | 522 as -> exprwidth = 8; |
523 e = lwasm_parse_expr(as, p); | 523 e = lwasm_parse_expr(as, p); |
524 as -> exprwidth = 16; | 524 as -> exprwidth = 16; |
525 if (!e) | 525 if (!e) |
526 { | 526 { |
527 lwasm_register_error(as, l, "Bad operand"); | 527 lwasm_register_error(as, l, E_OPERAND_BAD); |
528 return; | 528 return; |
529 } | 529 } |
530 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1; | 530 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1; |
531 lwasm_save_expr(l, 0, e); | 531 lwasm_save_expr(l, 0, e); |
532 } | 532 } |
533 else | 533 else |
534 { | 534 { |
535 lwasm_register_error(as, l, "Bad operand"); | 535 lwasm_register_error(as, l, E_OPERAND_BAD); |
536 } | 536 } |
537 } | 537 } |
538 | 538 |
539 EMITFUNC(insn_emit_imm8) | 539 EMITFUNC(insn_emit_imm8) |
540 { | 540 { |
546 { | 546 { |
547 int i; | 547 int i; |
548 i = lw_expr_intval(e); | 548 i = lw_expr_intval(e); |
549 if (i < -128 || i > 255) | 549 if (i < -128 || i > 255) |
550 { | 550 { |
551 lwasm_register_error(as, l, "Byte overflow"); | 551 lwasm_register_error(as, l, E_BYTE_OVERFLOW); |
552 } | 552 } |
553 } | 553 } |
554 lwasm_emitexpr(l, e, 1); | 554 lwasm_emitexpr(l, e, 1); |
555 } | 555 } |