From 5bd6b161d5fc77c827d1f70f97fd47da84628c25 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 27 Mar 2020 13:54:18 -0700 Subject: [PATCH] Create a valid target triple in the LLVM Module. --- Cargo.lock | 4 ++-- lib/llvm-backend/Cargo.toml | 4 ++-- lib/llvm-backend/src/code.rs | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af87c56c1..2de4ba2ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -645,7 +645,7 @@ dependencies = [ [[package]] name = "inkwell" 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 = [ "either", "inkwell_internals", @@ -659,7 +659,7 @@ dependencies = [ [[package]] name = "inkwell_internals" 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 = [ "proc-macro2 0.4.30", "quote 0.6.13", diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index 73ccafd00..f7c493ae9 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -19,13 +19,13 @@ byteorder = "1" [target.'cfg(target_arch = "x86_64")'.dependencies.inkwell] git = "https://github.com/TheDan64/inkwell" -rev = "af4cf4efbb27cdea8a54175ffc18ffd91964618c" +rev = "5610ee7e1fea4f177d1cd70516a988df286975d8" default-features = false features = ["llvm8-0", "target-x86"] [target.'cfg(target_arch = "aarch64")'.dependencies.inkwell] git = "https://github.com/TheDan64/inkwell" -rev = "af4cf4efbb27cdea8a54175ffc18ffd91964618c" +rev = "5610ee7e1fea4f177d1cd70516a988df286975d8" default-features = false features = ["llvm8-0", "target-aarch64"] diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 576242c0e..554628e25 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -12,7 +12,7 @@ use inkwell::{ context::Context, module::{Linkage, Module}, passes::PassManager, - targets::{CodeModel, InitializationConfig, RelocMode, Target, TargetMachine}, + targets::{CodeModel, InitializationConfig, RelocMode, Target, TargetMachine, TargetTriple}, types::{ BasicType, BasicTypeEnum, FloatMathType, FunctionType, IntType, PointerType, VectorType, }, @@ -8655,7 +8655,13 @@ impl<'ctx> ModuleCodeGenerator, LLVMBackend, Cod let context = unsafe { &*context_ptr }; 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 { #[cfg(target_arch = "x86_64")] @@ -8681,10 +8687,11 @@ impl<'ctx> ModuleCodeGenerator, LLVMBackend, Cod _ => 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 .create_target_machine( - &triple, + &target_triple, &cpu_name.unwrap_or(TargetMachine::get_host_cpu_name().to_string()), &cpu_features.unwrap_or(TargetMachine::get_host_cpu_features().to_string()), OptimizationLevel::Aggressive, @@ -8693,7 +8700,7 @@ impl<'ctx> ModuleCodeGenerator, LLVMBackend, Cod ) .unwrap(); - module.set_target(&target); + module.set_triple(&target_triple); module.set_data_layout(&target_machine.get_target_data().get_data_layout()); let intrinsics = Intrinsics::declare(&module, &context);