3 polygen grammar for LLVM assembly language.
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
13 I ::= "title: LLVM assembly language\n"
14 ^ "status: experimental\n"
15 ^ "audience: LLVM developers\n"
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.
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 ;
53 The rest of this file is derived directly from llvmAsmParser.y.
56 ArithmeticOps ::= add | sub | mul | udiv | sdiv | fdiv | urem | srem | frem ;
57 LogicalOps ::= shl | lshr | ashr | and | or | xor;
58 CastOps ::= trunc | zext | sext | fptrunc | fpext | bitcast |
59 uitofp | sitofp | fptoui | fptosi | inttoptr | ptrtoint ;
61 IPredicates ::= eq | ne | slt | sgt | sle | sge | ult | ugt | ule | uge ;
63 FPredicates ::= oeq | one | olt | ogt | ole | oge | ord | uno | ueq | une
64 | ult | ugt | ule | uge | true | false ;
67 FPType ::= float | double | "ppc_fp128" | fp128 | "x86_fp80";
69 LocalName ::= LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
70 OptLocalName ::= LocalName | _ ;
72 OptAddrSpace ::= - addrspace ^ "(" ^ EUINT64VAL ^ ")" | _ ;
74 OptLocalAssign ::= LocalName "=" | _ ;
76 GlobalName ::= GLOBALVAR | ATSTRINGCONSTANT ;
78 OptGlobalAssign ::= GlobalAssign | _ ;
80 GlobalAssign ::= GlobalName "=" ;
106 FunctionDeclareLinkage
112 FunctionDefineLinkage
122 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
124 OptCallingConv ::= + _ |
132 ParamAttr ::= zeroext
143 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
152 | OptRetAttrs RetAttr
155 FuncAttr ::= noreturn
169 OptFuncAttrs ::= + _ | OptFuncAttrs FuncAttr ;
171 OptGC ::= + _ | gc STRINGCONSTANT ;
173 OptAlign ::= + _ | align EUINT64VAL ;
174 OptCAlign ::= + _ | ^ "," align EUINT64VAL ;
176 SectionString ::= section STRINGCONSTANT ;
178 OptSection ::= + _ | SectionString ;
180 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
181 GlobalVarAttribute ::= SectionString | align EUINT64VAL ;
183 PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
189 | Types OptAddrSpace ^ "*"
192 | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
193 | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
194 | "[" ^ EUINT64VAL "x" Types ^ "]"
195 | "<" ^ EUINT64VAL "x" Types ^ ">"
198 | "<" ^ "{" TypeListI "}" ^ ">"
199 | "<" ^ "{" ^ "}" ^ ">"
202 ArgType ::= Types OptParamAttrs ;
204 ResultTypes ::= Types | void ;
206 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
208 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
210 TypeListI ::= Types | TypeListI ^ "," Types ;
212 ConstVal::= Types "[" ^ ConstVector ^ "]"
214 | Types "c" ^ STRINGCONSTANT
215 | Types "<" ^ ConstVector ^ ">"
216 | Types "{" ConstVector "}"
218 | Types "<" ^ "{" ConstVector "}" ^ ">"
219 | Types "<" ^ "{" ^ "}" ^ ">"
222 | Types SymbolicValueRef
224 | Types zeroinitializer
233 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
234 | getelementptr "(" ^ ConstVal IndexList ^ ")"
235 | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
236 | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
237 | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
238 | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
239 | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
240 | vicmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
241 | vfcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
242 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
243 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
244 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
245 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
246 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
248 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
250 GlobalType ::= global | constant ;
252 ThreadLocal ::= - "thread_local" | _ ;
254 AliaseeRef ::= ResultTypes SymbolicValueRef
255 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
257 Module ::= +++ DefinitionList | --- _ ;
259 DefinitionList ::= - Definition | + DefinitionList Definition ;
262 ::= ^ ( +++++ define Function
263 | declare FunctionProto
264 | - module asm AsmBlock
265 | OptLocalAssign type Types
266 | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
267 ConstVal GlobalVarAttributes
268 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
269 GlobalType ConstVal GlobalVarAttributes
270 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
271 GlobalType Types GlobalVarAttributes
272 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
273 | target TargetDefinition
274 | deplibs "=" LibrariesDefinition
277 AsmBlock ::= STRINGCONSTANT ;
279 TargetDefinition ::= triple "=" STRINGCONSTANT
280 | datalayout "=" STRINGCONSTANT ;
282 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
284 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
286 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
287 | Types OptParamAttrs OptLocalName ;
289 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
291 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
292 GlobalName ^ "(" ^ ArgList ^ ")"
293 OptFuncAttrs OptSection OptAlign OptGC ;
295 BEGIN ::= ( begin | "{" ) ^ "\n";
298 FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
300 END ::= ^ ( end | "}" ) ^ "\n";
302 Function ::= BasicBlockList END ;
304 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
306 OptSideEffect ::= _ | sideeffect ;
308 ConstValueRef ::= ESINT64VAL
316 | "<" ConstVector ">"
317 | "[" ConstVector "]"
319 | "c" ^ STRINGCONSTANT
320 | "{" ConstVector "}"
322 | "<" ^ "{" ConstVector "}" ^ ">"
323 | "<" ^ "{" ^ "}" ^ ">"
325 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
327 SymbolicValueRef ::= LOCALVALID
332 ValueRef ::= SymbolicValueRef | ConstValueRef;
334 ResolvedVal ::= Types ValueRef ;
336 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
338 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
340 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
342 InstructionList ::= +++ InstructionList Inst
344 | ^ LABELSTR ^ ":\n" ;
346 BBTerminatorInst ::= ^ " " ^
350 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
351 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
352 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
353 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
355 to label ValueRef unwind label ValueRef
357 | unreachable ) ^ "\n";
359 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
360 | IntType ConstValueRef ^ "," label ValueRef ;
362 Inst ::= ^ " " ^ OptLocalAssign InstVal ^ "\n";
364 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
365 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
367 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
368 | label OptParamAttrs ValueRef OptParamAttrs
369 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
370 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
373 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
375 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
377 OptTailCall ::= tail call | call ;
380 ArithmeticOps Types ValueRef ^ "," ValueRef
381 | LogicalOps Types ValueRef ^ "," ValueRef
382 | icmp IPredicates Types ValueRef ^ "," ValueRef
383 | fcmp FPredicates Types ValueRef ^ "," ValueRef
384 | vicmp IPredicates Types ValueRef ^ "," ValueRef
385 | vfcmp FPredicates Types ValueRef ^ "," ValueRef
386 | CastOps ResolvedVal to Types
387 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
388 | "va_arg" ResolvedVal ^ "," Types
389 | extractelement ResolvedVal ^ "," ResolvedVal
390 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
391 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
393 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
397 OptVolatile ::= - volatile | _ ;
399 MemoryInst ::= malloc Types OptCAlign
400 | malloc Types ^ "," INTTYPE ValueRef OptCAlign
401 | alloca Types OptCAlign
402 | alloca Types ^ "," INTTYPE ValueRef OptCAlign
404 | OptVolatile load Types ValueRef OptCAlign
405 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
406 | getresult Types ValueRef ^ "," EUINT64VAL
407 | getelementptr Types ValueRef IndexList
408 | extractvalue Types ValueRef ^ ConstantIndexList
409 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;