standalone: Expose flags in command-line

This commit is contained in:
David Mak 2023-09-06 18:49:58 +08:00
parent 3993a5cf3f
commit 14d1404f2e
1 changed files with 14 additions and 5 deletions

View File

@ -6,7 +6,7 @@ use inkwell::{
OptimizationLevel, OptimizationLevel,
}; };
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};
use std::{borrow::Borrow, collections::HashMap, fs, path::Path, sync::Arc}; use std::{borrow::Borrow, collections::HashMap, fs, mem::transmute, path::Path, sync::Arc};
use nac3core::{ use nac3core::{
codegen::{ codegen::{
@ -41,6 +41,14 @@ struct CommandLineArgs {
/// The number of threads allocated to processing the source file. /// The number of threads allocated to processing the source file.
#[arg(default_value_t = 1)] #[arg(default_value_t = 1)]
threads: u32, 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( fn handle_typevar_definition(
@ -169,7 +177,8 @@ fn handle_assignment_pattern(
fn main() { fn main() {
let cli = CommandLineArgs::parse(); 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()); Target::initialize_all(&InitializationConfig::default());
@ -256,8 +265,8 @@ fn main() {
}; };
let llvm_options = CodeGenLLVMOptions { let llvm_options = CodeGenLLVMOptions {
opt_level: OptimizationLevel::Default, opt_level,
emit_llvm: false, emit_llvm,
}; };
let task = CodeGenTask { let task = CodeGenTask {
subst: Default::default(), subst: Default::default(),
@ -322,7 +331,7 @@ fn main() {
&triple, &triple,
"", "",
"", "",
OptimizationLevel::Default, opt_level,
RelocMode::Default, RelocMode::Default,
CodeModel::Default, CodeModel::Default,
) )