-
Notifications
You must be signed in to change notification settings - Fork 9
/
print_opensparc_graphs.ml
56 lines (49 loc) · 2.51 KB
/
print_opensparc_graphs.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
(******************************************************************************)
(* PipeCheck: Specifying and Verifying Microarchitectural *)
(* Enforcement of Memory Consistency Models *)
(* *)
(* Copyright (c) 2014 Daniel Lustig, Princeton University *)
(* All rights reserved. *)
(* *)
(* This library is free software; you can redistribute it and/or *)
(* modify it under the terms of the GNU Lesser General Public *)
(* License as published by the Free Software Foundation; either *)
(* version 2.1 of the License, or (at your option) any later version. *)
(* *)
(* This library is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Lesser General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Lesser General Public *)
(* License along with this library; if not, write to the Free Software *)
(* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *)
(* USA *)
(******************************************************************************)
open Printf
open Opensparcgraphs2
let rec stringOfString s =
match s with
| String (c, s') -> String.make 1 c ^ stringOfString s'
| EmptyString -> ""
let printableCharOf c =
if (
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
(c == '-') ||
(c == '_'))
then c
else '_'
let graphFilename t n =
"graphs/" ^ (sprintf "%02d" n) ^ "_" ^
(String.map printableCharOf (stringOfString t)) ^ ".gv"
let rec printCase n l =
match l with
| Pair (title, graph) :: t ->
let oc = open_out (graphFilename title n) in
fprintf oc "%s" (stringOfString graph);
close_out oc;
printCase (n+1) t
| [] -> print_string "Output "; print_int n; print_string " graphs\n"
let _ = printCase 0 Opensparcgraphs2.allGraphs