2011-08-24 07:54:55 -05:00
|
|
|
import std::{vec, str};
|
|
|
|
import str::rustrt::sbuf;
|
|
|
|
import lib::llvm::llvm;
|
|
|
|
import llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef,
|
|
|
|
Opcode, ModuleRef};
|
|
|
|
import trans_common::block_ctxt;
|
|
|
|
|
|
|
|
fn RetVoid(cx: &@block_ctxt) -> ValueRef {
|
|
|
|
assert (!cx.terminated);;
|
|
|
|
cx.terminated = true;
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildRetVoid(B);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Ret(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
|
|
|
assert (!cx.terminated);;
|
|
|
|
cx.terminated = true;
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildRet(B, V);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn AggregateRet(cx: &@block_ctxt, RetVals: &[ValueRef]) -> ValueRef {
|
|
|
|
assert (!cx.terminated);;
|
|
|
|
cx.terminated = true;
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildAggregateRet(B, vec::to_ptr(RetVals),
|
2011-08-24 07:54:55 -05:00
|
|
|
vec::len(RetVals));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn Br(cx: &@block_ctxt, Dest: BasicBlockRef) -> ValueRef {
|
|
|
|
assert (!cx.terminated);;
|
|
|
|
cx.terminated = true;
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildBr(B, Dest);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn CondBr(cx: &@block_ctxt, If: ValueRef, Then: BasicBlockRef,
|
|
|
|
Else: BasicBlockRef) -> ValueRef {
|
|
|
|
assert (!cx.terminated);;
|
|
|
|
cx.terminated = true;
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildCondBr(B, If, Then, Else);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Switch(cx: &@block_ctxt, V: ValueRef, Else: BasicBlockRef,
|
|
|
|
NumCases: uint) -> ValueRef {
|
|
|
|
assert (!cx.terminated);;
|
|
|
|
cx.terminated = true;
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildSwitch(B, V, Else, NumCases);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn IndirectBr(cx: &@block_ctxt, Addr: ValueRef,
|
|
|
|
NumDests: uint) -> ValueRef {
|
|
|
|
assert (!cx.terminated);;
|
|
|
|
cx.terminated = true;
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildIndirectBr(B, Addr, NumDests);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Invoke(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef],
|
|
|
|
Then: BasicBlockRef, Catch: BasicBlockRef) -> ValueRef {
|
|
|
|
assert (!cx.terminated);;
|
|
|
|
cx.terminated = true;
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildInvoke(B, Fn, vec::to_ptr(Args),
|
2011-08-24 07:54:55 -05:00
|
|
|
vec::len(Args), Then, Catch, str::buf(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn Unreachable(cx: &@block_ctxt) -> ValueRef {
|
|
|
|
assert (!cx.terminated);;
|
|
|
|
cx.terminated = true;
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildUnreachable(B);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Arithmetic */
|
|
|
|
fn Add(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildAdd(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn NSWAdd(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNSWAdd(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn NUWAdd(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNUWAdd(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FAdd(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFAdd(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Sub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildSub(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn NSWSub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNSWSub(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn NUWSub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNUWSub(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FSub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFSub(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Mul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildMul(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn NSWMul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNSWMul(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn NUWMul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNUWMul(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FMul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFMul(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn UDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildUDiv(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn SDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildSDiv(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ExactSDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildExactSDiv(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFDiv(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn URem(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildURem(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn SRem(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildSRem(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FRem(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFRem(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Shl(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildShl(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn LShr(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildLShr(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn AShr(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildAShr(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn And(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildAnd(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Or(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildOr(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Xor(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildXor(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn BinOp(cx: &@block_ctxt, Op: Opcode, LHS: ValueRef,
|
|
|
|
RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildBinOp(B, Op, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Neg(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNeg(B, V, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn NSWNeg(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNSWNeg(B, V, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn NUWNeg(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNUWNeg(B, V, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
fn FNeg(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFNeg(B, V, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
fn Not(cx: &@block_ctxt, V: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildNot(B, V, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Memory */
|
|
|
|
fn Malloc(cx: &@block_ctxt, Ty: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildMalloc(B, Ty, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ArrayMalloc(cx: &@block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildArrayMalloc(B, Ty, Val, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Alloca(cx: &@block_ctxt, Ty: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildAlloca(B, Ty, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ArrayAlloca(cx: &@block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildArrayAlloca(B, Ty, Val, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Free(cx: &@block_ctxt, PointerVal: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFree(B, PointerVal);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Load(cx: &@block_ctxt, PointerVal: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildLoad(B, PointerVal, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Store(cx: &@block_ctxt, Val: ValueRef, Ptr: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildStore(B, Val, Ptr);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn GEP(cx: &@block_ctxt, Pointer: ValueRef,
|
|
|
|
Indices: &[ValueRef]) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildGEP(B, Pointer, vec::to_ptr(Indices),
|
2011-08-24 07:54:55 -05:00
|
|
|
vec::len(Indices), str::buf(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn InBoundsGEP(cx: &@block_ctxt, Pointer: ValueRef,
|
|
|
|
Indices: &[ValueRef]) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildInBoundsGEP(B, Pointer, vec::to_ptr(Indices),
|
2011-08-24 07:54:55 -05:00
|
|
|
vec::len(Indices), str::buf(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn StructGEP(cx: &@block_ctxt, Pointer: ValueRef, Idx: uint) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildStructGEP(B, Pointer, Idx, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn GlobalString(cx: &@block_ctxt, _Str: sbuf) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildGlobalString(B, _Str, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn GlobalStringPtr(cx: &@block_ctxt, _Str: sbuf) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildGlobalStringPtr(B, _Str, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Casts */
|
|
|
|
fn Trunc(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildTrunc(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ZExt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildZExt(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn SExt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildSExt(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FPToUI(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFPToUI(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FPToSI(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFPToSI(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn UIToFP(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildUIToFP(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn SIToFP(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildSIToFP(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FPTrunc(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFPTrunc(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FPExt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFPExt(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn PtrToInt(cx: &@block_ctxt, Val: ValueRef,
|
|
|
|
DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildPtrToInt(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn IntToPtr(cx: &@block_ctxt, Val: ValueRef,
|
|
|
|
DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildIntToPtr(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn BitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildBitCast(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ZExtOrBitCast(cx: &@block_ctxt, Val: ValueRef,
|
|
|
|
DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildZExtOrBitCast(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn SExtOrBitCast(cx: &@block_ctxt, Val: ValueRef,
|
|
|
|
DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildSExtOrBitCast(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn TruncOrBitCast(cx: &@block_ctxt, Val: ValueRef,
|
|
|
|
DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildTruncOrBitCast(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Cast(cx: &@block_ctxt, Op: Opcode, Val: ValueRef,
|
|
|
|
DestTy: TypeRef, _Name: sbuf) ->
|
|
|
|
ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildCast(B, Op, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn PointerCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildPointerCast(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn IntCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildIntCast(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FPCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFPCast(B, Val, DestTy, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Comparisons */
|
|
|
|
fn ICmp(cx: &@block_ctxt, Op: uint, LHS: ValueRef,
|
|
|
|
RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildICmp(B, Op, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn FCmp(cx: &@block_ctxt, Op: uint, LHS: ValueRef,
|
|
|
|
RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildFCmp(B, Op, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Miscellaneous instructions */
|
|
|
|
fn Phi(cx: &@block_ctxt, Ty: TypeRef, vals: &[ValueRef],
|
|
|
|
bbs: &[BasicBlockRef]) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
let phi = llvm::LLVMBuildPhi(B, Ty, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
assert (vec::len::<ValueRef>(vals) == vec::len::<BasicBlockRef>(bbs));
|
|
|
|
llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
|
|
|
|
vec::len(vals));
|
|
|
|
ret phi;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn AddIncomingToPhi(phi: ValueRef, vals: &[ValueRef], bbs: &[BasicBlockRef]) {
|
|
|
|
assert (vec::len::<ValueRef>(vals) == vec::len::<BasicBlockRef>(bbs));
|
|
|
|
llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
|
|
|
|
vec::len(vals));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn Call(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildCall(B, Fn, vec::to_ptr(Args), vec::len(Args),
|
2011-08-24 07:54:55 -05:00
|
|
|
str::buf(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn FastCall(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
2011-08-24 07:54:55 -05:00
|
|
|
let v =
|
2011-08-24 09:30:20 -05:00
|
|
|
llvm::LLVMBuildCall(B, Fn, vec::to_ptr(Args), vec::len(Args),
|
2011-08-24 07:54:55 -05:00
|
|
|
str::buf(""));
|
|
|
|
llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
|
|
|
|
ret v;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn CallWithConv(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef],
|
|
|
|
Conv: uint) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
2011-08-24 07:54:55 -05:00
|
|
|
let v =
|
2011-08-24 09:30:20 -05:00
|
|
|
llvm::LLVMBuildCall(B, Fn, vec::to_ptr(Args), vec::len(Args),
|
2011-08-24 07:54:55 -05:00
|
|
|
str::buf(""));
|
|
|
|
llvm::LLVMSetInstructionCallConv(v, Conv);
|
|
|
|
ret v;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn Select(cx: &@block_ctxt, If: ValueRef, Then: ValueRef,
|
|
|
|
Else: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildSelect(B, If, Then, Else, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn VAArg(cx: &@block_ctxt, list: ValueRef, Ty: TypeRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildVAArg(B, list, Ty, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ExtractElement(cx: &@block_ctxt, VecVal: ValueRef,
|
|
|
|
Index: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildExtractElement(B, VecVal, Index, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn InsertElement(cx: &@block_ctxt, VecVal: ValueRef, EltVal: ValueRef,
|
|
|
|
Index: ValueRef) ->
|
|
|
|
ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildInsertElement(B, VecVal, EltVal, Index,
|
2011-08-24 07:54:55 -05:00
|
|
|
str::buf(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ShuffleVector(cx: &@block_ctxt, V1: ValueRef, V2: ValueRef,
|
|
|
|
Mask: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildShuffleVector(B, V1, V2, Mask, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ExtractValue(cx: &@block_ctxt, AggVal: ValueRef, Index: uint) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildExtractValue(B, AggVal, Index, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn InsertValue(cx: &@block_ctxt, AggVal: ValueRef,
|
|
|
|
EltVal: ValueRef, Index: uint) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildInsertValue(B, AggVal, EltVal, Index,
|
2011-08-24 07:54:55 -05:00
|
|
|
str::buf(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn IsNull(cx: &@block_ctxt, Val: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildIsNull(B, Val, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn IsNotNull(cx: &@block_ctxt, Val: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildIsNotNull(B, Val, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn PtrDiff(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
ret llvm::LLVMBuildPtrDiff(B, LHS, RHS, str::buf(""));
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Trap(cx: &@block_ctxt) -> ValueRef {
|
2011-08-24 09:30:20 -05:00
|
|
|
let B = *cx.fcx.lcx.ccx.builder;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(B, cx.llbb);
|
|
|
|
let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(B);
|
2011-08-24 07:54:55 -05:00
|
|
|
let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB);
|
|
|
|
let M: ModuleRef = llvm::LLVMGetGlobalParent(FN);
|
|
|
|
let T: ValueRef =
|
|
|
|
llvm::LLVMGetNamedFunction(M, str::buf("llvm.trap"));
|
|
|
|
assert (T as int != 0);
|
|
|
|
let Args: [ValueRef] = [];
|
2011-08-24 09:30:20 -05:00
|
|
|
ret llvm::LLVMBuildCall(B, T, vec::to_ptr(Args), vec::len(Args),
|
2011-08-24 07:54:55 -05:00
|
|
|
str::buf(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|
|
|
|
//
|