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 | sub | mul | udiv | sdiv | fdiv | urem | srem | frem ;
57 LogicalOps ::= shl | lshr | ashr | and | or | xor;
58 CastOps ::= trunc | zext | sext | fptrunc | fpext | bitcast |
59 uitofp | sitofp | fptoui | fptosi | inttoptr | ptrtoint ;
61 IPredicates ::= eq | ne | slt | sgt | sle | sge | ult | ugt | ule | uge ;
63 FPredicates ::= oeq | one | olt | ogt | ole | oge | ord | uno | ueq | une
64 | ult | ugt | ule | uge | true | false ;
67 FPType ::= float | double | "ppc_fp128" | fp128 | "x86_fp80";
69 LocalName ::= LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
70 OptLocalName ::= LocalName | _ ;
72 OptAddrSpace ::= - addrspace "(" ^ EUINT64VAL ^ ")" | _ ;
74 OptLocalAssign ::= LocalName "=" | _ ;
76 GlobalName ::= GLOBALVAR | ATSTRINGCONSTANT ;
78 OptGlobalAssign ::= GlobalAssign | _ ;
80 GlobalAssign ::= GlobalName "=" ;
104 FunctionDeclareLinkage
110 FunctionDefineLinkage
118 AliasLinkage ::= + _ | weak | internal ;
120 OptCallingConv ::= + _ |
129 ParamAttr ::= zeroext
141 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
143 FuncAttr ::= noreturn
151 OptFuncAttrs ::= + _ | OptFuncAttrs FuncAttr ;
153 FuncNoteList ::= FuncNote
154 | FuncNoteList ^ "," FuncNote
157 FuncNote ::= inline ^ "=" ^ never
158 | inline ^ "=" ^ always
163 | notes ^ "(" ^ FuncNoteList ^ ")"
166 OptGC ::= + _ | gc STRINGCONSTANT ;
168 OptAlign ::= + _ | align EUINT64VAL ;
169 OptCAlign ::= + _ | ^ "," align EUINT64VAL ;
171 SectionString ::= section STRINGCONSTANT ;
173 OptSection ::= + _ | SectionString ;
175 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
176 GlobalVarAttribute ::= SectionString | align EUINT64VAL ;
178 PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
184 | Types OptAddrSpace ^ "*"
187 | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
188 | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
189 | "[" ^ EUINT64VAL "x" Types ^ "]"
190 | "<" ^ EUINT64VAL "x" Types ^ ">"
193 | "<" ^ "{" TypeListI "}" ^ ">"
194 | "<" ^ "{" ^ "}" ^ ">"
197 ArgType ::= Types OptParamAttrs ;
199 ResultTypes ::= Types | void ;
201 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
203 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
205 TypeListI ::= Types | TypeListI ^ "," Types ;
207 ConstVal::= Types "[" ^ ConstVector ^ "]"
209 | Types "c" ^ STRINGCONSTANT
210 | Types "<" ^ ConstVector ^ ">"
211 | Types "{" ConstVector "}"
213 | Types "<" ^ "{" ConstVector "}" ^ ">"
214 | Types "<" ^ "{" ^ "}" ^ ">"
217 | Types SymbolicValueRef
219 | Types zeroinitializer
228 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
229 | getelementptr "(" ^ ConstVal IndexList ^ ")"
230 | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
231 | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
232 | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
233 | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
234 | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
235 | vicmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
236 | vfcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
237 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
238 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
239 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
240 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
241 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
243 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
245 GlobalType ::= global | constant ;
247 ThreadLocal ::= - "thread_local" | _ ;
249 AliaseeRef ::= ResultTypes SymbolicValueRef
250 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
252 Module ::= +++ DefinitionList | --- _ ;
254 DefinitionList ::= - Definition | + DefinitionList Definition ;
257 ::= ^ ( +++++ define Function
258 | declare FunctionProto
259 | - module asm AsmBlock
260 | OptLocalAssign type Types
261 | OptLocalAssign type void
262 | OptGlobalAssign GVVisibilityStyle ThreadLocal GlobalType ConstVal
263 OptAddrSpace GlobalVarAttributes
264 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal GlobalType
265 ConstVal OptAddrSpace GlobalVarAttributes
266 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal GlobalType
267 Types OptAddrSpace GlobalVarAttributes
268 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
269 | target TargetDefinition
270 | deplibs "=" LibrariesDefinition
273 AsmBlock ::= STRINGCONSTANT ;
275 TargetDefinition ::= triple "=" STRINGCONSTANT
276 | datalayout "=" STRINGCONSTANT ;
278 LibrariesDefinition ::= "[" LibList "]";
280 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT | _ ;
282 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
283 | Types OptParamAttrs OptLocalName ;
285 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
287 FunctionHeaderH ::= OptCallingConv ResultTypes GlobalName "(" ^ ArgList ^ ")"
288 OptFuncAttrs OptSection OptAlign OptGC OptFuncNotes ;
290 BEGIN ::= ( begin | "{" ) ^ "\n";
293 FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
295 END ::= ^ ( end | "}" ) ^ "\n";
297 Function ::= BasicBlockList END ;
299 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
301 OptSideEffect ::= _ | sideeffect ;
303 ConstValueRef ::= ESINT64VAL
311 | "<" ConstVector ">"
312 | "[" ConstVector "]"
314 | "c" ^ STRINGCONSTANT
315 | "{" ConstVector "}"
317 | "<" ^ "{" ConstVector "}" ^ ">"
318 | "<" ^ "{" ^ "}" ^ ">"
320 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
322 SymbolicValueRef ::= LOCALVALID
327 ValueRef ::= SymbolicValueRef | ConstValueRef;
329 ResolvedVal ::= Types ValueRef ;
331 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
333 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
335 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
337 InstructionList ::= +++ InstructionList Inst
339 | ^ LABELSTR ^ ":\n" ;
341 BBTerminatorInst ::= ^ " " ^
345 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
346 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
347 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
348 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
350 to label ValueRef unwind label ValueRef
352 | unreachable ) ^ "\n";
354 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
355 | IntType ConstValueRef ^ "," label ValueRef ;
357 Inst ::= ^ " " ^ OptLocalAssign InstVal ^ "\n";
359 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
360 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
362 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
363 | label OptParamAttrs ValueRef OptParamAttrs
364 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
365 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
368 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
370 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
372 OptTailCall ::= tail call | call ;
375 ArithmeticOps Types ValueRef ^ "," ValueRef
376 | LogicalOps Types ValueRef ^ "," ValueRef
377 | icmp IPredicates Types ValueRef ^ "," ValueRef
378 | fcmp FPredicates Types ValueRef ^ "," ValueRef
379 | vicmp IPredicates Types ValueRef ^ "," ValueRef
380 | vfcmp FPredicates Types ValueRef ^ "," ValueRef
381 | CastOps ResolvedVal to Types
382 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
383 | "va_arg" ResolvedVal ^ "," Types
384 | extractelement ResolvedVal ^ "," ResolvedVal
385 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
386 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
388 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
392 OptVolatile ::= - volatile | _ ;
394 MemoryInst ::= malloc Types OptCAlign
395 | malloc Types ^ "," INTTYPE ValueRef OptCAlign
396 | alloca Types OptCAlign
397 | alloca Types ^ "," INTTYPE ValueRef OptCAlign
399 | OptVolatile load Types ValueRef OptCAlign
400 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
401 | getresult Types ValueRef ^ "," EUINT64VAL
402 | getelementptr Types ValueRef IndexList
403 | extractvalue Types ValueRef ^ ConstantIndexList
404 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;