Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Dec 17, 2024
1 parent 73bab9b commit e47ff83
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 96 deletions.
1 change: 0 additions & 1 deletion res/wrap/libmps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
library_name = "libmps"
output_file_path = "../../lib/mps/libmps.jl"
prologue_file_path = "libmps_prologue.jl"
#no_audit = true

printer_blacklist = [
"mt_macCatalyst",
Expand Down
1 change: 0 additions & 1 deletion res/wrap/libmtl.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[general]
library_name = "libmtl"
output_file_path = "../../lib/mtl/libmtl.jl"
no_audit = true

generate_isystem_symbols = false

Expand Down
118 changes: 24 additions & 94 deletions res/wrap/wrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,38 @@ function main(names=["all"]; sdk_path=SDK_PATH)

ctxs = []

if "all" in names
names = ["all"]
if "all" in names || "libmtl" in names || "mtl" in names
fwpath = path_to_framework("Metal")
tctx = wrap("libmtl", joinpath(fwpath, "Metal.h"); defines)
push!(ctxs, tctx)
end

for name in names
if name == "all" || name == "libmtl" || name == "mtl"
fwpath = path_to_framework("Metal")
tctx = wrap("libmtl", joinpath(fwpath, "Metal.h"); targets=glob("*.h", fwpath), defines,
include_dirs=[fwpath])
push!(ctxs, tctx)
end

if name == "all" || name == "libmps" || name == "mps"
mpsframeworks = ["MPSCore", "MPSImage", "MPSMatrix", "MPSNDArray", "MPSNeuralNetwork", "MPSRayIntersector"]
fwpaths = [path_to_framework("MetalPerformanceShaders")]
fwpaths = append!(fwpaths, path_to_mps_framework.(mpsframeworks))
if "all" in names || "libmps" in names || "mps" in names
mpsframeworks = ["MPSCore", "MPSImage", "MPSMatrix", "MPSNDArray", "MPSNeuralNetwork", "MPSRayIntersector"]
fwpaths = [path_to_framework("MetalPerformanceShaders")]
fwpaths = append!(fwpaths, path_to_mps_framework.(mpsframeworks))

getheaderfname(path) = Sys.splitext(Sys.splitpath(path)[end-1])[1] * ".h"
headers = joinpath.(fwpaths, getheaderfname.(fwpaths))

tctx = wrap("libmps", headers; defines,
include_dirs=fwpaths)
push!(ctxs, tctx)
end
getheaderfname(path) = Sys.splitext(Sys.splitpath(path)[end-1])[1] * ".h"
headers = joinpath.(fwpaths, getheaderfname.(fwpaths))

# if name == "all" || name == "libfoundation" || name == "foundation"
# fwpath = path_to_framework("Foundation")
# tctx = wrap("libfoundation", joinpath(foundation, "Foundation.h"); targets=glob("*.h", fwpath), defines=["__builtin_va_list"],
# include_dirs=[fwpath])
# push!(ctxs, tctx)
# end
# if name == "all" || name == "libcf" || name == "cf"
# fwpath = path_to_framework("CoreFoundation")
# tctx = wrap("libfoundation", joinpath(fwpath, "CoreFoundation.h"); targets=glob("*.h", fwpath), defines=["__builtin_va_list"],
# include_dirs=[fwpath])
# push!(ctxs, tctx)
# end
tctx = wrap("libmps", headers; defines)
push!(ctxs, tctx)
end

# if "all" in names || "libfoundation" in names || "foundation" in names
# fwpath = path_to_framework("Foundation")
# tctx = wrap("libfoundation", joinpath(foundation, "Foundation.h");, defines=["__builtin_va_list"])
# push!(ctxs, tctx)
# end
# if "all" in names || "libcf" in names || "cf" in names
# fwpath = path_to_framework("CoreFoundation")
# tctx = wrap("libfoundation", joinpath(fwpath, "CoreFoundation.h");, defines=["__builtin_va_list"])
# push!(ctxs, tctx)
# end
return ctxs
end

function wrap(name, headers; targets=headers, defines=[], include_dirs=[], precomp_header=nothing)
function wrap(name, headers; defines=[])
@info "Wrapping $name"

options = load_options(joinpath(@__DIR__, "$(name).toml"))
Expand Down Expand Up @@ -158,66 +148,6 @@ function create_objc_context(headers::Vector, args::Vector=String[], options::Di
parse_headers!(ctx, headers, args)

Generators.add_default_passes!(ctx, options, system_dirs, dependent_headers)

# push!(ctx.passes, CollectTopLevelNode(ctx.trans_units, dependent_headers, system_dirs))
# push!(ctx.passes, LinkTypedefToAnonymousTagType())
# push!(ctx.passes, LinkTypedefToAnonymousTagType(is_system=true))
# push!(ctx.passes, IndexDefinition())
# push!(ctx.passes, CollectDependentSystemNode())
# push!(ctx.passes, IndexDefinition())
# push!(ctx.passes, CollectNestedRecord())
# push!(ctx.passes, FindOpaques())
# push!(ctx.passes, ResolveDependency(info=false))
# push!(ctx.passes, RemoveCircularReference())
# push!(ctx.passes, TopologicalSort())
# push!(ctx.passes, IndexDefinition())
# push!(ctx.passes, ResolveDependency())
# push!(ctx.passes, CatchDuplicatedAnonymousTags())
# push!(ctx.passes, CodegenPreprocessing())

# general_options = get(options, "general", Dict())
# if get(general_options, "smart_de_anonymize", true)
# push!(ctx.passes, DeAnonymize())
# end
# if get(general_options, "no_audit", false)
# @error "The generator is running in `no_audit` mode. It could generate invalid Julia code. You can remove the `no_audit` entry in the `.toml` file to exit this mode."
# get(general_options, "link_enum_alias", true) && push!(ctx.passes, LinkEnumAlias())
# else
# push!(ctx.passes, Audit())
# end
# push!(ctx.passes, Codegen())
# push!(ctx.passes, CodegenMacro())

# if get(general_options, "add_fptr_methods", false)
# push!(ctx.passes, AddFPtrMethods())
# end
# if get(general_options, "auto_mutability", false)
# push!(ctx.passes, TweakMutability())
# end

# # support old behavior
# api_file = get(general_options, "output_api_file_path", "")
# common_file = get(general_options, "output_common_file_path", "")

# output_file_path = get(general_options, "output_file_path", "")

# if isempty(api_file) && isempty(common_file)
# if !isempty(output_file_path)
# push!(ctx.passes, ProloguePrinter(output_file_path))
# push!(ctx.passes, GeneralPrinter(output_file_path))
# push!(ctx.passes, EpiloguePrinter(output_file_path))
# else
# # print to stdout if there is no `output_file_path`
# # this is handy when playing in REPL
# push!(ctx.passes, StdPrinter())
# end
# else
# # let the user handle prologue and epilogue on their own
# push!(ctx.passes, FunctionPrinter(api_file))
# push!(ctx.passes, CommonPrinter(common_file))
# end

# return ctx
end

function rewriter!(ctx, options)
Expand Down

0 comments on commit e47ff83

Please sign in to comment.