From 98736fe310ccb7df202babbefe4317c76bcf04ae Mon Sep 17 00:00:00 2001 From: David Mak Date: Wed, 6 Sep 2023 18:49:58 +0800 Subject: [PATCH] standalone: Expose flags in command-line --- nac3standalone/src/main.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/nac3standalone/src/main.rs b/nac3standalone/src/main.rs index 14083b8..d1a9060 100644 --- a/nac3standalone/src/main.rs +++ b/nac3standalone/src/main.rs @@ -7,6 +7,7 @@ use inkwell::{ }; use parking_lot::{Mutex, RwLock}; use std::{borrow::Borrow, collections::HashMap, fs, path::Path, sync::Arc}; +use std::mem::transmute; use nac3core::{ codegen::{ @@ -41,6 +42,14 @@ struct CommandLineArgs { /// The number of threads allocated to processing the source file. #[arg(default_value_t = 1)] threads: u32, + + /// The level to optimize the LLVM IR. + #[arg(short = 'O', default_value_t = 2, value_parser = clap::value_parser!(u32).range(0..=3))] + opt_level: u32, + + /// Whether to emit LLVM IR at the end of every module. + #[arg(long, default_value_t = false)] + emit_llvm: bool, } fn handle_typevar_definition( @@ -169,7 +178,8 @@ fn handle_assignment_pattern( fn main() { let cli = CommandLineArgs::parse(); - let CommandLineArgs { file_name, threads } = cli; + let CommandLineArgs { file_name, threads, opt_level, emit_llvm } = cli; + let opt_level: OptimizationLevel = unsafe { transmute(opt_level) }; Target::initialize_all(&InitializationConfig::default()); @@ -266,8 +276,8 @@ fn main() { calls: instance.calls, id: 0, llvm_options: CodeGenLLVMOptions { - opt_level: OptimizationLevel::Default, - emit_llvm: false, + opt_level, + emit_llvm, }, }; @@ -322,7 +332,7 @@ fn main() { &triple, "", "", - OptimizationLevel::Default, + opt_level, RelocMode::Default, CodeModel::Default, )