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
11 TODO: Metadata, in all its forms
15 I ::= "title: LLVM assembly language\n"
16 ^ "status: experimental\n"
17 ^ "audience: LLVM developers\n"
23 Define rules for non-keyword tokens. This is currently just a bunch
24 of hacks. They don't cover many valid forms of tokens, and they also
25 generate some invalid forms of tokens. The LLVM parser has custom
26 C++ code to lex these; custom C++ code for emitting them would be
27 convenient, but polygen doesn't support that.
29 NonZeroDecimalDigit ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
30 DecimalDigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
31 DecimalDigitSeq ::= DecimalDigit [^ DecimalDigitSeq ];
32 HexDigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
33 | a | b | c | d | e | f ;
34 HexDigitSeq ::= HexDigit [^ HexDigitSeq ];
35 StringChar ::= a | b | c | d | e | f | g | h | i | j | k | l | m
36 | n | o | p | q | r | s | t | u | v | w | x | y | z ;
37 StringConstantSeq ::= StringChar [^ StringConstantSeq ];
38 StringConstant ::= StringChar [^ StringConstantSeq ];
39 EUINT64VAL ::= NonZeroDecimalDigit [^ DecimalDigitSeq ];
40 ESINT64VAL ::= [ "-" ] ^ EUINT64VAL ;
41 EUAPINTVAL ::= EUINT64VAL ;
42 ESAPINTVAL ::= ESINT64VAL ;
43 LOCALVALID ::= "%" ^ DecimalDigitSeq ;
44 GLOBALVALID ::= "@" ^ DecimalDigitSeq ;
45 INTTYPE ::= "i" ^ EUINT64VAL ;
46 GLOBALVAR ::= "@" ^ StringConstant ;
47 LOCALVAR ::= "%" ^ StringConstant ;
48 STRINGCONSTANT ::= "\"" ^ StringConstant ^ "\"" ;
49 ATSTRINGCONSTANT ::= "@" ^ STRINGCONSTANT ;
50 PCTSTRINGCONSTANT ::= "%" ^ STRINGCONSTANT ;
51 LABELSTR ::= StringConstant ;
52 FPVAL ::= ESAPINTVAL ^ "." ^ EUAPINTVAL | "0x" ^ HexDigitSeq ;
55 The rest of this file is derived directly from llvmAsmParser.y.
58 ArithmeticOps ::= + OptNW add | fadd | OptNW sub | fsub | OptNW mul | fmul |
59 udiv | OptExact sdiv | fdiv | urem | srem | frem ;
60 LogicalOps ::= shl | lshr | ashr | and | or | xor;
61 CastOps ::= trunc | zext | sext | fptrunc | fpext | bitcast |
62 uitofp | sitofp | fptoui | fptosi | inttoptr | ptrtoint ;
64 IPredicates ::= eq | ne | slt | sgt | sle | sge | ult | ugt | ule | uge ;
66 FPredicates ::= oeq | one | olt | ogt | ole | oge | ord | uno | ueq | une
67 | ult | ugt | ule | uge | true | false ;
70 FPType ::= float | double | "ppc_fp128" | fp128 | "x86_fp80";
72 LocalName ::= LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
73 OptLocalName ::= LocalName | _ ;
75 OptAddrSpace ::= - addrspace ^ "(" ^ EUINT64VAL ^ ")" | _ ;
77 OptLocalAssign ::= LocalName "=" | _ ;
79 GlobalName ::= GLOBALVAR | ATSTRINGCONSTANT ;
81 OptGlobalAssign ::= GlobalAssign | _ ;
83 GlobalAssign ::= GlobalName "=" ;
96 | "linker_private_weak"
112 FunctionDeclareLinkage
118 FunctionDefineLinkage
128 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
130 OptCallingConv ::= + _ |
138 ParamAttr ::= zeroext
149 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
158 | OptRetAttrs RetAttr
161 FuncAttr ::= noreturn
180 OptFuncAttrs ::= + _ | OptFuncAttrs FuncAttr ;
182 OptGC ::= + _ | gc STRINGCONSTANT ;
184 OptAlign ::= + _ | align EUINT64VAL ;
185 OptCAlign ::= + _ | ^ "," align EUINT64VAL ;
187 SectionString ::= section STRINGCONSTANT ;
189 OptSection ::= + _ | SectionString ;
191 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
192 GlobalVarAttribute ::= SectionString | align EUINT64VAL ;
194 PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
200 | Types OptAddrSpace ^ "*"
203 | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
204 | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
205 | "[" ^ EUINT64VAL "x" Types ^ "]"
206 | "<" ^ EUINT64VAL "x" Types ^ ">"
209 | "<" ^ "{" TypeListI "}" ^ ">"
210 | "<" ^ "{" ^ "}" ^ ">"
213 ArgType ::= Types OptParamAttrs ;
215 ResultTypes ::= Types | void ;
217 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
219 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
221 TypeListI ::= Types | TypeListI ^ "," Types ;
223 ConstVal::= Types "[" ^ ConstVector ^ "]"
225 | Types "c" ^ STRINGCONSTANT
226 | Types "<" ^ ConstVector ^ ">"
227 | Types "{" ConstVector "}"
229 | Types "<" ^ "{" ConstVector "}" ^ ">"
230 | Types "<" ^ "{" ^ "}" ^ ">"
233 | Types SymbolicValueRef
235 | Types zeroinitializer
244 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
245 | getelementptr OptInBounds "(" ^ ConstVal IndexList ^ ")"
246 | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
247 | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
248 | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
249 | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
250 | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
251 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
252 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
253 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
254 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
255 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
257 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
259 GlobalType ::= global | constant ;
261 ThreadLocal ::= - "thread_local" | _ ;
263 AliaseeRef ::= ResultTypes SymbolicValueRef
264 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
266 Module ::= +++ DefinitionList | --- _ ;
268 DefinitionList ::= - Definition | + DefinitionList Definition ;
271 ::= ^ ( +++++ define Function
272 | declare FunctionProto
273 | - module asm AsmBlock
274 | OptLocalAssign type Types
275 | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
276 ConstVal GlobalVarAttributes
277 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
278 GlobalType ConstVal GlobalVarAttributes
279 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
280 GlobalType Types GlobalVarAttributes
281 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
282 | target TargetDefinition
283 | deplibs "=" LibrariesDefinition
286 AsmBlock ::= STRINGCONSTANT ;
288 TargetDefinition ::= triple "=" STRINGCONSTANT
289 | datalayout "=" STRINGCONSTANT ;
291 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
293 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
295 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
296 | Types OptParamAttrs OptLocalName ;
298 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
300 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
301 GlobalName ^ "(" ^ ArgList ^ ")"
302 OptFuncAttrs OptSection OptAlign OptGC ;
304 BEGIN ::= ( begin | "{" ) ^ "\n";
307 FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
309 END ::= ^ ( end | "}" ) ^ "\n";
311 Function ::= BasicBlockList END ;
313 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
315 OptSideEffect ::= _ | sideeffect ;
317 ConstValueRef ::= ESINT64VAL
325 | "<" ConstVector ">"
326 | "[" ConstVector "]"
328 | "c" ^ STRINGCONSTANT
329 | "{" ConstVector "}"
331 | "<" ^ "{" ConstVector "}" ^ ">"
332 | "<" ^ "{" ^ "}" ^ ">"
334 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
336 SymbolicValueRef ::= LOCALVALID
341 ValueRef ::= SymbolicValueRef | ConstValueRef;
343 ResolvedVal ::= Types ValueRef ;
345 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
347 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
349 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
351 InstructionList ::= +++ InstructionList Inst
353 | ^ LABELSTR ^ ":\n" ;
355 BBTerminatorInst ::= ^ " " ^
359 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
360 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
361 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
362 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
364 to label ValueRef unwind label ValueRef
366 | unreachable ) ^ "\n";
368 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
369 | IntType ConstValueRef ^ "," label ValueRef ;
371 Inst ::= ^ " " ^ OptLocalAssign InstVal ^ "\n";
373 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
374 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
376 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
377 | label OptParamAttrs ValueRef OptParamAttrs
378 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
379 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
382 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
384 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
386 OptTailCall ::= tail call | call ;
389 ArithmeticOps Types ValueRef ^ "," ValueRef
390 | LogicalOps Types ValueRef ^ "," ValueRef
391 | icmp IPredicates Types ValueRef ^ "," ValueRef
392 | fcmp FPredicates Types ValueRef ^ "," ValueRef
393 | CastOps ResolvedVal to Types
394 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
395 | "va_arg" ResolvedVal ^ "," Types
396 | extractelement ResolvedVal ^ "," ResolvedVal
397 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
398 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
400 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
404 OptVolatile ::= - volatile | _ ;
405 OptExact ::= - exact | _ ;
406 OptNSW ::= - nsw | _ ;
407 OptNUW ::= - nuw | _ ;
408 OptNW ::= OptNUW OptNSW | OptNSW OptNUW ;
409 OptInBounds ::= - inbounds | _ ;
411 MemoryInst ::= malloc Types OptCAlign
412 | malloc Types ^ "," INTTYPE ValueRef OptCAlign
413 | alloca Types OptCAlign
414 | alloca Types ^ "," INTTYPE ValueRef OptCAlign
416 | OptVolatile load Types ValueRef OptCAlign
417 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
418 | getresult Types ValueRef ^ "," EUINT64VAL
419 | getelementptr OptInBounds Types ValueRef IndexList
420 | extractvalue Types ValueRef ^ ConstantIndexList
421 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;