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 | fadd | sub | fsub | mul | fmul |
57 udiv | sdiv | fdiv | urem | srem | frem ;
58 LogicalOps ::= shl | lshr | ashr | and | or | xor;
59 CastOps ::= trunc | zext | sext | fptrunc | fpext | bitcast |
60 uitofp | sitofp | fptoui | fptosi | inttoptr | ptrtoint ;
62 IPredicates ::= eq | ne | slt | sgt | sle | sge | ult | ugt | ule | uge ;
64 FPredicates ::= oeq | one | olt | ogt | ole | oge | ord | uno | ueq | une
65 | ult | ugt | ule | uge | true | false ;
68 FPType ::= float | double | "ppc_fp128" | fp128 | "x86_fp80";
70 LocalName ::= LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
71 OptLocalName ::= LocalName | _ ;
73 OptAddrSpace ::= - addrspace ^ "(" ^ EUINT64VAL ^ ")" | _ ;
75 OptLocalAssign ::= LocalName "=" | _ ;
77 GlobalName ::= GLOBALVAR | ATSTRINGCONSTANT ;
79 OptGlobalAssign ::= GlobalAssign | _ ;
81 GlobalAssign ::= GlobalName "=" ;
107 FunctionDeclareLinkage
113 FunctionDefineLinkage
123 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
125 OptCallingConv ::= + _ |
133 ParamAttr ::= zeroext
144 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
153 | OptRetAttrs RetAttr
156 FuncAttr ::= noreturn
170 OptFuncAttrs ::= + _ | OptFuncAttrs FuncAttr ;
172 OptGC ::= + _ | gc STRINGCONSTANT ;
174 OptAlign ::= + _ | align EUINT64VAL ;
175 OptCAlign ::= + _ | ^ "," align EUINT64VAL ;
177 SectionString ::= section STRINGCONSTANT ;
179 OptSection ::= + _ | SectionString ;
181 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
182 GlobalVarAttribute ::= SectionString | align EUINT64VAL ;
184 PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
190 | Types OptAddrSpace ^ "*"
193 | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
194 | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
195 | "[" ^ EUINT64VAL "x" Types ^ "]"
196 | "<" ^ EUINT64VAL "x" Types ^ ">"
199 | "<" ^ "{" TypeListI "}" ^ ">"
200 | "<" ^ "{" ^ "}" ^ ">"
203 ArgType ::= Types OptParamAttrs ;
205 ResultTypes ::= Types | void ;
207 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
209 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
211 TypeListI ::= Types | TypeListI ^ "," Types ;
213 ConstVal::= Types "[" ^ ConstVector ^ "]"
215 | Types "c" ^ STRINGCONSTANT
216 | Types "<" ^ ConstVector ^ ">"
217 | Types "{" ConstVector "}"
219 | Types "<" ^ "{" ConstVector "}" ^ ">"
220 | Types "<" ^ "{" ^ "}" ^ ">"
223 | Types SymbolicValueRef
225 | Types zeroinitializer
234 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
235 | getelementptr "(" ^ ConstVal IndexList ^ ")"
236 | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
237 | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
238 | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
239 | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
240 | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
241 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
242 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
243 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
244 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
245 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
247 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
249 GlobalType ::= global | constant ;
251 ThreadLocal ::= - "thread_local" | _ ;
253 AliaseeRef ::= ResultTypes SymbolicValueRef
254 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
256 Module ::= +++ DefinitionList | --- _ ;
258 DefinitionList ::= - Definition | + DefinitionList Definition ;
261 ::= ^ ( +++++ define Function
262 | declare FunctionProto
263 | - module asm AsmBlock
264 | OptLocalAssign type Types
265 | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
266 ConstVal GlobalVarAttributes
267 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
268 GlobalType ConstVal GlobalVarAttributes
269 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
270 GlobalType Types GlobalVarAttributes
271 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
272 | target TargetDefinition
273 | deplibs "=" LibrariesDefinition
276 AsmBlock ::= STRINGCONSTANT ;
278 TargetDefinition ::= triple "=" STRINGCONSTANT
279 | datalayout "=" STRINGCONSTANT ;
281 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
283 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
285 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
286 | Types OptParamAttrs OptLocalName ;
288 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
290 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
291 GlobalName ^ "(" ^ ArgList ^ ")"
292 OptFuncAttrs OptSection OptAlign OptGC ;
294 BEGIN ::= ( begin | "{" ) ^ "\n";
297 FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
299 END ::= ^ ( end | "}" ) ^ "\n";
301 Function ::= BasicBlockList END ;
303 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
305 OptSideEffect ::= _ | sideeffect ;
307 ConstValueRef ::= ESINT64VAL
315 | "<" ConstVector ">"
316 | "[" ConstVector "]"
318 | "c" ^ STRINGCONSTANT
319 | "{" ConstVector "}"
321 | "<" ^ "{" ConstVector "}" ^ ">"
322 | "<" ^ "{" ^ "}" ^ ">"
324 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
326 SymbolicValueRef ::= LOCALVALID
331 ValueRef ::= SymbolicValueRef | ConstValueRef;
333 ResolvedVal ::= Types ValueRef ;
335 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
337 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
339 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
341 InstructionList ::= +++ InstructionList Inst
343 | ^ LABELSTR ^ ":\n" ;
345 BBTerminatorInst ::= ^ " " ^
349 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
350 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
351 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
352 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
354 to label ValueRef unwind label ValueRef
356 | unreachable ) ^ "\n";
358 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
359 | IntType ConstValueRef ^ "," label ValueRef ;
361 Inst ::= ^ " " ^ OptLocalAssign InstVal ^ "\n";
363 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
364 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
366 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
367 | label OptParamAttrs ValueRef OptParamAttrs
368 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
369 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
372 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
374 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
376 OptTailCall ::= tail call | call ;
379 ArithmeticOps Types ValueRef ^ "," ValueRef
380 | LogicalOps Types ValueRef ^ "," ValueRef
381 | icmp IPredicates Types ValueRef ^ "," ValueRef
382 | fcmp FPredicates Types ValueRef ^ "," ValueRef
383 | CastOps ResolvedVal to Types
384 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
385 | "va_arg" ResolvedVal ^ "," Types
386 | extractelement ResolvedVal ^ "," ResolvedVal
387 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
388 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
390 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
394 OptVolatile ::= - volatile | _ ;
396 MemoryInst ::= malloc Types OptCAlign
397 | malloc Types ^ "," INTTYPE ValueRef OptCAlign
398 | alloca Types OptCAlign
399 | alloca Types ^ "," INTTYPE ValueRef OptCAlign
401 | OptVolatile load Types ValueRef OptCAlign
402 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
403 | getresult Types ValueRef ^ "," EUINT64VAL
404 | getelementptr Types ValueRef IndexList
405 | extractvalue Types ValueRef ^ ConstantIndexList
406 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;