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 ::= half | bfloat | 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 "=" ;
110 FunctionDeclareLinkage
116 FunctionDefineLinkage
126 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
128 OptCallingConv ::= + _ |
136 ParamAttr ::= zeroext
147 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
156 | OptRetAttrs RetAttr
159 FuncAttr ::= noreturn
180 | nosanitize_coverage
183 OptFuncAttrs ::= + _ | OptFuncAttrs FuncAttr ;
185 OptGC ::= + _ | gc STRINGCONSTANT ;
187 OptAlign ::= + _ | align EUINT64VAL ;
188 OptCAlign ::= + _ | ^ "," align EUINT64VAL ;
190 SectionString ::= section STRINGCONSTANT ;
192 OptSection ::= + _ | SectionString ;
194 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
195 GlobalVarAttribute ::= SectionString | align EUINT64VAL ;
197 PrimType ::= INTTYPE | half | bfloat | float | double | "ppc_fp128" | fp128
198 | "x86_fp80" | "x86_mmx" | "x86_amx" | - label ;
203 | Types OptAddrSpace ^ "*"
206 | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
207 | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
208 | "[" ^ EUINT64VAL "x" Types ^ "]"
209 | "<" ^ EUINT64VAL "x" Types ^ ">"
212 | "<" ^ "{" TypeListI "}" ^ ">"
213 | "<" ^ "{" ^ "}" ^ ">"
216 ArgType ::= Types OptParamAttrs ;
218 ResultTypes ::= Types | void ;
220 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
222 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
224 TypeListI ::= Types | TypeListI ^ "," Types ;
226 ConstVal::= Types "[" ^ ConstVector ^ "]"
228 | Types "c" ^ STRINGCONSTANT
229 | Types "<" ^ ConstVector ^ ">"
230 | Types "{" ConstVector "}"
232 | Types "<" ^ "{" ConstVector "}" ^ ">"
233 | Types "<" ^ "{" ^ "}" ^ ">"
236 | Types SymbolicValueRef
238 | Types zeroinitializer
247 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
248 | getelementptr OptInBounds "(" ^ ConstVal IndexList ^ ")"
249 | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
250 | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
251 | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
252 | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
253 | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
254 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
255 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
256 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
257 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
258 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
260 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
262 GlobalType ::= global | constant ;
264 ThreadLocal ::= - "thread_local" | _ ;
266 AliaseeRef ::= ResultTypes SymbolicValueRef
267 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
269 Module ::= +++ DefinitionList | --- _ ;
271 DefinitionList ::= - Definition | + DefinitionList Definition ;
274 ::= ^ ( +++++ define Function
275 | declare FunctionProto
276 | - module asm AsmBlock
277 | OptLocalAssign type Types
278 | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
279 ConstVal GlobalVarAttributes
280 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
281 GlobalType ConstVal GlobalVarAttributes
282 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
283 GlobalType Types GlobalVarAttributes
284 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
285 | target TargetDefinition
286 | deplibs "=" LibrariesDefinition
289 AsmBlock ::= STRINGCONSTANT ;
291 TargetDefinition ::= triple "=" STRINGCONSTANT
292 | datalayout "=" STRINGCONSTANT ;
294 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
296 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
298 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
299 | Types OptParamAttrs OptLocalName ;
301 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
303 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
304 GlobalName ^ "(" ^ ArgList ^ ")"
305 OptFuncAttrs OptSection OptAlign OptGC ;
307 BEGIN ::= ( begin | "{" ) ^ "\n";
310 FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
312 END ::= ^ ( end | "}" ) ^ "\n";
314 Function ::= BasicBlockList END ;
316 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
318 OptSideEffect ::= _ | sideeffect ;
320 ConstValueRef ::= ESINT64VAL
328 | "<" ConstVector ">"
329 | "[" ConstVector "]"
331 | "c" ^ STRINGCONSTANT
332 | "{" ConstVector "}"
334 | "<" ^ "{" ConstVector "}" ^ ">"
335 | "<" ^ "{" ^ "}" ^ ">"
337 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
339 SymbolicValueRef ::= LOCALVALID
344 ValueRef ::= SymbolicValueRef | ConstValueRef;
346 ResolvedVal ::= Types ValueRef ;
348 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
350 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
352 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
354 InstructionList ::= +++ InstructionList Inst
356 | ^ LABELSTR ^ ":\n" ;
358 BBTerminatorInst ::= ^ " " ^
362 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
363 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
364 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
365 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
367 to label ValueRef unwind label ValueRef
369 | unreachable ) ^ "\n";
371 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
372 | IntType ConstValueRef ^ "," label ValueRef ;
374 Inst ::= ^ " " ^ OptLocalAssign InstVal ^ "\n";
376 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
377 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
379 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
380 | label OptParamAttrs ValueRef OptParamAttrs
381 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
382 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
385 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
387 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
389 OptTailCall ::= tail call | call ;
392 ArithmeticOps Types ValueRef ^ "," ValueRef
393 | LogicalOps Types ValueRef ^ "," ValueRef
394 | icmp IPredicates Types ValueRef ^ "," ValueRef
395 | fcmp FPredicates Types ValueRef ^ "," ValueRef
396 | CastOps ResolvedVal to Types
397 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
398 | "va_arg" ResolvedVal ^ "," Types
399 | extractelement ResolvedVal ^ "," ResolvedVal
400 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
401 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
403 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
407 OptVolatile ::= - volatile | _ ;
408 OptExact ::= - exact | _ ;
409 OptNSW ::= - nsw | _ ;
410 OptNUW ::= - nuw | _ ;
411 OptNW ::= OptNUW OptNSW | OptNSW OptNUW ;
412 OptInBounds ::= - inbounds | _ ;
414 MemoryInst ::= malloc Types OptCAlign
415 | malloc Types ^ "," INTTYPE ValueRef OptCAlign
416 | alloca Types OptCAlign
417 | alloca Types ^ "," INTTYPE ValueRef OptCAlign
419 | OptVolatile load Types ValueRef OptCAlign
420 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
421 | getresult Types ValueRef ^ "," EUINT64VAL
422 | getelementptr OptInBounds Types ValueRef IndexList
423 | extractvalue Types ValueRef ^ ConstantIndexList
424 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;