-
Notifications
You must be signed in to change notification settings - Fork 3
/
grammar.lark
121 lines (75 loc) · 2.63 KB
/
grammar.lark
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
start : addresses threads commands
addresses: address_decl*
address_decl: "." space string (/physically/ "aliases" string)? ";"
| "." /texref/ string /virtually/ "aliases" string ";"
| "." /surfref/ string /virtually/ "aliases" string ";"
!space: "global" | "shared"
aliases: "[" string ("," string)* "]"
threads: thread+
thread : thread_scope_tree "{" instruction+ "}"
?instruction: load
| store
| atom
| red
| fence
| proxy_fence
| alias_fence
load : /ld/ sem scope reg "," address return_value ";"
| /tld/ weak none reg "," address return_value ";"
| /suld/ sem scope reg "," address return_value ";"
| /ldc/ weak none reg "," address return_value ";"
store : /st/ sem scope address "," value ";"
| /sust/ sem scope address "," value ";"
atom : /atom/ "." atomic_op sem scope reg "," address "," value return_value ";"
| /suatom/ "." atomic_op sem scope reg "," address "," value return_value ";"
red : /red/ "." atomic_op sem scope address "," value ";"
| /sured/ "." atomic_op sem scope address "," value ";"
fence : /fence/ sem scope ";"
proxy_fence: /fence/ "." "proxy" "." string ("." string)* ";"
alias_fence: /fence/ "." "alias" ";"
?address: "[" string "]"
!sem: "." "weak"
| "." "relaxed"
| "." "acquire"
| "." "release"
| "." "acq_rel"
| "." "sc"
| "." "volatile"
| none
!scope: "." "cta"
| "." "gpu"
| "." "sys"
| none
!weak: "." "weak"
| none
?none:
?value: integer | reg
integer: num
return_value: ("==" integer)?
!atomic_op: "add"
scope_tree: "d" num
| "d" num "." "b" num
| "d" num "." "b" num "." "t" num
thread_scope_tree: "d" num "." "b" num "." "t" num
reg: "r" num
commands: command*
command: "check" "(" condition ")" "as" string ";" -> check
| "permit" "(" condition ")" "as" string ";" -> permit
| "assert" "(" condition ")" "as" string ";" -> assert_
condition: condition_and
| condition "||" condition -> or_
?condition_and: condition_eq
| condition_and "&&" condition_and -> and_
condition_eq: value "==" value -> eq
| value "!=" value -> neq
| "not" condition -> not_
value_list: value
| "{" value ("or" value)* "}"
?string: CNAME
num: INT
%import common.INT
%import common.CNAME
%import common.WS
%ignore WS
COMMENT: "//" /[^\n]/*
%ignore COMMENT