brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.7 KiB · dddfe3c Raw
426 lines · plain
1(*2 3polygen grammar for LLVM assembly language.4 5This file defines an LLVM assembly language grammar for polygen,6which is a tool for generating random text based on a grammar.7It is strictly syntax-based, and makes no attempt to generate8IR that is semantically valid. Most of the IR produced doesn't9pass the Verifier.10 11TODO: Metadata, in all its forms12 13*)14 15I ::=   "title:    LLVM assembly language\n"16      ^ "status:   experimental\n"17      ^ "audience: LLVM developers\n"18;19 20S ::= Module ;21 22(*23Define rules for non-keyword tokens. This is currently just a bunch24of hacks. They don't cover many valid forms of tokens, and they also25generate some invalid forms of tokens. The LLVM parser has custom26C++ code to lex these; custom C++ code for emitting them would be27convenient, but polygen doesn't support that.28*)29NonZeroDecimalDigit ::=     1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;30DecimalDigit        ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;31DecimalDigitSeq     ::= DecimalDigit [^ DecimalDigitSeq ];32HexDigit            ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 933                      | a | b | c | d | e | f ;34HexDigitSeq         ::= HexDigit [^ HexDigitSeq ];35StringChar          ::= a | b | c | d | e | f | g | h | i | j | k | l | m36                      | n | o | p | q | r | s | t | u | v | w | x | y | z ;37StringConstantSeq   ::= StringChar [^ StringConstantSeq ];38StringConstant      ::= StringChar [^ StringConstantSeq ];39EUINT64VAL          ::= NonZeroDecimalDigit [^ DecimalDigitSeq ];40ESINT64VAL          ::= [ "-" ] ^ EUINT64VAL ;41EUAPINTVAL          ::= EUINT64VAL ;42ESAPINTVAL          ::= ESINT64VAL ;43LOCALVALID          ::= "%" ^ DecimalDigitSeq ;44GLOBALVALID         ::= "@" ^ DecimalDigitSeq ;45INTTYPE             ::= "i" ^ EUINT64VAL ;46GLOBALVAR           ::= "@" ^ StringConstant ;47LOCALVAR            ::= "%" ^ StringConstant ;48STRINGCONSTANT      ::= "\"" ^ StringConstant ^ "\"" ;49ATSTRINGCONSTANT    ::= "@" ^ STRINGCONSTANT ;50PCTSTRINGCONSTANT   ::= "%" ^ STRINGCONSTANT ;51LABELSTR            ::= StringConstant ;52FPVAL               ::= ESAPINTVAL ^ "." ^ EUAPINTVAL | "0x" ^ HexDigitSeq ;53 54(*55The rest of this file is derived directly from llvmAsmParser.y.56*)57 58ArithmeticOps ::= + OptNW add | fadd | OptNW sub | fsub | OptNW mul | fmul |59                  udiv | OptExact sdiv | fdiv | urem | srem | frem ;60LogicalOps    ::= shl | lshr | ashr | and | or | xor;61CastOps       ::= trunc | zext | sext | fptrunc | fpext | bitcast |62                  uitofp | sitofp | fptoui | fptosi | inttoptr | ptrtoint ;63 64IPredicates ::= eq | ne | slt | sgt | sle | sge | ult | ugt | ule | uge ;65 66FPredicates ::= oeq | one | olt | ogt | ole | oge | ord | uno | ueq | une67              | ult | ugt | ule | uge | true | false ;68 69IntType ::= INTTYPE;70FPType  ::= half | bfloat | float | double | "ppc_fp128" | fp128 | "x86_fp80";71 72LocalName ::= LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;73OptLocalName ::= LocalName | _ ;74 75OptAddrSpace ::= - addrspace ^ "(" ^ EUINT64VAL ^ ")" | _ ;76 77OptLocalAssign ::= LocalName "=" | _ ;78 79GlobalName ::= GLOBALVAR | ATSTRINGCONSTANT ;80 81OptGlobalAssign ::= GlobalAssign | _ ;82 83GlobalAssign ::= GlobalName "=" ;84 85GVInternalLinkage86  ::= + internal87 | weak88 | "weak_odr"89 | linkonce90 | "linkonce_odr"91 | appending92 | dllexport93 | common94 | private95 ;96 97GVExternalLinkage98  ::= dllimport99 | "extern_weak"100 | + external101 ;102 103GVVisibilityStyle104  ::= + _105 | default106 | hidden107 | protected108 ;109 110FunctionDeclareLinkage111  ::= + _112 | dllimport113 | "extern_weak"114 ;115 116FunctionDefineLinkage117  ::= + _118 | internal119 | linkonce120 | "linkonce_odr"121 | weak122 | "weak_odr"123 | dllexport124 ;125 126AliasLinkage ::= + _ | weak | "weak_odr" | internal ;127 128OptCallingConv ::= + _ |129                 ccc |130                 fastcc |131                 coldcc |132                 "x86_stdcallcc" |133                 "x86_fastcallcc" |134                 cc EUINT64VAL ;135 136ParamAttr ::= zeroext137 | signext138 | inreg139 | sret140 | noalias141 | nocapture142 | byval143 | nest144 | align EUINT64VAL145 ;146 147OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;148 149RetAttr       ::= inreg150              | zeroext151              | signext152              | noalias153              ;154 155OptRetAttrs  ::= _156             | OptRetAttrs RetAttr157             ;158 159FuncAttr      ::= noreturn160 | nounwind161 | inreg162 | zeroext163 | signext164 | readnone165 | readonly166 | inlinehint167 | alignstack168 | noinline169 | alwaysinline170 | optsize171 | ssp172 | sspreq173 | returns_twice174 | nonlazybind175 | sanitize_address176 | sanitize_alloc_token177 | sanitize_thread178 | sanitize_memory179 | mustprogress180 | nosanitize_bounds181 | nosanitize_coverage182 ;183 184OptFuncAttrs  ::= + _ | OptFuncAttrs FuncAttr ;185 186OptGC         ::= + _ | gc STRINGCONSTANT ;187 188OptAlign      ::= + _ | align EUINT64VAL ;189OptCAlign     ::= + _ | ^ "," align EUINT64VAL ;190 191SectionString ::= section STRINGCONSTANT ;192 193OptSection    ::= + _ | SectionString ;194 195GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;196GlobalVarAttribute  ::= SectionString | align EUINT64VAL ;197 198PrimType ::= INTTYPE | half | bfloat | float | double | "ppc_fp128" | fp128199          | "x86_fp80" | "x86_mmx" | "x86_amx" | - label ;200 201Types202  ::= opaque203 | PrimType204 | Types OptAddrSpace ^ "*"205 | SymbolicValueRef206 | "\\" ^ EUINT64VAL207 | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs208 | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs209 | "[" ^ EUINT64VAL "x" Types ^ "]"210 | "<" ^ EUINT64VAL "x" Types ^ ">"211 | "{" TypeListI "}"212 | "{" ^ "}"213 | "<" ^ "{" TypeListI "}" ^ ">"214 | "<" ^ "{" ^ "}" ^ ">"215 ;216 217ArgType ::= Types OptParamAttrs ;218 219ResultTypes ::= Types | void ;220 221ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;222 223ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;224 225TypeListI ::= Types | TypeListI ^ "," Types ;226 227ConstVal::= Types "[" ^ ConstVector ^ "]"228 | Types "[" ^ "]"229 | Types "c" ^ STRINGCONSTANT230 | Types "<" ^ ConstVector ^ ">"231 | Types "{" ConstVector "}"232 | Types "{" ^ "}"233 | Types "<" ^ "{" ConstVector "}" ^ ">"234 | Types "<" ^ "{" ^ "}" ^ ">"235 | Types null236 | Types undef237 | Types SymbolicValueRef238 | Types ConstExpr239 | Types zeroinitializer240 | Types ESINT64VAL241 | Types ESAPINTVAL242 | Types EUINT64VAL243 | Types EUAPINTVAL244 | Types true245 | Types false246 | Types FPVAL ;247 248ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"249 | getelementptr OptInBounds "(" ^ ConstVal IndexList ^ ")"250 | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"251 | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"252 | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"253 | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"254 | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"255 | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"256 | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"257 | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"258 | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"259 | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;260 261ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;262 263GlobalType ::= global | constant ;264 265ThreadLocal ::= - "thread_local" | _ ;266 267AliaseeRef ::= ResultTypes SymbolicValueRef268 | bitcast "(" ^ AliaseeRef to Types ^ ")" ;269 270Module ::= +++ DefinitionList | --- _ ;271 272DefinitionList ::= - Definition | + DefinitionList Definition ;273 274Definition275  ::= ^ ( +++++ define Function276 | declare FunctionProto277 | - module asm AsmBlock278 | OptLocalAssign type Types279 | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType280   ConstVal GlobalVarAttributes281 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace282   GlobalType ConstVal GlobalVarAttributes283 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace284   GlobalType Types GlobalVarAttributes285 | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef286 | target TargetDefinition287 | deplibs "=" LibrariesDefinition288 ) ^ "\n";289 290AsmBlock ::= STRINGCONSTANT ;291 292TargetDefinition ::= triple "=" STRINGCONSTANT293 | datalayout "=" STRINGCONSTANT ;294 295LibrariesDefinition ::= "[" ( LibList | _ ) "]";296 297LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;298 299ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName300 | Types OptParamAttrs OptLocalName ;301 302ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;303 304FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes305                  GlobalName ^ "(" ^ ArgList ^ ")"306                  OptFuncAttrs OptSection OptAlign OptGC ;307 308BEGIN ::= ( begin | "{" ) ^ "\n";309 310FunctionHeader ::=311  FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;312 313END ::= ^ ( end | "}" ) ^ "\n";314 315Function ::= BasicBlockList END ;316 317FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;318 319OptSideEffect ::= _ | sideeffect ;320 321ConstValueRef ::= ESINT64VAL322 | EUINT64VAL323 | FPVAL324 | true325 | false326 | null327 | undef328 | zeroinitializer329 | "<" ConstVector ">"330 | "[" ConstVector "]"331 | "[" ^ "]"332 | "c" ^ STRINGCONSTANT333 | "{" ConstVector "}"334 | "{" ^ "}"335 | "<" ^ "{" ConstVector "}" ^ ">"336 | "<" ^ "{" ^ "}" ^ ">"337 | ConstExpr338 | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;339 340SymbolicValueRef ::= LOCALVALID341 | GLOBALVALID342 | LocalName343 | GlobalName ;344 345ValueRef ::= SymbolicValueRef | ConstValueRef;346 347ResolvedVal ::= Types ValueRef ;348 349ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;350 351BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;352 353BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;354 355InstructionList ::= +++ InstructionList Inst356 | - _357 | ^ LABELSTR ^ ":\n" ;358 359BBTerminatorInst ::= ^ "  " ^360 ( ret ReturnedVal361 | ret void362 | br label ValueRef363 | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef364 | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"365 | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"366 | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"367   OptFuncAttrs368   to label ValueRef unwind label ValueRef369 | unwind370 | unreachable ) ^ "\n";371 372JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef373 | IntType ConstValueRef ^ "," label ValueRef ;374 375Inst ::= ^ "  " ^ OptLocalAssign InstVal ^ "\n";376 377PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"378 | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;379 380ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs381 | label OptParamAttrs ValueRef OptParamAttrs382 | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs383 | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs384 | - _ ;385 386IndexList ::= _ | IndexList ^ "," ResolvedVal ;387 388ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;389 390OptTailCall ::= tail call | call ;391 392InstVal ::=393   ArithmeticOps Types ValueRef ^ "," ValueRef394 | LogicalOps Types ValueRef ^ "," ValueRef395 | icmp IPredicates Types ValueRef ^ "," ValueRef396 | fcmp FPredicates Types ValueRef ^ "," ValueRef397 | CastOps ResolvedVal to Types398 | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal399 | "va_arg" ResolvedVal ^ "," Types400 | extractelement ResolvedVal ^ "," ResolvedVal401 | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal402 | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal403 | phi PHIList404 | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"405   OptFuncAttrs406 | MemoryInst ;407 408OptVolatile ::= - volatile | _ ;409OptExact ::= - exact | _ ;410OptNSW ::= - nsw | _ ;411OptNUW ::= - nuw | _ ;412OptNW  ::= OptNUW OptNSW | OptNSW OptNUW ;413OptInBounds  ::= - inbounds | _ ;414 415MemoryInst ::= malloc Types OptCAlign416 | malloc Types ^ "," INTTYPE ValueRef OptCAlign417 | alloca Types OptCAlign418 | alloca Types ^ "," INTTYPE ValueRef OptCAlign419 | free ResolvedVal420 | OptVolatile load Types ValueRef OptCAlign421 | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign422 | getresult Types ValueRef ^ "," EUINT64VAL423 | getelementptr OptInBounds Types ValueRef IndexList424 | extractvalue Types ValueRef ^ ConstantIndexList 425 | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;426