Skip to content

Commit 76f8388

Browse files
committed
Rewrite function pointer expressions
1 parent 464b06e commit 76f8388

File tree

5 files changed

+1315
-1279
lines changed

5 files changed

+1315
-1279
lines changed

Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ uuid = "66fc600b-dfda-50eb-8b99-91cfa97b1301"
33
version = "1.1.4"
44

55
[deps]
6+
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
67
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
78

89
[compat]

gen/generator.jl

+23-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,26 @@ options["general"]["output_file_path"] = joinpath(@__DIR__, "..", "src", "gl.jl"
1515

1616
ctx = create_context(GL_HEADERS, args, options)
1717

18-
build!(ctx)
18+
build!(ctx, BUILDSTAGE_NO_PRINTING)
19+
20+
# custom rewriter
21+
function rewrite!(dag::ExprDAG)
22+
for node in get_nodes(dag)
23+
node.type isa Generators.AbstractFunctionNodeType || continue
24+
for expr in node.exprs
25+
Meta.isexpr(expr, :function) || continue
26+
for block_expr in expr.args
27+
Meta.isexpr(block_expr, :block) || continue
28+
for ccall_expr in block_expr.args
29+
Meta.isexpr(ccall_expr, :call) || continue
30+
ccall_expr.args[2] = :(getprocaddress_e($(string(node.id))))
31+
end
32+
end
33+
end
34+
end
35+
end
36+
37+
rewrite!(ctx.dag)
38+
39+
# print
40+
build!(ctx, BUILDSTAGE_PRINTING_ONLY)

gen/generator.toml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ output_ignorelist = [
55
"APIENTRYP",
66
]
77

8+
export_symbol_prefixes = ["GL", "gl"]
9+
810
use_deterministic_symbol = true
911

1012
[codegen.macro]

src/ModernGL.jl

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module ModernGL
22

33
using Libdl
4+
using CEnum
45

56
function glXGetProcAddress(glFuncName)
67
ccall((:glXGetProcAddress, "libGL.so.1"), Ptr{Cvoid}, (Ptr{UInt8},), glFuncName)
@@ -93,5 +94,6 @@ end
9394
include("glTypes.jl")
9495
include("functionloading.jl")
9596
include("glConstants.jl")
97+
include("gl.jl")
9698

9799
end # module

0 commit comments

Comments
 (0)