aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/comp/driver/rustc.rs34
-rw-r--r--src/comp/lib/llvm.rs3
-rw-r--r--src/lib/sort.rs12
-rw-r--r--src/rustllvm/RustWrapper.cpp6
-rw-r--r--src/rustllvm/rustllvm.def.in1
5 files changed, 42 insertions, 14 deletions
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index aef6ef3b..9c6c352d 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -161,11 +161,27 @@ options:
--no-typestate don't run the typestate pass (unsafe!)\n\n");
}
-fn get_os() -> session.os {
- auto s = std.os.target_os();
- if (_str.eq(s, "win32")) { ret session.os_win32; }
- if (_str.eq(s, "macos")) { ret session.os_macos; }
- if (_str.eq(s, "linux")) { ret session.os_linux; }
+fn get_os(str triple) -> session.os {
+ if (_str.find(triple, "win32") > 0 ||
+ _str.find(triple, "mingw32") > 0 ) {
+ ret session.os_win32;
+ } else if (_str.find(triple, "darwin") > 0) { ret session.os_macos; }
+ else if (_str.find(triple, "linux") > 0) { ret session.os_linux; }
+}
+
+fn get_arch(str triple) -> session.arch {
+ if (_str.find(triple, "i386") > 0 ||
+ _str.find(triple, "i486") > 0 ||
+ _str.find(triple, "i586") > 0 ||
+ _str.find(triple, "i686") > 0 ||
+ _str.find(triple, "i786") > 0 ) {
+ ret session.arch_x86;
+ } else if (_str.find(triple, "x86_64") > 0) {
+ ret session.arch_x64;
+ } else if (_str.find(triple, "arm") > 0 ||
+ _str.find(triple, "xscale") > 0 ) {
+ ret session.arch_arm;
+ }
}
fn get_default_sysroot(str binary) -> str {
@@ -176,10 +192,12 @@ fn get_default_sysroot(str binary) -> str {
fn main(vec[str] args) {
- // FIXME: don't hard-wire this.
+ let str triple =
+ std._str.rustrt.str_from_cstr(llvm.llvm.LLVMRustGetHostTriple());
+
let @session.config target_cfg =
- @rec(os = get_os(),
- arch = session.arch_x86,
+ @rec(os = get_os(triple),
+ arch = get_arch(triple),
int_type = common.ty_i32,
uint_type = common.ty_u32,
float_type = common.ty_f64);
diff --git a/src/comp/lib/llvm.rs b/src/comp/lib/llvm.rs
index cfa82b03..f825e05d 100644
--- a/src/comp/lib/llvm.rs
+++ b/src/comp/lib/llvm.rs
@@ -848,6 +848,9 @@ native mod llvm = llvm_lib {
call. */
fn LLVMRustGetLastError() -> sbuf;
+ /** Returns a string describing the hosts triple */
+ fn LLVMRustGetHostTriple() -> sbuf;
+
/** Parses the bitcode in the given memory buffer. */
fn LLVMRustParseBitcode(MemoryBufferRef MemBuf) -> ModuleRef;
diff --git a/src/lib/sort.rs b/src/lib/sort.rs
index 0c518ae8..f712d22e 100644
--- a/src/lib/sort.rs
+++ b/src/lib/sort.rs
@@ -45,10 +45,10 @@ fn swap[T](vec[mutable T] arr, uint x, uint y) {
arr.(y) = a;
}
-fn part[T](lteq[mutable T] compare_func, vec[mutable T] arr, uint left,
+fn part[T](lteq[T] compare_func, vec[mutable T] arr, uint left,
uint right, uint pivot) -> uint {
- fn compare[T](lteq[mutable T] compare_func, vec[mutable T]arr,
+ fn compare[T](lteq[T] compare_func, vec[mutable T]arr,
uint arr_idx, &T arr_value) -> bool {
ret compare_func(arr.(arr_idx),arr_value);
@@ -69,7 +69,7 @@ fn part[T](lteq[mutable T] compare_func, vec[mutable T] arr, uint left,
ret storage_index;
}
-fn qsort[T](lteq[mutable T] compare_func, vec[mutable T] arr, uint left,
+fn qsort[T](lteq[T] compare_func, vec[mutable T] arr, uint left,
uint right) {
if (right > left) {
@@ -83,12 +83,12 @@ fn qsort[T](lteq[mutable T] compare_func, vec[mutable T] arr, uint left,
}
}
-fn quick_sort[T](lteq[mutable T] compare_func, vec[mutable T] arr) {
+fn quick_sort[T](lteq[T] compare_func, vec[mutable T] arr) {
- if (len[mutable T](arr) == 0u) {
+ if (len[T](arr) == 0u) {
ret;
}
- qsort[T](compare_func, arr, 0u, (len[mutable T](arr)) - 1u);
+ qsort[T](compare_func, arr, 0u, (len[T](arr)) - 1u);
}
// Local Variables:
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp
index 3c958830..20894ed8 100644
--- a/src/rustllvm/RustWrapper.cpp
+++ b/src/rustllvm/RustWrapper.cpp
@@ -20,6 +20,7 @@
#include "llvm/Target/TargetSelect.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetOptions.h"
+#include "llvm/Support/Host.h"
#include "llvm-c/Core.h"
#include "llvm-c/BitReader.h"
#include "llvm-c/Object.h"
@@ -106,3 +107,8 @@ extern "C" LLVMModuleRef LLVMRustParseBitcode(LLVMMemoryBufferRef MemBuf) {
? NULL : M;
}
+extern "C" const char *LLVMRustGetHostTriple(void)
+{
+ static std::string str = llvm::sys::getHostTriple();
+ return str.c_str();
+}
diff --git a/src/rustllvm/rustllvm.def.in b/src/rustllvm/rustllvm.def.in
index a5ffa04e..748c77aa 100644
--- a/src/rustllvm/rustllvm.def.in
+++ b/src/rustllvm/rustllvm.def.in
@@ -1,6 +1,7 @@
LLVMRustCreateMemoryBufferWithContentsOfFile
LLVMRustWriteOutputFile
LLVMRustGetLastError
+LLVMRustGetHostTriple
LLVMRustParseBitcode
LLVMLinkModules
LLVMCreateObjectFile