comparison lwasm/macro.c @ 49:bd8b3fbd1e28

Added ability to flag macros as "noexpand" so they are not expanded in the listing
author lost@l-w.ca
date Tue, 05 Apr 2011 00:06:28 -0600
parents d96037ea0b80
children e2728091b75a
comparison
equal deleted inserted replaced
48:1134255553bc 49:bd8b3fbd1e28
33 #include "instab.h" 33 #include "instab.h"
34 34
35 PARSEFUNC(pseudo_parse_macro) 35 PARSEFUNC(pseudo_parse_macro)
36 { 36 {
37 macrotab_t *m; 37 macrotab_t *m;
38 38 char *t;
39 char tc;
40
39 l -> len = 0; 41 l -> len = 0;
40 42
41 if (as -> skipcond) 43 if (as -> skipcond)
42 { 44 {
43 as -> skipmacro = 1; 45 as -> skipmacro = 1;
70 m = lw_alloc(sizeof(macrotab_t)); 72 m = lw_alloc(sizeof(macrotab_t));
71 m -> name = lw_strdup(l -> sym); 73 m -> name = lw_strdup(l -> sym);
72 m -> next = as -> macros; 74 m -> next = as -> macros;
73 m -> lines = NULL; 75 m -> lines = NULL;
74 m -> numlines = 0; 76 m -> numlines = 0;
77 m -> flags = 0;
75 as -> macros = m; 78 as -> macros = m;
76 79
80 t = *p;
77 while (**p && !isspace(**p)) 81 while (**p && !isspace(**p))
78 (*p)++; 82 (*p)++;
79 83 tc = **p;
84 /* ignore unknown flags */
85 if (strcasecmp(t, "noexpand") == 0)
86 m -> flags |= macro_noexpand;
87 **p = tc;
80 as -> inmacro = 1; 88 as -> inmacro = 1;
81 } 89 }
82 90
83 PARSEFUNC(pseudo_parse_endm) 91 PARSEFUNC(pseudo_parse_endm)
84 { 92 {
202 210
203 // now create a string for the macro 211 // now create a string for the macro
204 // and push it into the front of the input stack 212 // and push it into the front of the input stack
205 bloc = blen = 0; 213 bloc = blen = 0;
206 linebuff = NULL; 214 linebuff = NULL;
215
216 if (m -> flags & macro_noexpand)
217 {
218 char ctcbuf[100];
219 char *p;
220 snprintf(ctcbuf, 100, "\001\001SETNOEXPANDSTART\n");
221 for (p = ctcbuf; *p; p++)
222 macro_add_to_buff(&linebuff, &bloc, &blen, *p);
223 }
224
207 225
208 for (lc = 0; lc < m -> numlines; lc++) 226 for (lc = 0; lc < m -> numlines; lc++)
209 { 227 {
210 for (p2 = m -> lines[lc]; *p2; p2++) 228 for (p2 = m -> lines[lc]; *p2; p2++)
211 { 229 {
262 280
263 macro_add_to_buff(&linebuff, &bloc, &blen, '\n'); 281 macro_add_to_buff(&linebuff, &bloc, &blen, '\n');
264 282
265 } 283 }
266 284
285 if (m -> flags & macro_noexpand)
286 {
287 char ctcbuf[100];
288 char *p;
289 snprintf(ctcbuf, 100, "\001\001SETNOEXPANDEND\n");
290 for (p = ctcbuf; *p; p++)
291 macro_add_to_buff(&linebuff, &bloc, &blen, *p);
292 }
293
267 { 294 {
268 char ctcbuf[100]; 295 char ctcbuf[100];
269 char *p; 296 char *p;
270 snprintf(ctcbuf, 100, "\001\001SETCONTEXT %d\n\001\001SETLINENO %d\n", oldcontext, cl -> lineno + 1); 297 snprintf(ctcbuf, 100, "\001\001SETCONTEXT %d\n\001\001SETLINENO %d\n", oldcontext, cl -> lineno + 1);
271 for (p = ctcbuf; *p; p++) 298 for (p = ctcbuf; *p; p++)