Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libcdi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
libcdi
Commits
1b442110
Commit
1b442110
authored
4 years ago
by
Volker Neff
Browse files
Options
Downloads
Patches
Plain Diff
add script to create automatic an julia Interface
parent
c0c33a03
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
interfaces/julia/cdi2julia.jl
+51
-0
51 additions, 0 deletions
interfaces/julia/cdi2julia.jl
with
51 additions
and
0 deletions
interfaces/julia/cdi2julia.jl
0 → 100644
+
51
−
0
View file @
1b442110
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment