Skip to content

Commit

Permalink
Add cleanup rules in wrapper script
Browse files Browse the repository at this point in the history
  • Loading branch information
emmt committed Sep 22, 2023
1 parent 0dd233b commit 2980311
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
20 changes: 20 additions & 0 deletions gen/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ function main()
build!(ctx)

path = options["general"]["output_file_path"]
code = readlines(path)
for repl in [
# Simplify the name of non-exported but public symbols (they will be
# prefixed by the module name).
r"\bprima_message\b" => "Message",
r"\bprima_rc\b" => "Status",
r"\bPRIMA_" => "",
# Make enum signed (see PRIMA library doc. about negative `iprint`
# values).
r"^(\s*@enum\s+\w+)\s*::\s*U(Int[0-9]*)\s+begin\s*$" => s"\1::\2 begin",
# Remove some useless code.
r"^\s*const\s+PRIMAC_API\s*=.*$" => "",
]
for i in eachindex(code)
code[i] = replace(code[i], repl)
end
end
open(path, "w") do io
foreach(line -> println(io, line), code)
end
format_file(path, YASStyle())
return nothing
end
Expand Down
16 changes: 11 additions & 5 deletions src/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,38 @@ function prima_get_rc_string(rc)
@ccall libprimac.prima_get_rc_string(rc::Cint)::Cstring
end

# typedef void ( * prima_obj ) ( const double x [ ] , double * f )
const prima_obj = Ptr{Cvoid}

# typedef void ( * prima_objcon ) ( const double x [ ] , double * f , double constr [ ] )
const prima_objcon = Ptr{Cvoid}

function prima_bobyqa(calfun, n, x, f, xl, xu, nf, rhobeg, rhoend, ftarget, maxfun, npt,
iprint)
@ccall libprimac.prima_bobyqa(calfun::Ptr{Cvoid}, n::Cint, x::Ptr{Cdouble},
@ccall libprimac.prima_bobyqa(calfun::prima_obj, n::Cint, x::Ptr{Cdouble},
f::Ptr{Cdouble}, xl::Ptr{Cdouble}, xu::Ptr{Cdouble},
nf::Ptr{Cint}, rhobeg::Cdouble, rhoend::Cdouble,
ftarget::Cdouble, maxfun::Cint, npt::Cint,
iprint::Cint)::Cint
end

function prima_newuoa(calfun, n, x, f, nf, rhobeg, rhoend, ftarget, maxfun, npt, iprint)
@ccall libprimac.prima_newuoa(calfun::Ptr{Cvoid}, n::Cint, x::Ptr{Cdouble},
@ccall libprimac.prima_newuoa(calfun::prima_obj, n::Cint, x::Ptr{Cdouble},
f::Ptr{Cdouble}, nf::Ptr{Cint}, rhobeg::Cdouble,
rhoend::Cdouble, ftarget::Cdouble, maxfun::Cint,
npt::Cint, iprint::Cint)::Cint
end

function prima_uobyqa(calfun, n, x, f, nf, rhobeg, rhoend, ftarget, maxfun, iprint)
@ccall libprimac.prima_uobyqa(calfun::Ptr{Cvoid}, n::Cint, x::Ptr{Cdouble},
@ccall libprimac.prima_uobyqa(calfun::prima_obj, n::Cint, x::Ptr{Cdouble},
f::Ptr{Cdouble}, nf::Ptr{Cint}, rhobeg::Cdouble,
rhoend::Cdouble, ftarget::Cdouble, maxfun::Cint,
iprint::Cint)::Cint
end

function prima_cobyla(m_nlcon, calcfc, n, x, f, cstrv, nlconstr, m_ineq, Aineq, bineq, m_eq,
Aeq, beq, xl, xu, nf, rhobeg, rhoend, ftarget, maxfun, iprint)
@ccall libprimac.prima_cobyla(m_nlcon::Cint, calcfc::Ptr{Cvoid}, n::Cint,
@ccall libprimac.prima_cobyla(m_nlcon::Cint, calcfc::prima_objcon, n::Cint,
x::Ptr{Cdouble}, f::Ptr{Cdouble}, cstrv::Ptr{Cdouble},
nlconstr::Ptr{Cdouble}, m_ineq::Cint, Aineq::Ptr{Cdouble},
bineq::Ptr{Cdouble}, m_eq::Cint, Aeq::Ptr{Cdouble},
Expand All @@ -63,7 +69,7 @@ end

function prima_lincoa(calfun, n, x, f, cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu,
nf, rhobeg, rhoend, ftarget, maxfun, npt, iprint)
@ccall libprimac.prima_lincoa(calfun::Ptr{Cvoid}, n::Cint, x::Ptr{Cdouble},
@ccall libprimac.prima_lincoa(calfun::prima_obj, n::Cint, x::Ptr{Cdouble},
f::Ptr{Cdouble}, cstrv::Ptr{Cdouble}, m_ineq::Cint,
Aineq::Ptr{Cdouble}, bineq::Ptr{Cdouble}, m_eq::Cint,
Aeq::Ptr{Cdouble}, beq::Ptr{Cdouble}, xl::Ptr{Cdouble},
Expand Down

0 comments on commit 2980311

Please sign in to comment.