Mercurial > hg > index.cgi
annotate lwasm/main.c @ 576:40edb7de3857
Add 0b and 0B as a prefix for binary constants
author | William Astle <lost@l-w.ca> |
---|---|
date | Fri, 12 Jul 2024 23:02:57 -0600 |
parents | ddc7b05a5675 |
children |
rev | line source |
---|---|
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
2 main.c |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
3 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
4 Copyright © 2010 William Astle |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
5 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
6 This file is part of LWTOOLS. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
7 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
8 LWTOOLS is free software: you can redistribute it and/or modify it under the |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
9 terms of the GNU General Public License as published by the Free Software |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
10 Foundation, either version 3 of the License, or (at your option) any later |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
11 version. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
12 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, but WITHOUT |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
16 more details. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
17 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License along with |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
19 this program. If not, see <http://www.gnu.org/licenses/>. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
20 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
21 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
22 #include <stdio.h> |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
23 #include <stdlib.h> |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
24 #include <string.h> |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
25 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
26 #include <lw_alloc.h> |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
27 #include <lw_string.h> |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
28 #include <lw_stringlist.h> |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
29 #include <lw_expr.h> |
7 | 30 #include <lw_cmdline.h> |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
31 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
32 #include "lwasm.h" |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
33 #include "input.h" |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
34 |
374 | 35 void lwasm_do_unicorns(asmstate_t *as); |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
219
diff
changeset
|
36 |
374 | 37 int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
38 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
39 /* command line option handling */ |
7 | 40 #define PROGVER "lwasm from " PACKAGE_STRING |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
41 char *program_name; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
42 |
7 | 43 static struct lw_cmdline_options options[] = |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
44 { |
7 | 45 { "output", 'o', "FILE", 0, "Output to FILE"}, |
46 { "debug", 'd', "LEVEL", lw_cmdline_opt_optional, "Set debug mode"}, | |
543
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
47 { "format", 'f', "TYPE", 0, "Select output format: decb, basic, raw, obj, os9, ihex, srec, dragon, abs"}, |
7 | 48 { "list", 'l', "FILE", lw_cmdline_opt_optional, "Generate list [to FILE]"}, |
442
61580fc48f98
Add option to omit file names from lwasm listings
William Astle <lost@l-w.ca>
parents:
441
diff
changeset
|
49 { "list-nofiles", 0x104, 0, 0, "Omit file names in list output"}, |
7 | 50 { "symbols", 's', 0, lw_cmdline_opt_optional, "Generate symbol list in listing, no effect without --list"}, |
365
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
51 { "symbols-nolocals", 0x103, 0, lw_cmdline_opt_optional, "Same as --symbols but with local labels ignored"}, |
487
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
52 { "symbol-dump", 0x106, "FILE", lw_cmdline_opt_optional, "Dump global symbol table in assembly format" }, |
390
1ebb5a0b2874
Add option to specify tab width in listing
William Astle <lost@l-w.ca>
parents:
375
diff
changeset
|
53 { "tabs", 't', "WIDTH", 0, "Set tab spacing in listing (0=don't expand tabs)" }, |
365
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
54 { "map", 'm', "FILE", lw_cmdline_opt_optional, "Generate map [to FILE]"}, |
7 | 55 { "decb", 'b', 0, 0, "Generate DECB .bin format output, equivalent of --format=decb"}, |
543
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
56 { "dragon", 0x107, 0, 0, "Generate a Dragon DOS binary format, equivalent of --format=dragon"}, |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
57 { "abs", 0x108, 0, 0, "Generate absolute binary format, equivalent of --format=abs"}, |
7 | 58 { "raw", 'r', 0, 0, "Generate raw binary format output, equivalent of --format=raw"}, |
59 { "obj", 0x100, 0, 0, "Generate proprietary object file format for later linking, equivalent of --format=obj" }, | |
60 { "depend", 0x101, 0, 0, "Output a dependency list to stdout; do not do any actual output though assembly is completed as usual" }, | |
73
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
61 { "dependnoerr", 0x102, 0, 0, "Output a dependency list to stdout; do not do any actual output though assembly is completed as usual; don't bail on missing include files" }, |
7 | 62 { "pragma", 'p', "PRAGMA", 0, "Set an assembler pragma to any value understood by the \"pragma\" pseudo op"}, |
63 { "6809", '9', 0, 0, "Set assembler to 6809 only mode" }, | |
64 { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" }, | |
65 { "includedir", 'I', "PATH", 0, "Add entry to include path" }, | |
390
1ebb5a0b2874
Add option to specify tab width in listing
William Astle <lost@l-w.ca>
parents:
375
diff
changeset
|
66 { "define", 'D', "SYM[=VAL]",0, "Automatically define SYM to be VAL (or 1)"}, |
219 | 67 { "preprocess", 'P', 0, 0, "Preprocess macros and conditionals and output revised source to stdout" }, |
224
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
68 { "unicorns", 0x142, 0, 0, "Add sooper sekrit sauce"}, |
333
507f442dc71e
Add support for 6800 compatibility instructions.
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
69 { "6800compat", 0x200, 0, 0, "Enable 6800 compatibility instructions, equivalent to --pragma=6800compat" }, |
484
469a130e7029
Add option to suppress output file
William Astle <lost@l-w.ca>
parents:
444
diff
changeset
|
70 { "no-output", 0x105, 0, 0, "Inhibit creation of output file" }, |
559
ddc7b05a5675
Add --no-warn=ifp1 flag to suppress warnings about ifp1 and ipf2
William Astle <lost@l-w.ca>
parents:
543
diff
changeset
|
71 { "no-warn", 0x109, "FLAG", 0, "Suppress warnings of the specified type" }, |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
72 { 0 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
73 }; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
74 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
75 |
7 | 76 static int parse_opts(int key, char *arg, void *state) |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
77 { |
7 | 78 asmstate_t *as = state; |
106 | 79 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
80 switch (key) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
81 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
82 case 'I': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
83 lw_stringlist_addstring(as -> include_list, arg); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
84 break; |
101
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
85 |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
86 case 'D': |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
87 { |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
88 char *offs; |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
89 int val = 1; |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
90 lw_expr_t te; |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
91 |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
92 if ((offs = strchr(arg, '='))) |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
93 { |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
94 *offs = '\0'; |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
95 val = strtol(offs + 1, NULL, 0); |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
96 } |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
97 |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
98 /* register global symbol */ |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
99 te = lw_expr_build(lw_expr_type_int, val); |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
100 register_symbol(as, NULL, arg, te, symbol_flag_nocheck | symbol_flag_set); |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
101 lw_expr_destroy(te); |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
102 |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
103 if (offs) |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
104 *offs = '='; |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
105 break; |
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
73
diff
changeset
|
106 } |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
107 case 'o': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
108 if (as -> output_file) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
109 lw_free(as -> output_file); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
110 as -> output_file = lw_strdup(arg); |
484
469a130e7029
Add option to suppress output file
William Astle <lost@l-w.ca>
parents:
444
diff
changeset
|
111 as -> flags &= ~FLAG_NOOUT; |
469a130e7029
Add option to suppress output file
William Astle <lost@l-w.ca>
parents:
444
diff
changeset
|
112 break; |
469a130e7029
Add option to suppress output file
William Astle <lost@l-w.ca>
parents:
444
diff
changeset
|
113 |
469a130e7029
Add option to suppress output file
William Astle <lost@l-w.ca>
parents:
444
diff
changeset
|
114 case 0x105: |
469a130e7029
Add option to suppress output file
William Astle <lost@l-w.ca>
parents:
444
diff
changeset
|
115 as -> flags |= FLAG_NOOUT; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
116 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
117 |
487
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
118 case 0x106: |
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
119 if (as -> symbol_dump_file) |
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
120 lw_free(as -> symbol_dump_file); |
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
121 if (!arg) |
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
122 as -> symbol_dump_file = lw_strdup("-"); |
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
123 else |
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
124 as -> symbol_dump_file = lw_strdup(arg); |
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
125 as -> flags |= FLAG_SYMDUMP; |
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
126 break; |
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
127 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
128 case 'd': |
338
5d401d1eb3e9
Allow disabling debugging messages.
William Astle <lost@l-w.ca>
parents:
333
diff
changeset
|
129 #ifdef LWASM_NODEBUG |
5d401d1eb3e9
Allow disabling debugging messages.
William Astle <lost@l-w.ca>
parents:
333
diff
changeset
|
130 fprintf(stderr, "This binary has been built without debugging message support\n"); |
5d401d1eb3e9
Allow disabling debugging messages.
William Astle <lost@l-w.ca>
parents:
333
diff
changeset
|
131 #else |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
132 if (!arg) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
133 as -> debug_level = 50; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
134 else |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
135 as -> debug_level = atoi(arg); |
338
5d401d1eb3e9
Allow disabling debugging messages.
William Astle <lost@l-w.ca>
parents:
333
diff
changeset
|
136 #endif |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
137 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
138 |
390
1ebb5a0b2874
Add option to specify tab width in listing
William Astle <lost@l-w.ca>
parents:
375
diff
changeset
|
139 case 't': |
1ebb5a0b2874
Add option to specify tab width in listing
William Astle <lost@l-w.ca>
parents:
375
diff
changeset
|
140 if (arg) |
1ebb5a0b2874
Add option to specify tab width in listing
William Astle <lost@l-w.ca>
parents:
375
diff
changeset
|
141 as -> tabwidth = atoi(arg); |
1ebb5a0b2874
Add option to specify tab width in listing
William Astle <lost@l-w.ca>
parents:
375
diff
changeset
|
142 break; |
1ebb5a0b2874
Add option to specify tab width in listing
William Astle <lost@l-w.ca>
parents:
375
diff
changeset
|
143 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
144 case 'l': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
145 if (as -> list_file) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
146 lw_free(as -> list_file); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
147 if (!arg) |
106 | 148 as -> list_file = lw_strdup("-"); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
149 else |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
150 as -> list_file = lw_strdup(arg); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
151 as -> flags |= FLAG_LIST; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
152 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
153 |
365
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
154 case 'm': |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
155 if (as -> map_file) |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
156 lw_free(as -> map_file); |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
157 if (!arg) |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
158 as -> map_file = lw_strdup("-"); |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
159 else |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
160 as -> map_file = lw_strdup(arg); |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
161 as -> flags |= FLAG_MAP; |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
162 break; |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
163 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
164 case 's': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
165 as -> flags |= FLAG_SYMBOLS; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
166 break; |
365
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
167 |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
168 case 0x103: |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
169 as -> flags |= FLAG_SYMBOLS | FLAG_SYMBOLS_NOLOCALS; |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
170 break; |
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
171 |
442
61580fc48f98
Add option to omit file names from lwasm listings
William Astle <lost@l-w.ca>
parents:
441
diff
changeset
|
172 case 0x104: |
61580fc48f98
Add option to omit file names from lwasm listings
William Astle <lost@l-w.ca>
parents:
441
diff
changeset
|
173 as -> listnofile = 1; |
61580fc48f98
Add option to omit file names from lwasm listings
William Astle <lost@l-w.ca>
parents:
441
diff
changeset
|
174 break; |
61580fc48f98
Add option to omit file names from lwasm listings
William Astle <lost@l-w.ca>
parents:
441
diff
changeset
|
175 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
176 case 'b': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
177 as -> output_format = OUTPUT_DECB; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
178 break; |
543
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
179 |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
180 case 0x107: |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
181 as -> output_format = OUTPUT_DRAGON; |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
182 break; |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
183 |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
184 case 0x108: |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
185 as -> output_format = OUTPUT_ABS; |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
186 break; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
187 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
188 case 'r': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
189 as -> output_format = OUTPUT_RAW; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
190 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
191 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
192 case 0x100: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
193 as -> output_format = OUTPUT_OBJ; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
194 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
195 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
196 case 0x101: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
197 as -> flags |= FLAG_DEPEND; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
198 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
199 |
73
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
200 case 0x102: |
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
201 as -> flags |= FLAG_DEPEND | FLAG_DEPENDNOERR; |
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
202 break; |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
219
diff
changeset
|
203 |
224
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
204 case 0x142: |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
219
diff
changeset
|
205 as -> flags |= FLAG_UNICORNS; |
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
219
diff
changeset
|
206 break; |
73
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
207 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
208 case 'f': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
209 if (!strcasecmp(arg, "decb")) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
210 as -> output_format = OUTPUT_DECB; |
411
9f796134d6f4
Fix wrong sense in strcasecmp()
William Astle <lost@l-w.ca>
parents:
406
diff
changeset
|
211 else if (!strcasecmp(arg, "basic")) |
406 | 212 as -> output_format = OUTPUT_BASIC; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
213 else if (!strcasecmp(arg, "raw")) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
214 as -> output_format = OUTPUT_RAW; |
276 | 215 else if (!strcasecmp(arg, "rawrel")) |
216 as -> output_format = OUTPUT_RAWREL; | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
217 else if (!strcasecmp(arg, "obj")) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
218 as -> output_format = OUTPUT_OBJ; |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
276
diff
changeset
|
219 else if (!strcasecmp(arg, "srec")) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
276
diff
changeset
|
220 as -> output_format = OUTPUT_SREC; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
276
diff
changeset
|
221 else if (!strcasecmp(arg, "ihex")) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
276
diff
changeset
|
222 as -> output_format = OUTPUT_IHEX; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
276
diff
changeset
|
223 else if (!strcasecmp(arg, "hex")) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
276
diff
changeset
|
224 as -> output_format = OUTPUT_HEX; |
543
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
225 else if (!strcasecmp(arg, "dragon")) |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
226 as -> output_format = OUTPUT_DRAGON; |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
227 else if (!strcasecmp(arg, "abs")) |
e10618b48e68
Implement support for dragon format binaries
William Astle <lost@l-w.ca>
parents:
487
diff
changeset
|
228 as -> output_format = OUTPUT_ABS; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
229 else if (!strcasecmp(arg, "os9")) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
230 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
231 as -> pragmas |= PRAGMA_DOLLARNOTLOCAL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
232 as -> output_format = OUTPUT_OS9; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
233 } |
432
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
426
diff
changeset
|
234 else if (!strcasecmp(arg, "lwmod")) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
426
diff
changeset
|
235 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
426
diff
changeset
|
236 as -> output_format = OUTPUT_LWMOD; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
426
diff
changeset
|
237 } |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
238 else |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
239 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
240 fprintf(stderr, "Invalid output format: %s\n", arg); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
241 exit(1); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
242 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
243 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
244 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
245 case 'p': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
246 if (parse_pragma_string(as, arg, 0) == 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
247 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
248 fprintf(stderr, "Unrecognized pragma string: %s\n", arg); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
249 exit(1); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
250 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
251 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
252 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
253 case '9': |
367
c6d2a1f54e0c
Change processor target variations to pragmas.
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
254 as -> pragmas |= PRAGMA_6809; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
255 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
256 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
257 case '3': |
367
c6d2a1f54e0c
Change processor target variations to pragmas.
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
258 as -> pragmas &= ~PRAGMA_6809; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
259 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
260 |
219 | 261 case 'P': |
262 as -> preprocess = 1; | |
263 break; | |
333
507f442dc71e
Add support for 6800 compatibility instructions.
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
264 |
559
ddc7b05a5675
Add --no-warn=ifp1 flag to suppress warnings about ifp1 and ipf2
William Astle <lost@l-w.ca>
parents:
543
diff
changeset
|
265 case 0x109: |
ddc7b05a5675
Add --no-warn=ifp1 flag to suppress warnings about ifp1 and ipf2
William Astle <lost@l-w.ca>
parents:
543
diff
changeset
|
266 if (!strcasecmp(arg, "ifp1") || !strcasecmp(arg, "ifp2")) |
ddc7b05a5675
Add --no-warn=ifp1 flag to suppress warnings about ifp1 and ipf2
William Astle <lost@l-w.ca>
parents:
543
diff
changeset
|
267 as -> nowarn_flags |= NOWARN_IFP1; |
ddc7b05a5675
Add --no-warn=ifp1 flag to suppress warnings about ifp1 and ipf2
William Astle <lost@l-w.ca>
parents:
543
diff
changeset
|
268 break; |
ddc7b05a5675
Add --no-warn=ifp1 flag to suppress warnings about ifp1 and ipf2
William Astle <lost@l-w.ca>
parents:
543
diff
changeset
|
269 |
333
507f442dc71e
Add support for 6800 compatibility instructions.
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
270 case 0x200: |
507f442dc71e
Add support for 6800 compatibility instructions.
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
271 as -> pragmas |= PRAGMA_6800COMPAT; |
507f442dc71e
Add support for 6800 compatibility instructions.
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
272 break; |
219 | 273 |
7 | 274 case lw_cmdline_key_end: |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
275 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
276 |
7 | 277 case lw_cmdline_key_arg: |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
278 lw_stringlist_addstring(as -> input_files, arg); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
279 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
280 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
281 default: |
7 | 282 return lw_cmdline_err_unknown; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
283 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
284 return 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
285 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
286 |
7 | 287 static struct lw_cmdline_parser cmdline_parser = |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
288 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
289 options, |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
290 parse_opts, |
7 | 291 "INPUTFILE", |
292 "lwasm, a HD6309 and MC6809 cross-assembler\vPlease report bugs to lost@l-w.ca.", | |
293 PROGVER | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
294 }; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
295 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
296 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
297 main function; parse command line, set up assembler state, and run the |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
298 assembler on the first file |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
299 */ |
374 | 300 void do_pass1(asmstate_t *as); |
301 void do_pass2(asmstate_t *as); | |
302 void do_pass3(asmstate_t *as); | |
303 void do_pass4(asmstate_t *as); | |
304 void do_pass5(asmstate_t *as); | |
305 void do_pass6(asmstate_t *as); | |
306 void do_pass7(asmstate_t *as); | |
307 void do_output(asmstate_t *as); | |
487
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
308 void do_symdump(asmstate_t *as); |
374 | 309 void do_list(asmstate_t *as); |
310 void do_map(asmstate_t *as); | |
311 lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv); | |
312 lw_expr_t lwasm_evaluate_var(char *var, void *priv); | |
313 lw_expr_t lwasm_parse_term(char **p, void *priv); | |
314 void lwasm_dividezero(void *priv); | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
315 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
316 struct passlist_s |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
317 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
318 char *passname; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
319 void (*fn)(asmstate_t *as); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
320 int fordep; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
321 } passlist[] = { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
322 { "parse", do_pass1, 1 }, |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
323 { "symcheck", do_pass2 }, |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
324 { "resolve1", do_pass3 }, |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
325 { "resolve2", do_pass4 }, |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
326 { "addressresolve", do_pass5 }, |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
327 { "finalize", do_pass6 }, |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
328 { "emit", do_pass7 }, |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
329 { NULL, NULL } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
330 }; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
331 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
332 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
333 int main(int argc, char **argv) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
334 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
335 int passnum; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
336 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
337 /* assembler state */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
338 asmstate_t asmstate = { 0 }; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
339 program_name = argv[0]; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
340 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
341 lw_expr_set_special_handler(lwasm_evaluate_special); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
342 lw_expr_set_var_handler(lwasm_evaluate_var); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
343 lw_expr_set_term_parser(lwasm_parse_term); |
249
1f1a28b797e1
Add trap for divide by zero in expression library
William Astle <lost@l-w.ca>
parents:
229
diff
changeset
|
344 lw_expr_setdivzero(lwasm_dividezero); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
345 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
346 /* initialize assembler state */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
347 asmstate.include_list = lw_stringlist_create(); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
348 asmstate.input_files = lw_stringlist_create(); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
349 asmstate.nextcontext = 1; |
366
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
365
diff
changeset
|
350 asmstate.exprwidth = 16; |
390
1ebb5a0b2874
Add option to specify tab width in listing
William Astle <lost@l-w.ca>
parents:
375
diff
changeset
|
351 asmstate.tabwidth = 8; |
426
b4825b42c151
Change to engage forwardrefmax pragma by default
William Astle <lost@l-w.ca>
parents:
411
diff
changeset
|
352 |
b4825b42c151
Change to engage forwardrefmax pragma by default
William Astle <lost@l-w.ca>
parents:
411
diff
changeset
|
353 // enable the "forward reference maximum size" pragma; old available |
b4825b42c151
Change to engage forwardrefmax pragma by default
William Astle <lost@l-w.ca>
parents:
411
diff
changeset
|
354 // can be obtained with --pragma=noforwardrefmax |
b4825b42c151
Change to engage forwardrefmax pragma by default
William Astle <lost@l-w.ca>
parents:
411
diff
changeset
|
355 asmstate.pragmas = PRAGMA_FORWARDREFMAX; |
212
b0d53e2f3f53
Make --6309/--6809 work properly
William Astle <lost@l-w.ca>
parents:
186
diff
changeset
|
356 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
357 /* parse command line arguments */ |
441
b138b4005125
Make missing command line arguments fail properly
William Astle <lost@l-w.ca>
parents:
432
diff
changeset
|
358 if (lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, &asmstate) != 0) |
b138b4005125
Make missing command line arguments fail properly
William Astle <lost@l-w.ca>
parents:
432
diff
changeset
|
359 { |
b138b4005125
Make missing command line arguments fail properly
William Astle <lost@l-w.ca>
parents:
432
diff
changeset
|
360 exit(1); |
b138b4005125
Make missing command line arguments fail properly
William Astle <lost@l-w.ca>
parents:
432
diff
changeset
|
361 } |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
362 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
363 if (!asmstate.output_file) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
364 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
365 asmstate.output_file = lw_strdup("a.out"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
366 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
367 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
368 input_init(&asmstate); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
369 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
370 for (passnum = 0; passlist[passnum].fn; passnum++) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
371 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
372 if ((asmstate.flags & FLAG_DEPEND) && passlist[passnum].fordep == 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
373 continue; |
70
ceab04fd2969
Fixed premature installation of external reference under UNDEFEXTERN pragma; should not resolve to external references until after the initial parsing pass
lost@l-w.ca
parents:
7
diff
changeset
|
374 asmstate.passno = passnum; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
375 debug_message(&asmstate, 50, "Doing pass %d (%s)\n", passnum, passlist[passnum].passname); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
376 (passlist[passnum].fn)(&asmstate); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
377 debug_message(&asmstate, 50, "After pass %d (%s)\n", passnum, passlist[passnum].passname); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
378 dump_state(&asmstate); |
219 | 379 |
380 if (asmstate.preprocess) | |
381 { | |
382 /* we're done if we were preprocessing */ | |
383 exit(0); | |
384 } | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
385 if (asmstate.errorcount > 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
386 { |
73
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
387 if (asmstate.flags & FLAG_DEPEND) |
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
388 { |
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
389 // don't show errors during dependency scanning but |
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
390 // stop processing immediately |
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
391 break; |
1f77ae5c3590
Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
lost@l-w.ca
parents:
70
diff
changeset
|
392 } |
226
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
224
diff
changeset
|
393 if (asmstate.flags & FLAG_UNICORNS) |
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
224
diff
changeset
|
394 lwasm_do_unicorns(&asmstate); |
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
224
diff
changeset
|
395 else |
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
224
diff
changeset
|
396 lwasm_show_errors(&asmstate); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
397 exit(1); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
398 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
399 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
400 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
401 if (asmstate.flags & FLAG_DEPEND) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
402 { |
224
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
403 // output dependencies (other than "includebin") |
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
404 char *n; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
405 |
224
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
406 while ((n = lw_stack_pop(asmstate.includelist))) |
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
407 { |
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
408 fprintf(stdout, "%s\n", n); |
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
409 lw_free(n); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
410 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
411 } |
484
469a130e7029
Add option to suppress output file
William Astle <lost@l-w.ca>
parents:
444
diff
changeset
|
412 else if ((asmstate.flags & FLAG_NOOUT) == 0) |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
413 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
414 debug_message(&asmstate, 50, "Doing output"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
415 do_output(&asmstate); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
416 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
417 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
418 debug_message(&asmstate, 50, "Done assembly"); |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
219
diff
changeset
|
419 |
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
219
diff
changeset
|
420 if (asmstate.flags & FLAG_UNICORNS) |
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
219
diff
changeset
|
421 { |
224
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
422 debug_message(&asmstate, 50, "Invoking unicorns"); |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
219
diff
changeset
|
423 lwasm_do_unicorns(&asmstate); |
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
219
diff
changeset
|
424 } |
487
7fbf3171ca15
Add symbol table dump in assembly format
William Astle <lost@l-w.ca>
parents:
484
diff
changeset
|
425 do_symdump(&asmstate); |
229
164487152dd9
Add flag to output stream for end of unicorns
William Astle <lost@l-w.ca>
parents:
226
diff
changeset
|
426 do_list(&asmstate); |
365
3f8abaac214c
Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents:
338
diff
changeset
|
427 do_map(&asmstate); |
375 | 428 |
429 if (asmstate.testmode_errorcount > 0) exit(1); | |
430 | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
431 exit(0); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
432 } |