diff --git a/COVERAGE.md b/COVERAGE.md index 58267511..54045744 100644 --- a/COVERAGE.md +++ b/COVERAGE.md @@ -501,7 +501,7 @@ Core - [ ] LLVMConstShuffleVector - [ ] LLVMConstExtractValue - [ ] LLVMConstInsertValue -- [ ] LLVMConstInlineAsm +- [x] LLVMConstInlineAsm - [ ] LLVMBlockAddress **Global Values** @@ -653,7 +653,7 @@ Function parameters: - [ ] LLVMGetCallSiteStringAttribute - [ ] LLVMRemoveCallSiteEnumAttribute - [ ] LLVMRemoveCallSiteStringAttribute -- [ ] LLVMGetCalledValue +- [x] LLVMGetCalledValue - [x] LLVMIsTailCall - [x] LLVMSetTailCall diff --git a/src/core/instructions.jl b/src/core/instructions.jl index 5ffd935f..d684672c 100644 --- a/src/core/instructions.jl +++ b/src/core/instructions.jl @@ -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) = @@ -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 diff --git a/src/core/value/constant.jl b/src/core/value/constant.jl index 12ca297b..abfef6df 100644 --- a/src/core/value/constant.jl +++ b/src/core/value/constant.jl @@ -31,6 +31,7 @@ PointerNull(typ::PointerType) = PointerNull(API.LLVMConstPointerNull(ref(typ))) end @compat abstract type Instruction <: User end + ## scalar import Base: convert @@ -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 @@ -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 - diff --git a/test/core.jl b/test/core.jl index 94d9c2e8..42997587 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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 diff --git a/test/irbuilder.jl b/test/irbuilder.jl index 482f638e..55cabb49 100644 --- a/test/irbuilder.jl +++ b/test/irbuilder.jl @@ -1,9 +1,3 @@ -macro check_ir(inst, str) - quote - @test contains(string($(esc(inst))), $(esc(str))) - end -end - @testset "irbuilder" begin let @@ -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" diff --git a/test/util.jl b/test/util.jl index f612e4a0..27750b4d 100644 --- a/test/util.jl +++ b/test/util.jl @@ -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