Mercurial > hg > index.cgi
diff lwasm/insn_gen.c @ 402:b20f14edda5a
Completed initial conversion to new parser allowing spaces in operands
Converted the remaining addressing modes. This required a complete rewrite
of a large portion of the indexed addressing parser. Now the entire indexed
parsing system is programmatic without cheating with a lookup table.
This update also fixes the "force 0,r" by writing a literal 0,r which is
*supposed* to work.
There will likely be some pseudo ops that need tweaking for space handling,
specially those that take multiple operands of some description which are
not expressions. (The expression parser call eats the spaces both before and
after the expression, if appropriate.)
author | William Astle <lost@l-w.ca> |
---|---|
date | Wed, 14 Oct 2015 20:49:41 -0600 |
parents | 2d9b7ae6c329 |
children | 3948c874901b |
line wrap: on
line diff
--- a/lwasm/insn_gen.c Wed Oct 14 19:15:41 2015 -0600 +++ b/lwasm/insn_gen.c Wed Oct 14 20:49:41 2015 -0600 @@ -37,36 +37,35 @@ // "extra" is required due to the way OIM, EIM, TIM, and AIM work void insn_parse_gen_aux(asmstate_t *as, line_t *l, char **p, int elen) { - const char *optr2; + char *optr2; int v1, tv; lw_expr_t s; - + if (!**p) { lwasm_register_error(as, l, E_OPERAND_BAD); return; } - optr2 = *p; - while (*optr2 && !isspace(*optr2) && *optr2 != ',') optr2++ - /* do nothing */ ; - - if (*optr2 == ',' || **p == '[') + /* this is the easy case - start it [ or , means indexed */ + if (**p == ',' || **p == '[') { +indexed: l -> lint = -1; - l -> lint2 = 1; + l -> lint2 = 1; insn_parse_indexed_aux(as, l, p); l -> minlen = OPLEN(instab[l -> insn].ops[1]) + 1 + elen; l -> maxlen = OPLEN(instab[l -> insn].ops[1]) + 3 + elen; goto out; } + /* we have to parse the first expression to find if we have a comma after it */ + optr2 = *p; if (**p == '<') { (*p)++; l -> lint2 = 0; } - // for compatibility with asxxxx // * followed by a digit, alpha, or _, or ., or ?, or another * is "f8" else if (**p == '*') @@ -87,10 +86,17 @@ { l -> lint2 = -1; } - - l -> minlen = OPLEN(instab[l -> insn].ops[0]) + 1 + elen; - l -> maxlen = OPLEN(instab[l -> insn].ops[2]) + 2 + elen; + lwasm_skip_to_next_token(l, p); + s = lwasm_parse_expr(as, p); + + if (**p == ',') + { + /* we have an indexed mode here - reset and transfer control to indexing mode */ + lw_expr_destroy(s); + *p = optr2; + goto indexed; + } if (!s) { lwasm_register_error(as, l, E_OPERAND_BAD); @@ -99,6 +105,8 @@ lwasm_save_expr(l, 0, s); + l -> minlen = OPLEN(instab[l -> insn].ops[0]) + 1 + elen; + l -> maxlen = OPLEN(instab[l -> insn].ops[2]) + 2 + elen; if (as -> output_format == OUTPUT_OBJ && l -> lint2 == -1) { l -> lint2 = 2;