-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.ml
80 lines (73 loc) · 3.11 KB
/
main.ml
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
(* Copyright 2020 Maria A Schett and Julian Nagele
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
open Core
open Ppltr
type mode =
| BLOCK_GEN
| WINDOW_GEN
| OPTZ_GEN
| RULE_GEN
| BLOCK_RW
| RULE_RW
| CONTRACT_RW
[@@deriving show { with_path = false }]
let mode_of_string = function
| "BG" -> BLOCK_GEN
| "WG" -> WINDOW_GEN
| "OG" -> OPTZ_GEN
| "RG" -> RULE_GEN
| "BR" -> BLOCK_RW
| "RR" -> RULE_RW
| "CR" -> CONTRACT_RW
| _ -> failwith "Unknown mode"
let get_rules rs = Option.value_exn ~message:"No rules given for rewriting" rs
let () =
let open Command.Let_syntax in
Command.basic ~summary:"ppltr: A PoPuLaToR for a PeePhoLe opTimizeR of EVM bytecode"
[%map_open
let in_csv = anon ("INPUT" %: string)
and out_csv = anon ("OUTPUT" %: string)
and rules = flag "rules" (optional string)
~doc:"csv file containing rules for rewriting (use with mode BR/RR/CR)"
and out_rew_only = flag "out-rewritten-only" no_arg
~doc:"only output rows that were rewritten (use with mode BR/RR/CR)"
and peephole_sz = flag "peephole-size" (optional_with_default 6 int)
~doc:"sz maximal size of the peephole window (default: 6)"
and stats_dir = flag "dir" (optional_with_default "" string)
~doc:"dir directory to write the stats files (ending with /)"
and mode = flag "mode"
(required (Arg_type.create mode_of_string))
~doc:"mode: BG .. Generate ebso Blocks\n
WG .. Generate Windowed blocks of maximal -peehole_sz\n
OG .. prepare Optimizations Generated by ebso for sorg\n
RG .. analyze and deduplicate Rules Generated by sorg\n
BR .. Rewrite Blocks\n
RR .. Rewrite Right-hand sides of rules
CR .. Rewrite Contracts and gather statistics"
in
fun () ->
match mode with
| BLOCK_GEN -> Blk_generator.write_blks in_csv out_csv
| WINDOW_GEN -> Blk_generator.write_windowed_blks in_csv out_csv peephole_sz
| OPTZ_GEN -> Optz_generator.write_optz in_csv out_csv
| RULE_GEN ->
let (rules, stats) = Rule_generator.compute_results in_csv in
Rule_generator.write_rules out_csv rules;
Rule_generator.print_stats stats rules stats_dir
| BLOCK_RW ->
Rewriter.process_blocks in_csv (get_rules rules) out_csv out_rew_only
| RULE_RW ->
Rewriter.process_rules in_csv (get_rules rules) out_csv out_rew_only
| CONTRACT_RW ->
Rewriter.process_contracts in_csv (get_rules rules) out_csv out_rew_only
]
|> Command.run ~version:"1.0"