-
Notifications
You must be signed in to change notification settings - Fork 16
/
wrapper.jl
125 lines (99 loc) · 4.17 KB
/
wrapper.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Script to parse HSL headers and generate Julia wrappers.
using HSL_jll
using Clang
using Clang.Generators
using JuliaFormatter
include("rewriter.jl")
function wrapper(name::String, headers::Vector{String}, optimized::Bool)
@info "Wrapping $name"
cd(@__DIR__)
include_dir = joinpath(HSL_jll.artifact_dir, "include", "libhsl")
options = load_options(joinpath(@__DIR__, "hsl.toml"))
options["general"]["output_file_path"] = joinpath("..", "src", "C", "$(name).jl")
if name != "libhsl"
solver = split(name, "_")[2]
optimized && (options["general"]["output_ignorelist"] = ["$(solver)realtype_[sdcz]_\$",
"$(solver)pkgtype_[sdcz]_\$",
"$(solver)pkgtype_[il]_\$",
"$(solver)_pkgtype_[il]_\$",
"$(solver)cntltype_[sdcz]_\$",
"$(solver)_control_[dczl]\$",
"$(solver)_info_[dczl]\$",
"$(solver)_[afs]info_d\$",
"$(solver)_solve_control_d\$"])
end
args = get_default_args()
push!(args, "-I$include_dir")
ctx = create_context(headers, args, options)
build!(ctx)
path = options["general"]["output_file_path"]
(name != "libhsl") && format_file(path, YASStyle())
rewrite!(path, name, optimized)
return nothing
end
function hsl_headers(include::String, package::String, precisions::Vector{Char})
headers = [joinpath(include, package) * precision * ".h" for precision in precisions]
return headers
end
function main(name::String="all"; optimized::Bool=false)
include = joinpath(HSL_jll.artifact_dir, "include", "libhsl")
if name == "all" || name == "libhsl"
wrapper("libhsl", [joinpath(include, "libhsl.h")], optimized)
end
if name == "all" || name == "hsl_ma48"
precisions = ['s', 'd']
wrapper("hsl_ma48", hsl_headers(include, "hsl_ma48", precisions), optimized)
end
if name == "all" || name == "hsl_ma57"
precisions = ['s', 'd']
wrapper("hsl_ma57", hsl_headers(include, "hsl_ma57", precisions), optimized)
end
if name == "all" || name == "hsl_ma77"
precisions = ['s', 'd']
wrapper("hsl_ma77", hsl_headers(include, "hsl_ma77", precisions), optimized)
end
if name == "all" || name == "hsl_ma86"
precisions = ['s', 'd', 'c', 'z']
wrapper("hsl_ma86", hsl_headers(include, "hsl_ma86", precisions), optimized)
end
if name == "all" || name == "hsl_ma87"
precisions = ['s', 'd', 'c', 'z']
wrapper("hsl_ma87", hsl_headers(include, "hsl_ma87", precisions), optimized)
end
if name == "all" || name == "hsl_ma97"
precisions = ['s', 'd', 'c', 'z']
wrapper("hsl_ma97", hsl_headers(include, "hsl_ma97", precisions), optimized)
end
if name == "all" || name == "hsl_mc64"
precisions = ['s', 'd', 'c', 'z']
wrapper("hsl_mc64", hsl_headers(include, "hsl_mc64", precisions), optimized)
end
if name == "all" || name == "hsl_mc68"
precisions = ['i']
wrapper("hsl_mc68", hsl_headers(include, "hsl_mc68", precisions), optimized)
end
if name == "all" || name == "hsl_mc69"
precisions = ['s', 'd', 'c', 'z']
wrapper("hsl_mc69", hsl_headers(include, "hsl_mc69", precisions), optimized)
end
if name == "all" || name == "hsl_mc78"
precisions = ['i', 'l']
wrapper("hsl_mc78", hsl_headers(include, "hsl_mc78", precisions), optimized)
end
if name == "all" || name == "hsl_mc79"
precisions = ['i']
wrapper("hsl_mc79", hsl_headers(include, "hsl_mc79", precisions), optimized)
end
if name == "all" || name == "hsl_mi20"
precisions = ['s', 'd']
wrapper("hsl_mi20", hsl_headers(include, "hsl_mi20", precisions), optimized)
end
if name == "all" || name == "hsl_mi28"
precisions = ['s', 'd']
wrapper("hsl_mi28", hsl_headers(include, "hsl_mi28", precisions), optimized)
end
end
# If we want to use the file as a script with `julia wrapper.jl`
if abspath(PROGRAM_FILE) == @__FILE__
main()
end