Skip to content

Commit

Permalink
Add dibuilder and file!
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Jan 31, 2023
1 parent 9f9d2fa commit b5cca3f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
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
22 changes: 22 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 Down Expand Up @@ -106,6 +121,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
7 changes: 0 additions & 7 deletions src/dibuilder.jl

This file was deleted.

22 changes: 22 additions & 0 deletions test/dibuilder.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@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) == joinpath("src", "test.jl")

finalize(dibuilder)
dispose(builder)
end
end
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

0 comments on commit b5cca3f

Please sign in to comment.