Create a valid target triple in the LLVM Module.

This commit is contained in:
Nick Lewycky 2020-03-27 13:54:18 -07:00
parent 531ec45f34
commit 5bd6b161d5
3 changed files with 16 additions and 9 deletions

4
Cargo.lock generated
View File

@ -645,7 +645,7 @@ dependencies = [
[[package]] [[package]]
name = "inkwell" name = "inkwell"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/TheDan64/inkwell?rev=af4cf4efbb27cdea8a54175ffc18ffd91964618c#af4cf4efbb27cdea8a54175ffc18ffd91964618c" source = "git+https://github.com/TheDan64/inkwell?rev=5610ee7e1fea4f177d1cd70516a988df286975d8#5610ee7e1fea4f177d1cd70516a988df286975d8"
dependencies = [ dependencies = [
"either", "either",
"inkwell_internals", "inkwell_internals",
@ -659,7 +659,7 @@ dependencies = [
[[package]] [[package]]
name = "inkwell_internals" name = "inkwell_internals"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/TheDan64/inkwell?rev=af4cf4efbb27cdea8a54175ffc18ffd91964618c#af4cf4efbb27cdea8a54175ffc18ffd91964618c" source = "git+https://github.com/TheDan64/inkwell?rev=5610ee7e1fea4f177d1cd70516a988df286975d8#5610ee7e1fea4f177d1cd70516a988df286975d8"
dependencies = [ dependencies = [
"proc-macro2 0.4.30", "proc-macro2 0.4.30",
"quote 0.6.13", "quote 0.6.13",

View File

@ -19,13 +19,13 @@ byteorder = "1"
[target.'cfg(target_arch = "x86_64")'.dependencies.inkwell] [target.'cfg(target_arch = "x86_64")'.dependencies.inkwell]
git = "https://github.com/TheDan64/inkwell" git = "https://github.com/TheDan64/inkwell"
rev = "af4cf4efbb27cdea8a54175ffc18ffd91964618c" rev = "5610ee7e1fea4f177d1cd70516a988df286975d8"
default-features = false default-features = false
features = ["llvm8-0", "target-x86"] features = ["llvm8-0", "target-x86"]
[target.'cfg(target_arch = "aarch64")'.dependencies.inkwell] [target.'cfg(target_arch = "aarch64")'.dependencies.inkwell]
git = "https://github.com/TheDan64/inkwell" git = "https://github.com/TheDan64/inkwell"
rev = "af4cf4efbb27cdea8a54175ffc18ffd91964618c" rev = "5610ee7e1fea4f177d1cd70516a988df286975d8"
default-features = false default-features = false
features = ["llvm8-0", "target-aarch64"] features = ["llvm8-0", "target-aarch64"]

View File

@ -12,7 +12,7 @@ use inkwell::{
context::Context, context::Context,
module::{Linkage, Module}, module::{Linkage, Module},
passes::PassManager, passes::PassManager,
targets::{CodeModel, InitializationConfig, RelocMode, Target, TargetMachine}, targets::{CodeModel, InitializationConfig, RelocMode, Target, TargetMachine, TargetTriple},
types::{ types::{
BasicType, BasicTypeEnum, FloatMathType, FunctionType, IntType, PointerType, VectorType, BasicType, BasicTypeEnum, FloatMathType, FunctionType, IntType, PointerType, VectorType,
}, },
@ -8655,7 +8655,13 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
let context = unsafe { &*context_ptr }; let context = unsafe { &*context_ptr };
let module = context.create_module("module"); let module = context.create_module("module");
let triple = triple.unwrap_or(TargetMachine::get_default_triple().to_string()); let triple = triple.unwrap_or(
TargetMachine::get_default_triple()
.as_str()
.to_str()
.unwrap()
.to_string(),
);
match triple { match triple {
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
@ -8681,10 +8687,11 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
_ => unimplemented!("target {} not supported", triple), _ => unimplemented!("target {} not supported", triple),
} }
let target = Target::from_triple(&triple).unwrap(); let target_triple = TargetTriple::create(&triple);
let target = Target::from_triple(&target_triple).unwrap();
let target_machine = target let target_machine = target
.create_target_machine( .create_target_machine(
&triple, &target_triple,
&cpu_name.unwrap_or(TargetMachine::get_host_cpu_name().to_string()), &cpu_name.unwrap_or(TargetMachine::get_host_cpu_name().to_string()),
&cpu_features.unwrap_or(TargetMachine::get_host_cpu_features().to_string()), &cpu_features.unwrap_or(TargetMachine::get_host_cpu_features().to_string()),
OptimizationLevel::Aggressive, OptimizationLevel::Aggressive,
@ -8693,7 +8700,7 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
) )
.unwrap(); .unwrap();
module.set_target(&target); module.set_triple(&target_triple);
module.set_data_layout(&target_machine.get_target_data().get_data_layout()); module.set_data_layout(&target_machine.get_target_data().get_data_layout());
let intrinsics = Intrinsics::declare(&module, &context); let intrinsics = Intrinsics::declare(&module, &context);