Skip to content
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

prototype support for DIBuilder #139

Closed
wants to merge 16 commits into from
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ variables:

include:
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/common.yml'
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_v0.7.yml'
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_v1.0.yml'
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_v1.1.yml'
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_dev.yml'
Expand Down
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ uuid = "929cbde3-209d-540e-8aea-75f648917ca0"
version = "1.1.1"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[compat]
julia = "1"

[extras]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "InteractiveUtils"]

[compat]
julia = "0.7, 1"
6 changes: 5 additions & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ function main()
end

# TODO: figure out the name of the native target
config[:libllvm_targets] = [:NVPTX, :AMDGPU]
if config[:libllvm_version] < v"8.0.0"
config[:libllvm_targets] = [:NVPTX, :AMDGPU]
else
config[:libllvm_targets] = [:NVPTX, :AMDGPU, :WebAssembly]
end

# backwards-compatibility
config[:libllvm_system] = false
Expand Down
37 changes: 23 additions & 14 deletions deps/wrap.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# generate LLVM wrappers

using Clang: cindex, wrap_c
using Clang

function wrap(config, destdir)
info("Wrapping LLVM C API at $destdir")
@info("Wrapping LLVM C API at $destdir")
if !isdir(destdir)
mkdir(destdir)
end
Expand All @@ -12,15 +12,18 @@ function wrap(config, destdir)
cppflags = split(readchomp(`$config --cppflags`))

# TODO: this should really be taken care of by Clang.jl...
haskey(ENV, "LLVM_CONFIG") || error("please provide the llvm-config Clang.jl was build with using LLVM_CONFIG")
clang_config = ENV["LLVM_CONFIG"]
if haskey(ENV, "LLVM_CONFIG")
clang_config = ENV["LLVM_CONFIG"]
else
clang_config = joinpath(dirname(pathof(Clang)), "..", "deps", "usr", "tools", "llvm-config")
end
clang_libdir = readchomp(`$clang_config --libdir`)
clang_version = readchomp(`$clang_config --version`)

# Set-up arguments to clang
clang_includes = map(x->x[3:end], filter( x->startswith(x,"-I"), cppflags))
clang_includes = map(x->x[3:end], filter( x->startswith(x,"-I"), cppflags))
push!(clang_includes, "$clang_libdir/clang/$clang_version/include")
clang_extraargs = filter(x->!startswith(x,"-I"), cppflags)
clang_extraargs = filter(x->!startswith(x,"-I"), cppflags)

# Recursively discover LLVM C API headers (files ending in .h)
header_dirs = String[joinpath(includedir, "llvm-c")]
Expand All @@ -38,21 +41,27 @@ function wrap(config, destdir)
end
end

context = wrap_c.init(;
output_file = "$destdir/libLLVM_h.jl",
common_file = "$destdir/libLLVM_common.jl",
clang_includes = convert(Vector{String}, clang_includes),
clang_args = convert(Vector{String}, clang_extraargs),
header_library = x->:libllvm,
header_wrapped = (top,cursor)->contains(cursor, "include/llvm") )
context = init(;
headers = header_files,
output_file = "$destdir/libLLVM_h.jl",
common_file = "$destdir/libLLVM_common.jl",
clang_includes = convert(Vector{String}, clang_includes),
clang_args = convert(Vector{String}, clang_extraargs),
header_library = x->"libllvm",
header_wrapped = (top,cursor)->occursin("include/llvm", cursor)
)

context.headers = header_files
run(context)
end

length(ARGS) == 2 || error("Usage: wrap.jl /path/to/llvm-config target")
config = ARGS[1]
ispath(config) || error("llvm-config at $config is't a valid path")

# Use `ccall\(\((:.+), libllvm\), (.*)\)` and replace with `@apicall($1, $2)`
# Use `const (LLVMOpaque.*) = Cvoid` and replace with `mutable struct $1 end`
# Use `awk '/^[[:blank:]]*$/ { print; next; }; {cur = seen[$0]; if(!seen[$0]++ || (/^end$/ && !prev) || /^.*Clang.*$/) print $0; prev=cur}' libLLVM_h.jl > libLLVM_g.jl` to remove duplicates
# Use `cat -s` to remove duplicate empty lines

target = ARGS[2]
wrap(config, target)
Loading