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 "=" ;
107 FunctionDeclareLinkage
113 FunctionDefineLinkage
123 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
125 OptCallingConv ::= + _ |
133 ParamAttr ::= zeroext
146 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
155 | OptRetAttrs RetAttr
158 FuncAttr ::= noreturn
172 OptFuncAttrs ::= + _ | OptFuncAttrs FuncAttr ;
174 OptGC ::= + _ | gc STRINGCONSTANT ;
176 OptAlign ::= + _ | align EUINT64VAL ;
177 OptCAlign ::= + _ | ^ "," align EUINT64VAL ;
179 SectionString ::= section STRINGCONSTANT ;
181 OptSection ::= + _ | SectionString ;
183 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
184 GlobalVarAttribute ::= SectionString | align EUINT64VAL ;
186 PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
192 | Types OptAddrSpace ^ "*"
195 | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
196 | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
197 | "[" ^ EUINT64VAL "x" Types ^ "]"
198 | "<" ^ EUINT64VAL "x" Types ^ ">"
201 | "<" ^ "{" TypeListI "}" ^ ">"
202 | "<" ^ "{" ^ "}" ^ ">"
205 ArgType ::= Types OptParamAttrs ;
207 ResultTypes ::= Types | void ;
209 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
211 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
213 TypeListI ::= Types | TypeListI ^ "," Types ;
215 ConstVal::= Types "[" ^ ConstVector ^ "]"
217 | Types "c" ^ STRINGCONSTANT
218 | Types "<" ^ ConstVector ^ ">"
219 | Types "{" ConstVector "}"
221 | Types "<" ^ "{" ConstVector "}" ^ ">"
222 | Types "<" ^ "{" ^ "}" ^ ">"
225 | Types SymbolicValueRef
227 | Types zeroinitializer
236 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
237 | getelementptr "(" ^ ConstVal IndexList ^ ")"
238 | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
239 | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
240 | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
241 | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
242 | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
243 | vicmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
244 | vfcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
245 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
246 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
247 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
248 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
249 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
251 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
253 GlobalType ::= global | constant ;
255 ThreadLocal ::= - "thread_local" | _ ;
257 AliaseeRef ::= ResultTypes SymbolicValueRef
258 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
260 Module ::= +++ DefinitionList | --- _ ;
262 DefinitionList ::= - Definition | + DefinitionList Definition ;
265 ::= ^ ( +++++ define Function
266 | declare FunctionProto
267 | - module asm AsmBlock
268 | OptLocalAssign type Types
269 | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
270 ConstVal GlobalVarAttributes
271 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
272 GlobalType ConstVal GlobalVarAttributes
273 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
274 GlobalType Types GlobalVarAttributes
275 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
276 | target TargetDefinition
277 | deplibs "=" LibrariesDefinition
280 AsmBlock ::= STRINGCONSTANT ;
282 TargetDefinition ::= triple "=" STRINGCONSTANT
283 | datalayout "=" STRINGCONSTANT ;
285 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
287 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
289 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
290 | Types OptParamAttrs OptLocalName ;
292 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
294 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
295 GlobalName ^ "(" ^ ArgList ^ ")"
296 OptFuncAttrs OptSection OptAlign OptGC ;
298 BEGIN ::= ( begin | "{" ) ^ "\n";
301 FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
303 END ::= ^ ( end | "}" ) ^ "\n";
305 Function ::= BasicBlockList END ;
307 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
309 OptSideEffect ::= _ | sideeffect ;
311 ConstValueRef ::= ESINT64VAL
319 | "<" ConstVector ">"
320 | "[" ConstVector "]"
322 | "c" ^ STRINGCONSTANT
323 | "{" ConstVector "}"
325 | "<" ^ "{" ConstVector "}" ^ ">"
326 | "<" ^ "{" ^ "}" ^ ">"
328 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
330 SymbolicValueRef ::= LOCALVALID
335 ValueRef ::= SymbolicValueRef | ConstValueRef;
337 ResolvedVal ::= Types ValueRef ;
339 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
341 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
343 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
345 InstructionList ::= +++ InstructionList Inst
347 | ^ LABELSTR ^ ":\n" ;
349 BBTerminatorInst ::= ^ " " ^
353 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
354 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
355 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
356 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
358 to label ValueRef unwind label ValueRef
360 | unreachable ) ^ "\n";
362 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
363 | IntType ConstValueRef ^ "," label ValueRef ;
365 Inst ::= ^ " " ^ OptLocalAssign InstVal ^ "\n";
367 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
368 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
370 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
371 | label OptParamAttrs ValueRef OptParamAttrs
372 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
373 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
376 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
378 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
380 OptTailCall ::= tail call | call ;
383 ArithmeticOps Types ValueRef ^ "," ValueRef
384 | LogicalOps Types ValueRef ^ "," ValueRef
385 | icmp IPredicates Types ValueRef ^ "," ValueRef
386 | fcmp FPredicates Types ValueRef ^ "," ValueRef
387 | vicmp IPredicates Types ValueRef ^ "," ValueRef
388 | vfcmp FPredicates Types ValueRef ^ "," ValueRef
389 | CastOps ResolvedVal to Types
390 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
391 | "va_arg" ResolvedVal ^ "," Types
392 | extractelement ResolvedVal ^ "," ResolvedVal
393 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
394 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
396 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
400 OptVolatile ::= - volatile | _ ;
402 MemoryInst ::= malloc Types OptCAlign
403 | malloc Types ^ "," INTTYPE ValueRef OptCAlign
404 | alloca Types OptCAlign
405 | alloca Types ^ "," INTTYPE ValueRef OptCAlign
407 | OptVolatile load Types ValueRef OptCAlign
408 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
409 | getresult Types ValueRef ^ "," EUINT64VAL
410 | getelementptr Types ValueRef IndexList
411 | extractvalue Types ValueRef ^ ConstantIndexList
412 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;