Mercurial > hg-old > index.cgi
annotate src/main.c @ 318:be4d471f3de5 lwlink-1.0
Moved old tags and branches for lwlink to global tags/branches dirs
author | lost |
---|---|
date | Wed, 28 Jan 2009 05:54:43 +0000 |
parents | 87c4e65074f0 |
children |
rev | line source |
---|---|
294 | 1 /* |
2 main.c | |
300 | 3 Copyright © 2009 William Astle |
294 | 4 |
5 This file is part of LWLINK. | |
6 | |
7 LWLINK is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 Implements the program startup code | |
22 | |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include "config.h" | |
27 #endif | |
28 | |
29 #include <argp.h> | |
30 #include <errno.h> | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 | |
34 #include "lwlink.h" | |
35 | |
36 // command line option handling | |
37 const char *argp_program_version = PACKAGE_STRING; | |
38 const char *argp_program_bug_address = PACKAGE_BUGREPORT; | |
39 | |
40 static error_t parse_opts(int key, char *arg, struct argp_state *state) | |
41 { | |
42 switch (key) | |
43 { | |
44 case 'o': | |
45 // output | |
46 outfile = arg; | |
47 break; | |
48 | |
299 | 49 case 's': |
50 // script file | |
51 scriptfile = arg; | |
52 break; | |
53 | |
294 | 54 case 'd': |
55 // debug | |
56 debug_level++; | |
57 break; | |
58 | |
59 case 'b': | |
60 // decb output | |
61 outformat = OUTPUT_DECB; | |
62 break; | |
63 | |
64 case 'r': | |
65 // raw binary output | |
66 outformat = OUTPUT_RAW; | |
67 break; | |
68 | |
69 case 'f': | |
70 // output format | |
71 if (!strcasecmp(arg, "decb")) | |
72 outformat = OUTPUT_DECB; | |
73 else if (!strcasecmp(arg, "raw")) | |
74 outformat = OUTPUT_RAW; | |
75 else | |
76 { | |
77 fprintf(stderr, "Invalid output format: %s\n", arg); | |
78 exit(1); | |
79 } | |
80 break; | |
81 case ARGP_KEY_END: | |
82 // done; sanity check | |
83 if (!outfile) | |
84 outfile = "a.out"; | |
85 break; | |
86 | |
87 case ARGP_KEY_ARG: | |
296
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
88 add_input_file(arg); |
294 | 89 break; |
90 | |
91 default: | |
92 return ARGP_ERR_UNKNOWN; | |
93 } | |
94 return 0; | |
95 } | |
96 | |
97 static struct argp_option options[] = | |
98 { | |
99 { "output", 'o', "FILE", 0, | |
100 "Output to FILE"}, | |
101 { "debug", 'd', 0, 0, | |
102 "Set debug mode"}, | |
103 { "format", 'f', "TYPE", 0, | |
104 "Select output format: decb, raw, obj"}, | |
105 { "decb", 'b', 0, 0, | |
106 "Generate DECB .bin format output, equivalent of --format=decb"}, | |
107 { "raw", 'r', 0, 0, | |
108 "Generate raw binary format output, equivalent of --format=raw"}, | |
307
87c4e65074f0
Actually allow script file to be specified and fix segfault on parsing script file
lost
parents:
303
diff
changeset
|
109 { "script", 's', "FILE", 0, |
299 | 110 "Specify the linking script (overrides the build in defaults)"}, |
294 | 111 { 0 } |
112 }; | |
113 | |
114 static struct argp argp = | |
115 { | |
116 options, | |
117 parse_opts, | |
118 "<input file> ...", | |
119 "LWLINK, a HD6309 and MC6809 cross-linker" | |
120 }; | |
121 | |
297 | 122 extern void read_files(void); |
299 | 123 extern void setup_script(void); |
301 | 124 extern void resolve_sections(void); |
303 | 125 extern void resolve_references(void); |
126 extern void do_output(void); | |
297 | 127 |
294 | 128 // main function; parse command line, set up assembler state, and run the |
129 // assembler on the first file | |
130 int main(int argc, char **argv) | |
131 { | |
132 argp_parse(&argp, argc, argv, 0, 0, NULL); | |
296
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
133 if (ninputfiles == 0) |
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
134 { |
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
135 fprintf(stderr, "No input files\n"); |
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
136 exit(1); |
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
137 } |
297 | 138 |
301 | 139 // handle the linker script |
299 | 140 setup_script(); |
141 | |
297 | 142 // read the input files |
143 read_files(); | |
296
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
144 |
301 | 145 // resolve section bases and section order |
146 resolve_sections(); | |
147 | |
303 | 148 // resolve incomplete references |
149 resolve_references(); | |
150 | |
151 // do the actual output | |
152 do_output(); | |
153 | |
294 | 154 exit(0); |
155 } |