Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
caisar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
caisar
Commits
353db2ec
Commit
353db2ec
authored
2 years ago
by
Michele Alberti
Browse files
Options
Downloads
Patches
Plain Diff
[cmdline] Simplify code for handling time and memory limits.
parent
cc4e446a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.ml
+33
-50
33 additions, 50 deletions
src/main.ml
with
33 additions
and
50 deletions
src/main.ml
+
33
−
50
View file @
353db2ec
...
...
@@ -87,59 +87,42 @@ let config detect () =
Whyconf
.
print_prover
Pp
.
nothing
)
provers
))
(* conversion string -> int for memlimit and timeout *)
(* auxiliary functions, TODO move to a better place *)
(* first, find the first non-numerical character, and return a couple of
substrings *)
let
rec
find_first_non_num
(
s
:
string
)
(
i
:
int
)
(
m
:
int
)
=
(* MUST be called with m = String.length s*)
if
i
>=
m
then
i
else
match
s
.
[
i
]
with
|
'
0
'
|
'
1
'
|
'
2
'
|
'
3
'
|
'
4
'
|
'
5
'
|
'
6
'
|
'
7
'
|
'
8
'
|
'
9
'
->
find_first_non_num
s
(
i
+
1
)
m
|
_
->
i
let
split_non_num
(
s
:
string
)
=
let
m
=
String
.
length
s
in
let
x
=
find_first_non_num
s
0
m
in
if
x
=
m
then
(
s
,
""
)
else
(
String
.
sub
s
~
pos
:
0
~
len
:
x
,
String
.
sub
s
~
pos
:
x
~
len
:
(
m
-
x
))
let
find_mult_memlimit
=
function
|
""
->
1
|
"M"
|
"MB"
|
"mega"
|
"megabytes"
->
1
|
"G"
|
"GB"
|
"giga"
|
"gigabytes"
->
1000
|
"T"
|
"TB"
|
"tera"
|
"terabytes"
->
1000000
|
_
->
failwith
"Unknown unit for memory limit"
let
find_mult_timeout
=
function
|
""
->
1
|
"s"
|
"seconds"
->
1
|
"min"
|
"minutes"
->
60
|
"h"
|
"hours"
->
3600
|
_
->
failwith
"Unknown unit for timeout"
let
convert_memlimit
(
s
:
string
option
)
:
int
option
=
match
s
with
|
None
->
None
|
Some
s
->
let
mem1
,
mem2
=
split_non_num
(
String
.
strip
s
)
in
Some
(
Int
.
of_string
mem1
*
find_mult_memlimit
mem2
)
let
memlimit_of_string
s
=
let
s
=
String
.
strip
s
in
let
value
=
let
re
=
Re__Pcre
.
regexp
"[0-9]+"
in
Re__Core
.
matches
re
s
in
let
unit
=
let
re
=
Re__Pcre
.
regexp
"MB?|GB?|TB?"
in
Re__Core
.
matches
re
s
in
match
(
value
,
unit
)
with
|
[
v
]
,
([]
|
[
"M"
]
|
[
"MB"
])
->
Int
.
of_string
v
|
[
v
]
,
([
"G"
]
|
[
"GB"
])
->
Int
.
of_string
v
*
1000
|
[
v
]
,
([
"T"
]
|
[
"TB"
])
->
Int
.
of_string
v
*
1000000
|
_
->
failwith
"Unrecognized memory limit"
let
convert_timelimit
s
=
match
s
with
|
None
->
None
|
Some
s
->
let
time1
,
time2
=
split_non_num
(
String
.
strip
s
)
in
Some
(
Int
.
of_string
time1
*
find_mult_timeout
time2
)
let
timelimit_of_string
s
=
let
s
=
String
.
strip
s
in
let
value
=
let
re
=
Re__Pcre
.
regexp
"[0-9]+"
in
Re__Core
.
matches
re
s
in
let
unit
=
let
re
=
Re__Pcre
.
regexp
"[a-z]"
in
Re__Core
.
matches
re
s
in
match
(
value
,
unit
)
with
|
[
v
]
,
([]
|
[
"s"
])
->
Int
.
of_string
v
|
[
v
]
,
[
"m"
]
->
Int
.
of_string
v
*
60
|
[
v
]
,
[
"h"
]
->
Int
.
of_string
v
*
3600
|
_
->
failwith
"Unrecognized time limit"
let
verify
format
loadpath
memlimit
time
ou
t
prover
dataset_csv
files
=
let
verify
format
loadpath
memlimit
time
limi
t
prover
dataset_csv
files
=
let
debug
=
log_level_is_debug
()
in
let
memlimit
=
convert_
memlimit
memlimit
in
let
timelimit
=
convert_
timelimit
time
out
in
let
memlimit
=
Option
.
map
memlimit
~
f
:
memlimit
_of_string
in
let
timelimit
=
Option
.
map
timelimit
~
f
:
time
limit_of_string
in
List
.
iter
~
f
:
(
Verification
.
verify
~
debug
format
loadpath
?
memlimit
?
timelimit
prover
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment