@@ -4,6 +4,7 @@ import front.creader;
4
4
import front. parser ;
5
5
import front. token ;
6
6
import front. eval ;
7
+ import front. ast ;
7
8
import middle. trans ;
8
9
import middle. resolve ;
9
10
import middle. capture ;
@@ -19,6 +20,7 @@ import std.option.none;
19
20
import std. _str ;
20
21
import std. _vec ;
21
22
import std. io ;
23
+ import std. Time ;
22
24
23
25
import std. GetOpts ;
24
26
import std. GetOpts . optopt ;
@@ -52,7 +54,7 @@ fn default_environment(session.session sess,
52
54
53
55
fn parse_input ( session . session sess,
54
56
parser . parser p,
55
- str input ) -> @front . ast. crate {
57
+ str input ) -> @ast. crate {
56
58
if ( _str. ends_with ( input, ".rc" ) ) {
57
59
ret parser. parse_crate_from_crate_file ( p) ;
58
60
} else if ( _str. ends_with ( input, ".rs" ) ) {
@@ -62,6 +64,18 @@ fn parse_input(session.session sess,
62
64
fail;
63
65
}
64
66
67
+ fn time[ T ] ( bool do_it, str what, fn ( ) ->T thunk) -> T {
68
+ if ( !do_it) { ret thunk ( ) ; }
69
+
70
+ auto start = Time . get_time ( ) ;
71
+ auto rv = thunk ( ) ;
72
+ auto end = Time . get_time ( ) ;
73
+
74
+ // FIXME: Actually do timeval math.
75
+ log_err #fmt( "time: %s took %u s" , what, ( end. sec - start. sec ) as uint ) ;
76
+ ret rv;
77
+ }
78
+
65
79
fn compile_input ( session . session sess,
66
80
eval . env env,
67
81
str input , str output ,
@@ -70,23 +84,34 @@ fn compile_input(session.session sess,
70
84
bool verify ,
71
85
bool save_temps ,
72
86
trans. output_type ot ,
87
+ bool time_passes ,
73
88
vec[ str] library_search_paths ) {
74
89
auto def = tup ( 0 , 0 ) ;
75
90
auto p = parser. new_parser ( sess, env, def, input, 0 u) ;
76
- auto crate = parse_input ( sess, p, input) ;
91
+ auto crate = time[ @ast. crate ] ( time_passes, "parsing" ,
92
+ bind parse_input ( sess, p, input) ) ;
77
93
if ( ot == trans. output_type_none ) { ret; }
78
94
79
- crate = creader. read_crates ( sess, crate , library_search_paths) ;
80
- crate = resolve. resolve_crate ( sess, crate ) ;
81
- capture. check_for_captures ( sess, crate ) ;
95
+ crate = time[ @ast. crate ] ( time_passes, "external crate reading" ,
96
+ bind creader. read_crates ( sess, crate , library_search_paths) ) ;
97
+ crate = time[ @ast. crate ] ( time_passes, "resolution" ,
98
+ bind resolve. resolve_crate ( sess, crate ) ) ;
99
+ time[ ( ) ] ( time_passes, "capture checking" ,
100
+ bind capture. check_for_captures ( sess, crate ) ) ;
82
101
83
102
auto ty_cx = ty. mk_ctxt ( sess) ;
84
- auto typeck_result = typeck. check_crate ( ty_cx, crate ) ;
103
+ auto typeck_result =
104
+ time[ typeck. typecheck_result ] ( time_passes, "typechecking" ,
105
+ bind typeck. check_crate ( ty_cx, crate ) ) ;
85
106
crate = typeck_result. _0 ;
86
107
auto type_cache = typeck_result. _1 ;
87
- crate = typestate_check. check_crate ( crate ) ;
88
- trans. trans_crate ( sess, crate , ty_cx, type_cache, output, shared,
89
- optimize, verify, save_temps, ot) ;
108
+
109
+ crate = time[ @ast. crate ] ( time_passes, "typestate checking" ,
110
+ bind typestate_check. check_crate ( crate ) ) ;
111
+
112
+ time[ ( ) ] ( time_passes, "translation" ,
113
+ bind trans. trans_crate ( sess, crate , ty_cx, type_cache, output, shared,
114
+ optimize, verify, save_temps, ot) ) ;
90
115
}
91
116
92
117
fn pretty_print_input ( session . session sess,
@@ -114,6 +139,7 @@ options:
114
139
-S compile only; do not assemble or link
115
140
-c compile and assemble, but do not link
116
141
--save-temps write intermediate files in addition to normal output
142
+ --time-passes time the individual phases of the compiler
117
143
-h display this message\n \n " ) ;
118
144
}
119
145
@@ -135,15 +161,16 @@ fn main(vec[str] args) {
135
161
136
162
auto crate_cache = common. new_int_hash [ session. crate_metadata ] ( ) ;
137
163
auto target_crate_num = 0 ;
138
- let vec[ @front . ast. meta_item] md = vec ( ) ;
164
+ let vec[ @ast. meta_item] md = vec ( ) ;
139
165
auto sess = session. session ( target_crate_num, target_cfg, crate_cache,
140
166
md, front. codemap . new_codemap ( ) ) ;
141
167
142
168
auto opts = vec ( optflag ( "h" ) , optflag ( "glue" ) ,
143
169
optflag ( "pretty" ) , optflag ( "ls" ) , optflag ( "parse-only" ) ,
144
170
optflag ( "O" ) , optflag ( "shared" ) , optmulti ( "L" ) ,
145
171
optflag ( "S" ) , optflag ( "c" ) , optopt ( "o" ) ,
146
- optflag ( "save-temps" ) , optflag ( "noverify" ) ) ;
172
+ optflag ( "save-temps" ) , optflag ( "time-passes" ) ,
173
+ optflag ( "noverify" ) ) ;
147
174
auto binary = _vec. shift [ str] ( args) ;
148
175
auto match;
149
176
alt ( GetOpts . getopts ( args, opts) ) {
@@ -173,6 +200,7 @@ fn main(vec[str] args) {
173
200
auto save_temps = opt_present ( match , "save-temps" ) ;
174
201
// FIXME: Maybe we should support -O0, -O1, -Os, etc
175
202
auto optimize = opt_present ( match , "O" ) ;
203
+ auto time_passes = opt_present ( match , "time-passes" ) ;
176
204
auto n_inputs = _vec. len [ str] ( match . free) ;
177
205
178
206
if ( glue) {
@@ -205,12 +233,12 @@ fn main(vec[str] args) {
205
233
auto ofile = _str. concat ( parts) ;
206
234
compile_input ( sess, env, ifile, ofile, shared,
207
235
optimize, verify, save_temps, ot,
208
- library_search_paths) ;
236
+ time_passes , library_search_paths) ;
209
237
}
210
238
case ( some[ str] ( ?ofile) ) {
211
239
compile_input ( sess, env, ifile, ofile, shared,
212
240
optimize, verify, save_temps, ot,
213
- library_search_paths) ;
241
+ time_passes , library_search_paths) ;
214
242
}
215
243
}
216
244
}
0 commit comments