Skip to content

support for DIBuilder on LLVM8 #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/LLVM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ include("ir.jl")
include("bitcode.jl")
include("transform.jl")
include("debuginfo.jl")
include("dibuilder.jl")
include("jitevents.jl")
include("utils.jl")

Expand Down
48 changes: 48 additions & 0 deletions src/debuginfo.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## DIBuilder

export DIBuilder

@checked struct DIBuilder
ref::API.LLVMDIBuilderRef
end
Base.unsafe_convert(::Type{API.LLVMDIBuilderRef}, builder::DIBuilder) = builder.ref

# LLVMCreateDIBuilderDisallowUnresolved
DIBuilder(mod::Module) = DIBuilder(API.LLVMCreateDIBuilder(mod))

dispose(builder::DIBuilder) = API.LLVMDisposeDIBuilder(builder)
finalize(builder::DIBuilder) = API.LLVMDIBuilderFinalize(builder)

## location information

export DILocation
Expand All @@ -20,6 +35,11 @@ function inlined_at(location::DILocation)
ref == C_NULL ? nothing : Metadata(ref)::DILocation
end

function DILocation(line, col, scope=nothing, inlined_at=nothing; ctx::Context)
DILocation(API.LLVMDIBuilderCreateDebugLocation(ctx, line, col,
something(scope, C_NULL),
something(inlined_at, C_NULL)))
end

## nodes

Expand Down Expand Up @@ -106,6 +126,13 @@ function source(file::DIFile)
unsafe_string(convert(Ptr{Int8}, data), len[])
end

function file!(builder::DIBuilder, file::String, dir::String)
DIFile(API.LLVMDIBuilderCreateFile(
builder,
file, convert(Csize_t, length(file)),
dir, convert(Csize_t, length(dir))
))
end

## type

Expand Down Expand Up @@ -158,6 +185,27 @@ export DICompileUnit
end
register(DICompileUnit, API.LLVMDICompileUnitMetadataKind)

function compilationunit!(builder::DIBuilder, lang, file, producer;
optimized::Base.Bool=true, flags="", runtime_version=0, split_name=nothing, emission_kind=API.LLVMDWARFEmissionFull,
dwo_id=0, split_debug_inlining=true, debug_info_for_profiling=false, sysroot="", sdk="")

DICompileUnit(API.LLVMDIBuilderCreateCompileUnit(
builder,
lang,
file,
producer, length(producer),
optimized ? LLVM.True : LLVM.False,
flags, length(flags),
runtime_version,
something(split_name, C_NULL), split_name === nothing ? 0 : length(split_name),
emission_kind,
dwo_id,
split_debug_inlining ? LLVM.True : LLVM.False,
debug_info_for_profiling ? LLVM.True : LLVM.False,
sysroot, length(sysroot),
sdk, length(sdk)
))
end

## other

Expand Down
7 changes: 0 additions & 7 deletions src/dibuilder.jl

This file was deleted.

27 changes: 27 additions & 0 deletions test/dibuilder.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@testset "dibuilder" begin

Context() do ctx
LLVM.Module("SomeModule"; ctx) do mod
builder = DIBuilder(mod)
dispose(builder)
end
end

Context() do ctx
LLVM.Module("SomeModule"; ctx) do mod
di_builder = DIBuilder(mod)
file = LLVM.file!(di_builder, "test.jl", "src")

@test LLVM.filename(file) == "test.jl"
@test LLVM.directory(file) == "src"
@test LLVM.source(file) == "" # No C-API to attach source

cu = LLVM.compilationunit!(di_builder,
LLVM.API.LLVMDWARFSourceLanguageJulia, file, "LLVM.jl Tests")

finalize(di_builder)
dispose(di_builder)
end
end

end # testset
2 changes: 1 addition & 1 deletion test/instructions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@assert position(builder) == entrybb

@test debuglocation(builder) === nothing
loc = DILocation(ctx, 1, 1)
loc = DILocation(1, 1; ctx)
debuglocation!(builder, loc)
@test debuglocation(builder) == loc
debuglocation!(builder)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ include("target.jl")
include("targetmachine.jl")
include("datalayout.jl")
include("debuginfo.jl")
include("dibuilder.jl")
include("utils.jl")
if LLVM.has_orc_v1()
include("orc.jl")
Expand Down