1
1
use clap:: { Parser , ValueEnum } ;
2
2
use log:: LevelFilter ;
3
3
use regex:: Regex ;
4
- use std:: { fs, path:: PathBuf , collections :: HashSet , thread} ;
4
+ use std:: { collections :: HashSet , fs, path:: PathBuf , thread} ;
5
5
6
6
use c2rust_transpile:: { Derive , Diagnostic , ReplaceMode , TranspilerConfig } ;
7
7
8
8
const DEFAULT_DERIVES : & [ Derive ] = & [ Derive :: Clone , Derive :: Copy , Derive :: BitfieldStruct ] ;
9
9
10
+ const DEFAULT_STACK_SIZE : usize = 2 * 1024 * 1024 ;
11
+
10
12
#[ derive( Debug , Parser ) ]
11
13
#[ clap(
12
14
name = "transpile" ,
@@ -168,6 +170,11 @@ struct Args {
168
170
/// whether `--derive Debug` is specified.
169
171
#[ clap( long = "derive" , value_enum, value_name = "TRAIT" ) ]
170
172
extra_derives : Vec < ExtraDerive > ,
173
+
174
+ /// Specify the maximum stack size in bytes for the transpile procedure. May
175
+ /// be necessary for processing extremely large input files
176
+ #[ clap( long, default_value_t = DEFAULT_STACK_SIZE ) ]
177
+ stack_size : usize ,
171
178
}
172
179
173
180
#[ derive( Debug , PartialEq , Eq , ValueEnum , Clone ) ]
@@ -191,19 +198,16 @@ impl ExtraDerive {
191
198
}
192
199
}
193
200
194
- const STACK_SIZE : usize = 40 * 1024 * 1024 ;
195
-
196
201
fn main ( ) {
202
+ let args = Args :: parse ( ) ;
197
203
let child = thread:: Builder :: new ( )
198
- . stack_size ( STACK_SIZE )
199
- . spawn ( run)
204
+ . stack_size ( args . stack_size )
205
+ . spawn ( || run ( args ) )
200
206
. unwrap ( ) ;
201
207
child. join ( ) . unwrap ( ) ;
202
208
}
203
209
204
- fn run ( ) {
205
- let args = Args :: parse ( ) ;
206
-
210
+ fn run ( args : Args ) {
207
211
// Build a TranspilerConfig from the command line
208
212
let mut tcfg = TranspilerConfig {
209
213
dump_untyped_context : args. dump_untyped_clang_ast ,
0 commit comments