rustllvm: Add a GetOrInsertFunction wrapper

Fixes issue #1161

Test-case-by: Brian Anderson <banderson@mozilla.com>
Signed-off-by: Haitao Li <lihaitao@gmail.com>
This commit is contained in:
Haitao Li 2011-11-15 00:32:31 +08:00
parent 453168d917
commit b8dd148444
5 changed files with 23 additions and 1 deletions

View File

@ -448,6 +448,8 @@ native "cdecl" mod llvm = "rustllvm" {
fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
fn LLVMDeleteFunction(Fn: ValueRef);
fn LLVMGetOrInsertFunction(M: ModuleRef, Name: sbuf, FunctionTy: TypeRef)
-> ValueRef;
fn LLVMGetIntrinsicID(Fn: ValueRef) -> uint;
fn LLVMGetFunctionCallConv(Fn: ValueRef) -> uint;
fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: uint);

View File

@ -301,7 +301,8 @@ fn log_fn_time(ccx: @crate_ctxt, name: str, start: time::timeval,
fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) -> ValueRef {
let llfn: ValueRef =
str::as_buf(name, {|buf| llvm::LLVMAddFunction(llmod, buf, llty) });
str::as_buf(name, {|buf|
llvm::LLVMGetOrInsertFunction(llmod, buf, llty) });
llvm::LLVMSetFunctionCallConv(llfn, cc);
ret llfn;
}

View File

@ -141,3 +141,9 @@ extern "C" void LLVMRustEnableSegmentedStacks() {
EnableSegmentedStacks = true;
}
extern "C" LLVMValueRef LLVMGetOrInsertFunction(LLVMModuleRef M,
const char* Name,
LLVMTypeRef FunctionTy) {
return wrap(unwrap(M)->getOrInsertFunction(Name,
unwrap<FunctionType>(FunctionTy)));
}

View File

@ -364,6 +364,7 @@ LLVMGetNextParam
LLVMGetNextUse
LLVMGetNumOperands
LLVMGetOperand
LLVMGetOrInsertFunction
LLVMGetParam
LLVMGetParamParent
LLVMGetParamTypes

View File

@ -0,0 +1,12 @@
native "cdecl" mod rustrt1 = "rustrt" {
fn pin_task();
}
native "cdecl" mod rustrt2 = "rustrt" {
fn pin_task();
}
fn main() {
rustrt1::pin_task();
rustrt2::pin_task();
}