annotate lwcc/lwcc.c @ 245:0bc1c88fe776

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