Skip to content

Commit

Permalink
Ge the host triple using LLVM. Fix a few 'mutable' warnings also.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonk authored and graydon committed May 6, 2011
1 parent 1e03f00 commit b4a0d89
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
34 changes: 26 additions & 8 deletions src/comp/driver/rustc.rs
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/comp/lib/llvm.rs
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/lib/sort.rs
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/rustllvm/RustWrapper.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions src/rustllvm/rustllvm.def.in
@@ -1,6 +1,7 @@
LLVMRustCreateMemoryBufferWithContentsOfFile
LLVMRustWriteOutputFile
LLVMRustGetLastError
LLVMRustGetHostTriple
LLVMRustParseBitcode
LLVMLinkModules
LLVMCreateObjectFile
Expand Down

0 comments on commit b4a0d89

Please sign in to comment.