annotate lwasm/main.c @ 355:3afb809c7add

Make 8 bit immediate operands flag a byte overflow if not in 8 bit range. 8 bit immediate operands should flag a byte overflow if they are out of range. The acceptable range is -128 <= x <= 255 to cover both signed and unsigned values.
author William Astle <lost@l-w.ca>
date Tue, 19 May 2015 12:26:35 -0600
parents 5d401d1eb3e9
children 3f8abaac214c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
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
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
35 extern void lwasm_do_unicorns(asmstate_t *as);
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
36
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
37 extern int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr);
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
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
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
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
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
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
45 { "output", 'o', "FILE", 0, "Output to FILE"},
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
46 { "debug", 'd', "LEVEL", lw_cmdline_opt_optional, "Set debug mode"},
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
47 { "format", 'f', "TYPE", 0, "Select output format: decb, raw, obj, os9"},
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
48 { "list", 'l', "FILE", lw_cmdline_opt_optional, "Generate list [to FILE]"},
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
49 { "symbols", 's', 0, lw_cmdline_opt_optional, "Generate symbol list in listing, no effect without --list"},
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
50 { "decb", 'b', 0, 0, "Generate DECB .bin format output, equivalent of --format=decb"},
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
51 { "raw", 'r', 0, 0, "Generate raw binary format output, equivalent of --format=raw"},
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
52 { "obj", 0x100, 0, 0, "Generate proprietary object file format for later linking, equivalent of --format=obj" },
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
53 { "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
54 { "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
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
55 { "pragma", 'p', "PRAGMA", 0, "Set an assembler pragma to any value understood by the \"pragma\" pseudo op"},
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
56 { "6809", '9', 0, 0, "Set assembler to 6809 only mode" },
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
57 { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" },
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
58 { "includedir", 'I', "PATH", 0, "Add entry to include path" },
101
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
59 { "define", 'D', "SYM[=VAL]", 0, "Automatically define SYM to be VAL (or 1)"},
219
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
60 { "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
61 { "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
62 { "6800compat", 0x200, 0, 0, "Enable 6800 compatibility instructions, equivalent to --pragma=6800compat" },
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
63 { 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
64 };
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
65
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
66
7
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
67 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
68 {
7
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
69 asmstate_t *as = state;
106
43a3f1068027 Adjustments for list code
lost@l-w.ca
parents: 101
diff changeset
70
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
71 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
72 {
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 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
74 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
75 break;
101
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
76
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
77 case 'D':
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
78 {
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
79 char *offs;
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
80 int val = 1;
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
81 lw_expr_t te;
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
82
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
83 if ((offs = strchr(arg, '=')))
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
84 {
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
85 *offs = '\0';
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
86 val = strtol(offs + 1, NULL, 0);
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
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
89 /* register global symbol */
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
90 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
91 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
92 lw_expr_destroy(te);
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 if (offs)
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
95 *offs = '=';
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
96 break;
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 73
diff changeset
97 }
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
98 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
99 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
100 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
101 as -> output_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
102 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
103
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
104 case 'd':
338
5d401d1eb3e9 Allow disabling debugging messages.
William Astle <lost@l-w.ca>
parents: 333
diff changeset
105 #ifdef LWASM_NODEBUG
5d401d1eb3e9 Allow disabling debugging messages.
William Astle <lost@l-w.ca>
parents: 333
diff changeset
106 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
107 #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
108 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
109 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
110 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
111 as -> debug_level = atoi(arg);
338
5d401d1eb3e9 Allow disabling debugging messages.
William Astle <lost@l-w.ca>
parents: 333
diff changeset
112 #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
113 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
114
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
115 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
116 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
117 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
118 if (!arg)
106
43a3f1068027 Adjustments for list code
lost@l-w.ca
parents: 101
diff changeset
119 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
120 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
121 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
122 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
123 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
124
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
125 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
126 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
127 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
128
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
129 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
130 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
131 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
132
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 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
134 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
135 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
136
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 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
138 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
139 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
140
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
141 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
142 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
143 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
144
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
145 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
146 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
147 break;
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
148
224
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 222
diff changeset
149 case 0x142:
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
150 as -> flags |= FLAG_UNICORNS;
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
151 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
152
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
153 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
154 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
155 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
156 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
157 as -> output_format = OUTPUT_RAW;
276
49010c6653e7 Re-enable rawrel output format
William Astle <lost@l-w.ca>
parents: 249
diff changeset
158 else if (!strcasecmp(arg, "rawrel"))
49010c6653e7 Re-enable rawrel output format
William Astle <lost@l-w.ca>
parents: 249
diff changeset
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166 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
167 as -> output_format = OUTPUT_HEX;
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
168 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
169 {
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
170 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
171 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
172 }
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
173 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
174 {
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
175 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
176 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
177 }
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;
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
179
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
180 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
181 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
182 {
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
183 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
184 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
185 }
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
186 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
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 '9':
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 -> target = TARGET_6809;
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 '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
193 as -> target = TARGET_6309;
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
219
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
196 case 'P':
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
197 as -> preprocess = 1;
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
198 break;
333
507f442dc71e Add support for 6800 compatibility instructions.
William Astle <lost@l-w.ca>
parents: 321
diff changeset
199
507f442dc71e Add support for 6800 compatibility instructions.
William Astle <lost@l-w.ca>
parents: 321
diff changeset
200 case 0x200:
507f442dc71e Add support for 6800 compatibility instructions.
William Astle <lost@l-w.ca>
parents: 321
diff changeset
201 as -> pragmas |= PRAGMA_6800COMPAT;
507f442dc71e Add support for 6800 compatibility instructions.
William Astle <lost@l-w.ca>
parents: 321
diff changeset
202 break;
219
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
203
7
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
204 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
205 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
206
7
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
207 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
208 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
209 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
210
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
211 default:
7
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
212 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
213 }
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 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
215 }
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
216
7
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
217 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
218 {
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
219 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
220 parse_opts,
7
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
221 "INPUTFILE",
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
222 "lwasm, a HD6309 and MC6809 cross-assembler\vPlease report bugs to lost@l-w.ca.",
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
223 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
224 };
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
225
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
226 /*
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
227 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
228 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
229 */
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 extern void do_pass1(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
231 extern void do_pass2(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
232 extern void do_pass3(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
233 extern void do_pass4(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
234 extern void do_pass5(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
235 extern void do_pass6(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
236 extern void do_pass7(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
237 extern void do_output(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
238 extern void do_list(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
239 extern lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv);
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 extern lw_expr_t lwasm_evaluate_var(char *var, void *priv);
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 extern lw_expr_t lwasm_parse_term(char **p, void *priv);
249
1f1a28b797e1 Add trap for divide by zero in expression library
William Astle <lost@l-w.ca>
parents: 229
diff changeset
242 extern 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
243
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 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
245 {
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 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
247 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
248 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
249 } 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
250 { "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
251 { "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
252 { "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
253 { "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
254 { "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
255 { "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
256 { "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
257 { 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
258 };
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
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
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
261 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
262 {
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
263 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
264
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
265 /* 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
266 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
267 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
268
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
269 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
270 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
271 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
272 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
273
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
274 /* 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
275 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
276 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
277 asmstate.nextcontext = 1;
212
b0d53e2f3f53 Make --6309/--6809 work properly
William Astle <lost@l-w.ca>
parents: 186
diff changeset
278 asmstate.target = TARGET_6309;
b0d53e2f3f53 Make --6309/--6809 work properly
William Astle <lost@l-w.ca>
parents: 186
diff changeset
279
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
280 /* parse command line arguments */
7
917b608b8c66 Switched lwasm to lw_cmdline from argp
lost@l-w.ca
parents: 2
diff changeset
281 lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, &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
282
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 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
284 {
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 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
286 }
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
287
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 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
289
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 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
291 {
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
292 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
293 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
294 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
295 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
296 (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
297 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
298 dump_state(&asmstate);
219
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
299
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
300 if (asmstate.preprocess)
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
301 {
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
302 /* we're done if we were preprocessing */
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
303 exit(0);
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
304 }
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
305 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
306 {
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
307 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
308 {
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
309 // 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
310 // 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
311 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
312 }
226
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
313 if (asmstate.flags & FLAG_UNICORNS)
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
314 lwasm_do_unicorns(&asmstate);
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
315 else
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
316 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
317 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
318 }
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 }
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
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 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
322 {
224
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 222
diff changeset
323 // output dependencies (other than "includebin")
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 222
diff changeset
324 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
325
224
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 222
diff changeset
326 while ((n = lw_stack_pop(asmstate.includelist)))
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 222
diff changeset
327 {
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 222
diff changeset
328 fprintf(stdout, "%s\n", n);
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 222
diff changeset
329 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
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 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
333 {
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 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
335 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
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
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 debug_message(&asmstate, 50, "Done assembly");
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
339
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
340 if (asmstate.flags & FLAG_UNICORNS)
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
341 {
224
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 222
diff changeset
342 debug_message(&asmstate, 50, "Invoking unicorns");
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
343 lwasm_do_unicorns(&asmstate);
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents: 219
diff changeset
344 }
229
164487152dd9 Add flag to output stream for end of unicorns
William Astle <lost@l-w.ca>
parents: 226
diff changeset
345 do_list(&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
346 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
347 }