-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathconfig-gcc.ncl
94 lines (87 loc) · 2.45 KB
/
config-gcc.ncl
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
# test = 'pass'
# Validate and normalize gcc flags. They can be either a string `-Wextra` or
# a structured value `{flag = "W", arg = "extra"}`. Arguments are not checked.
let
GccFlag =
let supported_flags = ["W", "c", "S", "e", "o"] in
let is_valid_flag
| doc "check if a string of length > 0 is a valid flag"
= fun string =>
std.array.elem (std.string.substring 0 1 string) supported_flags
in
std.contract.custom (fun label =>
match {
value if std.is_string value && is_valid_flag value => 'Ok value,
{ flag, arg } if std.array.elem flag supported_flags =>
# We normalize a record representation to a string
'Ok "%{flag}%{arg}",
value if std.is_string value =>
'Error { message = "unknown flag %{value}" },
{ flag, arg = _ } =>
'Error { message = "unknown flag %{flag}" },
{ .. } =>
'Error {
message = "bad record structure: missing field `flag` or `arg`",
},
_ => 'Error { message = "expected record or string" },
}
),
Path =
let pattern = m%"^(.+)/([^/]+)$"% in
std.contract.from_validator (fun value =>
if std.is_string value then
if std.string.is_match pattern value then
'Ok
else
'Error { message = "invalid path" }
else
'Error { message = "not a string" }
),
SharedObjectFile =
std.contract.from_validator (fun value =>
if std.is_string value then
if std.string.is_match m%"\.so$"% value then
'Ok
else
'Error { message = "not an .so file" }
else
'Error { message = "not a string" }
),
OptLevel =
std.contract.from_predicate (match {
0 or 1 or 2 => true,
_ => false,
}
),
in
let GccConf = {
path_libc
| doc "Path to libc."
| Path
| SharedObjectFile
| default
= "/lib/x86_64-linux-gnu/libc.so",
flags
| doc m%"
Additional flags to pass to GCC. Either provide a string without the
leading `-`, or a structured value `{flag : String, arg: String}`.
"%
| Array GccFlag
| default
= [],
optimization_level
| doc m%"
Optimization level. Possible values:
- *0*: unoptimized
- *1*: normal
- *2*: use optimizations
"%
| OptLevel
| default
= 1,
}
in
{
flags = ["Wextra", { flag = "o", arg = "stuff.o" }],
optimization_level = 2,
} | GccConf