188
|
1 /*
|
|
2
|
|
3 This is the front-end program for the C compiler.
|
|
4
|
193
|
5 Copyright © 2012 William Astle
|
188
|
6
|
|
7 This file is part of LWTOOLS.
|
|
8
|
|
9 LWTOOLS is free software: you can redistribute it and/or modify it under the
|
|
10 terms of the GNU General Public License as published by the Free Software
|
|
11 Foundation, either version 3 of the License, or (at your option) any later
|
|
12 version.
|
|
13
|
|
14 This program is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
17 more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License along with
|
|
20 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
21
|
|
22 */
|
|
23
|
|
24 #include <stdio.h>
|
|
25 #include <stdlib.h>
|
|
26 #include <string.h>
|
|
27
|
|
28 #include <lw_alloc.h>
|
|
29 #include <lw_string.h>
|
|
30 #include <lw_cmdline.h>
|
|
31
|
|
32 /* command line option handling */
|
|
33 #define PROGVER "lwcc from " PACKAGE_STRING
|
|
34 char *program_name;
|
|
35
|
|
36 /* global state */
|
|
37 char *output_file = NULL;
|
|
38 int debug_level = 0;
|
|
39
|
|
40
|
|
41 static struct lw_cmdline_options options[] =
|
|
42 {
|
|
43 { "output", 'o', "FILE", 0, "Output to FILE"},
|
|
44 { "debug", 'd', "LEVEL", lw_cmdline_opt_optional, "Set debug mode"},
|
|
45 { 0 }
|
|
46 };
|
|
47
|
|
48
|
|
49 static int parse_opts(int key, char *arg, void *state)
|
|
50 {
|
|
51 switch (key)
|
|
52 {
|
|
53 case 'o':
|
|
54 if (output_file)
|
|
55 lw_free(output_file);
|
|
56 output_file = lw_strdup(arg);
|
|
57 break;
|
|
58
|
|
59 case 'd':
|
|
60 if (!arg)
|
|
61 debug_level = 50;
|
|
62 else
|
|
63 debug_level = atoi(arg);
|
|
64 break;
|
|
65
|
|
66 case lw_cmdline_key_end:
|
|
67 break;
|
|
68
|
|
69 case lw_cmdline_key_arg:
|
|
70 printf("Input file: %s\n", arg);
|
|
71 break;
|
|
72
|
|
73 default:
|
|
74 return lw_cmdline_err_unknown;
|
|
75 }
|
|
76 return 0;
|
|
77 }
|
|
78
|
|
79 static struct lw_cmdline_parser cmdline_parser =
|
|
80 {
|
|
81 options,
|
|
82 parse_opts,
|
|
83 "INPUTFILE",
|
|
84 "lwcc, a HD6309 and MC6809 cross-compiler\vPlease report bugs to lost@l-w.ca.",
|
|
85 PROGVER
|
|
86 };
|
|
87
|
|
88 int main(int argc, char **argv)
|
|
89 {
|
|
90 program_name = argv[0];
|
|
91
|
|
92 /* parse command line arguments */
|
|
93 lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, NULL);
|
|
94
|
|
95 if (!output_file)
|
|
96 {
|
|
97 output_file = lw_strdup("a.out");
|
|
98 }
|
|
99
|
|
100 exit(0);
|
|
101 }
|