comparison lwasm/main.c @ 219:afd50d6b4113

Add --preprocess option Add --preprocess option which expands macros, resolves conditions, and resolves include files if possible. If an include file is not available, it the include directive is retained.
author William Astle <lost@l-w.ca>
date Sun, 10 Jun 2012 18:24:31 -0600
parents b0d53e2f3f53
children 03f7192fcd20
comparison
equal deleted inserted replaced
218:b0c9df865b25 219:afd50d6b4113
53 { "pragma", 'p', "PRAGMA", 0, "Set an assembler pragma to any value understood by the \"pragma\" pseudo op"}, 53 { "pragma", 'p', "PRAGMA", 0, "Set an assembler pragma to any value understood by the \"pragma\" pseudo op"},
54 { "6809", '9', 0, 0, "Set assembler to 6809 only mode" }, 54 { "6809", '9', 0, 0, "Set assembler to 6809 only mode" },
55 { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" }, 55 { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" },
56 { "includedir", 'I', "PATH", 0, "Add entry to include path" }, 56 { "includedir", 'I', "PATH", 0, "Add entry to include path" },
57 { "define", 'D', "SYM[=VAL]", 0, "Automatically define SYM to be VAL (or 1)"}, 57 { "define", 'D', "SYM[=VAL]", 0, "Automatically define SYM to be VAL (or 1)"},
58 { "preprocess", 'P', 0, 0, "Preprocess macros and conditionals and output revised source to stdout" },
58 { 0 } 59 { 0 }
59 }; 60 };
60 61
61 62
62 static int parse_opts(int key, char *arg, void *state) 63 static int parse_opts(int key, char *arg, void *state)
170 171
171 case '3': 172 case '3':
172 as -> target = TARGET_6309; 173 as -> target = TARGET_6309;
173 break; 174 break;
174 175
176 case 'P':
177 as -> preprocess = 1;
178 break;
179
175 case lw_cmdline_key_end: 180 case lw_cmdline_key_end:
176 break; 181 break;
177 182
178 case lw_cmdline_key_arg: 183 case lw_cmdline_key_arg:
179 lw_stringlist_addstring(as -> input_files, arg); 184 lw_stringlist_addstring(as -> input_files, arg);
263 asmstate.passno = passnum; 268 asmstate.passno = passnum;
264 debug_message(&asmstate, 50, "Doing pass %d (%s)\n", passnum, passlist[passnum].passname); 269 debug_message(&asmstate, 50, "Doing pass %d (%s)\n", passnum, passlist[passnum].passname);
265 (passlist[passnum].fn)(&asmstate); 270 (passlist[passnum].fn)(&asmstate);
266 debug_message(&asmstate, 50, "After pass %d (%s)\n", passnum, passlist[passnum].passname); 271 debug_message(&asmstate, 50, "After pass %d (%s)\n", passnum, passlist[passnum].passname);
267 dump_state(&asmstate); 272 dump_state(&asmstate);
268 273
274 if (asmstate.preprocess)
275 {
276 /* we're done if we were preprocessing */
277 exit(0);
278 }
269 if (asmstate.errorcount > 0) 279 if (asmstate.errorcount > 0)
270 { 280 {
271 if (asmstate.flags & FLAG_DEPEND) 281 if (asmstate.flags & FLAG_DEPEND)
272 { 282 {
273 // don't show errors during dependency scanning but 283 // don't show errors during dependency scanning but