annotate lwasm/main.c @ 257:e27279180a73 2.x

Added support for include path to LWASM
author lost
date Tue, 22 Dec 2009 04:53:20 +0000
parents a58f49a77441
children c79b3c88adbc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
1 /*
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
2 main.c
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
3 Copyright © 2008 William Astle
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
5 This file is part of LWASM.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
6
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
8 terms of the GNU General Public License as published by the Free Software
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
10 version.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
11
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
15 more details.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
16
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
17 You should have received a copy of the GNU General Public License along with
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
19
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
20
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
21 Implements the program startup code
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
22
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23 */
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24
212
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 182
diff changeset
25 #include <config.h>
5
287a6905a63c Moved config.h to src/ and switched version strings to use autotools version
lost
parents: 4
diff changeset
26
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
27 #include <argp.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
28 #include <errno.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
29 #include <stdio.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30 #include <stdlib.h>
182
833d392fec82 Arranged for lwasm and lwlink to remove the output file in case they fail
lost
parents: 151
diff changeset
31 #include <unistd.h>
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
32
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
33 #include "lwasm.h"
257
e27279180a73 Added support for include path to LWASM
lost
parents: 236
diff changeset
34 #include "util.h"
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
35
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
36 // external declarations
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 5
diff changeset
37 extern void lwasm_pass1(asmstate_t *as);
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 5
diff changeset
38 extern void lwasm_pass2(asmstate_t *as);
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 19
diff changeset
39 extern void lwasm_list(asmstate_t *as);
46
b962cee20bf4 Ported output modules forward from old version
lost
parents: 38
diff changeset
40 extern void lwasm_output(asmstate_t *as);
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
41 extern void pseudo_pragma_real(asmstate_t *as, lwasm_line_t *cl, char **optr, int error);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
42
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
43 // command line option handling
142
36ca3fa755e0 Autotools merge of packages done
lost
parents: 102
diff changeset
44 const char *argp_program_version = "LWASM from " PACKAGE_STRING;
5
287a6905a63c Moved config.h to src/ and switched version strings to use autotools version
lost
parents: 4
diff changeset
45 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
46
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
47 static error_t parse_opts(int key, char *arg, struct argp_state *state)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
48 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
49 asmstate_t *as = state -> input;
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
50 char *p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
51
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
52 switch (key)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
53 {
257
e27279180a73 Added support for include path to LWASM
lost
parents: 236
diff changeset
54 case 'I':
e27279180a73 Added support for include path to LWASM
lost
parents: 236
diff changeset
55 as -> includedirs = lwasm_realloc(as -> includedirs, (as -> nincludedirs + 1) * sizeof(char *));
e27279180a73 Added support for include path to LWASM
lost
parents: 236
diff changeset
56 as -> includedirs[as -> nincludedirs++] = arg;
e27279180a73 Added support for include path to LWASM
lost
parents: 236
diff changeset
57 break;
e27279180a73 Added support for include path to LWASM
lost
parents: 236
diff changeset
58
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
59 case 'o':
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
60 // output
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
61 if (as -> outfile)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
62 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
63 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
64 as -> outfile = arg;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
65 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
66
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
67 case 'd':
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
68 // debug
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 35
diff changeset
69 debug_level++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
70 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
71
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
72 case 'l':
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
73 // list
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
74 if (arg)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
75 as -> listfile = arg;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
76 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
77 as -> listfile = "-";
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
78 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
79
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
80 case 'b':
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
81 // decb output
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
82 as -> outformat = OUTPUT_DECB;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
83 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
84
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
85 case 'r':
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
86 // raw binary output
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
87 as -> outformat = OUTPUT_RAW;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
88 break;
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 5
diff changeset
89
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 5
diff changeset
90 case 0x100:
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 5
diff changeset
91 // proprietary object format
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 5
diff changeset
92 as -> outformat = OUTPUT_OBJ;
19
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
93 break;
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
94
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
95 case 'f':
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
96 // output format
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
97 if (!strcasecmp(arg, "decb"))
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
98 as -> outformat = OUTPUT_DECB;
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
99 else if (!strcasecmp(arg, "raw"))
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
100 as -> outformat = OUTPUT_RAW;
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
101 else if (!strcasecmp(arg, "obj"))
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
102 as -> outformat = OUTPUT_OBJ;
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
103 else if (!strcasecmp(arg, "os9"))
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
104 {
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
105 as -> pragmas |= PRAGMA_DOLLARNOTLOCAL;
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
106 as -> outformat = OUTPUT_OS9;
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
107 }
19
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
108 else
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
109 {
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
110 fprintf(stderr, "Invalid output format: %s\n", arg);
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
111 exit(1);
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
112 }
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
113 break;
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
114
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
115 case 'p':
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
116 // pragmas
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
117 p = arg;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
118 pseudo_pragma_real(as, NULL, &p, 2);
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
119 if (!p)
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
120 {
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
121 fprintf(stderr, "Invalid pragma string: %s\n", arg);
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
122 exit(1);
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
123 }
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
124 break;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
125
230
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
126 case '9':
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
127 as -> no6309 = 1;
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
128 break;
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
129
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
130 case '3':
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
131 as -> no6309 = 0;
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
132 break;
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
133
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
134 case ARGP_KEY_END:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
135 // done; sanity check
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
136 if (!as -> outfile)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
137 as -> outfile = "a.out";
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
138 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
139
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
140 case ARGP_KEY_ARG:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
141 // non-option arg
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
142 if (as -> infile)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
143 argp_usage(state);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
144 as -> infile = arg;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
145 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
146
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
147 default:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
148 return ARGP_ERR_UNKNOWN;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
149 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
150 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
151 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
152
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
153 static struct argp_option options[] =
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
154 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
155 { "output", 'o', "FILE", 0,
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
156 "Output to FILE"},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
157 { "debug", 'd', 0, 0,
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
158 "Set debug mode"},
19
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
159 { "format", 'f', "TYPE", 0,
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 230
diff changeset
160 "Select output format: decb, raw, obj, os9"},
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
161 { "list", 'l', "FILE", OPTION_ARG_OPTIONAL,
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
162 "Generate list [to FILE]"},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
163 { "decb", 'b', 0, 0,
19
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
164 "Generate DECB .bin format output, equivalent of --format=decb"},
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
165 { "raw", 'r', 0, 0,
19
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
166 "Generate raw binary format output, equivalent of --format=raw"},
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 46
diff changeset
167 { "obj", 0x100, 0, 0,
19
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
168 "Generate proprietary object file format for later linking, equivalent of --format=obj" },
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
169 { "pragma", 'p', "PRAGMA", 0,
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 142
diff changeset
170 "Set an assembler pragma to any value understood by the \"pragma\" pseudo op"},
230
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
171 { "6809", '9', 0, 0,
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
172 "Set assembler to 6809 only mode" },
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
173 { "6309", '3', 0, 0,
0df2a39a268c Added --6809/--6309 switches and some cleanups in error reporting
lost
parents: 212
diff changeset
174 "Set assembler to 6309 mode (default)" },
257
e27279180a73 Added support for include path to LWASM
lost
parents: 236
diff changeset
175 { "includedir", 'I', "PATH", 0,
e27279180a73 Added support for include path to LWASM
lost
parents: 236
diff changeset
176 "Add entry to include path" },
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
177 { 0 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
178 };
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
179
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
180 static struct argp argp =
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
181 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
182 options,
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
183 parse_opts,
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
184 "<input file>",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
185 "LWASM, a HD6309 and MC6809 cross-assembler"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
186 };
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
187
212
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 182
diff changeset
188 char *program_name;
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 182
diff changeset
189
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
190 // main function; parse command line, set up assembler state, and run the
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
191 // assembler on the first file
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
192 int main(int argc, char **argv)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
193 {
212
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 182
diff changeset
194
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 182
diff changeset
195 program_name = argv[0];
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 182
diff changeset
196
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
197 // assembler state
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
198 asmstate_t asmstate = { 0 };
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
199
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
200 argp_parse(&argp, argc, argv, 0, 0, &asmstate);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
201
19
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
202 if (!asmstate.infile)
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
203 {
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
204 fprintf(stderr, "No input files specified.\n");
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
205 exit(1);
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
206 }
925105ccf22f small reworking of command arguments
lost
parents: 13
diff changeset
207
182
833d392fec82 Arranged for lwasm and lwlink to remove the output file in case they fail
lost
parents: 151
diff changeset
208 // lose the output file if it already exists...
833d392fec82 Arranged for lwasm and lwlink to remove the output file in case they fail
lost
parents: 151
diff changeset
209 unlink(asmstate.outfile);
833d392fec82 Arranged for lwasm and lwlink to remove the output file in case they fail
lost
parents: 151
diff changeset
210
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
211 /* pass 1 - collect the symbols and assign addresses where possible */
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
212 /* pass 1 also resolves included files, etc. */
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
213 /* that means files are read exactly once unless included multiple times */
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 5
diff changeset
214 lwasm_pass1(&asmstate);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
215
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
216 // pass 2: actually generate the code; if any phasing errors appear
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
217 // at this stage, we have a bug
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 5
diff changeset
218 lwasm_pass2(&asmstate);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
219
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
220 // now make a pretty listing
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 19
diff changeset
221 lwasm_list(&asmstate);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
222
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
223 // now write the code out to the output file
46
b962cee20bf4 Ported output modules forward from old version
lost
parents: 38
diff changeset
224 lwasm_output(&asmstate);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
225
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
226 if (asmstate.errorcount > 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
227 exit(1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
228
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
229 exit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
230 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
231