Skip to content

Commit

Permalink
Generated C interface with Clang
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jan 10, 2023
1 parent 873a026 commit 76c45c3
Show file tree
Hide file tree
Showing 7 changed files with 6,541 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manifest.toml
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ name = "ParmaPolyhedra"
uuid = "c52f9019-f606-409c-9f36-a954b424c0b9"
authors = ["Benoît Legat <[email protected]>"]
version = "0.1.0"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
PPL_jll = "80dd9cbb-8b87-5171-a280-372cc418f402"
3 changes: 3 additions & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
PPL_jll = "80dd9cbb-8b87-5171-a280-372cc418f402"
32 changes: 32 additions & 0 deletions gen/gen.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Clang.Generators
using PPL_jll

cd(@__DIR__)

include_dir = normpath(PPL_jll.artifact_dir, "include")

options = load_options(joinpath(@__DIR__, "generator.toml"))

args = get_default_args()
push!(args, "-I$include_dir")

headers = [joinpath(include_dir, header) for header in readdir(include_dir) if endswith(header, ".h")]

ctx = create_context(headers, args, options)

build!(ctx)

function manual_corrections(file)
tmp = tempname()
cp(file, tmp)
open(tmp, "r") do input
open(file, "w") do output
for line in readlines(input)
if !contains(line, "protos") && !contains(line, "PPL_DECLARE_IO_FUNCTIONS")
println(output, line)
end
end
end
end
end
manual_corrections(joinpath(@__DIR__, "..", "src", "gen", "ppl.jl"))
5 changes: 5 additions & 0 deletions gen/generator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[general]
library_name = "ppl"
output_file_path = "../src/gen/ppl.jl"
module_name = "PPL"
jll_pkg_name = "PPL_jll"
2 changes: 1 addition & 1 deletion src/ParmaPolyhedra.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ParmaPolyhedra

greet() = print("Hello World!")
include("gen/ppl.jl")

end # module ParmaPolyhedra
Loading

0 comments on commit 76c45c3

Please sign in to comment.