Mercurial > hg-old > index.cgi
annotate lwasm/lwasm.c @ 372:90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
author | lost@starbug |
---|---|
date | Thu, 22 Apr 2010 18:19:06 -0600 |
parents | 9c24d9d485b9 |
children | d99322ef6f21 |
rev | line source |
---|---|
337 | 1 /* |
2 lwasm.c | |
3 | |
4 Copyright © 2010 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
22 #define ___lwasm_c_seen___ |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
23 |
337 | 24 #include <config.h> |
25 | |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
26 #include <stdio.h> |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
27 #include <stdarg.h> |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
28 #include <string.h> |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
29 |
337 | 30 #include <lw_expr.h> |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
31 #include <lw_alloc.h> |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
32 #include <lw_string.h> |
337 | 33 |
34 #include "lwasm.h" | |
35 | |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
36 void lwasm_register_error(asmstate_t *as, line_t *l, const char *msg, ...); |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
37 |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
38 lw_expr_t lwasm_evaluate_var(char *var, void *priv) |
337 | 39 { |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
40 asmstate_t *as = (asmstate_t *)priv; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
41 lw_expr_t e; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
42 importlist_t *im; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
43 struct symtabe *s; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
44 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
45 s = lookup_symbol(as, as -> cl, var); |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
46 if (s) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
47 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
48 e = lw_expr_build(lw_expr_type_special, lwasm_expr_syment, s); |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
49 return e; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
50 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
51 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
52 // undefined here is undefied unless output is object |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
53 if (as -> output_format != OUTPUT_OBJ) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
54 goto nomatch; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
55 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
56 // check for import |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
57 for (im = as -> importlist; im; im = im -> next) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
58 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
59 if (!strcmp(im -> symbol, var)) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
60 break; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
61 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
62 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
63 // check for "undefined" to import automatically |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
64 if (!im && CURPRAGMA(as -> cl, PRAGMA_UNDEFEXTERN)) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
65 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
66 im = lw_alloc(sizeof(importlist_t)); |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
67 im -> symbol = lw_strdup(var); |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
68 im -> next = as -> importlist; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
69 as -> importlist = im; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
70 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
71 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
72 if (!im) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
73 goto nomatch; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
74 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
75 e = lw_expr_build(lw_expr_type_special, lwasm_expr_import, im); |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
76 return e; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
77 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
78 nomatch: |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
79 if (as -> badsymerr) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
80 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
81 lwasm_register_error(as, as -> cl, "Undefined symbol %s", var); |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
82 } |
337 | 83 return NULL; |
84 } | |
85 | |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
86 lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv) |
337 | 87 { |
88 switch (t) | |
89 { | |
90 case lwasm_expr_linelen: | |
91 { | |
92 line_t *cl = ptr; | |
93 if (cl -> len == -1) | |
94 return NULL; | |
95 return lw_expr_build(lw_expr_type_int, cl -> len); | |
96 } | |
97 break; | |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
98 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
99 case lwasm_expr_lineaddr: |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
100 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
101 line_t *cl = ptr; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
102 if (cl -> addr) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
103 return lw_expr_copy(cl -> addr); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
104 else |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
105 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
106 } |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
107 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
108 case lwasm_expr_syment: |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
109 { |
371 | 110 struct symtabe *sym = ptr; |
111 return lw_expr_copy(sym -> value); | |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
112 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
113 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
114 case lwasm_expr_import: |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
115 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
116 return NULL; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
117 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
118 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
119 case lwasm_expr_nextbp: |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
120 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
121 return NULL; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
122 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
123 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
124 case lwasm_expr_prevbp: |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
125 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
126 return NULL; |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
127 } |
337 | 128 } |
129 return NULL; | |
130 } | |
344
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
131 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
132 void lwasm_register_error(asmstate_t *as, line_t *l, const char *msg, ...) |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
133 { |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
134 lwasm_error_t *e; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
135 va_list args; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
136 char errbuff[1024]; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
137 int r; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
138 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
139 if (!l) |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
140 return; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
141 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
142 va_start(args, msg); |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
143 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
144 e = lw_alloc(sizeof(lwasm_error_t)); |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
145 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
146 e -> next = l -> err; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
147 l -> err = e; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
148 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
149 as -> errorcount++; |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
150 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
151 r = vsnprintf(errbuff, 1024, msg, args); |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
152 e -> mess = lw_strdup(errbuff); |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
153 |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
154 va_end(args); |
0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
lost@starbug
parents:
337
diff
changeset
|
155 } |
345
7416c3f9c321
Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents:
344
diff
changeset
|
156 |
351 | 157 void lwasm_register_warning(asmstate_t *as, line_t *l, const char *msg, ...) |
158 { | |
159 lwasm_error_t *e; | |
160 va_list args; | |
161 char errbuff[1024]; | |
162 int r; | |
163 | |
164 if (!l) | |
165 return; | |
166 | |
167 va_start(args, msg); | |
168 | |
169 e = lw_alloc(sizeof(lwasm_error_t)); | |
170 | |
171 e -> next = l -> err; | |
172 l -> err = e; | |
173 | |
174 as -> errorcount++; | |
175 | |
176 r = vsnprintf(errbuff, 1024, msg, args); | |
177 e -> mess = lw_strdup(errbuff); | |
178 | |
179 va_end(args); | |
180 } | |
181 | |
345
7416c3f9c321
Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents:
344
diff
changeset
|
182 int lwasm_next_context(asmstate_t *as) |
7416c3f9c321
Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents:
344
diff
changeset
|
183 { |
7416c3f9c321
Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents:
344
diff
changeset
|
184 int r; |
7416c3f9c321
Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents:
344
diff
changeset
|
185 r = as -> nextcontext; |
7416c3f9c321
Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents:
344
diff
changeset
|
186 as -> nextcontext++; |
7416c3f9c321
Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents:
344
diff
changeset
|
187 return r; |
7416c3f9c321
Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents:
344
diff
changeset
|
188 } |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
189 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
190 void lwasm_emit(line_t *cl, int byte) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
191 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
192 if (cl -> outputl == cl -> outputbl) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
193 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
194 cl -> output = lw_realloc(cl -> output, cl -> outputbl + 8); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
195 cl -> outputbl += 8; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
196 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
197 cl -> output[cl -> outputl++] = byte & 0xff; |
354 | 198 |
199 if (cl -> inmod) | |
200 { | |
201 asmstate_t *as = cl -> as; | |
202 // update module CRC | |
203 // this is a direct transliteration from the nitros9 asm source | |
204 // to C; it can, no doubt, be optimized for 32 bit processing | |
205 byte &= 0xff; | |
206 | |
207 byte ^= (as -> crc)[0]; | |
208 (as -> crc)[0] = (as -> crc)[1]; | |
209 (as -> crc)[1] = (as -> crc)[2]; | |
210 (as -> crc)[1] ^= (byte >> 7); | |
211 (as -> crc)[2] = (byte << 1); | |
212 (as -> crc)[1] ^= (byte >> 2); | |
213 (as -> crc)[2] ^= (byte << 6); | |
214 byte ^= (byte << 1); | |
215 byte ^= (byte << 2); | |
216 byte ^= (byte << 4); | |
217 if (byte & 0x80) | |
218 { | |
219 (as -> crc)[0] ^= 0x80; | |
220 (as -> crc)[2] ^= 0x21; | |
221 } | |
222 } | |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
223 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
224 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
225 void lwasm_emitop(line_t *cl, int opc) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
226 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
227 if (opc > 0x100) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
228 lwasm_emit(cl, opc >> 8); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
229 lwasm_emit(cl, opc); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
230 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
231 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
232 lw_expr_t lwasm_parse_term(char **p, void *priv) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
233 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
234 asmstate_t *as = priv; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
235 int val; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
236 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
237 if (!**p) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
238 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
239 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
240 if (**p == '*' || ( |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
241 **p == '.' |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
242 && !((*p)[1] >= 'A' && (*p)[1] <= 'Z') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
243 && !((*p)[1] >= 'a' && (*p)[1] <= 'z') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
244 && !((*p)[1] >= '0' && (*p)[1] <= '9') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
245 )) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
246 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
247 // special "symbol" for current line addr (*, .) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
248 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
249 return lw_expr_build(lw_expr_type_special, lwasm_expr_lineaddr, as -> cl); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
250 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
251 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
252 // branch points |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
253 if (**p == '<') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
254 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
255 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
256 return lw_expr_build(lw_expr_type_special, lwasm_expr_prevbp, as -> cl); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
257 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
258 if (**p == '>') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
259 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
260 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
261 return lw_expr_build(lw_expr_type_special, lwasm_expr_nextbp, as -> cl); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
262 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
263 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
264 // double ascii constant |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
265 if (**p == '"') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
266 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
267 int v; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
268 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
269 if (!**p) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
270 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
271 if (!*((*p)+1)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
272 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
273 v = (unsigned char)**p << 8 | (unsigned char)*((*p)+1); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
274 (*p) += 2; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
275 return lw_expr_build(lw_expr_type_int, v); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
276 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
277 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
278 if (**p == '\'') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
279 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
280 int v; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
281 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
282 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
283 if (!**p) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
284 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
285 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
286 v = (unsigned char)**p; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
287 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
288 return lw_expr_build(lw_expr_type_int, v); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
289 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
290 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
291 if (**p == '&') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
292 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
293 // decimal constant |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
294 int v = 0; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
295 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
296 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
297 if (!strchr("0123456789", **p)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
298 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
299 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
300 while (**p && strchr("0123456789", **p)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
301 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
302 val = val * 10 + (**p - '0'); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
303 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
304 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
305 return lw_expr_build(lw_expr_type_int, v); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
306 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
307 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
308 if (**p == '%') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
309 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
310 // binary constant |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
311 int v = 0; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
312 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
313 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
314 if (**p != '0' && **p != '1') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
315 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
316 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
317 while (**p && (**p == '0' || **p == '1')) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
318 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
319 val = val * 2 + (**p - '0'); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
320 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
321 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
322 return lw_expr_build(lw_expr_type_int, v); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
323 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
324 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
325 if (**p == '$') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
326 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
327 // hexadecimal constant |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
328 int v = 0, v2; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
329 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
330 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
331 if (!strchr("0123456789abcdefABCDEF", **p)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
332 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
333 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
334 while (**p && strchr("0123456789abcdefABCDEF", **p)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
335 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
336 v2 = toupper(**p) - '0'; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
337 if (v2 > 9) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
338 v2 -= 7; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
339 val = val * 16 + v2; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
340 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
341 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
342 return lw_expr_build(lw_expr_type_int, v); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
343 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
344 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
345 if (**p == '0' && (*((*p)+1) == 'x' || *((*p)+1) == 'X')) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
346 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
347 // hexadecimal constant, C style |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
348 int v = 0, v2; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
349 (*p)+=2; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
350 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
351 if (!strchr("0123456789abcdefABCDEF", **p)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
352 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
353 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
354 while (**p && strchr("0123456789abcdefABCDEF", **p)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
355 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
356 v2 = toupper(**p) - '0'; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
357 if (v2 > 9) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
358 v2 -= 7; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
359 val = val * 16 + v2; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
360 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
361 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
362 return lw_expr_build(lw_expr_type_int, v); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
363 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
364 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
365 if (**p == '@' && (*((*p)+1) >= '0' && *((*p)+1) <= '7')) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
366 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
367 // octal constant |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
368 int v = 0; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
369 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
370 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
371 if (!strchr("01234567", **p)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
372 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
373 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
374 while (**p && strchr("01234567", **p)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
375 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
376 val = val * 8 + (**p - '0'); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
377 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
378 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
379 return lw_expr_build(lw_expr_type_int, v); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
380 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
381 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
382 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
383 // symbol or bare decimal or suffix constant here |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
384 do |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
385 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
386 int havedol = 0; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
387 int l = 0; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
388 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
389 while ((*p)[l] && strchr(SYMCHARS, (*p)[l])) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
390 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
391 if ((*p)[l] == '$') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
392 havedol = 1; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
393 l++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
394 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
395 if (l == 0) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
396 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
397 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
398 if (havedol || **p < '0' || **p > '9') |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
399 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
400 // have a symbol here |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
401 char *sym; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
402 lw_expr_t term; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
403 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
404 sym = lw_strndup(*p, l); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
405 (*p) += l; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
406 term = lw_expr_build(lw_expr_type_var, sym); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
407 lw_free(sym); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
408 return term; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
409 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
410 } while (0); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
411 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
412 if (!**p) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
413 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
414 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
415 // we have a numeric constant here, either decimal or postfix base notation |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
416 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
417 int decval = 0, binval = 0, hexval = 0, octval = 0; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
418 int valtype = 15; // 1 = bin, 2 = oct, 4 = dec, 8 = hex |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
419 int bindone = 0; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
420 int val; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
421 int dval; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
422 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
423 while (1) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
424 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
425 if (!**p || !strchr("0123456789ABCDEFabcdefqhoQHO", **p)) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
426 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
427 // we can legally be bin or decimal here |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
428 if (bindone) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
429 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
430 // just finished a binary value |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
431 val = binval; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
432 break; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
433 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
434 else if (valtype & 4) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
435 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
436 val = decval; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
437 break; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
438 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
439 else |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
440 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
441 // bad value |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
442 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
443 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
444 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
445 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
446 dval = toupper(**p); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
447 (*p)++; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
448 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
449 if (bindone) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
450 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
451 // any characters past "B" means it is not binary |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
452 bindone = 0; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
453 valtype &= 14; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
454 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
455 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
456 switch (dval) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
457 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
458 case 'Q': |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
459 case 'O': |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
460 if (valtype & 2) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
461 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
462 val = octval; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
463 valtype = -1; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
464 break; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
465 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
466 else |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
467 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
468 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
469 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
470 /* can't get here */ |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
471 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
472 case 'H': |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
473 if (valtype & 8) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
474 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
475 val = hexval; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
476 valtype = -1; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
477 break; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
478 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
479 else |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
480 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
481 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
482 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
483 /* can't get here */ |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
484 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
485 case 'B': |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
486 // this is a bit of a sticky one since B may be a |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
487 // hex number instead of the end of a binary number |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
488 // so it falls through to the digit case |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
489 if (valtype & 1) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
490 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
491 // could still be binary of hex |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
492 bindone = 1; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
493 valtype = 9; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
494 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
495 /* fall through intented */ |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
496 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
497 default: |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
498 // digit |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
499 dval -= '0'; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
500 if (dval > 9) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
501 dval -= 7; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
502 if (valtype & 8) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
503 hexval = hexval * 16 + dval; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
504 if (valtype & 4) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
505 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
506 if (dval > 9) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
507 valtype &= 11; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
508 else |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
509 decval = decval * 10 + dval; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
510 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
511 if (valtype & 2) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
512 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
513 if (dval > 7) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
514 valtype &= 13; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
515 else |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
516 octval = octval * 8 + dval; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
517 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
518 if (valtype & 1) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
519 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
520 if (dval > 1) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
521 valtype &= 14; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
522 else |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
523 binval = binval * 2 + dval; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
524 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
525 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
526 if (valtype == -1) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
527 break; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
528 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
529 // return if no more valid types |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
530 if (valtype == 0) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
531 return NULL; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
532 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
533 val = decval; // in case we fall through |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
534 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
535 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
536 // get here if we have a value |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
537 return lw_expr_build(lw_expr_type_int, val); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
538 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
539 // can't get here |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
540 } |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
541 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
542 lw_expr_t lwasm_parse_expr(asmstate_t *as, char **p) |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
543 { |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
544 lw_expr_t e; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
545 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
546 e = lw_expr_parse(p, as); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
547 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
548 return e; |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
345
diff
changeset
|
549 } |
347 | 550 |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
551 int lwasm_reduce_expr(asmstate_t *as, lw_expr_t expr) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
552 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
553 lw_expr_simplify(expr, as); |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
554 } |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
555 |
347 | 556 void lwasm_save_expr(line_t *cl, int id, lw_expr_t expr) |
557 { | |
558 struct line_expr_s *e; | |
559 | |
560 for (e = cl -> exprs; e; e = e -> next) | |
561 { | |
562 if (e -> id == id) | |
563 { | |
564 lw_expr_destroy(e -> expr); | |
565 e -> expr = expr; | |
566 return; | |
567 } | |
568 } | |
569 | |
570 e = lw_alloc(sizeof(struct line_expr_s)); | |
571 e -> expr = expr; | |
572 e -> id = id; | |
573 e -> next = cl -> exprs; | |
574 cl -> exprs = e; | |
575 } | |
576 | |
577 lw_expr_t lwasm_fetch_expr(line_t *cl, int id) | |
578 { | |
579 struct line_expr_s *e; | |
580 | |
581 for (e = cl -> exprs; e; e = e -> next) | |
582 { | |
583 if (e -> id == id) | |
584 { | |
585 return e -> expr; | |
586 } | |
587 } | |
588 return NULL; | |
589 } | |
590 | |
591 void skip_operand(char **p) | |
592 { | |
593 for (; **p && !isspace(**p); (*p)++) | |
594 /* do nothing */ ; | |
595 } | |
596 | |
597 int lwasm_emitexpr(line_t *l, lw_expr_t expr, int size) | |
598 { | |
599 int v; | |
600 | |
601 if (lw_expr_istype(expr, lw_expr_type_int)) | |
602 { | |
603 v = lw_expr_intval(expr); | |
604 } | |
348
11a95c6414b4
Added third func to instab to split resolve and emit logic
lost@starbug
parents:
347
diff
changeset
|
605 // handle external/cross-section/incomplete references here |
347 | 606 else |
607 { | |
608 lwasm_register_error(l -> as, l, "Expression not fully resolved"); | |
609 return -1; | |
610 } | |
611 | |
612 switch (size) | |
613 { | |
614 case 4: | |
615 lwasm_emit(l, v >> 24); | |
616 lwasm_emit(l, v >> 16); | |
617 /* fallthrough intended */ | |
618 | |
619 case 2: | |
620 lwasm_emit(l, v >> 8); | |
621 /* fallthrough intended */ | |
622 | |
623 case 1: | |
624 lwasm_emit(l, v); | |
625 } | |
626 | |
627 return 0; | |
628 } | |
357 | 629 |
630 int lwasm_lookupreg2(const char *regs, char **p) | |
631 { | |
632 int rval = 0; | |
633 | |
634 while (*regs) | |
635 { | |
636 if (toupper(**p) == *regs) | |
637 { | |
638 if (regs[1] == ' ' && !isalpha(*(*p + 1))) | |
639 break; | |
640 if (toupper(*(*p + 1)) == regs[1]) | |
641 break; | |
642 } | |
643 regs += 2; | |
644 rval++; | |
645 } | |
646 if (!*regs) | |
647 return -1; | |
648 if (regs[1] == ' ') | |
649 (*p)++; | |
650 else | |
651 (*p) += 2; | |
652 return rval; | |
653 } | |
359 | 654 |
655 int lwasm_lookupreg3(const char *regs, char **p) | |
656 { | |
657 int rval = 0; | |
658 | |
659 while (*regs) | |
660 { | |
661 if (toupper(**p) == *regs) | |
662 { | |
663 if (regs[1] == ' ' && !isalpha(*(*p + 1))) | |
664 break; | |
665 if (toupper(*(*p + 1)) == regs[1]) | |
666 { | |
667 if (regs[2] == ' ' && !isalpha(*(*p + 2))) | |
668 break; | |
669 if (toupper(*(*p + 2)) == regs[2]) | |
670 break; | |
671 } | |
672 } | |
673 regs += 3; | |
674 rval++; | |
675 } | |
676 if (!*regs) | |
677 return -1; | |
678 if (regs[1] == ' ') | |
679 (*p)++; | |
680 else if (regs[2] == ' ') | |
681 (*p) += 2; | |
682 else | |
683 (*p) += 3; | |
684 return rval; | |
685 } | |
363
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
686 |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
687 void lwasm_show_errors(asmstate_t *as) |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
688 { |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
689 fprintf(stderr, "Errors encountered. FIXME - print out errors.\n"); |
d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents:
359
diff
changeset
|
690 } |