comparison src/main.c @ 13:05d4115b4860

Started work on new expression evaluator system and major code re-work for next release
author lost
date Wed, 22 Oct 2008 04:51:16 +0000
parents 287a6905a63c
children 925105ccf22f
comparison
equal deleted inserted replaced
5:287a6905a63c 13:05d4115b4860
20 20
21 Implements the program startup code 21 Implements the program startup code
22 22
23 */ 23 */
24 24
25 #ifdef HAVE_CONFIG_H
25 #include "config.h" 26 #include "config.h"
27 #endif
26 28
27 #include <argp.h> 29 #include <argp.h>
28 #include <errno.h> 30 #include <errno.h>
29 #include <stdio.h> 31 #include <stdio.h>
30 #include <stdlib.h> 32 #include <stdlib.h>
31 33
32 #include "lwasm.h" 34 #include "lwasm.h"
33 35
34 // external declarations 36 // external declarations
35 extern void resolve_phasing(asmstate_t *as); 37 extern void lwasm_pass1(asmstate_t *as);
36 extern void generate_code(asmstate_t *as); 38 extern void lwasm_pass2(asmstate_t *as);
37 extern void list_code(asmstate_t *as);
38 extern void write_code(asmstate_t *as);
39 39
40 40
41 // command line option handling 41 // command line option handling
42 const char *argp_program_version = PACKAGE_STRING; 42 const char *argp_program_version = PACKAGE_STRING;
43 const char *argp_program_bug_address = PACKAGE_BUGREPORT; 43 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
76 76
77 case 'r': 77 case 'r':
78 // raw binary output 78 // raw binary output
79 as -> outformat = OUTPUT_RAW; 79 as -> outformat = OUTPUT_RAW;
80 break; 80 break;
81 81
82 case 0x100:
83 // proprietary object format
84 as -> outformat = OUTPUT_OBJ;
85
82 case ARGP_KEY_END: 86 case ARGP_KEY_END:
83 // done; sanity check 87 // done; sanity check
84 if (!as -> outfile) 88 if (!as -> outfile)
85 as -> outfile = "a.out"; 89 as -> outfile = "a.out";
86 break; 90 break;
110 "Generate DECB .bin format output"}, 114 "Generate DECB .bin format output"},
111 { "raw", 'r', 0, 0, 115 { "raw", 'r', 0, 0,
112 "Generate raw binary format output"}, 116 "Generate raw binary format output"},
113 { "rawrel", 0, 0, 0, 117 { "rawrel", 0, 0, 0,
114 "Generate raw binary respecing ORG statements as offsets from the start of the file"}, 118 "Generate raw binary respecing ORG statements as offsets from the start of the file"},
119 { "obj", 0, 0, 0,
120 "Generate proprietary object file format for later linking" },
115 { 0 } 121 { 0 }
116 }; 122 };
117 123
118 static struct argp argp = 124 static struct argp argp =
119 { 125 {
131 asmstate_t asmstate = { 0 }; 137 asmstate_t asmstate = { 0 };
132 138
133 argp_parse(&argp, argc, argv, 0, 0, &asmstate); 139 argp_parse(&argp, argc, argv, 0, 0, &asmstate);
134 if (!asmstate.listfile) 140 if (!asmstate.listfile)
135 asmstate.listfile = "-"; 141 asmstate.listfile = "-";
136
137 // printf("Assembling %s to %s; list to %s\n", asmstate.infile, asmstate.outfile, asmstate.listfile);
138 142
139 /* pass 1 - collect the symbols and assign addresses where possible */ 143 /* pass 1 - collect the symbols and assign addresses where possible */
140 /* pass 1 also resolves included files, etc. */ 144 /* pass 1 also resolves included files, etc. */
141 /* that means files are read exactly once unless included multiple times */ 145 /* that means files are read exactly once unless included multiple times */
142 lwasm_read_file(&asmstate, (char *)(asmstate.infile)); 146 lwasm_pass1(&asmstate);
143 147
144 // pass 2: actually generate the code; if any phasing errors appear 148 // pass 2: actually generate the code; if any phasing errors appear
145 // at this stage, we have a bug 149 // at this stage, we have a bug
146 generate_code(&asmstate); 150 lwasm_pass2(&asmstate);
147 151
148 // now make a pretty listing 152 // now make a pretty listing
149 list_code(&asmstate); 153 // lwasm_list(&asmstate);
150 154
151 // now write the code out to the output file 155 // now write the code out to the output file
152 write_code(&asmstate); 156 // lwasm_output(&asmstate);
153 157
154 if (asmstate.errorcount > 0) 158 if (asmstate.errorcount > 0)
155 exit(1); 159 exit(1);
156 160
157 exit(0); 161 exit(0);