Skip to content

Commit 294b005

Browse files
committed
fixup! fixup! support for DIBuilder on LLVM8
1 parent ed9a4cb commit 294b005

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/dibuilder.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export DIBuilder, DIFile, DICompileUnit, DILexicalBlock, DIFunction
1+
export DIBuilder, DIFile, DICompileUnit, DILexicalBlock, DISubprogram
22

33
@checked struct DIBuilder
44
ref::API.LLVMDIBuilderRef
@@ -84,7 +84,7 @@ function lexicalblock!(builder::DIBuilder, scope::Metadata, file::Metadata, disc
8484
Metadata(md)
8585
end
8686

87-
struct DIFunction
87+
struct DISubprogram
8888
name::String
8989
linkageName::String
9090
file::Metadata
@@ -97,10 +97,10 @@ struct DIFunction
9797
optimized::Core.Bool
9898
end
9999

100-
function subprogram!(builder::DIBuilder, scope::Metadata, f::DIFunction)
100+
function subprogram!(builder::DIBuilder, f::DISubprogram)
101101
md = API.LLVMDIBuilderCreateFunction(
102102
builder,
103-
scope,
103+
f.file,
104104
f.name, convert(Csize_t, length(f.name)),
105105
f.linkageName, convert(Csize_t, length(f.linkageName)),
106106
f.file,
@@ -120,30 +120,28 @@ end
120120
function basictype!(builder::DIBuilder, name, size, encoding)
121121
md = LLVM.API.LLVMDIBuilderCreateBasicType(
122122
builder,
123-
name,
124-
convert(Csize_t, length(name)),
123+
name, convert(Csize_t, length(name)),
125124
convert(UInt64, size),
126125
encoding,
127126
LLVM.API.LLVMDIFlagZero
128127
)
129128
Metadata(md)
130129
end
131130

132-
function pointertype!(builder::DIBuilder, pointee::Metadata, size, as, align=0, name="")
131+
function pointertype!(builder::DIBuilder, basetype::Metadata, size, as, align=0, name="")
133132
md = LLVM.API.LLVMDIBuilderCreatePointerType(
134133
builder,
135-
pointee,
134+
basetype,
136135
convert(UInt64, size),
137136
convert(UInt32, align),
138137
convert(Cuint, as),
139-
name,
140-
convert(Csize_t, length(name)),
138+
name, convert(Csize_t, length(name)),
141139
)
142140
Metadata(md)
143141
end
144142

145143
function subroutinetype!(builder::DIBuilder, file::Metadata, rettype, paramtypes...)
146-
params = collect(ref(x) for x in (rettype, paramtypes...))
144+
params = collect(x for x in (rettype, paramtypes...))
147145
md = LLVM.API.LLVMDIBuilderCreateSubroutineType(
148146
builder,
149147
file,

test/dibuilder.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@ LLVM.Module("SomeModule", ctx) do mod
1616
cu_md = LLVM.compileunit!(dibuilder, cu)
1717

1818
Builder(ctx) do builder
19-
ft = LLVM.FunctionType(LLVM.VoidType(ctx), [LLVM.Int32Type(ctx)])
19+
ft = LLVM.FunctionType(LLVM.VoidType(ctx), [LLVM.Int64Type(ctx)])
20+
rt_md = LLVM.basictype!(dibuilder, "Nothing", 0, 0)
21+
param_md = LLVM.basictype!(dibuilder, "Int64", sizeof(Int64), 0)
22+
dift_md = LLVM.subroutinetype!(dibuilder, file_md, rt_md, param_md)
2023
fn = LLVM.Function(mod, "SomeFunction", ft)
24+
difn = DISubprogram(LLVM.name(fn), "linkage", file_md, 3, dift_md, true, true, 5, LLVM.API.LLVMDIFlagPublic, false)
25+
difn_md = LLVM.subprogram!(dibuilder, difn)
26+
LLVM.set_subprogram!(fn, difn_md)
2127

2228
entrybb = BasicBlock(fn, "entry")
2329
position!(builder, entrybb)
2430

31+
ptr = inttoptr!(builder, parameters(fn)[1], LLVM.PointerType(LLVM.Int64Type(ctx)))
32+
ptr_md = LLVM.pointertype!(dibuilder, param_md, sizeof(Ptr{Int64}), LLVM.addrspace(llvmtype(ptr)), 0, "MyPtr")
33+
# TODO: LLVM.dbg_declare!(builder, mod, ptr, ptr_md)
34+
val = ptrtoint!(builder, ptr, LLVM.Int64Type(ctx))
35+
2536
block = DILexicalBlock(file_md, 1, 1)
2637
block_md = LLVM.lexicalblock!(dibuilder, file_md, block) # could also be file
2738
debuglocation!(builder, LLVM.MetadataAsValue(LLVM.API.LLVMMetadataAsValue(ctx, block_md)))
@@ -33,11 +44,10 @@ LLVM.Module("SomeModule", ctx) do mod
3344

3445
fun = functions(mod)["SomeFunction"]
3546
bb = entry(fun)
36-
inst = first(instructions(bb))
47+
inst = last(instructions(bb))
3748
@test !isempty(metadata(inst))
3849
inst_str = sprint(io->Base.show(io, inst))
3950
@test occursin("!dbg", inst_str)
40-
@show mod inst
4151

4252
@test !isempty(metadata(inst))
4353
mod_str = sprint(io->Base.show(io, mod))
@@ -46,6 +56,9 @@ LLVM.Module("SomeModule", ctx) do mod
4656
@test occursin("!DIFile", mod_str)
4757
@test occursin("!DILexicalBlock", mod_str)
4858
@test !occursin("scope: null", mod_str)
59+
@test occursin("DISubprogram", mod_str)
60+
@test occursin("DISubroutineType", mod_str)
61+
@test occursin("DIBasicType", mod_str)
4962

5063
strip_debuginfo!(mod)
5164
@test isempty(metadata(inst))

0 commit comments

Comments
 (0)