Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ge the host triple using LLVM. Fix a few 'mutable' warnings also. #354

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions src/comp/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,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 @@ -175,10 +191,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
LLVMRustCreateMemoryBufferWithContentsOfFile
LLVMRustWriteOutputFile
LLVMRustGetLastError
LLVMRustGetHostTriple
LLVMRustParseBitcode
LLVMLinkModules
LLVMCreateObjectFile
Expand Down