From 86f973d82fc54e6189a820232d9537f8d693767a Mon Sep 17 00:00:00 2001 From: melonedo <44501064+melonedo@users.noreply.github.com> Date: Sat, 28 Aug 2021 15:48:38 +0800 Subject: [PATCH] Support common and API file --- gen/generator.toml | 5 +++++ src/generator/context.jl | 8 +++++++- src/generator/passes.jl | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gen/generator.toml b/gen/generator.toml index 794a2cb0..0fbbe454 100644 --- a/gen/generator.toml +++ b/gen/generator.toml @@ -14,6 +14,11 @@ library_names = {} # output file path relative to the working directory output_file_path = "../lib/LibClang.jl" +# if these are set, common file (types and constants) and API file (functions) will be seperated +# this is for compatibility, so prologue and epilogue are not supported. +# output_api_file_path = "api.jl" +# output_common_file_path = "common.jl" + # if this entry is not empty, the generator will print the code below to the `output_file_path`. # module module_name # diff --git a/src/generator/context.jl b/src/generator/context.jl index 2a4f8bea..256bdb8f 100644 --- a/src/generator/context.jl +++ b/src/generator/context.jl @@ -136,7 +136,9 @@ function create_context(headers::Vector, args::Vector=String[], options::Dict=Di push!(ctx.passes, StdPrinter()) end else - # TODO: impl + # 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 @@ -157,6 +159,10 @@ Run all passes. function build!(ctx::Context, stage=BUILDSTAGE_ALL) reset_counter() for pass in ctx.passes + if pass isa ResolveDependency + println("hello") + end + pass isa CollectDependentSystemNode && stage != BUILDSTAGE_PRINTING_ONLY && @info "Building the DAG..." pass isa Codegen && stage != BUILDSTAGE_PRINTING_ONLY && @info "Emit Julia expressions..." if stage == BUILDSTAGE_NO_PRINTING diff --git a/src/generator/passes.jl b/src/generator/passes.jl index 588b99b3..5324a511 100644 --- a/src/generator/passes.jl +++ b/src/generator/passes.jl @@ -873,7 +873,7 @@ function (x::CommonPrinter)(dag::ExprDAG, options::Dict) open(x.file, "w") do io for node in dag.nodes string(node.id) ∈ blacklist && continue - node.type isa AbstractMacroNodeType && 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