Skip to content

Commit

Permalink
Ask host target triple to LLVM, now that the llvm-c 3.5 API gives acc…
Browse files Browse the repository at this point in the history
…ess to that
  • Loading branch information
Ary Borenszweig committed Sep 25, 2014
1 parent 2018497 commit b6da89c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 36 deletions.
1 change: 1 addition & 0 deletions libs/llvm/lib_llvm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@ lib LibLLVM
fun initialize_target = LLVMInitializeTarget(r : PassRegistryRef)
fun add_target_data = LLVMAddTargetData(td : TargetDataRef, pm : PassManagerRef)
fun get_next_target = LLVMGetNextTarget(t : TargetRef) : TargetRef
fun get_default_target_triple = LLVMGetDefaultTargetTriple : UInt8*
end
5 changes: 5 additions & 0 deletions libs/llvm/llvm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ module LLVM
LibLLVM.delete_basic_block(block)
end

def self.default_target_triple
chars = LibLLVM.get_default_target_triple
String.new(chars).tap { LibLLVM.dispose_message(chars) }
end

Void = LibLLVM.void_type
Int1 = LibLLVM.int_type(1)
Int8 = LibLLVM.int_type(8)
Expand Down
35 changes: 0 additions & 35 deletions src/compiler/crystal/codegen/target_machine.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ require "../program"

module Crystal
module TargetMachine
HOST_TARGET_TRIPLE = guess_host_target_triple

def self.create(target_triple, cpu, release)
LLVM.init_x86

Expand All @@ -13,38 +11,5 @@ module Crystal
target = LLVM::Target.first
target.create_target_machine(target_triple, cpu: cpu, opt_level: opt_level).not_nil!
end

private def self.guess_host_target_triple
# Some uname -m -s -r samples:
#
# Linux 3.15.3-tinycore64 x86_64
# Linux 3.2.0-23-generic-pae i686
# Linux 3.2.0-23-generic x86_64
# Darwin 13.3.0 x86_64
#
# And some triples:
#
# x86_64-pc-linux-gnu
# i686-pc-linux-gnu
# x86_64-apple-darwin12.3.0
system, version, arch = `uname -m -s -r`.split

case system
when "Darwin"
if arch == "x86_64"
"x86_64-apple-darwin#{version}"
else
"x86-apple-darwin#{version}"
end
when "Linux"
if arch == "x86_64"
"x86_64-pc-linux-gnu"
else
"i686-pc-linux-gnu"
end
else
raise "Unsupported system: #{system}"
end
end
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ module Crystal

def target_machine
@target_machine ||= begin
triple = @target_triple || TargetMachine::HOST_TARGET_TRIPLE
triple = @target_triple || LLVM.default_target_triple
TargetMachine.create(triple, @mcpu || "", @release)
end
end
Expand Down

0 comments on commit b6da89c

Please sign in to comment.