提交 b4a0d891 编写于 作者: K Kelly Wilson 提交者: Graydon Hoare

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

上级 1e03f004
......@@ -161,11 +161,27 @@ fn usage(str argv0) {
--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);
......
......@@ -848,6 +848,9 @@ fn LLVMRustWriteOutputFile(PassManagerRef PM, ModuleRef M,
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;
......
......@@ -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 compare[T](lteq[mutable T] compare_func, vec[mutable T]arr,
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:
......
......@@ -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();
}
LLVMRustCreateMemoryBufferWithContentsOfFile
LLVMRustWriteOutputFile
LLVMRustGetLastError
LLVMRustGetHostTriple
LLVMRustParseBitcode
LLVMLinkModules
LLVMCreateObjectFile
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册