Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.wav
.ipynb_checkpoints
/Manifest.toml
test/Manifest.toml
/docs/build/
test/build
test/products
test/products
150 changes: 122 additions & 28 deletions gen/Manifest.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gen/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
soapysdr_jll = "343a40d9-ed99-5d34-8b56-649aaa4ecee6"

[compat]
Clang = "0.15"
Clang = "0.18"
soapysdr_jll = "0.8"
12 changes: 0 additions & 12 deletions gen/README.md

This file was deleted.

74 changes: 50 additions & 24 deletions gen/gen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,63 @@

using soapysdr_jll

using Clang
using Clang.Generators

include_dir = joinpath(soapysdr_jll.artifact_dir, "include") |> normpath
clang_dir = joinpath(include_dir, "clang-c")
using JuliaFormatter

options = load_options(joinpath(@__DIR__, "generator.toml"))
function rewriter!(ctx, options)
for node in get_nodes(ctx.dag)
if Generators.is_function(node) && !Generators.is_variadic_function(node)
expr = node.exprs[1]
fn = String(expr.args[1].args[1])
ccall_expr = expr.args[2].args[1] # assumes `use_ccall_macro` is false

@show options
if startswith(fn, "SoapySDRDevice") &&
!in(fn, ["SoapySDRDevice_lastStatus", "SoapySDRDevice_lastError"])
# insert `@soapy_checked` before each function with a `ccall`
expr.args[2].args[1] = Expr(:macrocall, Symbol("@soapy_checked"), nothing, ccall_expr)
end
end
end
end

# add compiler flags, e.g. "-DXXXXXXXXX"
args = get_default_args()
push!(args, "-I$include_dir")
@show args
function main()
include_dir = joinpath(soapysdr_jll.artifact_dir, "include") |> normpath
clang_dir = joinpath(include_dir, "clang-c")

headers = [
joinpath(include_dir, "SoapySDR", header) for
header in readdir(joinpath(include_dir, "SoapySDR")) if endswith(header, ".h")
]
@show headers
@show basename.(headers)
# there is also an experimental `detect_headers` function for auto-detecting top-level headers in the directory
# headers = detect_headers(clang_dir, args)
options = load_options(joinpath(@__DIR__, "generator.toml"))

filter!(s -> basename(s) ∉ ["Config.h"], headers) # Deivce is hand-wrapped and COnfig is not needed
# add compiler flags, e.g. "-DXXXXXXXXX"
args = get_default_args()
push!(args, "-I$include_dir")

# A few macros that don't translate well, and not applicable
options["general"]["output_ignorelist"] = ["SOAPY_SDR_API", "SOAPY_SDR_LOCAL"]
headers = [
joinpath(include_dir, "SoapySDR", header) for
header in readdir(joinpath(include_dir, "SoapySDR")) if endswith(header, ".h")
]
filter!(s -> basename(s) ∉ ["Config.h"], headers)

# create context
@show options
ctx = create_context(headers, args, options)
# create context
ctx = create_context(headers, args, options)

# run generator
build!(ctx)
# run generator
build!(ctx, BUILDSTAGE_NO_PRINTING)
rewriter!(ctx, options)
build!(ctx, BUILDSTAGE_PRINTING_ONLY)

output_file = options["general"]["output_file_path"]

# prepend "autogenerated, do not edit!" comment
output_data = read(output_file, String)
open(output_file, "w") do io
println(io, """# This file is automatically generated. Do not edit!
# To re-generate, execute gen/gen.jl""")
println(io)
print(io, output_data)
end

format_file(output_file)
end

isinteractive() || main()
Loading