Skip to content

Commit b9917ac

Browse files
committed
Add DIBuilder and constructors for DIInfo
1 parent 9f9d2fa commit b9917ac

File tree

6 files changed

+77
-9
lines changed

6 files changed

+77
-9
lines changed

src/LLVM.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ include("ir.jl")
6161
include("bitcode.jl")
6262
include("transform.jl")
6363
include("debuginfo.jl")
64-
include("dibuilder.jl")
6564
include("jitevents.jl")
6665
include("utils.jl")
6766

src/debuginfo.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## DIBuilder
2+
3+
export DIBuilder
4+
5+
@checked struct DIBuilder
6+
ref::API.LLVMDIBuilderRef
7+
end
8+
Base.unsafe_convert(::Type{API.LLVMDIBuilderRef}, builder::DIBuilder) = builder.ref
9+
10+
# LLVMCreateDIBuilderDisallowUnresolved
11+
DIBuilder(mod::Module) = DIBuilder(API.LLVMCreateDIBuilder(mod))
12+
13+
dispose(builder::DIBuilder) = API.LLVMDisposeDIBuilder(builder)
14+
finalize(builder::DIBuilder) = API.LLVMDIBuilderFinalize(builder)
15+
116
## location information
217

318
export DILocation
@@ -20,6 +35,11 @@ function inlined_at(location::DILocation)
2035
ref == C_NULL ? nothing : Metadata(ref)::DILocation
2136
end
2237

38+
function DILocation(line, col, scope=nothing, inlined_at=nothing; ctx::Context)
39+
DILocation(API.LLVMDIBuilderCreateDebugLocation(ctx, line, col,
40+
something(scope, C_NULL),
41+
something(inlined_at, C_NULL)))
42+
end
2343

2444
## nodes
2545

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

129+
function file!(builder::DIBuilder, file::String, dir::String)
130+
DIFile(API.LLVMDIBuilderCreateFile(
131+
builder,
132+
file, convert(Csize_t, length(file)),
133+
dir, convert(Csize_t, length(dir))
134+
))
135+
end
109136

110137
## type
111138

@@ -158,6 +185,27 @@ export DICompileUnit
158185
end
159186
register(DICompileUnit, API.LLVMDICompileUnitMetadataKind)
160187

188+
function compilationunit!(builder::DIBuilder, lang, file, producer;
189+
optimized::Base.Bool=true, flags="", runtime_version=0, split_name=nothing, emission_kind=API.LLVMDWARFEmissionFull,
190+
dwo_id=0, split_debug_inlining=true, debug_info_for_profiling=false, sysroot="", sdk="")
191+
192+
DICompileUnit(API.LLVMDIBuilderCreateCompileUnit(
193+
builder,
194+
lang,
195+
file,
196+
producer, length(producer),
197+
optimized ? LLVM.True : LLVM.False,
198+
flags, length(flags),
199+
runtime_version,
200+
something(split_name, C_NULL), split_name === nothing ? 0 : length(split_name),
201+
emission_kind,
202+
dwo_id,
203+
split_debug_inlining ? LLVM.True : LLVM.False,
204+
debug_info_for_profiling ? LLVM.True : LLVM.False,
205+
sysroot, length(sysroot),
206+
sdk, length(sdk)
207+
))
208+
end
161209

162210
## other
163211

src/dibuilder.jl

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/dibuilder.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@testset "dibuilder" begin
2+
3+
Context() do ctx
4+
LLVM.Module("SomeModule"; ctx) do mod
5+
builder = DIBuilder(mod)
6+
dispose(builder)
7+
end
8+
end
9+
10+
Context() do ctx
11+
LLVM.Module("SomeModule"; ctx) do mod
12+
di_builder = DIBuilder(mod)
13+
file = LLVM.file!(di_builder, "test.jl", "src")
14+
15+
@test LLVM.filename(file) == "test.jl"
16+
@test LLVM.directory(file) == "src"
17+
@test LLVM.source(file) == "" # No C-API to attach source
18+
19+
cu = LLVM.compilationunit!(di_builder,
20+
LLVM.API.LLVMDWARFSourceLanguageJulia, file, "LLVM.jl Tests")
21+
22+
finalize(di_builder)
23+
dispose(di_builder)
24+
end
25+
end
26+
27+
end # testset

test/instructions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@assert position(builder) == entrybb
1414

1515
@test debuglocation(builder) === nothing
16-
loc = DILocation(ctx, 1, 1)
16+
loc = DILocation(1, 1; ctx)
1717
debuglocation!(builder, loc)
1818
@test debuglocation(builder) == loc
1919
debuglocation!(builder)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ include("target.jl")
6464
include("targetmachine.jl")
6565
include("datalayout.jl")
6666
include("debuginfo.jl")
67+
include("dibuilder.jl")
6768
include("utils.jl")
6869
if LLVM.has_orc_v1()
6970
include("orc.jl")

0 commit comments

Comments
 (0)