-
Notifications
You must be signed in to change notification settings - Fork 3
/
execlexer.mll
227 lines (211 loc) · 9.51 KB
/
execlexer.mll
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
(*========================================================================*)
(* *)
(* cppmem model exploration tool *)
(* *)
(* Mark Batty *)
(* Scott Owens *)
(* Jean Pichon *)
(* Susmit Sarkar *)
(* Peter Sewell *)
(* *)
(* This file is copyright 2011, 2012 by the above authors. *)
(* *)
(* Redistribution and use in source and binary forms, with or without *)
(* modification, are permitted provided that the following conditions *)
(* are met: *)
(* 1. Redistributions of source code must retain the above copyright *)
(* notice, this list of conditions and the following disclaimer. *)
(* 2. Redistributions in binary form must reproduce the above copyright *)
(* notice, this list of conditions and the following disclaimer in the *)
(* documentation and/or other materials provided with the distribution. *)
(* 3. The names of the authors may not be used to endorse or promote *)
(* products derived from this software without specific prior written *)
(* permission. *)
(* *)
(* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS *)
(* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *)
(* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *)
(* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY *)
(* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *)
(* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE *)
(* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *)
(* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHE *)
(* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR *)
(* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN *)
(* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *)
(*========================================================================*)
(* lexer for executions *)
{
(*open Location*)
open Types
open Auxl
open Execparser
exception Eof
exception CannotHappen
let incr_linenum lexbuf =
let pos = lexbuf.Lexing.lex_curr_p in
lexbuf.Lexing.lex_curr_p <-
{ pos with
Lexing.pos_lnum = pos.Lexing.pos_lnum + 1;
Lexing.pos_bol = pos.Lexing.pos_cnum }
type lexer = Lexing.lexbuf -> Execparser.token
let keyword_table = Hashtbl.create 53
let _ =
List.iter (fun (kwd, tok) -> Hashtbl.add keyword_table kwd tok)
([
"model", MODEL;
"location_kinds" , LOCATION_KINDS;
"atomic" , ATOMIC;
"nonatomic" , NONATOMIC;
"mutex" , MUTEX;
"sameloc" , SAMELOC ;
"atomiclocs" , ATOMICLOCS ;
"help" , HELP ;
"relabel" , RELABEL ;
"ignore" , IGNORE ;
"consider" , CONSIDER ;
"display_action", DISPLAY_ACTION;
"display_edge", DISPLAY_EDGE;
"suppress_action", SUPPRESS_ACTION;
"suppress_edge", SUPPRESS_EDGE;
"add" , ADD ;
"remove" , REMOVE ;
"generate" , GENERATE ;
"quit" , QUIT ;
"next" , NEXT ;
"intermediate" , INTERMEDIATE ;
"next_candidate" , NEXTCANDIDATE ;
"next_consistent" , NEXTCONSISTENT ;
"non_stop" , NONSTOP ;
"set" , SET ;
"fontsize" , FONTSIZE ;
"node_height" , NODE_HEIGHT ;
"node_width" , NODE_WIDTH ;
"penwidth" , PENWIDTH ;
"filled" , FILLED ;
"xscale" , XSCALE ;
"yscale" , YSCALE ;
"ranksep" , RANKSEP;
"nodesep" , NODESEP;
"legend" , LEGEND ;
"layout" , LAYOUT ;
"neato_par" , NEATO_PAR ;
"neato_par_init" , NEATO_PAR_INIT ;
"neato_downwards", NEATO_DOWNWARDS ;
"dot" , DOTFILE ;
"neato" , NEATO ;
"fig" , FIG ;
"ps" , PS ;
"tex" , TEX ;
"thread_ids" , THREAD_IDS ;
"txt" , TXT ;
"isa" , ISAFILE ;
"exc" , EXCFILE ;
"dsp" , INSTRFILE ;
"init" , INIT ;
"par" , PAR ;
"from" , FROM ;
"to" , TO ;
"all" , ALL ;
"show" , SHOW ;
"true" , BOOL(true) ;
"false" , BOOL(false) ;
"L" , L ;
"U" , U ;
"R" , RSKEL ;
"W" , WSKEL ;
"RMW" , RMWSKEL ;
"F" , FSKEL ;
]
@
(let action_types = [
"R" , (function ot -> R ot );
"W" , (function ot -> W ot);
"RMW", (function ot -> RMW ot);
"F" , (function ot -> F ot );
] in
let order_types = [
"na" , Nonatomic ;
"NA" , Nonatomic ;
"sc" , Atomic Cmm.Seq_cst;
"SC" , Atomic Cmm.Seq_cst;
"rlx" , Atomic Cmm.Relaxed;
"RLX" , Atomic Cmm.Relaxed;
"rel" , Atomic Cmm.Release;
"REL" , Atomic Cmm.Release;
"acq" , Atomic Cmm.Acquire;
"ACQ" , Atomic Cmm.Acquire;
"con" , Atomic Cmm.Consume;
"CON" , Atomic Cmm.Consume;
"a/r" , Atomic Cmm.Acq_rel;
"A/R" , Atomic Cmm.Acq_rel;
] in
List.flatten
(List.map
(function (at,ac) -> List.map
(function (ot,oc) -> at^ot, ac oc)
order_types)
action_types))
@ [
"na" , MO(Nonatomic );
"NA" , MO(Nonatomic );
"sc" , MO(Atomic Cmm.Seq_cst);
"SC" , MO(Atomic Cmm.Seq_cst);
"rlx" , MO(Atomic Cmm.Relaxed);
"RLX" , MO(Atomic Cmm.Relaxed);
"rel" , MO(Atomic Cmm.Release);
"REL" , MO(Atomic Cmm.Release);
"acq" , MO(Atomic Cmm.Acquire);
"ACQ" , MO(Atomic Cmm.Acquire);
"con" , MO(Atomic Cmm.Consume);
"CON" , MO(Atomic Cmm.Consume);
"a/r" , MO(Atomic Cmm.Acq_rel);
"A/R" , MO(Atomic Cmm.Acq_rel);
]
@ [
"Success", LOCKOUTCOME Cmm.Locked;
"Blocked", LOCKOUTCOME Cmm.Blocked
]
)
}
let whitespace = (' ' | '\t' | '\010' | '\012' | '\013')
let newline = ('\010' | '\013' | "\013\010")
let non_newline = [^ '\010' '\013']
let non_newline_whitespace = (' ' | '\t' |'\012')
let identchar = (['A'-'Z'] | ['a'-'z'] | ['0'-'9'] | "_" | "'")
let ident = identchar (identchar)*
let filename = identchar (identchar)* ('.' (identchar)*)+
let digit = ['0'-'9']
let num = digit+
let float = digit+ | digit+ '.' digit+
rule mylexer = parse
['A'-'Z' 'a'-'z'] ['A'-'Z' 'a'-'z' '0'-'9' '_' '/'] * as id
{ try
Hashtbl.find keyword_table id
with Not_found ->
IDENT id }
| ident "." ident as lxm { FILENAME(lxm) }
| ident as lxm { IDENT(lxm) }
| "-->" { EDGEHEAD }
| "--" { EDGETAIL }
| ":" { COLON }
| ";" { SEMICOLON }
| "." { DOT }
| "=" { EQUALS }
| "/" { SLASH }
| "{" { LBRACE }
| "}" { RBRACE }
| "," { COMMA }
| "*" { STAR }
| '"' ([^'"']* as lxm) '"' { STRING(lxm) }
| eof { EOF }
| (non_newline_whitespace non_newline_whitespace*) { mylexer lexbuf}
| newline { incr_linenum lexbuf; mylexer lexbuf }
| (non_newline_whitespace* "%"[^'\n' '\013']* newline) { incr_linenum lexbuf; mylexer lexbuf }
| (non_newline_whitespace* "%"[^'\n' '\013']* eof) { EOF }
| _ as c { let p = lexbuf.Lexing.lex_curr_p in raise (Exc_lex_error (c, p.Lexing.pos_lnum, p.Lexing.pos_cnum - p.Lexing.pos_bol)) }
(*
| "--" (edge_type as lxm) "-->" { EDGE(lxm) }
| num as lxm { NUM(int_of_string lxm) }
| float as lxm { FLOAT(float_of_string lxm) }
*)