@@ -10,6 +10,7 @@ import middle::resolve;
10
10
import middle:: ty;
11
11
import middle:: typeck;
12
12
import middle:: tstate:: ck;
13
+ import pretty:: pprust;
13
14
import back:: link;
14
15
import lib:: llvm;
15
16
import util:: common;
@@ -117,14 +118,26 @@ fn compile_input(session::session sess,
117
118
bind link:: write:: run_passes ( sess, llmod, output) ) ;
118
119
}
119
120
120
- fn pretty_print_input ( session:: session sess,
121
- eval:: env env,
122
- str input ) {
121
+ fn pretty_print_input ( session:: session sess, eval:: env env, str input ,
122
+ bool typed ) {
123
123
auto def = tup ( ast:: local_crate, 0 ) ;
124
124
auto p = front:: parser:: new_parser ( sess, env, def, input, 0 u, 0 u) ;
125
125
auto crate = front:: parser:: parse_crate_from_source_file ( p) ;
126
- pretty:: pprust:: print_file ( sess, crate . node. module , input,
127
- std:: io:: stdout ( ) ) ;
126
+
127
+ auto mode;
128
+ if ( typed) {
129
+ crate = creader:: read_crates ( sess, crate ) ;
130
+ auto def_map = resolve:: resolve_crate ( sess, crate ) ;
131
+ auto ty_cx = ty:: mk_ctxt ( sess, def_map) ;
132
+ auto typeck_result = typeck:: check_crate ( ty_cx, crate ) ;
133
+ crate = typeck_result. _2 ;
134
+ mode = pprust:: mo_typed ( ty_cx, typeck_result. _0 , typeck_result. _1 ) ;
135
+ } else {
136
+ mode = pprust:: mo_untyped;
137
+ }
138
+
139
+ pprust:: print_file ( sess, crate . node. module , input, std:: io:: stdout ( ) ,
140
+ mode) ;
128
141
}
129
142
130
143
fn version ( str argv0 ) {
@@ -147,6 +160,7 @@ options:
147
160
--glue generate glue.bc file
148
161
--shared compile a shared-library crate
149
162
--pretty pretty-print the input instead of compiling
163
+ --typed-pretty pretty-print the input with types instead of compiling
150
164
--ls list the symbols defined by a crate file
151
165
-L <path> add a directory to the library search path
152
166
--noverify suppress LLVM verification step (slight speedup)
@@ -214,7 +228,8 @@ fn main(vec[str] args) {
214
228
auto opts = [ optflag ( "h" ) , optflag ( "help" ) ,
215
229
optflag ( "v" ) , optflag ( "version" ) ,
216
230
optflag ( "glue" ) , optflag ( "emit-llvm" ) ,
217
- optflag ( "pretty" ) , optflag ( "ls" ) , optflag ( "parse-only" ) ,
231
+ optflag ( "pretty" ) , optflag ( "typed-pretty" ) ,
232
+ optflag ( "ls" ) , optflag ( "parse-only" ) ,
218
233
optflag ( "O" ) , optflag ( "shared" ) , optmulti ( "L" ) ,
219
234
optflag ( "S" ) , optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) ,
220
235
optflag ( "save-temps" ) , optopt ( "sysroot" ) ,
@@ -243,6 +258,7 @@ fn main(vec[str] args) {
243
258
}
244
259
245
260
auto pretty = opt_present( match, "pretty" ) ;
261
+ auto typed_pretty = opt_present( match, "typed-pretty" ) ;
246
262
auto ls = opt_present( match, "ls" ) ;
247
263
auto glue = opt_present( match, "glue" ) ;
248
264
auto shared = opt_present( match, "shared" ) ;
@@ -318,8 +334,8 @@ fn main(vec[str] args) {
318
334
auto ifile = match . free. ( 0 ) ;
319
335
let str saved_out_filename = "" ;
320
336
auto env = default_environment( sess, args. ( 0 ) , ifile) ;
321
- if ( pretty) {
322
- pretty_print_input ( sess, env, ifile) ;
337
+ if ( pretty || typed_pretty ) {
338
+ pretty_print_input ( sess, env, ifile, typed_pretty ) ;
323
339
} else if ( ls) {
324
340
front:: creader:: list_file_metadata ( ifile, std:: io:: stdout ( ) ) ;
325
341
} else {
0 commit comments