Skip to content

Commit

Permalink
Merge pull request #46 from maleadt/tb/inflight
Browse files Browse the repository at this point in the history
Wrap InlineAsm and GetCalledValue
  • Loading branch information
maleadt committed Sep 4, 2017
2 parents 04162e0 + 6fe8843 commit e434b17
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 19 deletions.
4 changes: 2 additions & 2 deletions COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ Core
- [ ] LLVMConstShuffleVector
- [ ] LLVMConstExtractValue
- [ ] LLVMConstInsertValue
- [ ] LLVMConstInlineAsm
- [x] LLVMConstInlineAsm
- [ ] LLVMBlockAddress

**Global Values**
Expand Down Expand Up @@ -653,7 +653,7 @@ Function parameters:
- [ ] LLVMGetCallSiteStringAttribute
- [ ] LLVMRemoveCallSiteEnumAttribute
- [ ] LLVMRemoveCallSiteStringAttribute
- [ ] LLVMGetCalledValue
- [x] LLVMGetCalledValue
- [x] LLVMIsTailCall
- [x] LLVMSetTailCall

Expand Down
5 changes: 4 additions & 1 deletion src/core/instructions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ end
## call sites and invocations

export callconv, callconv!,
istailcall, tailcall!
istailcall, tailcall!,
called_value

callconv(inst::Instruction) = API.LLVMGetInstructionCallConv(ref(inst))
callconv!(inst::Instruction, cc) =
Expand All @@ -89,6 +90,8 @@ callconv!(inst::Instruction, cc) =
istailcall(inst::Instruction) = convert(Core.Bool, API.LLVMIsTailCall(ref(inst)))
tailcall!(inst::Instruction, bool) = API.LLVMSetTailCall(ref(inst), convert(Bool, bool))

called_value(inst::Instruction) = Value(API.LLVMGetCalledValue(ref( inst)))


## terminators

Expand Down
32 changes: 22 additions & 10 deletions src/core/value/constant.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PointerNull(typ::PointerType) = PointerNull(API.LLVMConstPointerNull(ref(typ)))
end
@compat abstract type Instruction <: User end


## scalar

import Base: convert
Expand Down Expand Up @@ -87,6 +88,27 @@ convert(::Type{Float64}, val::ConstantFP) =
API.LLVMConstRealGetDouble(ref(val), Ref{API.LLVMBool}())


## constant expressions

export ConstantExpr, InlineAsm

@checked immutable ConstantExpr <: Constant
ref::reftype(Constant)
end
identify(::Type{Value}, ::Val{API.LLVMConstantExprValueKind}) = ConstantExpr

@checked immutable InlineAsm <: Constant
ref::reftype(Constant)
end
identify(::Type{Value}, ::Val{API.LLVMInlineAsmValueKind}) = InlineAsm

InlineAsm(typ::FunctionType, asm::String, constraints::String,
side_effects::Core.Bool, align_stack::Core.Bool=false) =
InlineAsm(API.LLVMConstInlineAsm(ref(typ), asm, constraints,
convert(Bool, side_effects),
convert(Bool, align_stack)))


## global values

@compat abstract type GlobalValue <: Constant end
Expand Down Expand Up @@ -191,13 +213,3 @@ isextinit(gv::GlobalVariable) =
extinit!(gv::GlobalVariable, bool) =
API.LLVMSetExternallyInitialized(ref(gv), convert(Bool, bool))


## expressions

export ConstantExpr

@checked immutable ConstantExpr <: Constant
ref::reftype(Constant)
end
identify(::Type{Value}, ::Val{API.LLVMConstantExprValueKind}) = ConstantExpr

14 changes: 14 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ Context() do ctx
end
end

# constant expressions
Context() do ctx
@testset "constant expressions" begin

# inline assembly
let
ft = LLVM.FunctionType(LLVM.VoidType(ctx))
asm = InlineAsm(ft, "nop", "", false)
@check_ir asm "void ()* asm \"nop\", \"\""
end

end
end

# global values
Context() do ctx
LLVM.Module("SomeModule", ctx) do mod
Expand Down
7 changes: 1 addition & 6 deletions test/irbuilder.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
macro check_ir(inst, str)
quote
@test contains(string($(esc(inst))), $(esc(str)))
end
end

@testset "irbuilder" begin

let
Expand Down Expand Up @@ -255,6 +249,7 @@ LLVM.Module("SomeModule", ctx) do mod
trap = LLVM.Function(mod, "llvm.trap", LLVM.FunctionType(LLVM.VoidType(ctx)))
callinst = call!(builder, trap)
@check_ir callinst "call void @llvm.trap()"
@test called_value(callinst) == trap

neginst = neg!(builder, int1)
@check_ir neginst "sub i32 0, %0"
Expand Down
6 changes: 6 additions & 0 deletions test/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ function julia_cmd(cmd)
$cmd
`
end

macro check_ir(inst, str)
quote
@test contains(string($(esc(inst))), $(esc(str)))
end
end

0 comments on commit e434b17

Please sign in to comment.