blob: fa0dcd1e1520ccddf80d0aeb5d71dfdd6a5179e7 [file] [log] [blame]
Dan Gohman890c31c2008-05-22 22:45:03 +00001(*
2
3polygen grammar for LLVM assembly language.
4
5This file defines an LLVM assembly language grammar for polygen,
6which is a tool for generating random text based on a grammar.
7It is strictly syntax-based, and makes no attempt to generate
8IR that is semantically valid. Most of the IR produced doesn't
9pass the Verifier.
10
11*)
12
13I ::= "title: LLVM assembly language\n"
14 ^ "status: experimental\n"
15 ^ "audience: LLVM developers\n"
16;
17
18S ::= Module ;
19
20(*
21Define rules for non-keyword tokens. This is currently just a bunch
22of hacks. They don't cover many valid forms of tokens, and they also
23generate some invalid forms of tokens. The LLVM parser has custom
24C++ code to lex these; custom C++ code for emitting them would be
25convenient, but polygen doesn't support that.
26*)
27NonZeroDecimalDigit ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
28DecimalDigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
29DecimalDigitSeq ::= DecimalDigit [^ DecimalDigitSeq ];
30HexDigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
31 | a | b | c | d | e | f ;
32HexDigitSeq ::= HexDigit [^ HexDigitSeq ];
33StringChar ::= 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 ;
35StringConstantSeq ::= StringChar [^ StringConstantSeq ];
36StringConstant ::= StringChar [^ StringConstantSeq ];
37EUINT64VAL ::= NonZeroDecimalDigit [^ DecimalDigitSeq ];
38ESINT64VAL ::= [ "-" ] ^ EUINT64VAL ;
39EUAPINTVAL ::= EUINT64VAL ;
40ESAPINTVAL ::= ESINT64VAL ;
41LOCALVALID ::= "%" ^ DecimalDigitSeq ;
42GLOBALVALID ::= "@" ^ DecimalDigitSeq ;
43INTTYPE ::= "i" ^ EUINT64VAL ;
44GLOBALVAR ::= "@" ^ StringConstant ;
45LOCALVAR ::= "%" ^ StringConstant ;
46STRINGCONSTANT ::= "\"" ^ StringConstant ^ "\"" ;
47ATSTRINGCONSTANT ::= "@" ^ STRINGCONSTANT ;
48PCTSTRINGCONSTANT ::= "%" ^ STRINGCONSTANT ;
49LABELSTR ::= StringConstant ;
50FPVAL ::= ESAPINTVAL ^ "." ^ EUAPINTVAL | "0x" ^ HexDigitSeq ;
51
52(*
53The rest of this file is derived directly from llvmAsmParser.y.
54*)
55
Dan Gohmanbfacb7e2009-07-22 22:45:30 +000056ArithmeticOps ::= + OptNW add | fadd | OptNW sub | fsub | OptNW mul | fmul |
57 udiv | OptExact sdiv | fdiv | urem | srem | frem ;
Dan Gohman890c31c2008-05-22 22:45:03 +000058LogicalOps ::= shl | lshr | ashr | and | or | xor;
59CastOps ::= trunc | zext | sext | fptrunc | fpext | bitcast |
60 uitofp | sitofp | fptoui | fptosi | inttoptr | ptrtoint ;
61
62IPredicates ::= eq | ne | slt | sgt | sle | sge | ult | ugt | ule | uge ;
63
64FPredicates ::= oeq | one | olt | ogt | ole | oge | ord | uno | ueq | une
65 | ult | ugt | ule | uge | true | false ;
66
67IntType ::= INTTYPE;
68FPType ::= float | double | "ppc_fp128" | fp128 | "x86_fp80";
69
70LocalName ::= LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
71OptLocalName ::= LocalName | _ ;
72
Dan Gohman8f56eba2009-01-05 17:29:42 +000073OptAddrSpace ::= - addrspace ^ "(" ^ EUINT64VAL ^ ")" | _ ;
Dan Gohman890c31c2008-05-22 22:45:03 +000074
75OptLocalAssign ::= LocalName "=" | _ ;
76
77GlobalName ::= GLOBALVAR | ATSTRINGCONSTANT ;
78
79OptGlobalAssign ::= GlobalAssign | _ ;
80
81GlobalAssign ::= GlobalName "=" ;
82
83GVInternalLinkage
84 ::= + internal
85 | weak
Duncan Sands667d4b82009-03-07 15:45:40 +000086 | "weak_odr"
Dan Gohman890c31c2008-05-22 22:45:03 +000087 | linkonce
Duncan Sands667d4b82009-03-07 15:45:40 +000088 | "linkonce_odr"
Dan Gohman890c31c2008-05-22 22:45:03 +000089 | appending
90 | dllexport
91 | common
Dan Gohman923a5792009-07-17 01:07:45 +000092 | private
Dan Gohman890c31c2008-05-22 22:45:03 +000093 ;
94
95GVExternalLinkage
96 ::= dllimport
97 | "extern_weak"
98 | + external
99 ;
100
101GVVisibilityStyle
102 ::= + _
103 | default
104 | hidden
105 | protected
106 ;
107
108FunctionDeclareLinkage
109 ::= + _
110 | dllimport
111 | "extern_weak"
112 ;
113
114FunctionDefineLinkage
115 ::= + _
116 | internal
117 | linkonce
Duncan Sands667d4b82009-03-07 15:45:40 +0000118 | "linkonce_odr"
Dan Gohman890c31c2008-05-22 22:45:03 +0000119 | weak
Duncan Sands667d4b82009-03-07 15:45:40 +0000120 | "weak_odr"
Dan Gohman890c31c2008-05-22 22:45:03 +0000121 | dllexport
122 ;
123
Duncan Sands667d4b82009-03-07 15:45:40 +0000124AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
Dan Gohman890c31c2008-05-22 22:45:03 +0000125
126OptCallingConv ::= + _ |
127 ccc |
128 fastcc |
129 coldcc |
130 "x86_stdcallcc" |
131 "x86_fastcallcc" |
132 cc EUINT64VAL ;
133
134ParamAttr ::= zeroext
Dan Gohman890c31c2008-05-22 22:45:03 +0000135 | signext
Dan Gohman890c31c2008-05-22 22:45:03 +0000136 | inreg
137 | sret
138 | noalias
Dan Gohman571238a2009-01-05 03:21:23 +0000139 | nocapture
Dan Gohman890c31c2008-05-22 22:45:03 +0000140 | byval
141 | nest
142 | align EUINT64VAL
143 ;
144
145OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
146
Dan Gohman571238a2009-01-05 03:21:23 +0000147RetAttr ::= inreg
148 | zeroext
149 | signext
150 | noalias
151 ;
152
153OptRetAttrs ::= _
154 | OptRetAttrs RetAttr
155 ;
156
Dan Gohman890c31c2008-05-22 22:45:03 +0000157FuncAttr ::= noreturn
158 | nounwind
Dan Gohman571238a2009-01-05 03:21:23 +0000159 | inreg
Dan Gohman890c31c2008-05-22 22:45:03 +0000160 | zeroext
161 | signext
162 | readnone
163 | readonly
Jakob Stoklund Olesen570a4a52010-02-06 01:16:28 +0000164 | inlinehint
Dan Gohmanc235a0c2010-03-01 17:53:39 +0000165 | alignstack
Dan Gohman571238a2009-01-05 03:21:23 +0000166 | noinline
167 | alwaysinline
168 | optsize
169 | ssp
170 | sspreq
Dan Gohman890c31c2008-05-22 22:45:03 +0000171 ;
172
173OptFuncAttrs ::= + _ | OptFuncAttrs FuncAttr ;
174
175OptGC ::= + _ | gc STRINGCONSTANT ;
176
177OptAlign ::= + _ | align EUINT64VAL ;
178OptCAlign ::= + _ | ^ "," align EUINT64VAL ;
179
180SectionString ::= section STRINGCONSTANT ;
181
182OptSection ::= + _ | SectionString ;
183
184GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
185GlobalVarAttribute ::= SectionString | align EUINT64VAL ;
186
187PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
188 | - label ;
189
190Types
191 ::= opaque
192 | PrimType
193 | Types OptAddrSpace ^ "*"
194 | SymbolicValueRef
195 | "\\" ^ EUINT64VAL
196 | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
197 | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
198 | "[" ^ EUINT64VAL "x" Types ^ "]"
199 | "<" ^ EUINT64VAL "x" Types ^ ">"
200 | "{" TypeListI "}"
Dan Gohman0d58eb62008-09-15 16:10:51 +0000201 | "{" ^ "}"
Dan Gohman890c31c2008-05-22 22:45:03 +0000202 | "<" ^ "{" TypeListI "}" ^ ">"
Dan Gohman0d58eb62008-09-15 16:10:51 +0000203 | "<" ^ "{" ^ "}" ^ ">"
Dan Gohman890c31c2008-05-22 22:45:03 +0000204 ;
205
206ArgType ::= Types OptParamAttrs ;
207
208ResultTypes ::= Types | void ;
209
210ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
211
212ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
213
214TypeListI ::= Types | TypeListI ^ "," Types ;
215
216ConstVal::= Types "[" ^ ConstVector ^ "]"
Dan Gohman0d58eb62008-09-15 16:10:51 +0000217 | Types "[" ^ "]"
Dan Gohman890c31c2008-05-22 22:45:03 +0000218 | Types "c" ^ STRINGCONSTANT
219 | Types "<" ^ ConstVector ^ ">"
220 | Types "{" ConstVector "}"
Dan Gohman0d58eb62008-09-15 16:10:51 +0000221 | Types "{" ^ "}"
Dan Gohman890c31c2008-05-22 22:45:03 +0000222 | Types "<" ^ "{" ConstVector "}" ^ ">"
Dan Gohman0d58eb62008-09-15 16:10:51 +0000223 | Types "<" ^ "{" ^ "}" ^ ">"
Dan Gohman890c31c2008-05-22 22:45:03 +0000224 | Types null
225 | Types undef
226 | Types SymbolicValueRef
227 | Types ConstExpr
228 | Types zeroinitializer
Dan Gohman571238a2009-01-05 03:21:23 +0000229 | Types ESINT64VAL
230 | Types ESAPINTVAL
231 | Types EUINT64VAL
232 | Types EUAPINTVAL
233 | Types true
234 | Types false
235 | Types FPVAL ;
Dan Gohman890c31c2008-05-22 22:45:03 +0000236
237ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
Dan Gohman224251d2009-07-27 21:55:32 +0000238 | getelementptr OptInBounds "(" ^ ConstVal IndexList ^ ")"
Dan Gohman890c31c2008-05-22 22:45:03 +0000239 | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
240 | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
241 | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
242 | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
243 | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
Dan Gohman890c31c2008-05-22 22:45:03 +0000244 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
245 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
Dan Gohmane4977cf2008-05-23 01:55:30 +0000246 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
Dan Gohman34e71fe2008-06-02 19:47:09 +0000247 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
248 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
Dan Gohman890c31c2008-05-22 22:45:03 +0000249
250ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
251
252GlobalType ::= global | constant ;
253
254ThreadLocal ::= - "thread_local" | _ ;
255
256AliaseeRef ::= ResultTypes SymbolicValueRef
257 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
258
259Module ::= +++ DefinitionList | --- _ ;
260
261DefinitionList ::= - Definition | + DefinitionList Definition ;
262
263Definition
264 ::= ^ ( +++++ define Function
265 | declare FunctionProto
266 | - module asm AsmBlock
267 | OptLocalAssign type Types
Dan Gohmande0e7f22009-01-05 23:03:03 +0000268 | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
Dan Gohman8f56eba2009-01-05 17:29:42 +0000269 ConstVal GlobalVarAttributes
270 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
271 GlobalType ConstVal GlobalVarAttributes
272 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
273 GlobalType Types GlobalVarAttributes
Dan Gohman890c31c2008-05-22 22:45:03 +0000274 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
275 | target TargetDefinition
276 | deplibs "=" LibrariesDefinition
277 ) ^ "\n";
278
279AsmBlock ::= STRINGCONSTANT ;
280
281TargetDefinition ::= triple "=" STRINGCONSTANT
282 | datalayout "=" STRINGCONSTANT ;
283
Dan Gohman8f56eba2009-01-05 17:29:42 +0000284LibrariesDefinition ::= "[" ( LibList | _ ) "]";
Dan Gohman890c31c2008-05-22 22:45:03 +0000285
Dan Gohman8f56eba2009-01-05 17:29:42 +0000286LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
Dan Gohman890c31c2008-05-22 22:45:03 +0000287
288ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
289 | Types OptParamAttrs OptLocalName ;
290
291ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
292
Dan Gohman571238a2009-01-05 03:21:23 +0000293FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
Dan Gohman8f56eba2009-01-05 17:29:42 +0000294 GlobalName ^ "(" ^ ArgList ^ ")"
Dan Gohman571238a2009-01-05 03:21:23 +0000295 OptFuncAttrs OptSection OptAlign OptGC ;
Dan Gohman890c31c2008-05-22 22:45:03 +0000296
297BEGIN ::= ( begin | "{" ) ^ "\n";
298
299FunctionHeader ::=
300 FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
301
302END ::= ^ ( end | "}" ) ^ "\n";
303
304Function ::= BasicBlockList END ;
305
306FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
307
308OptSideEffect ::= _ | sideeffect ;
309
310ConstValueRef ::= ESINT64VAL
311 | EUINT64VAL
312 | FPVAL
313 | true
314 | false
315 | null
316 | undef
317 | zeroinitializer
318 | "<" ConstVector ">"
Dan Gohmanf910eaa2008-06-09 14:45:02 +0000319 | "[" ConstVector "]"
Dan Gohman0d58eb62008-09-15 16:10:51 +0000320 | "[" ^ "]"
Dan Gohmanf910eaa2008-06-09 14:45:02 +0000321 | "c" ^ STRINGCONSTANT
322 | "{" ConstVector "}"
Dan Gohman0d58eb62008-09-15 16:10:51 +0000323 | "{" ^ "}"
Dan Gohmanf910eaa2008-06-09 14:45:02 +0000324 | "<" ^ "{" ConstVector "}" ^ ">"
Dan Gohman0d58eb62008-09-15 16:10:51 +0000325 | "<" ^ "{" ^ "}" ^ ">"
Dan Gohman890c31c2008-05-22 22:45:03 +0000326 | ConstExpr
327 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
328
329SymbolicValueRef ::= LOCALVALID
330 | GLOBALVALID
331 | LocalName
332 | GlobalName ;
333
334ValueRef ::= SymbolicValueRef | ConstValueRef;
335
336ResolvedVal ::= Types ValueRef ;
337
338ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
339
340BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
341
342BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
343
344InstructionList ::= +++ InstructionList Inst
345 | - _
346 | ^ LABELSTR ^ ":\n" ;
347
348BBTerminatorInst ::= ^ " " ^
349 ( ret ReturnedVal
350 | ret void
351 | br label ValueRef
352 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
353 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
Dan Gohman0d58eb62008-09-15 16:10:51 +0000354 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
355 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
356 OptFuncAttrs
Dan Gohman890c31c2008-05-22 22:45:03 +0000357 to label ValueRef unwind label ValueRef
358 | unwind
359 | unreachable ) ^ "\n";
360
361JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
362 | IntType ConstValueRef ^ "," label ValueRef ;
363
364Inst ::= ^ " " ^ OptLocalAssign InstVal ^ "\n";
365
366PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
367 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
368
369ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
370 | label OptParamAttrs ValueRef OptParamAttrs
371 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
372 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
373 | - _ ;
374
375IndexList ::= _ | IndexList ^ "," ResolvedVal ;
376
Dan Gohman34e71fe2008-06-02 19:47:09 +0000377ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
378
Dan Gohman890c31c2008-05-22 22:45:03 +0000379OptTailCall ::= tail call | call ;
380
381InstVal ::=
382 ArithmeticOps Types ValueRef ^ "," ValueRef
383 | LogicalOps Types ValueRef ^ "," ValueRef
384 | icmp IPredicates Types ValueRef ^ "," ValueRef
385 | fcmp FPredicates Types ValueRef ^ "," ValueRef
Dan Gohman890c31c2008-05-22 22:45:03 +0000386 | CastOps ResolvedVal to Types
387 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
Dan Gohmanb737a642008-05-23 17:11:55 +0000388 | "va_arg" ResolvedVal ^ "," Types
Dan Gohman890c31c2008-05-22 22:45:03 +0000389 | extractelement ResolvedVal ^ "," ResolvedVal
390 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
391 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
392 | phi PHIList
Dan Gohman0d58eb62008-09-15 16:10:51 +0000393 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
Dan Gohman890c31c2008-05-22 22:45:03 +0000394 OptFuncAttrs
395 | MemoryInst ;
396
397OptVolatile ::= - volatile | _ ;
Dan Gohmanbfacb7e2009-07-22 22:45:30 +0000398OptExact ::= - exact | _ ;
399OptNSW ::= - nsw | _ ;
400OptNUW ::= - nuw | _ ;
Dan Gohmand622b0b2010-05-04 00:13:24 +0000401OptNW ::= OptNUW OptNSW | OptNSW OptNUW ;
Dan Gohman224251d2009-07-27 21:55:32 +0000402OptInBounds ::= - inbounds | _ ;
Dan Gohman890c31c2008-05-22 22:45:03 +0000403
404MemoryInst ::= malloc Types OptCAlign
405 | malloc Types ^ "," INTTYPE ValueRef OptCAlign
406 | alloca Types OptCAlign
407 | alloca Types ^ "," INTTYPE ValueRef OptCAlign
408 | free ResolvedVal
409 | OptVolatile load Types ValueRef OptCAlign
410 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
411 | getresult Types ValueRef ^ "," EUINT64VAL
Dan Gohman224251d2009-07-27 21:55:32 +0000412 | getelementptr OptInBounds Types ValueRef IndexList
Dan Gohman34e71fe2008-06-02 19:47:09 +0000413 | extractvalue Types ValueRef ^ ConstantIndexList
414 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;