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
179 OptFuncAttrs ::= + _ | OptFuncAttrs FuncAttr ;
181 OptGC ::= + _ | gc STRINGCONSTANT ;
183 OptAlign ::= + _ | align EUINT64VAL ;
184 OptCAlign ::= + _ | ^ "," align EUINT64VAL ;
186 SectionString ::= section STRINGCONSTANT ;
188 OptSection ::= + _ | SectionString ;
190 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
191 GlobalVarAttribute ::= SectionString | align EUINT64VAL ;
193 PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
199 | Types OptAddrSpace ^ "*"
202 | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
203 | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
204 | "[" ^ EUINT64VAL "x" Types ^ "]"
205 | "<" ^ EUINT64VAL "x" Types ^ ">"
208 | "<" ^ "{" TypeListI "}" ^ ">"
209 | "<" ^ "{" ^ "}" ^ ">"
212 ArgType ::= Types OptParamAttrs ;
214 ResultTypes ::= Types | void ;
216 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
218 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
220 TypeListI ::= Types | TypeListI ^ "," Types ;
222 ConstVal::= Types "[" ^ ConstVector ^ "]"
224 | Types "c" ^ STRINGCONSTANT
225 | Types "<" ^ ConstVector ^ ">"
226 | Types "{" ConstVector "}"
228 | Types "<" ^ "{" ConstVector "}" ^ ">"
229 | Types "<" ^ "{" ^ "}" ^ ">"
232 | Types SymbolicValueRef
234 | Types zeroinitializer
243 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
244 | getelementptr OptInBounds "(" ^ ConstVal IndexList ^ ")"
245 | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
246 | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
247 | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
248 | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
249 | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
250 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
251 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
252 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
253 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
254 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
256 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
258 GlobalType ::= global | constant ;
260 ThreadLocal ::= - "thread_local" | _ ;
262 AliaseeRef ::= ResultTypes SymbolicValueRef
263 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
265 Module ::= +++ DefinitionList | --- _ ;
267 DefinitionList ::= - Definition | + DefinitionList Definition ;
270 ::= ^ ( +++++ define Function
271 | declare FunctionProto
272 | - module asm AsmBlock
273 | OptLocalAssign type Types
274 | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
275 ConstVal GlobalVarAttributes
276 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
277 GlobalType ConstVal GlobalVarAttributes
278 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
279 GlobalType Types GlobalVarAttributes
280 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
281 | target TargetDefinition
282 | deplibs "=" LibrariesDefinition
285 AsmBlock ::= STRINGCONSTANT ;
287 TargetDefinition ::= triple "=" STRINGCONSTANT
288 | datalayout "=" STRINGCONSTANT ;
290 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
292 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
294 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
295 | Types OptParamAttrs OptLocalName ;
297 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
299 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
300 GlobalName ^ "(" ^ ArgList ^ ")"
301 OptFuncAttrs OptSection OptAlign OptGC ;
303 BEGIN ::= ( begin | "{" ) ^ "\n";
306 FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
308 END ::= ^ ( end | "}" ) ^ "\n";
310 Function ::= BasicBlockList END ;
312 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
314 OptSideEffect ::= _ | sideeffect ;
316 ConstValueRef ::= ESINT64VAL
324 | "<" ConstVector ">"
325 | "[" ConstVector "]"
327 | "c" ^ STRINGCONSTANT
328 | "{" ConstVector "}"
330 | "<" ^ "{" ConstVector "}" ^ ">"
331 | "<" ^ "{" ^ "}" ^ ">"
333 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
335 SymbolicValueRef ::= LOCALVALID
340 ValueRef ::= SymbolicValueRef | ConstValueRef;
342 ResolvedVal ::= Types ValueRef ;
344 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
346 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
348 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
350 InstructionList ::= +++ InstructionList Inst
352 | ^ LABELSTR ^ ":\n" ;
354 BBTerminatorInst ::= ^ " " ^
358 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
359 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
360 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
361 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
363 to label ValueRef unwind label ValueRef
365 | unreachable ) ^ "\n";
367 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
368 | IntType ConstValueRef ^ "," label ValueRef ;
370 Inst ::= ^ " " ^ OptLocalAssign InstVal ^ "\n";
372 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
373 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
375 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
376 | label OptParamAttrs ValueRef OptParamAttrs
377 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
378 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
381 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
383 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
385 OptTailCall ::= tail call | call ;
388 ArithmeticOps Types ValueRef ^ "," ValueRef
389 | LogicalOps Types ValueRef ^ "," ValueRef
390 | icmp IPredicates Types ValueRef ^ "," ValueRef
391 | fcmp FPredicates Types ValueRef ^ "," ValueRef
392 | CastOps ResolvedVal to Types
393 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
394 | "va_arg" ResolvedVal ^ "," Types
395 | extractelement ResolvedVal ^ "," ResolvedVal
396 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
397 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
399 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
403 OptVolatile ::= - volatile | _ ;
404 OptExact ::= - exact | _ ;
405 OptNSW ::= - nsw | _ ;
406 OptNUW ::= - nuw | _ ;
407 OptNW ::= OptNUW OptNSW | OptNSW OptNUW ;
408 OptInBounds ::= - inbounds | _ ;
410 MemoryInst ::= malloc Types OptCAlign
411 | malloc Types ^ "," INTTYPE ValueRef OptCAlign
412 | alloca Types OptCAlign
413 | alloca Types ^ "," INTTYPE ValueRef OptCAlign
415 | OptVolatile load Types ValueRef OptCAlign
416 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
417 | getresult Types ValueRef ^ "," EUINT64VAL
418 | getelementptr OptInBounds Types ValueRef IndexList
419 | extractvalue Types ValueRef ^ ConstantIndexList
420 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;