Mention that llvm_report_error() does not return.
[oota-llvm.git] / utils / llvm.grm
1 (*
2
3 polygen grammar for LLVM assembly language.
4
5 This file defines an LLVM assembly language grammar for polygen,
6 which is a tool for generating random text based on a grammar.
7 It is strictly syntax-based, and makes no attempt to generate
8 IR that is semantically valid. Most of the IR produced doesn't
9 pass the Verifier.
10
11 *)
12
13 I ::=   "title:    LLVM assembly language\n"
14       ^ "status:   experimental\n"
15       ^ "audience: LLVM developers\n"
16 ;
17
18 S ::= Module ;
19
20 (*
21 Define rules for non-keyword tokens. This is currently just a bunch
22 of hacks. They don't cover many valid forms of tokens, and they also
23 generate some invalid forms of tokens. The LLVM parser has custom
24 C++ code to lex these; custom C++ code for emitting them would be
25 convenient, but polygen doesn't support that.
26 *)
27 NonZeroDecimalDigit ::=     1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
28 DecimalDigit        ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
29 DecimalDigitSeq     ::= DecimalDigit [^ DecimalDigitSeq ];
30 HexDigit            ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
31                       | a | b | c | d | e | f ;
32 HexDigitSeq         ::= HexDigit [^ HexDigitSeq ];
33 StringChar          ::= a | b | c | d | e | f | g | h | i | j | k | l | m
34                       | n | o | p | q | r | s | t | u | v | w | x | y | z ;
35 StringConstantSeq   ::= StringChar [^ StringConstantSeq ];
36 StringConstant      ::= StringChar [^ StringConstantSeq ];
37 EUINT64VAL          ::= NonZeroDecimalDigit [^ DecimalDigitSeq ];
38 ESINT64VAL          ::= [ "-" ] ^ EUINT64VAL ;
39 EUAPINTVAL          ::= EUINT64VAL ;
40 ESAPINTVAL          ::= ESINT64VAL ;
41 LOCALVALID          ::= "%" ^ DecimalDigitSeq ;
42 GLOBALVALID         ::= "@" ^ DecimalDigitSeq ;
43 INTTYPE             ::= "i" ^ EUINT64VAL ;
44 GLOBALVAR           ::= "@" ^ StringConstant ;
45 LOCALVAR            ::= "%" ^ StringConstant ;
46 STRINGCONSTANT      ::= "\"" ^ StringConstant ^ "\"" ;
47 ATSTRINGCONSTANT    ::= "@" ^ STRINGCONSTANT ;
48 PCTSTRINGCONSTANT   ::= "%" ^ STRINGCONSTANT ;
49 LABELSTR            ::= StringConstant ;
50 FPVAL               ::= ESAPINTVAL ^ "." ^ EUAPINTVAL | "0x" ^ HexDigitSeq ;
51
52 (*
53 The rest of this file is derived directly from llvmAsmParser.y.
54 *)
55
56 ArithmeticOps ::= add | fadd | sub | fsub | mul | fmul |
57                   udiv | sdiv | fdiv | urem | srem | frem ;
58 LogicalOps    ::= shl | lshr | ashr | and | or | xor;
59 CastOps       ::= trunc | zext | sext | fptrunc | fpext | bitcast |
60                   uitofp | sitofp | fptoui | fptosi | inttoptr | ptrtoint ;
61
62 IPredicates ::= eq | ne | slt | sgt | sle | sge | ult | ugt | ule | uge ;
63
64 FPredicates ::= oeq | one | olt | ogt | ole | oge | ord | uno | ueq | une
65               | ult | ugt | ule | uge | true | false ;
66
67 IntType ::= INTTYPE;
68 FPType  ::= float | double | "ppc_fp128" | fp128 | "x86_fp80";
69
70 LocalName ::= LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
71 OptLocalName ::= LocalName | _ ;
72
73 OptAddrSpace ::= - addrspace ^ "(" ^ EUINT64VAL ^ ")" | _ ;
74
75 OptLocalAssign ::= LocalName "=" | _ ;
76
77 GlobalName ::= GLOBALVAR | ATSTRINGCONSTANT ;
78
79 OptGlobalAssign ::= GlobalAssign | _ ;
80
81 GlobalAssign ::= GlobalName "=" ;
82
83 GVInternalLinkage
84   ::= + internal
85  | weak
86  | "weak_odr"
87  | linkonce
88  | "linkonce_odr"
89  | appending
90  | dllexport
91  | common
92  ;
93
94 GVExternalLinkage
95   ::= dllimport
96  | "extern_weak"
97  | + external
98  ;
99
100 GVVisibilityStyle
101   ::= + _
102  | default
103  | hidden
104  | protected
105  ;
106
107 FunctionDeclareLinkage
108   ::= + _
109  | dllimport
110  | "extern_weak"
111  ;
112
113 FunctionDefineLinkage
114   ::= + _
115  | internal
116  | linkonce
117  | "linkonce_odr"
118  | weak
119  | "weak_odr"
120  | dllexport
121  ;
122
123 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
124
125 OptCallingConv ::= + _ |
126                  ccc |
127                  fastcc |
128                  coldcc |
129                  "x86_stdcallcc" |
130                  "x86_fastcallcc" |
131                  cc EUINT64VAL ;
132
133 ParamAttr ::= zeroext
134  | signext
135  | inreg
136  | sret
137  | noalias
138  | nocapture
139  | byval
140  | nest
141  | align EUINT64VAL
142  ;
143
144 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
145
146 RetAttr       ::= inreg
147               | zeroext
148               | signext
149               | noalias
150               ;
151
152 OptRetAttrs  ::= _
153              | OptRetAttrs RetAttr
154              ;
155
156 FuncAttr      ::= noreturn
157  | nounwind
158  | inreg
159  | zeroext
160  | signext
161  | readnone
162  | readonly
163  | noinline
164  | alwaysinline
165  | optsize
166  | ssp
167  | sspreq
168  ;
169
170 OptFuncAttrs  ::= + _ | OptFuncAttrs FuncAttr ;
171
172 OptGC         ::= + _ | gc STRINGCONSTANT ;
173
174 OptAlign      ::= + _ | align EUINT64VAL ;
175 OptCAlign     ::= + _ | ^ "," align EUINT64VAL ;
176
177 SectionString ::= section STRINGCONSTANT ;
178
179 OptSection    ::= + _ | SectionString ;
180
181 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
182 GlobalVarAttribute  ::= SectionString | align EUINT64VAL ;
183
184 PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
185           | - label ;
186
187 Types
188   ::= opaque
189  | PrimType
190  | Types OptAddrSpace ^ "*"
191  | SymbolicValueRef
192  | "\\" ^ EUINT64VAL
193  | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
194  | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
195  | "[" ^ EUINT64VAL "x" Types ^ "]"
196  | "<" ^ EUINT64VAL "x" Types ^ ">"
197  | "{" TypeListI "}"
198  | "{" ^ "}"
199  | "<" ^ "{" TypeListI "}" ^ ">"
200  | "<" ^ "{" ^ "}" ^ ">"
201  ;
202
203 ArgType ::= Types OptParamAttrs ;
204
205 ResultTypes ::= Types | void ;
206
207 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
208
209 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
210
211 TypeListI ::= Types | TypeListI ^ "," Types ;
212
213 ConstVal::= Types "[" ^ ConstVector ^ "]"
214  | Types "[" ^ "]"
215  | Types "c" ^ STRINGCONSTANT
216  | Types "<" ^ ConstVector ^ ">"
217  | Types "{" ConstVector "}"
218  | Types "{" ^ "}"
219  | Types "<" ^ "{" ConstVector "}" ^ ">"
220  | Types "<" ^ "{" ^ "}" ^ ">"
221  | Types null
222  | Types undef
223  | Types SymbolicValueRef
224  | Types ConstExpr
225  | Types zeroinitializer
226  | Types ESINT64VAL
227  | Types ESAPINTVAL
228  | Types EUINT64VAL
229  | Types EUAPINTVAL
230  | Types true
231  | Types false
232  | Types FPVAL ;
233
234 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
235  | getelementptr "(" ^ ConstVal IndexList ^ ")"
236  | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
237  | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
238  | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
239  | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
240  | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
241  | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
242  | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
243  | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
244  | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
245  | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
246
247 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
248
249 GlobalType ::= global | constant ;
250
251 ThreadLocal ::= - "thread_local" | _ ;
252
253 AliaseeRef ::= ResultTypes SymbolicValueRef
254  | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
255
256 Module ::= +++ DefinitionList | --- _ ;
257
258 DefinitionList ::= - Definition | + DefinitionList Definition ;
259
260 Definition
261   ::= ^ ( +++++ define Function
262  | declare FunctionProto
263  | - module asm AsmBlock
264  | OptLocalAssign type Types
265  | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
266    ConstVal GlobalVarAttributes
267  | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
268    GlobalType ConstVal GlobalVarAttributes
269  | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
270    GlobalType Types GlobalVarAttributes
271  | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
272  | target TargetDefinition
273  | deplibs "=" LibrariesDefinition
274  ) ^ "\n";
275
276 AsmBlock ::= STRINGCONSTANT ;
277
278 TargetDefinition ::= triple "=" STRINGCONSTANT
279  | datalayout "=" STRINGCONSTANT ;
280
281 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
282
283 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
284
285 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
286  | Types OptParamAttrs OptLocalName ;
287
288 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
289
290 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
291                   GlobalName ^ "(" ^ ArgList ^ ")"
292                   OptFuncAttrs OptSection OptAlign OptGC ;
293
294 BEGIN ::= ( begin | "{" ) ^ "\n";
295
296 FunctionHeader ::=
297   FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
298
299 END ::= ^ ( end | "}" ) ^ "\n";
300
301 Function ::= BasicBlockList END ;
302
303 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
304
305 OptSideEffect ::= _ | sideeffect ;
306
307 ConstValueRef ::= ESINT64VAL
308  | EUINT64VAL
309  | FPVAL
310  | true
311  | false
312  | null
313  | undef
314  | zeroinitializer
315  | "<" ConstVector ">"
316  | "[" ConstVector "]"
317  | "[" ^ "]"
318  | "c" ^ STRINGCONSTANT
319  | "{" ConstVector "}"
320  | "{" ^ "}"
321  | "<" ^ "{" ConstVector "}" ^ ">"
322  | "<" ^ "{" ^ "}" ^ ">"
323  | ConstExpr
324  | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
325
326 SymbolicValueRef ::= LOCALVALID
327  | GLOBALVALID
328  | LocalName
329  | GlobalName ;
330
331 ValueRef ::= SymbolicValueRef | ConstValueRef;
332
333 ResolvedVal ::= Types ValueRef ;
334
335 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
336
337 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
338
339 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
340
341 InstructionList ::= +++ InstructionList Inst
342  | - _
343  | ^ LABELSTR ^ ":\n" ;
344
345 BBTerminatorInst ::= ^ "  " ^
346  ( ret ReturnedVal
347  | ret void
348  | br label ValueRef
349  | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
350  | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
351  | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
352  | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
353    OptFuncAttrs
354    to label ValueRef unwind label ValueRef
355  | unwind
356  | unreachable ) ^ "\n";
357
358 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
359  | IntType ConstValueRef ^ "," label ValueRef ;
360
361 Inst ::= ^ "  " ^ OptLocalAssign InstVal ^ "\n";
362
363 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
364  | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
365
366 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
367  | label OptParamAttrs ValueRef OptParamAttrs
368  | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
369  | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
370  | - _ ;
371
372 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
373
374 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
375
376 OptTailCall ::= tail call | call ;
377
378 InstVal ::=
379    ArithmeticOps Types ValueRef ^ "," ValueRef
380  | LogicalOps Types ValueRef ^ "," ValueRef
381  | icmp IPredicates Types ValueRef ^ "," ValueRef
382  | fcmp FPredicates Types ValueRef ^ "," ValueRef
383  | CastOps ResolvedVal to Types
384  | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
385  | "va_arg" ResolvedVal ^ "," Types
386  | extractelement ResolvedVal ^ "," ResolvedVal
387  | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
388  | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
389  | phi PHIList
390  | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
391    OptFuncAttrs
392  | MemoryInst ;
393
394 OptVolatile ::= - volatile | _ ;
395
396 MemoryInst ::= malloc Types OptCAlign
397  | malloc Types ^ "," INTTYPE ValueRef OptCAlign
398  | alloca Types OptCAlign
399  | alloca Types ^ "," INTTYPE ValueRef OptCAlign
400  | free ResolvedVal
401  | OptVolatile load Types ValueRef OptCAlign
402  | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
403  | getresult Types ValueRef ^ "," EUINT64VAL
404  | getelementptr Types ValueRef IndexList
405  | extractvalue Types ValueRef ^ ConstantIndexList 
406  | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;