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 ::= + OptNW add | fadd | OptNW sub | fsub | OptNW mul | fmul |
57 udiv | OptExact 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 "=" ;
108 FunctionDeclareLinkage
114 FunctionDefineLinkage
124 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
126 OptCallingConv ::= + _ |
134 ParamAttr ::= zeroext
145 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
154 | OptRetAttrs RetAttr
157 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 OptInBounds "(" ^ 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 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
244 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
245 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
246 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
247 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
249 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
251 GlobalType ::= global | constant ;
253 ThreadLocal ::= - "thread_local" | _ ;
255 AliaseeRef ::= ResultTypes SymbolicValueRef
256 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
258 Module ::= +++ DefinitionList | --- _ ;
260 DefinitionList ::= - Definition | + DefinitionList Definition ;
263 ::= ^ ( +++++ define Function
264 | declare FunctionProto
265 | - module asm AsmBlock
266 | OptLocalAssign type Types
267 | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
268 ConstVal GlobalVarAttributes
269 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
270 GlobalType ConstVal GlobalVarAttributes
271 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
272 GlobalType Types GlobalVarAttributes
273 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
274 | target TargetDefinition
275 | deplibs "=" LibrariesDefinition
278 AsmBlock ::= STRINGCONSTANT ;
280 TargetDefinition ::= triple "=" STRINGCONSTANT
281 | datalayout "=" STRINGCONSTANT ;
283 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
285 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
287 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
288 | Types OptParamAttrs OptLocalName ;
290 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
292 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
293 GlobalName ^ "(" ^ ArgList ^ ")"
294 OptFuncAttrs OptSection OptAlign OptGC ;
296 BEGIN ::= ( begin | "{" ) ^ "\n";
299 FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
301 END ::= ^ ( end | "}" ) ^ "\n";
303 Function ::= BasicBlockList END ;
305 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
307 OptSideEffect ::= _ | sideeffect ;
309 ConstValueRef ::= ESINT64VAL
317 | "<" ConstVector ">"
318 | "[" ConstVector "]"
320 | "c" ^ STRINGCONSTANT
321 | "{" ConstVector "}"
323 | "<" ^ "{" ConstVector "}" ^ ">"
324 | "<" ^ "{" ^ "}" ^ ">"
326 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
328 SymbolicValueRef ::= LOCALVALID
333 ValueRef ::= SymbolicValueRef | ConstValueRef;
335 ResolvedVal ::= Types ValueRef ;
337 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
339 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
341 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
343 InstructionList ::= +++ InstructionList Inst
345 | ^ LABELSTR ^ ":\n" ;
347 BBTerminatorInst ::= ^ " " ^
351 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
352 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
353 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
354 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
356 to label ValueRef unwind label ValueRef
358 | unreachable ) ^ "\n";
360 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
361 | IntType ConstValueRef ^ "," label ValueRef ;
363 Inst ::= ^ " " ^ OptLocalAssign InstVal ^ "\n";
365 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
366 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
368 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
369 | label OptParamAttrs ValueRef OptParamAttrs
370 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
371 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
374 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
376 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
378 OptTailCall ::= tail call | call ;
381 ArithmeticOps Types ValueRef ^ "," ValueRef
382 | LogicalOps Types ValueRef ^ "," ValueRef
383 | icmp IPredicates Types ValueRef ^ "," ValueRef
384 | fcmp FPredicates Types ValueRef ^ "," ValueRef
385 | CastOps ResolvedVal to Types
386 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
387 | "va_arg" ResolvedVal ^ "," Types
388 | extractelement ResolvedVal ^ "," ResolvedVal
389 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
390 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
392 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
396 OptVolatile ::= - volatile | _ ;
397 OptExact ::= - exact | _ ;
398 OptNSW ::= - nsw | _ ;
399 OptNUW ::= - nuw | _ ;
400 OptNW ::= OptNUW OptNSW ;
401 OptInBounds ::= - inbounds | _ ;
403 MemoryInst ::= malloc Types OptCAlign
404 | malloc Types ^ "," INTTYPE ValueRef OptCAlign
405 | alloca Types OptCAlign
406 | alloca Types ^ "," INTTYPE ValueRef OptCAlign
408 | OptVolatile load Types ValueRef OptCAlign
409 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
410 | getresult Types ValueRef ^ "," EUINT64VAL
411 | getelementptr OptInBounds Types ValueRef IndexList
412 | extractvalue Types ValueRef ^ ConstantIndexList
413 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;