Skip to content

Commit

Permalink
Wrap IRBuilder/icmp! (#15)
Browse files Browse the repository at this point in the history
Fixes #12.
  • Loading branch information
TheOnlySilverClaw authored and maleadt committed Jan 19, 2017
1 parent 85bdce3 commit 8478f92
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/irbuilder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ debuglocation!(builder::Builder, inst::Instruction) =
# NOTE: we can't use type information for differentiating eg. add! and fadd! based on args,
# as ArgumentKind (LLVM's way of referring to contained function arguments) is untyped

export unreachable!, ret!, add!, fadd!, br!, alloca!, call!
export unreachable!, ret!, add!, fadd!, icmp!, br!, alloca!, call!

unreachable!(builder::Builder) =
Instruction(API.LLVMBuildUnreachable(ref(builder)))
Expand All @@ -69,6 +69,10 @@ fadd!(builder::Builder, lhs::Value, rhs::Value, name::String="") =
Instruction(API.LLVMBuildFAdd(ref(builder), ref(lhs),
ref(rhs), name))

icmp!(builder::Builder, op::API.LLVMIntPredicate, rhs::Value,
lhs::Value, name::String="") =
Instruction(API.LLVMBuildICmp(ref(builder), op, ref(rhs), ref(lhs), name))

br!(builder::Builder, dest::BasicBlock) =
Instruction(API.LLVMBuildBr(ref(builder), blockref(dest)))

Expand Down
5 changes: 4 additions & 1 deletion test/irbuilder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ LLVM.Module("SomeModule", ctx) do mod
insert!(builder, retinst2)
@test collect(instructions(entry)) == [unrinst, addinst, retinst2, retinst]

position!(builder, retinst)
icmpinst = icmp!(builder, LLVM.API.LLVMIntEQ, addinst, ConstantInt(LLVM.Int32Type(), 1))

allocinst1 = alloca!(builder, LLVM.Int32Type(), "foo")
allocinst2 = Instruction(allocinst1)
@test name(allocinst2) == ""
insert!(builder, allocinst2, "bar")
@test name(allocinst2) == "bar"
@test collect(instructions(entry)) == [unrinst, addinst, retinst2, allocinst1, allocinst2, retinst]
@test collect(instructions(entry)) == [unrinst, addinst, retinst2, icmpinst, allocinst1, allocinst2, retinst]

trap = LLVM.Function(mod, "llvm.trap", LLVM.FunctionType(LLVM.VoidType(ctx)))
call!(builder, trap)
Expand Down

0 comments on commit 8478f92

Please sign in to comment.