Skip to content

Commit 30ebe2c

Browse files
committed
Stack size flag
1 parent 5aa7780 commit 30ebe2c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

c2rust/src/bin/c2rust-transpile.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use clap::{Parser, ValueEnum};
22
use log::LevelFilter;
33
use regex::Regex;
4-
use std::{fs, path::PathBuf, collections::HashSet, thread};
4+
use std::{collections::HashSet, fs, path::PathBuf, thread};
55

66
use c2rust_transpile::{Derive, Diagnostic, ReplaceMode, TranspilerConfig};
77

88
const DEFAULT_DERIVES: &[Derive] = &[Derive::Clone, Derive::Copy, Derive::BitfieldStruct];
99

10+
const DEFAULT_STACK_SIZE: usize = 2 * 1024 * 1024;
11+
1012
#[derive(Debug, Parser)]
1113
#[clap(
1214
name = "transpile",
@@ -168,6 +170,11 @@ struct Args {
168170
/// whether `--derive Debug` is specified.
169171
#[clap(long = "derive", value_enum, value_name = "TRAIT")]
170172
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,
171178
}
172179

173180
#[derive(Debug, PartialEq, Eq, ValueEnum, Clone)]
@@ -191,19 +198,16 @@ impl ExtraDerive {
191198
}
192199
}
193200

194-
const STACK_SIZE: usize = 40 * 1024 * 1024;
195-
196201
fn main() {
202+
let args = Args::parse();
197203
let child = thread::Builder::new()
198-
.stack_size(STACK_SIZE)
199-
.spawn(run)
204+
.stack_size(args.stack_size)
205+
.spawn(|| run(args))
200206
.unwrap();
201207
child.join().unwrap();
202208
}
203209

204-
fn run() {
205-
let args = Args::parse();
206-
210+
fn run(args: Args) {
207211
// Build a TranspilerConfig from the command line
208212
let mut tcfg = TranspilerConfig {
209213
dump_untyped_context: args.dump_untyped_clang_ast,

0 commit comments

Comments
 (0)