@@ -20,12 +20,6 @@ import std._str;
20
20
import std. _vec ;
21
21
import std. io ;
22
22
23
- import std. GetOpts ;
24
- import std. GetOpts . optopt ;
25
- import std. GetOpts . optmulti ;
26
- import std. GetOpts . optflag ;
27
- import std. GetOpts . opt_present ;
28
-
29
23
fn default_environment ( session . session sess,
30
24
str argv0 ,
31
25
str input ) -> eval . env {
@@ -111,18 +105,18 @@ fn usage(session.session sess, str argv0) {
111
105
options:
112
106
113
107
-o <filename> write output to <filename>
114
- -- nowarn suppress wrong-compiler warning
115
- -- glue generate glue.bc file
116
- -- shared compile a shared-library crate
117
- --pretty pretty-print the input instead of compiling
118
- --ls list the symbols defined by a crate file
108
+ -nowarn suppress wrong-compiler warning
109
+ -glue generate glue.bc file
110
+ -shared compile a shared-library crate
111
+ -pp pretty-print the input instead of compiling
112
+ -ls list the symbols defined by a crate file
119
113
-L <path> add a directory to the library search path
120
- -- noverify suppress LLVM verification step (slight speedup)
121
- -- parse-only parse only; do not compile, assemble, or link
114
+ -noverify suppress LLVM verification step (slight speedup)
115
+ -parse-only parse only; do not compile, assemble, or link
122
116
-O optimize
123
117
-S compile only; do not assemble or link
124
118
-c compile and assemble, but do not link
125
- -- save-temps write intermediate files in addition to normal output
119
+ -save-temps write intermediate files in addition to normal output
126
120
-h display this message\n \n " ) ;
127
121
}
128
122
@@ -148,81 +142,133 @@ fn main(vec[str] args) {
148
142
auto sess = session. session ( target_crate_num, target_cfg, crate_cache,
149
143
md, front. codemap . new_codemap ( ) ) ;
150
144
151
- auto opts = vec ( optflag ( "nowarn" ) , optflag ( "h" ) , optflag ( "glue" ) ,
152
- optflag ( "pretty" ) , optflag ( "ls" ) , optflag ( "parse-only" ) ,
153
- optflag ( "O" ) , optflag ( "shared" ) , optmulti ( "L" ) ,
154
- optflag ( "S" ) , optflag ( "c" ) , optopt ( "o" ) ,
155
- optflag ( "save-temps" ) , optflag ( "noverify" ) ) ;
156
- auto binary = _vec. shift [ str] ( args) ;
157
- auto match;
158
- alt ( GetOpts . getopts ( args, opts) ) {
159
- case ( GetOpts . failure ( ?f) ) { sess. err ( GetOpts . fail_str ( f) ) ; fail; }
160
- case ( GetOpts . success ( ?m) ) { match = m; }
161
- }
162
- if ( !opt_present ( match , "nowarn" ) ) {
163
- warn_wrong_compiler ( ) ;
164
- }
165
- if ( opt_present ( match , "h" ) ) {
166
- usage ( sess, binary) ;
167
- ret;
168
- }
169
-
170
- auto pretty = opt_present ( match , "pretty" ) ;
171
- auto ls = opt_present ( match , "ls" ) ;
172
- auto glue = opt_present ( match , "glue" ) ;
173
- auto shared = opt_present ( match , "shared" ) ;
174
- auto output_file = GetOpts . opt_maybe_str ( match , "o" ) ;
175
- auto library_search_paths = GetOpts . opt_strs ( match , "L" ) ;
145
+ let option. t[ str] input_file = none[ str] ;
146
+ let option. t[ str] output_file = none[ str] ;
147
+ let vec[ str] library_search_paths = vec ( ) ;
148
+ let bool do_warn = true ;
149
+ let bool shared = false ;
150
+ let bool pretty = false ;
151
+ let bool ls = false ;
176
152
auto ot = trans. output_type_bitcode ;
177
- if ( opt_present ( match , "parse-only" ) ) {
178
- ot = trans. output_type_none ;
179
- } else if ( opt_present ( match , "S" ) ) {
180
- ot = trans. output_type_assembly ;
181
- } else if ( opt_present ( match , "c" ) ) {
182
- ot = trans. output_type_object ;
183
- }
184
- auto verify = !opt_present ( match , "noverify" ) ;
185
- auto save_temps = opt_present ( match , "save-temps" ) ;
153
+ let bool glue = false ;
154
+ let bool verify = true ;
155
+ let bool save_temps = false ;
156
+
186
157
// FIXME: Maybe we should support -O0, -O1, -Os, etc
187
- auto optimize = opt_present ( match , "O" ) ;
188
- auto n_inputs = _vec. len [ str] ( match . free) ;
158
+ let bool optimize = false ;
189
159
190
- if ( glue) {
191
- if ( n_inputs > 0 u) {
192
- sess. err ( "No input files allowed with --glue." ) ;
160
+ auto i = 1 u;
161
+ auto len = _vec. len [ str] ( args) ;
162
+
163
+ // FIXME: a getopt module would be nice.
164
+ while ( i < len) {
165
+ auto arg = args. ( i) ;
166
+ if ( _str. byte_len ( arg) > 0 u && arg. ( 0 ) == '-' as u8 ) {
167
+ if ( _str. eq ( arg, "-nowarn" ) ) {
168
+ do_warn = false ;
169
+ } else if ( _str. eq ( arg, "-O" ) ) {
170
+ optimize = true ;
171
+ } else if ( _str. eq ( arg, "-glue" ) ) {
172
+ glue = true ;
173
+ } else if ( _str. eq ( arg, "-shared" ) ) {
174
+ shared = true ;
175
+ } else if ( _str. eq ( arg, "-pp" ) ) {
176
+ pretty = true ;
177
+ } else if ( _str. eq ( arg, "-ls" ) ) {
178
+ ls = true ;
179
+ } else if ( _str. eq ( arg, "-parse-only" ) ) {
180
+ ot = trans. output_type_none ;
181
+ } else if ( _str. eq ( arg, "-S" ) ) {
182
+ ot = trans. output_type_assembly ;
183
+ } else if ( _str. eq ( arg, "-c" ) ) {
184
+ ot = trans. output_type_object ;
185
+ } else if ( _str. eq ( arg, "-o" ) ) {
186
+ if ( i+1 u < len) {
187
+ output_file = some ( args. ( i +1 u) ) ;
188
+ i += 1 u;
189
+ } else {
190
+ usage ( sess, args. ( 0 ) ) ;
191
+ sess. err ( "-o requires an argument" ) ;
192
+ }
193
+ } else if ( _str. eq ( arg, "-save-temps" ) ) {
194
+ save_temps = true ;
195
+ } else if ( _str. eq ( arg, "-L" ) ) {
196
+ if ( i+1 u < len) {
197
+ library_search_paths += vec ( args. ( i +1 u) ) ;
198
+ i += 1 u;
199
+ } else {
200
+ usage ( sess, args. ( 0 ) ) ;
201
+ sess. err ( "-L requires an argument" ) ;
202
+ }
203
+ } else if ( _str. eq ( arg, "-noverify" ) ) {
204
+ verify = false ;
205
+ } else if ( _str. eq ( arg, "-h" ) ) {
206
+ usage ( sess, args. ( 0 ) ) ;
207
+ } else {
208
+ usage ( sess, args. ( 0 ) ) ;
209
+ sess. err ( "unrecognized option: " + arg) ;
210
+ }
211
+ } else {
212
+ alt ( input_file) {
213
+ case ( some[ str] ( _) ) {
214
+ usage ( sess, args. ( 0 ) ) ;
215
+ sess. err ( "multiple inputs provided" ) ;
216
+ }
217
+ case ( none[ str] ) {
218
+ input_file = some[ str] ( arg) ;
219
+ }
220
+ }
193
221
}
194
- auto out = option. from_maybe [ str] ( "glue.bc" , output_file) ;
195
- middle. trans . make_common_glue ( out, optimize, verify, save_temps, ot) ;
196
- ret;
222
+ i += 1 u;
197
223
}
198
224
199
- if ( n_inputs == 0 u) {
200
- sess. err ( "No input filename given." ) ;
201
- } else if ( n_inputs > 1 u) {
202
- sess. err ( "Multiple input filenames provided." ) ;
225
+ if ( do_warn) {
226
+ warn_wrong_compiler ( ) ;
203
227
}
204
228
205
- auto ifile = match . free . ( 0 ) ;
206
- auto env = default_environment ( sess, args. ( 0 ) , ifile) ;
207
- if ( pretty) {
208
- pretty_print_input ( sess, env, ifile) ;
209
- } else if ( ls) {
210
- front. creader . list_file_metadata ( ifile, std. io . stdout ( ) ) ;
211
- } else {
229
+ if ( glue) {
212
230
alt ( output_file) {
213
231
case ( none[ str] ) {
214
- let vec[ str] parts = _str. split ( ifile, '.' as u8 ) ;
215
- _vec. pop [ str] ( parts) ;
216
- parts += vec ( ".bc" ) ;
217
- auto ofile = _str. concat ( parts) ;
218
- compile_input ( sess, env, ifile, ofile, shared,
219
- optimize, verify, save_temps, ot,
220
- library_search_paths) ;
232
+ middle. trans . make_common_glue ( "glue.bc" , optimize, verify,
233
+ save_temps, ot) ;
234
+ }
235
+ case ( some[ str] ( ?s) ) {
236
+ middle. trans . make_common_glue ( s, optimize, verify, save_temps,
237
+ ot) ;
221
238
}
222
- case ( some[ str] ( ?ofile) ) {
223
- compile_input ( sess, env, ifile, ofile, shared,
224
- optimize, verify, save_temps, ot,
225
- library_search_paths) ;
239
+ }
240
+ ret;
241
+ }
242
+
243
+ alt ( input_file) {
244
+ case ( none[ str] ) {
245
+ usage ( sess, args. ( 0 ) ) ;
246
+ sess. err ( "no input filename" ) ;
247
+ }
248
+ case ( some[ str] ( ?ifile) ) {
249
+
250
+ auto env = default_environment ( sess, args. ( 0 ) , ifile) ;
251
+ if ( pretty) {
252
+ pretty_print_input ( sess, env, ifile) ;
253
+ } else if ( ls) {
254
+ front. creader . list_file_metadata ( ifile, std. io . stdout ( ) ) ;
255
+ } else {
256
+ alt ( output_file) {
257
+ case ( none[ str] ) {
258
+ let vec[ str] parts = _str. split ( ifile, '.' as u8 ) ;
259
+ _vec. pop [ str] ( parts) ;
260
+ parts += vec ( ".bc" ) ;
261
+ auto ofile = _str. concat ( parts) ;
262
+ compile_input ( sess, env, ifile, ofile, shared,
263
+ optimize, verify, save_temps, ot,
264
+ library_search_paths) ;
265
+ }
266
+ case ( some[ str] ( ?ofile) ) {
267
+ compile_input ( sess, env, ifile, ofile, shared,
268
+ optimize, verify, save_temps, ot,
269
+ library_search_paths) ;
270
+ }
271
+ }
226
272
}
227
273
}
228
274
}
0 commit comments