comparison lwasm/main.c @ 323:473ed9b353eb

Started framework for lwasm binary
author lost
date Tue, 09 Feb 2010 05:33:35 +0000
parents
children 619fd6ad4ab9
comparison
equal deleted inserted replaced
322:3ff493a445ed 323:473ed9b353eb
1 /*
2 main.c
3
4 Copyright © 2010 William Astle
5
6 This file is part of LWTOOLS.
7
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation, either version 3 of the License, or (at your option) any later
11 version.
12
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 more details.
17
18 You should have received a copy of the GNU General Public License along with
19 this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <config.h>
23
24 #include <argp.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #include "lwasm.h"
29
30 /* command line option handling */
31 const char *argp_program_version = "lwasm from " PACKAGE_STRING;
32 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
33 char *program_name;
34
35 static struct argp_option options[] =
36 {
37 { "output", 'o', "FILE", 0, "Output to FILE"},
38 { "debug", 'd', 0, 0, "Set debug mode"},
39 { "format", 'f', "TYPE", 0, "Select output format: decb, raw, obj, os9"},
40 { "list", 'l', "FILE", OPTION_ARG_OPTIONAL, "Generate list [to FILE]"},
41 { "decb", 'b', 0, 0, "Generate DECB .bin format output, equivalent of --format=decb"},
42 { "raw", 'r', 0, 0, "Generate raw binary format output, equivalent of --format=raw"},
43 { "obj", 0x100, 0, 0, "Generate proprietary object file format for later linking, equivalent of --format=obj" },
44 { "depend", 0x101, 0, 0, "Output a dependency list to stdout; do not do any actual output though assembly is completed as usual" },
45 { "pragma", 'p', "PRAGMA", 0, "Set an assembler pragma to any value understood by the \"pragma\" pseudo op"},
46 { "6809", '9', 0, 0, "Set assembler to 6809 only mode" },
47 { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" },
48 { "includedir", 'I', "PATH", 0, "Add entry to include path" },
49 { 0 }
50 };
51
52
53 static error_t parse_opts(int key, char *arg, struct argp_state *state)
54 {
55 asmstate_t *as = state -> input;
56
57 switch (key)
58 {
59 case 'I':
60 case 'o':
61 case 'd':
62 as -> debug_level++;
63 break;
64
65 case 'l':
66
67 case 'b':
68 as -> output_format = OUTPUT_DECB;
69 break;
70
71 case 'r':
72 as -> output_format = OUTPUT_RAW;
73 break;
74
75 case 0x100:
76 as -> output_format = OUTPUT_OBJ;
77 break;
78
79 case 0x101:
80 case 'f':
81 if (!strcasecmp(arg, "decb"))
82 as -> output_format = OUTPUT_DECB;
83 else if (!strcasecmp(arg, "raw"))
84 as -> output_format = OUTPUT_RAW;
85 else if (!strcasecmp(arg, "obj"))
86 as -> output_format = OUTPUT_OBJ;
87 else if (!strcasecmp(arg, "os9"))
88 {
89 //as -> pragmas |= PRAGMA_DOLLARNOTLOCAL;
90 as -> output_format = OUTPUT_OS9;
91 }
92 else
93 {
94 fprintf(stderr, "Invalid output format: %s\n", arg);
95 exit(1);
96 }
97 break;
98
99 case 'p':
100 case '9':
101 as -> target = TARGET_6809;
102 break;
103
104 case '3':
105 as -> target = TARGET_6309;
106 break;
107
108 case ARGP_KEY_END:
109 break;
110
111 case ARGP_KEY_ARG:
112 break;
113
114 default:
115 return ARGP_ERR_UNKNOWN;
116 }
117 return 0;
118 }
119
120 static struct argp argp =
121 {
122 options,
123 parse_opts,
124 "<input file>",
125 "LWASM, a HD6309 and MC6809 cross-assembler"
126 };
127
128 /*
129 main function; parse command line, set up assembler state, and run the
130 assembler on the first file
131 */
132 int main(int argc, char **argv)
133 {
134 /* assembler state */
135 asmstate_t asmstate = { 0 };
136
137 program_name = argv[0];
138
139 argp_parse(&argp, argc, argv, 0, 0, &asmstate);
140
141 exit(0);
142 }