Skip to content
Snippets Groups Projects
Commit 1b442110 authored by Volker Neff's avatar Volker Neff
Browse files

add script to create automatic an julia Interface

parent c0c33a03
No related branches found
No related tags found
No related merge requests found
using Clang
const LIBCDI_H = joinpath(dirname("./../../bin/"), "include", "cdi.h") |> normpath
# create a work context
ctx = DefaultContext()
# parse headers
parse_headers!(ctx, [LIBCDI_H], args=[map(x->"-I"*x, find_std_headers())..., ""], includes=[LLVM_INCLUDE])
# settings
ctx.libname = "libcdi"
ctx.options["is_function_strictly_typed"] = false
ctx.options["is_struct_mutable"] = false
# write output
api_file = joinpath(@__DIR__, "libcdi_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)
# write "common" definitions: types, typealiases, etc.
common_file = joinpath(@__DIR__, "libcdi_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))
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment