@@ -29,17 +29,10 @@ import std::getopts;
29
29
import std:: getopts:: optopt;
30
30
import std:: getopts:: optmulti;
31
31
import std:: getopts:: optflag;
32
- import std:: getopts:: optflagopt;
33
32
import std:: getopts:: opt_present;
34
33
35
34
import back:: link:: output_type;
36
35
37
- tag pp_mode {
38
- ppm_normal;
39
- ppm_typed;
40
- ppm_identified;
41
- }
42
-
43
36
fn default_environment ( session:: session sess,
44
37
str argv0 ,
45
38
str input ) -> eval:: env {
@@ -119,21 +112,19 @@ fn compile_input(session::session sess,
119
112
}
120
113
121
114
fn pretty_print_input ( session:: session sess, eval:: env env, str input ,
122
- pp_mode ppm ) {
115
+ bool typed ) {
123
116
auto def = tup ( ast:: local_crate, 0 ) ;
124
117
auto p = front:: parser:: new_parser ( sess, env, def, input, 0 u, 0 u) ;
125
118
auto crate = front:: parser:: parse_crate_from_source_file ( p) ;
126
119
127
120
auto mode;
128
- alt ( ppm) {
129
- case ( ppm_typed) {
130
- auto def_map = resolve:: resolve_crate ( sess, crate ) ;
131
- auto ty_cx = ty:: mk_ctxt ( sess, def_map) ;
132
- typeck:: check_crate ( ty_cx, crate ) ;
133
- mode = pprust:: mo_typed ( ty_cx) ;
134
- }
135
- case ( ppm_normal) { mode = pprust:: mo_untyped; }
136
- case ( ppm_identified) { mode = pprust:: mo_identified; }
121
+ if ( typed) {
122
+ auto def_map = resolve:: resolve_crate ( sess, crate ) ;
123
+ auto ty_cx = ty:: mk_ctxt ( sess, def_map) ;
124
+ typeck:: check_crate ( ty_cx, crate ) ;
125
+ mode = pprust:: mo_typed ( ty_cx) ;
126
+ } else {
127
+ mode = pprust:: mo_untyped;
137
128
}
138
129
139
130
pprust:: print_file ( sess, crate . node. module , input, std:: io:: stdout ( ) ,
@@ -159,7 +150,8 @@ options:
159
150
-o <filename> write output to <filename>
160
151
--glue generate glue.bc file
161
152
--shared compile a shared-library crate
162
- --pretty [type] pretty-print the input instead of compiling
153
+ --pretty pretty-print the input instead of compiling
154
+ --typed-pretty pretty-print the input with types instead of compiling
163
155
--ls list the symbols defined by a crate file
164
156
-L <path> add a directory to the library search path
165
157
--noverify suppress LLVM verification step (slight speedup)
@@ -312,21 +304,12 @@ fn build_session(@session::options sopts) -> session::session {
312
304
ret sess;
313
305
}
314
306
315
- fn parse_pretty( session:: session sess, & str name) -> pp_mode {
316
- if ( str:: eq ( name, "normal" ) ) { ret ppm_normal; }
317
- else if ( str:: eq ( name, "typed" ) ) { ret ppm_typed; }
318
- else if ( str:: eq ( name, "identified" ) ) { ret ppm_identified; }
319
-
320
- sess. err ( "argument to `pretty` must be one of `normal`, `typed`, or " +
321
- "`identified`" ) ;
322
- }
323
-
324
307
fn main( vec[ str] args) {
325
308
326
309
auto opts = [ optflag ( "h" ) , optflag ( "help" ) ,
327
310
optflag ( "v" ) , optflag ( "version" ) ,
328
311
optflag ( "glue" ) , optflag ( "emit-llvm" ) ,
329
- optflagopt ( " pretty") ,
312
+ optflag ( "pretty" ) , optflag ( "typed- pretty") ,
330
313
optflag ( "ls" ) , optflag ( "parse-only" ) ,
331
314
optflag ( "O" ) , optopt ( "OptLevel" ) ,
332
315
optflag ( "shared" ) , optmulti ( "L" ) ,
@@ -382,50 +365,42 @@ fn main(vec[str] args) {
382
365
auto ifile = match . free . ( 0 ) ;
383
366
let str saved_out_filename = "" ;
384
367
auto env = default_environment ( sess, binary, ifile) ;
385
- auto pretty = option :: map [ str , pp_mode ] ( bind parse_pretty ( sess , _ ) ,
386
- getopts :: opt_default ( match , "pretty" , "normal" ) ) ;
368
+ auto pretty = opt_present ( match , "pretty" ) ;
369
+ auto typed_pretty = opt_present ( match , "typed- pretty" ) ;
387
370
auto ls = opt_present ( match , "ls" ) ;
388
-
389
- alt ( pretty) {
390
- case ( some[ pp_mode] ( ?ppm) ) {
391
- pretty_print_input ( sess, env, ifile, ppm) ;
392
- ret;
393
- }
394
- case ( none[ pp_mode] ) { /* continue */ }
395
- }
396
-
397
- if ( ls) {
371
+ if ( pretty || typed_pretty) {
372
+ pretty_print_input ( sess, env, ifile, typed_pretty) ;
373
+ ret;
374
+ } else if ( ls) {
398
375
front:: creader:: list_file_metadata ( ifile, std:: io:: stdout ( ) ) ;
399
376
ret;
400
- }
401
-
402
- alt ( output_file) {
403
- case ( none) {
404
- let vec[ str] parts = str:: split ( ifile, '.' as u8 ) ;
405
- vec:: pop[ str] ( parts) ;
406
- saved_out_filename = parts. ( 0 ) ;
407
- alt ( sopts. output_type ) {
408
- case ( link:: output_type_none) { parts += [ "pp" ] ; }
409
- case ( link:: output_type_bitcode) { parts += [ "bc" ] ; }
410
- case ( link:: output_type_assembly) { parts += [ "s" ] ; }
411
-
412
- // Object and exe output both use the '.o' extension here
413
- case ( link:: output_type_object) { parts += [ "o" ] ; }
414
- case ( link:: output_type_exe) { parts += [ "o" ] ; }
377
+ } else {
378
+ alt ( output_file) {
379
+ case ( none) {
380
+ let vec[ str] parts = str:: split ( ifile, '.' as u8 ) ;
381
+ vec:: pop[ str] ( parts) ;
382
+ saved_out_filename = parts. ( 0 ) ;
383
+ alt ( sopts. output_type ) {
384
+ case ( link:: output_type_none) { parts += [ "pp" ] ; }
385
+ case ( link:: output_type_bitcode) { parts += [ "bc" ] ; }
386
+ case ( link:: output_type_assembly) { parts += [ "s" ] ; }
387
+
388
+ // Object and exe output both use the '.o' extension here
389
+ case ( link:: output_type_object) { parts += [ "o" ] ; }
390
+ case ( link:: output_type_exe) { parts += [ "o" ] ; }
391
+ }
392
+ auto ofile = str:: connect ( parts, "." ) ;
393
+ compile_input ( sess, env, ifile, ofile) ;
394
+ }
395
+ case ( some ( ?ofile) ) {
396
+ saved_out_filename = ofile;
397
+ compile_input ( sess, env, ifile, ofile) ;
415
398
}
416
- auto ofile = str:: connect ( parts, "." ) ;
417
- compile_input ( sess, env, ifile, ofile) ;
418
- }
419
- case ( some ( ?ofile) ) {
420
- saved_out_filename = ofile;
421
- compile_input ( sess, env, ifile, ofile) ;
422
399
}
423
400
}
424
401
425
402
// If the user wants an exe generated we need to invoke
426
403
// gcc to link the object file with some libs
427
- //
428
- // TODO: Factor this out of main.
429
404
if ( sopts. output_type == link:: output_type_exe) {
430
405
431
406
//FIXME: Should we make the 'stage3's variable here?
0 commit comments