Skip to content

Commit

Permalink
Fix generator script for static inline functions
Browse files Browse the repository at this point in the history
Also name another anonymous enum.
  • Loading branch information
Gnimuc committed Mar 2, 2021
1 parent 58f7082 commit 3f8ad6f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
22 changes: 11 additions & 11 deletions lib/libLLVM_h.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3371,7 +3371,7 @@ end
LLVMDWARFEmissionLineTablesOnly = 2
end

@cenum var"##Ctag#412"::UInt32 begin
@cenum LLVMMetadataKind_::UInt32 begin
LLVMMDStringMetadataKind = 0
LLVMConstantAsMetadataMetadataKind = 1
LLVMLocalAsMetadataMetadataKind = 2
Expand Down Expand Up @@ -4735,43 +4735,43 @@ mutable struct LLVMOpaqueTargetLibraryInfotData end
const LLVMTargetLibraryInfoRef = Ptr{LLVMOpaqueTargetLibraryInfotData}

function LLVMInitializeAllTargetInfos()
ccall((:LLVMInitializeAllTargetInfos, libllvm[]), Cvoid, ())
ccall(:LLVMInitializeAllTargetInfos, Cvoid, ())
end

function LLVMInitializeAllTargets()
ccall((:LLVMInitializeAllTargets, libllvm[]), Cvoid, ())
ccall(:LLVMInitializeAllTargets, Cvoid, ())
end

function LLVMInitializeAllTargetMCs()
ccall((:LLVMInitializeAllTargetMCs, libllvm[]), Cvoid, ())
ccall(:LLVMInitializeAllTargetMCs, Cvoid, ())
end

function LLVMInitializeAllAsmPrinters()
ccall((:LLVMInitializeAllAsmPrinters, libllvm[]), Cvoid, ())
ccall(:LLVMInitializeAllAsmPrinters, Cvoid, ())
end

function LLVMInitializeAllAsmParsers()
ccall((:LLVMInitializeAllAsmParsers, libllvm[]), Cvoid, ())
ccall(:LLVMInitializeAllAsmParsers, Cvoid, ())
end

function LLVMInitializeAllDisassemblers()
ccall((:LLVMInitializeAllDisassemblers, libllvm[]), Cvoid, ())
ccall(:LLVMInitializeAllDisassemblers, Cvoid, ())
end

function LLVMInitializeNativeTarget()
ccall((:LLVMInitializeNativeTarget, libllvm[]), LLVMBool, ())
ccall(:LLVMInitializeNativeTarget, LLVMBool, ())
end

function LLVMInitializeNativeAsmParser()
ccall((:LLVMInitializeNativeAsmParser, libllvm[]), LLVMBool, ())
ccall(:LLVMInitializeNativeAsmParser, LLVMBool, ())
end

function LLVMInitializeNativeAsmPrinter()
ccall((:LLVMInitializeNativeAsmPrinter, libllvm[]), LLVMBool, ())
ccall(:LLVMInitializeNativeAsmPrinter, LLVMBool, ())
end

function LLVMInitializeNativeDisassembler()
ccall((:LLVMInitializeNativeDisassembler, libllvm[]), LLVMBool, ())
ccall(:LLVMInitializeNativeDisassembler, LLVMBool, ())
end

function LLVMGetModuleDataLayout(M)
Expand Down
59 changes: 35 additions & 24 deletions res/wrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ using Clang.Generators

@add_def off_t

function rewriter!(ctx)
# 1. replace `ccall` with `@runtime_ccall`
# 2. remove libname for static inline functions (there is no exported symbol for them in the shared library.)
static_inlines = [
:LLVMInitializeAllTargetInfos,
:LLVMInitializeAllTargets,
:LLVMInitializeAllTargetMCs,
:LLVMInitializeAllAsmPrinters,
:LLVMInitializeAllAsmParsers,
:LLVMInitializeAllDisassemblers,
:LLVMInitializeNativeTarget,
:LLVMInitializeNativeAsmPrinter,
:LLVMInitializeNativeAsmParser,
:LLVMInitializeNativeDisassembler,
]
for node in get_nodes(ctx.dag)
Generators.is_function(node) || continue
if !Generators.is_variadic_function(node)
expr = node.exprs[1]
call_expr = expr.args[2].args[1]
if expr.args[1].args[1] static_inlines
call_expr.args[2] = call_expr.args[2].args[1]
else
call_expr.head = :macrocall
call_expr.args[1] = Symbol("@runtime_ccall")
insert!(call_expr.args, 2, nothing)
end
end
end
end

function main()
options = load_options(joinpath(@__DIR__, "wrap.toml"))

Expand Down Expand Up @@ -41,32 +72,12 @@ function main()

build!(ctx, BUILDSTAGE_NO_PRINTING)

# replace `ccall` with `@runtime_ccall`
blacklist = [
:LLVMInitializeAllTargetInfos,
:LLVMInitializeAllTargets,
:LLVMInitializeAllTargetMCs,
:LLVMInitializeAllAsmPrinters,
:LLVMInitializeAllAsmParsers,
:LLVMInitializeAllDisassemblers,
:LLVMInitializeNativeTarget,
:LLVMInitializeNativeAsmPrinter,
:LLVMInitializeNativeAsmParser,
:LLVMInitializeNativeDisassembler,
]
for node in get_nodes(ctx.dag)
Generators.is_function(node) || continue
if !Generators.is_variadic_function(node)
expr = node.exprs[1]
expr.args[1].args[1] blacklist && continue
call_expr = expr.args[2].args[1]
call_expr.head = :macrocall
call_expr.args[1] = Symbol("@runtime_ccall")
insert!(call_expr.args, 2, nothing)
end
end
rewriter!(ctx)

build!(ctx, BUILDSTAGE_PRINTING_ONLY)
end

isinteractive() || main()

# manually clean up
# * search `##Ctag`-prefixed enums and give them a name

0 comments on commit 3f8ad6f

Please sign in to comment.