Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to control outputting of system code #485

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Clang"
uuid = "40e3b903-d033-50b4-a0cc-940c62c95e31"
version = "0.18.1"
version = "0.18.2"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down
30 changes: 22 additions & 8 deletions src/generator/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,10 @@ function (x::Audit)(dag::ExprDAG, options::Dict)
return dag
end

function should_exclude_node(node, ignorelist, exclusivelist)
function should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist=[])
str_node = string(node.id)
str_node ∈ isystem_ignorelist && return true

for item ∈ ignorelist
the_match = match(Regex(item), str_node)
if the_match !== nothing && the_match.match == str_node
Expand Down Expand Up @@ -944,10 +946,13 @@ function (x::FunctionPrinter)(dag::ExprDAG, options::Dict)
ignorelist = get(general_options, "output_ignorelist", get(general_options, "printer_blacklist", []))
exclusivelist = get(general_options, "output_exclusivelist", nothing)

isystem_ignorelist = []
!get(general_options, "generate_isystem_symbols", true) && append!(isystem_ignorelist, string(x.id) for x in dag.sys)

show_info && @info "[FunctionPrinter]: print to $(x.file)"
open(x.file, "w") do io
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractFunctionNodeType || continue
pretty_print(io, node, general_options)
end
Expand All @@ -972,16 +977,19 @@ function (x::CommonPrinter)(dag::ExprDAG, options::Dict)
ignorelist = get(general_options, "output_ignorelist", get(general_options, "printer_blacklist", []))
exclusivelist = get(general_options, "output_exclusivelist", nothing)

isystem_ignorelist = []
!get(general_options, "generate_isystem_symbols", true) && append!(isystem_ignorelist, string(x.id) for x in dag.sys)

show_info && @info "[CommonPrinter]: print to $(x.file)"
open(x.file, "w") do io
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
(node.type isa AbstractMacroNodeType || node.type isa AbstractFunctionNodeType) && continue
pretty_print(io, node, general_options)
end
# print macros in the bottom of the file
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractMacroNodeType || continue
pretty_print(io, node, options)
end
Expand All @@ -1007,16 +1015,19 @@ function (x::GeneralPrinter)(dag::ExprDAG, options::Dict)
general_options["DAG_ids"] = merge(dag.ids, dag.tags)
exclusivelist = get(general_options, "output_exclusivelist", nothing)

isystem_ignorelist = []
!get(general_options, "generate_isystem_symbols", true) && append!(isystem_ignorelist, string(x.id) for x in dag.sys)

show_info && @info "[GeneralPrinter]: print to $(x.file)"
open(x.file, "a") do io
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractMacroNodeType && continue
pretty_print(io, node, general_options)
end
# print macros in the bottom of the file
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractMacroNodeType || continue
isempty(node.exprs)
pretty_print(io, node, options)
Expand All @@ -1043,14 +1054,17 @@ function (x::StdPrinter)(dag::ExprDAG, options::Dict)
ignorelist = get(general_options, "output_ignorelist", get(general_options, "printer_blacklist", []))
exclusivelist = get(general_options, "output_exclusivelist", nothing)

isystem_ignorelist = []
!get(general_options, "generate_isystem_symbols", true) && append!(isystem_ignorelist, string(x.id) for x in dag.sys)

for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractMacroNodeType && continue
pretty_print(stdout, node, general_options)
end
# print macros
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractMacroNodeType || continue
pretty_print(stdout, node, options)
end
Expand Down
Loading