Mercurial > hg > index.cgi
comparison lwasm/pass1.c @ 59:1830faeef332
Added ?? prefix for opcode to inhibit macro expansion
author | lost@l-w.ca |
---|---|
date | Wed, 06 Apr 2011 20:23:43 -0600 |
parents | cb4efc47ce9d |
children | 8fa52c3f2970 |
comparison
equal
deleted
inserted
replaced
58:62372522ce9c | 59:1830faeef332 |
---|---|
56 char *p1; | 56 char *p1; |
57 int stspace; | 57 int stspace; |
58 char *tok, *sym; | 58 char *tok, *sym; |
59 int opnum; | 59 int opnum; |
60 int lc = 1; | 60 int lc = 1; |
61 int nomacro; | |
62 | |
61 for (;;) | 63 for (;;) |
62 { | 64 { |
65 nomacro = 0; | |
63 sym = NULL; | 66 sym = NULL; |
64 line = input_readline(as); | 67 line = input_readline(as); |
65 if (!line) | 68 if (!line) |
66 break; | 69 break; |
67 if (line[0] == 1 && line[1] == 1) | 70 if (line[0] == 1 && line[1] == 1) |
229 else if (sym) | 232 else if (sym) |
230 cl -> sym = lw_strdup(sym); | 233 cl -> sym = lw_strdup(sym); |
231 cl -> symset = 0; | 234 cl -> symset = 0; |
232 | 235 |
233 // tok points to the opcode for the line or NUL if none | 236 // tok points to the opcode for the line or NUL if none |
237 | |
238 // if the first two chars of the opcode are "??", that's | |
239 // a flag to inhibit macro expansion | |
240 if (*tok && tok[0] == '?' && tok[1] == '?') | |
241 { | |
242 nomacro = 1; | |
243 tok += 2; | |
244 } | |
234 if (*tok) | 245 if (*tok) |
235 { | 246 { |
236 // look up operation code | 247 // look up operation code |
237 sym = lw_strndup(tok, p1 - tok); | 248 sym = lw_strndup(tok, p1 - tok); |
238 for (; *p1 && isspace(*p1); p1++) | 249 for (; *p1 && isspace(*p1); p1++) |
258 // operate within a condition (not a conditional) | 269 // operate within a condition (not a conditional) |
259 // do nothing | 270 // do nothing |
260 if (as -> skipcond && !(instab[opnum].flags & lwasm_insn_cond)) | 271 if (as -> skipcond && !(instab[opnum].flags & lwasm_insn_cond)) |
261 goto linedone; | 272 goto linedone; |
262 | 273 |
263 if (as -> pragmas & PRAGMA_SHADOW) | 274 if (!nomacro && (as -> pragmas & PRAGMA_SHADOW)) |
264 { | 275 { |
265 // check for macros even if they shadow real operations | 276 // check for macros even if they shadow real operations |
266 // NOTE: "ENDM" cannot be shadowed | 277 // NOTE: "ENDM" cannot be shadowed |
267 if (expand_macro(as, cl, &p1, sym) == 0) | 278 if (expand_macro(as, cl, &p1, sym) == 0) |
268 { | 279 { |
274 { | 285 { |
275 cl -> insn = -1; | 286 cl -> insn = -1; |
276 if (*tok != ';' && *tok != '*') | 287 if (*tok != ';' && *tok != '*') |
277 { | 288 { |
278 // bad opcode; check for macro here | 289 // bad opcode; check for macro here |
279 if (expand_macro(as, cl, &p1, sym) != 0) | 290 // but don't expand it if "nomacro" is in effect |
291 if (nomacro || expand_macro(as, cl, &p1, sym) != 0) | |
280 { | 292 { |
281 // macro expansion failed | 293 // macro expansion failed |
282 if (expand_struct(as, cl, &p1, sym) != 0) | 294 if (expand_struct(as, cl, &p1, sym) != 0) |
283 { | 295 { |
284 // structure expansion failed | 296 // structure expansion failed |