[standalone] Remove redundant recreation of TargetMachine

This commit is contained in:
David Mak 2024-09-09 14:27:10 +08:00
parent f3dc02d646
commit abbaa506ad

View File

@ -279,18 +279,14 @@ fn main() {
reloc_mode: RelocMode::PIC, reloc_mode: RelocMode::PIC,
..host_target_machine ..host_target_machine
}; };
let target_machine = target_machine_options
.create_target_machine(opt_level)
.expect("couldn't create target machine");
let context = nac3core::inkwell::context::Context::create(); let context = nac3core::inkwell::context::Context::create();
let size_t = context let size_t =
.ptr_sized_int_type( context.ptr_sized_int_type(&target_machine.get_target_data(), None).get_bit_width();
&target_machine_options
.create_target_machine(opt_level)
.map(|tm| tm.get_target_data())
.unwrap(),
None,
)
.get_bit_width();
let program = match fs::read_to_string(file_name.clone()) { let program = match fs::read_to_string(file_name.clone()) {
Ok(program) => program, Ok(program) => program,
@ -458,11 +454,6 @@ fn main() {
} }
// Optimize `main` // Optimize `main`
let target_machine = llvm_options
.target
.create_target_machine(llvm_options.opt_level)
.expect("couldn't create target machine");
let pass_options = PassBuilderOptions::create(); let pass_options = PassBuilderOptions::create();
pass_options.set_merge_functions(true); pass_options.set_merge_functions(true);
let passes = format!("default<O{}>", opt_level as u32); let passes = format!("default<O{}>", opt_level as u32);