-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Gnimuc/regenerate
Test Clang.jl's new generator
- Loading branch information
Showing
10 changed files
with
6,873 additions
and
6,795 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,28 @@ | ||
using Clang | ||
using Clang.Generators | ||
using CImGui.LibCImGui.CImGui_jll | ||
|
||
const CIMGUI_H = joinpath(dirname(CImGui_jll.libcimgui_path), "..", "include", "cimgui.h") |> normpath | ||
|
||
# create a work context | ||
ctx = DefaultContext() | ||
|
||
# parse headers | ||
parse_headers!(ctx, [CIMGUI_H], args=[map(x->"-I"*x, find_std_headers())..., "-DCIMGUI_DEFINE_ENUMS_AND_STRUCTS"], includes=[LLVM_INCLUDE]) | ||
|
||
# settings | ||
ctx.libname = "libcimgui" | ||
ctx.options["is_function_strictly_typed"] = false | ||
ctx.options["is_struct_mutable"] = false | ||
|
||
# write output | ||
api_file = joinpath(@__DIR__, "libcimgui_api.jl") | ||
api_stream = open(api_file, "w") | ||
|
||
for trans_unit in ctx.trans_units | ||
root_cursor = getcursor(trans_unit) | ||
push!(ctx.cursor_stack, root_cursor) | ||
header = spelling(root_cursor) | ||
@info "wrapping header: $header ..." | ||
# loop over all of the child cursors and wrap them, if appropriate. | ||
ctx.children = children(root_cursor) | ||
for (i, child) in enumerate(ctx.children) | ||
child_name = name(child) | ||
child_header = filename(child) | ||
ctx.children_index = i | ||
# choose which cursor to wrap | ||
startswith(child_name, "__") && continue # skip compiler definitions | ||
child_name in keys(ctx.common_buffer) && continue # already wrapped | ||
child_header != header && continue # skip if cursor filename is not in the headers to be wrapped | ||
|
||
wrap!(ctx, child) | ||
end | ||
@info "writing $(api_file)" | ||
println(api_stream, "# Julia wrapper for header: $(basename(header))") | ||
println(api_stream, "# Automatically generated using Clang.jl\n") | ||
print_buffer(api_stream, ctx.api_buffer) | ||
empty!(ctx.api_buffer) # clean up api_buffer for the next header | ||
end | ||
close(api_stream) | ||
include_dir = joinpath(CImGui_jll.artifact_dir, "include") | ||
|
||
const CIMGUI_H = joinpath(include_dir, "cimgui.h") |> normpath | ||
const HELPER_H = joinpath(include_dir, "helper.h") |> normpath | ||
|
||
options = load_options(joinpath(@__DIR__, "libcimgui.toml")) | ||
|
||
# write "common" definitions: types, typealiases, etc. | ||
common_file = joinpath(@__DIR__, "libcimgui_common.jl") | ||
open(common_file, "w") do f | ||
println(f, "# Automatically generated using Clang.jl\n") | ||
print_buffer(f, dump_to_buffer(ctx.common_buffer)) | ||
args = ["-I$include_dir", "-DCIMGUI_DEFINE_ENUMS_AND_STRUCTS"] | ||
|
||
ctx = create_context([CIMGUI_H, HELPER_H], args, options) | ||
|
||
build!(ctx, BUILDSTAGE_NO_PRINTING) | ||
|
||
for node in get_nodes(ctx.dag) | ||
file = get_filename(node.cursor) | ||
file == HELPER_H || continue | ||
Generators.is_function(node) || continue | ||
if !Generators.is_variadic_function(node) | ||
expr = node.exprs[1] | ||
expr.args[2].args[1].args[2].args[2] = :libcimgui_helper | ||
end | ||
end | ||
|
||
# uncomment the following code to generate dependency and template files | ||
# copydeps(dirname(api_file)) | ||
# print_template(joinpath(dirname(api_file), "LibTemplate.jl")) | ||
build!(ctx, BUILDSTAGE_PRINTING_ONLY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[general] | ||
library_name = "libcimgui" | ||
output_file_path = "./src/LibCImGui.jl" | ||
module_name = "LibCImGui" | ||
jll_pkg_name = "CImGui_jll" | ||
export_symbol_prefixes = ["ig", "Im"] | ||
prologue_file_path = "" | ||
epilogue_file_path = "./gen/epilogue.jl" | ||
|
Oops, something went wrong.