comparison 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
comparison
equal deleted inserted replaced
401:bbe5401a9bf3 402:b20f14edda5a
35 void insn_resolve_indexed_aux(asmstate_t *as, line_t *l, int force, int elen); 35 void insn_resolve_indexed_aux(asmstate_t *as, line_t *l, int force, int elen);
36 36
37 // "extra" is required due to the way OIM, EIM, TIM, and AIM work 37 // "extra" is required due to the way OIM, EIM, TIM, and AIM work
38 void insn_parse_gen_aux(asmstate_t *as, line_t *l, char **p, int elen) 38 void insn_parse_gen_aux(asmstate_t *as, line_t *l, char **p, int elen)
39 { 39 {
40 const char *optr2; 40 char *optr2;
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, E_OPERAND_BAD); 46 lwasm_register_error(as, l, E_OPERAND_BAD);
47 return; 47 return;
48 } 48 }
49 49
50 optr2 = *p; 50 /* this is the easy case - start it [ or , means indexed */
51 while (*optr2 && !isspace(*optr2) && *optr2 != ',') optr2++ 51 if (**p == ',' || **p == '[')
52 /* do nothing */ ; 52 {
53 53 indexed:
54 if (*optr2 == ',' || **p == '[')
55 {
56 l -> lint = -1; 54 l -> lint = -1;
57 l -> lint2 = 1; 55 l -> lint2 = 1;
58 insn_parse_indexed_aux(as, l, p); 56 insn_parse_indexed_aux(as, l, p);
59 l -> minlen = OPLEN(instab[l -> insn].ops[1]) + 1 + elen; 57 l -> minlen = OPLEN(instab[l -> insn].ops[1]) + 1 + elen;
60 l -> maxlen = OPLEN(instab[l -> insn].ops[1]) + 3 + elen; 58 l -> maxlen = OPLEN(instab[l -> insn].ops[1]) + 3 + elen;
61 goto out; 59 goto out;
62 } 60 }
63 61
62 /* we have to parse the first expression to find if we have a comma after it */
63 optr2 = *p;
64 if (**p == '<') 64 if (**p == '<')
65 { 65 {
66 (*p)++; 66 (*p)++;
67 l -> lint2 = 0; 67 l -> lint2 = 0;
68 } 68 }
69
70 // for compatibility with asxxxx 69 // for compatibility with asxxxx
71 // * followed by a digit, alpha, or _, or ., or ?, or another * is "f8" 70 // * followed by a digit, alpha, or _, or ., or ?, or another * is "f8"
72 else if (**p == '*') 71 else if (**p == '*')
73 { 72 {
74 tv = *(*p + 1); 73 tv = *(*p + 1);
85 } 84 }
86 else 85 else
87 { 86 {
88 l -> lint2 = -1; 87 l -> lint2 = -1;
89 } 88 }
89 lwasm_skip_to_next_token(l, p);
90
91 s = lwasm_parse_expr(as, p);
92
93 if (**p == ',')
94 {
95 /* we have an indexed mode here - reset and transfer control to indexing mode */
96 lw_expr_destroy(s);
97 *p = optr2;
98 goto indexed;
99 }
100 if (!s)
101 {
102 lwasm_register_error(as, l, E_OPERAND_BAD);
103 return;
104 }
105
106 lwasm_save_expr(l, 0, s);
90 107
91 l -> minlen = OPLEN(instab[l -> insn].ops[0]) + 1 + elen; 108 l -> minlen = OPLEN(instab[l -> insn].ops[0]) + 1 + elen;
92 l -> maxlen = OPLEN(instab[l -> insn].ops[2]) + 2 + elen; 109 l -> maxlen = OPLEN(instab[l -> insn].ops[2]) + 2 + elen;
93 s = lwasm_parse_expr(as, p);
94 if (!s)
95 {
96 lwasm_register_error(as, l, E_OPERAND_BAD);
97 return;
98 }
99
100 lwasm_save_expr(l, 0, s);
101
102 if (as -> output_format == OUTPUT_OBJ && l -> lint2 == -1) 110 if (as -> output_format == OUTPUT_OBJ && l -> lint2 == -1)
103 { 111 {
104 l -> lint2 = 2; 112 l -> lint2 = 2;
105 goto out; 113 goto out;
106 } 114 }