Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 1 | //===-- UpgradeParser.y - Upgrade parser for llvm assmbly -------*- C++ -*-===// |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Reid Spencer and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 10 | // This file implements the bison parser for LLVM 1.9 assembly language. |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | %{ |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 15 | #include "ParserInternals.h" |
| 16 | #include <llvm/ADT/StringExtras.h> |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | #include <list> |
| 19 | #include <utility> |
| 20 | #include <iostream> |
| 21 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 22 | #define YYERROR_VERBOSE 1 |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 23 | #define YYINCLUDED_STDLIB_H |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 24 | #define YYDEBUG 1 |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 25 | |
| 26 | int yylex(); // declaration" of xxx warnings. |
| 27 | int yyparse(); |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 28 | extern int yydebug; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 29 | |
| 30 | static std::string CurFilename; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 31 | static std::ostream *O = 0; |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 32 | std::istream* LexInput = 0; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 33 | unsigned SizeOfPointer = 32; |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 34 | |
| 35 | void UpgradeAssembly(const std::string &infile, std::istream& in, |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 36 | std::ostream &out, bool debug) |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 37 | { |
| 38 | Upgradelineno = 1; |
| 39 | CurFilename = infile; |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 40 | LexInput = ∈ |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 41 | yydebug = debug; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 42 | O = &out; |
| 43 | |
| 44 | if (yyparse()) { |
| 45 | std::cerr << "Parse failed.\n"; |
| 46 | exit(1); |
| 47 | } |
| 48 | } |
| 49 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 50 | const char* getCastOpcode(TypeInfo& SrcTy, TypeInfo&DstTy) { |
| 51 | unsigned SrcBits = SrcTy.getBitWidth(); |
| 52 | unsigned DstBits = DstTy.getBitWidth(); |
| 53 | const char* opcode = "bitcast"; |
| 54 | // Run through the possibilities ... |
| 55 | if (DstTy.isIntegral()) { // Casting to integral |
| 56 | if (SrcTy.isIntegral()) { // Casting from integral |
| 57 | if (DstBits < SrcBits) |
| 58 | opcode = "trunc"; |
| 59 | else if (DstBits > SrcBits) { // its an extension |
| 60 | if (SrcTy.isSigned()) |
| 61 | opcode ="sext"; // signed -> SEXT |
| 62 | else |
| 63 | opcode = "zext"; // unsigned -> ZEXT |
| 64 | } else { |
| 65 | opcode = "bitcast"; // Same size, No-op cast |
| 66 | } |
| 67 | } else if (SrcTy.isFloatingPoint()) { // Casting from floating pt |
| 68 | if (DstTy.isSigned()) |
| 69 | opcode = "fptosi"; // FP -> sint |
| 70 | else |
| 71 | opcode = "fptoui"; // FP -> uint |
| 72 | } else if (SrcTy.isPacked()) { |
| 73 | assert(DstBits == SrcTy.getBitWidth() && |
| 74 | "Casting packed to integer of different width"); |
| 75 | opcode = "bitcast"; // same size, no-op cast |
| 76 | } else { |
| 77 | assert(SrcTy.isPointer() && |
| 78 | "Casting from a value that is not first-class type"); |
| 79 | opcode = "ptrtoint"; // ptr -> int |
| 80 | } |
| 81 | } else if (DstTy.isFloatingPoint()) { // Casting to floating pt |
| 82 | if (SrcTy.isIntegral()) { // Casting from integral |
| 83 | if (SrcTy.isSigned()) |
| 84 | opcode = "sitofp"; // sint -> FP |
| 85 | else |
| 86 | opcode = "uitofp"; // uint -> FP |
| 87 | } else if (SrcTy.isFloatingPoint()) { // Casting from floating pt |
| 88 | if (DstBits < SrcBits) { |
| 89 | opcode = "fptrunc"; // FP -> smaller FP |
| 90 | } else if (DstBits > SrcBits) { |
| 91 | opcode = "fpext"; // FP -> larger FP |
| 92 | } else { |
| 93 | opcode ="bitcast"; // same size, no-op cast |
| 94 | } |
| 95 | } else if (SrcTy.isPacked()) { |
| 96 | assert(DstBits == SrcTy.getBitWidth() && |
| 97 | "Casting packed to floating point of different width"); |
| 98 | opcode = "bitcast"; // same size, no-op cast |
| 99 | } else { |
| 100 | assert(0 && "Casting pointer or non-first class to float"); |
| 101 | } |
| 102 | } else if (DstTy.isPacked()) { |
| 103 | if (SrcTy.isPacked()) { |
| 104 | assert(DstTy.getBitWidth() == SrcTy.getBitWidth() && |
| 105 | "Casting packed to packed of different widths"); |
| 106 | opcode = "bitcast"; // packed -> packed |
| 107 | } else if (DstTy.getBitWidth() == SrcBits) { |
| 108 | opcode = "bitcast"; // float/int -> packed |
| 109 | } else { |
| 110 | assert(!"Illegal cast to packed (wrong type or size)"); |
| 111 | } |
| 112 | } else if (DstTy.isPointer()) { |
| 113 | if (SrcTy.isPointer()) { |
| 114 | opcode = "bitcast"; // ptr -> ptr |
| 115 | } else if (SrcTy.isIntegral()) { |
| 116 | opcode = "inttoptr"; // int -> ptr |
| 117 | } else { |
| 118 | assert(!"Casting pointer to other than pointer or int"); |
| 119 | } |
| 120 | } else { |
| 121 | assert(!"Casting to type that is not first-class"); |
| 122 | } |
| 123 | return opcode; |
| 124 | } |
| 125 | |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 126 | %} |
| 127 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 128 | %file-prefix="UpgradeParser" |
| 129 | |
| 130 | %union { |
| 131 | std::string* String; |
| 132 | TypeInfo Type; |
| 133 | ValueInfo Value; |
| 134 | ConstInfo Const; |
| 135 | } |
| 136 | |
| 137 | %token <Const> ESINT64VAL EUINT64VAL SINTVAL UINTVAL FPVAL TRUETOK FALSETOK |
| 138 | %token <Const> NULL_TOK UNDEF ZEROINITIALIZER |
| 139 | |
| 140 | %token <Type> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG |
| 141 | %token <Type> FLOAT DOUBLE LABEL OPAQUE |
| 142 | |
| 143 | %token <String> TYPE VAR_ID LABELSTR STRINGCONSTANT |
| 144 | %token <String> IMPLEMENTATION BEGINTOK ENDTOK |
| 145 | %token <String> DECLARE GLOBAL CONSTANT SECTION VOLATILE |
| 146 | %token <String> TO DOTDOTDOT CONST INTERNAL LINKONCE WEAK |
| 147 | %token <String> DLLIMPORT DLLEXPORT EXTERN_WEAK APPENDING |
| 148 | %token <String> NOT EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG |
| 149 | %token <String> ALIGN |
| 150 | %token <String> DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT |
| 151 | %token <String> CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK |
| 152 | %token <String> X86_STDCALLCC_TOK X86_FASTCALLCC_TOK |
| 153 | %token <String> DATALAYOUT |
| 154 | %token <String> RET BR SWITCH INVOKE UNWIND UNREACHABLE |
| 155 | %token <String> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR |
| 156 | %token <String> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators |
| 157 | %token <String> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR |
| 158 | %token <String> PHI_TOK SELECT SHL LSHR ASHR VAARG |
| 159 | %token <String> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR |
| 160 | %token <String> CAST |
| 161 | |
| 162 | %type <String> OptAssign OptLinkage OptCallingConv OptAlign OptCAlign |
| 163 | %type <String> SectionString OptSection GlobalVarAttributes GlobalVarAttribute |
| 164 | %type <String> ArgTypeListI ConstExpr DefinitionList |
| 165 | %type <String> ConstPool TargetDefinition LibrariesDefinition LibList OptName |
| 166 | %type <String> ArgVal ArgListH ArgList FunctionHeaderH BEGIN FunctionHeader END |
| 167 | %type <String> Function FunctionProto BasicBlock TypeListI |
| 168 | %type <String> InstructionList BBTerminatorInst JumpTable Inst PHIList |
| 169 | %type <String> ValueRefList OptTailCall InstVal IndexList OptVolatile |
| 170 | %type <String> MemoryInst SymbolicValueRef OptSideEffect GlobalType |
| 171 | %type <String> FnDeclareLinkage BasicBlockList BigOrLittle AsmBlock |
| 172 | %type <String> Name ValueRef ValueRefListE |
| 173 | %type <String> ShiftOps SetCondOps LogicalOps ArithmeticOps ConstValueRef |
| 174 | |
| 175 | %type <String> ConstVector |
| 176 | |
| 177 | %type <Type> IntType SIntType UIntType FPType TypesV Types |
| 178 | %type <Type> PrimType UpRTypesV UpRTypes |
| 179 | |
| 180 | %type <Const> IntVal EInt64Val ConstVal |
| 181 | |
| 182 | %type <Value> ResolvedVal |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 183 | |
| 184 | %start Module |
| 185 | |
| 186 | %% |
| 187 | |
| 188 | // Handle constant integer size restriction and conversion... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 189 | IntVal : SINTVAL | UINTVAL |
| 190 | EInt64Val : ESINT64VAL | EUINT64VAL; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 191 | |
| 192 | // Operations that are notably excluded from this list include: |
| 193 | // RET, BR, & SWITCH because they end basic blocks and are treated specially. |
| 194 | ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM; |
| 195 | LogicalOps : AND | OR | XOR; |
| 196 | SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 197 | ShiftOps : SHL | LSHR | ASHR; |
| 198 | |
| 199 | // These are some types that allow classification if we only want a particular |
| 200 | // thing... for example, only a signed, unsigned, or integral type. |
| 201 | SIntType : LONG | INT | SHORT | SBYTE; |
| 202 | UIntType : ULONG | UINT | USHORT | UBYTE; |
| 203 | IntType : SIntType | UIntType; |
| 204 | FPType : FLOAT | DOUBLE; |
| 205 | |
| 206 | // OptAssign - Value producing statements have an optional assignment component |
| 207 | OptAssign : Name '=' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 208 | *$1 += " = "; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 209 | $$ = $1; |
| 210 | } |
| 211 | | /*empty*/ { |
| 212 | $$ = new std::string(""); |
| 213 | }; |
| 214 | |
| 215 | OptLinkage |
| 216 | : INTERNAL | LINKONCE | WEAK | APPENDING | DLLIMPORT | DLLEXPORT |
| 217 | | EXTERN_WEAK |
| 218 | | /*empty*/ { $$ = new std::string(""); } ; |
| 219 | |
| 220 | OptCallingConv |
| 221 | : CCC_TOK | CSRETCC_TOK | FASTCC_TOK | COLDCC_TOK | X86_STDCALLCC_TOK |
Reid Spencer | 16244f4 | 2006-12-01 21:10:07 +0000 | [diff] [blame^] | 222 | | X86_FASTCALLCC_TOK |
| 223 | | CC_TOK EUINT64VAL { |
| 224 | *$1 += *$2.cnst; |
| 225 | $2.destroy(); |
| 226 | $$ = $1; |
| 227 | } |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 228 | | /*empty*/ { $$ = new std::string(""); } ; |
| 229 | |
| 230 | // OptAlign/OptCAlign - An optional alignment, and an optional alignment with |
| 231 | // a comma before it. |
| 232 | OptAlign |
| 233 | : /*empty*/ { $$ = new std::string(); } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 234 | | ALIGN EUINT64VAL { *$1 += " " + *$2.cnst; delete $2.cnst; $$ = $1; }; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 235 | ; |
| 236 | OptCAlign |
| 237 | : /*empty*/ { $$ = new std::string(); } |
| 238 | | ',' ALIGN EUINT64VAL { |
| 239 | $2->insert(0, ", "); |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 240 | *$2 += " " + *$3.cnst; |
| 241 | delete $3.cnst; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 242 | $$ = $2; |
| 243 | }; |
| 244 | |
| 245 | SectionString |
| 246 | : SECTION STRINGCONSTANT { |
| 247 | *$1 += " " + *$2; |
| 248 | delete $2; |
| 249 | $$ = $1; |
| 250 | }; |
| 251 | |
| 252 | OptSection : /*empty*/ { $$ = new std::string(); } |
| 253 | | SectionString; |
| 254 | |
| 255 | GlobalVarAttributes |
| 256 | : /* empty */ { $$ = new std::string(); } |
| 257 | | ',' GlobalVarAttribute GlobalVarAttributes { |
| 258 | $2->insert(0, ", "); |
| 259 | if (!$3->empty()) |
| 260 | *$2 += " " + *$3; |
| 261 | delete $3; |
| 262 | $$ = $2; |
| 263 | }; |
| 264 | |
| 265 | GlobalVarAttribute |
| 266 | : SectionString |
| 267 | | ALIGN EUINT64VAL { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 268 | *$1 += " " + *$2.cnst; |
| 269 | delete $2.cnst; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 270 | $$ = $1; |
| 271 | }; |
| 272 | |
| 273 | //===----------------------------------------------------------------------===// |
| 274 | // Types includes all predefined types... except void, because it can only be |
| 275 | // used in specific contexts (function returning void for example). To have |
| 276 | // access to it, a user must explicitly use TypesV. |
| 277 | // |
| 278 | |
| 279 | // TypesV includes all of 'Types', but it also includes the void type. |
| 280 | TypesV : Types | VOID ; |
| 281 | UpRTypesV : UpRTypes | VOID ; |
| 282 | Types : UpRTypes ; |
| 283 | |
| 284 | // Derived types are added later... |
| 285 | // |
| 286 | PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 287 | PrimType : LONG | ULONG | FLOAT | DOUBLE | LABEL; |
Reid Spencer | d154b57 | 2006-12-01 20:36:40 +0000 | [diff] [blame] | 288 | UpRTypes : OPAQUE | PrimType |
| 289 | | SymbolicValueRef { |
| 290 | $$.newTy = $1; $$.oldTy = OpaqueTy; |
| 291 | }; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 292 | |
| 293 | // Include derived types in the Types production. |
| 294 | // |
| 295 | UpRTypes : '\\' EUINT64VAL { // Type UpReference |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 296 | $2.cnst->insert(0, "\\"); |
| 297 | $$.newTy = $2.cnst; |
| 298 | $$.oldTy = OpaqueTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 299 | } |
| 300 | | UpRTypesV '(' ArgTypeListI ')' { // Function derived type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 301 | *$1.newTy += "( " + *$3 + " )"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 302 | delete $3; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 303 | $$.newTy = $1.newTy; |
| 304 | $$.oldTy = FunctionTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 305 | } |
| 306 | | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 307 | $2.cnst->insert(0,"[ "); |
| 308 | *$2.cnst += " x " + *$4.newTy + " ]"; |
| 309 | delete $4.newTy; |
| 310 | $$.newTy = $2.cnst; |
| 311 | $$.oldTy = ArrayTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 312 | } |
| 313 | | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 314 | $2.cnst->insert(0,"< "); |
| 315 | *$2.cnst += " x " + *$4.newTy + " >"; |
| 316 | delete $4.newTy; |
| 317 | $$.newTy = $2.cnst; |
| 318 | $$.oldTy = PackedTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 319 | } |
| 320 | | '{' TypeListI '}' { // Structure type? |
| 321 | $2->insert(0, "{ "); |
| 322 | *$2 += " }"; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 323 | $$.newTy = $2; |
| 324 | $$.oldTy = StructTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 325 | } |
| 326 | | '{' '}' { // Empty structure type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 327 | $$.newTy = new std::string("{ }"); |
| 328 | $$.oldTy = StructTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 329 | } |
| 330 | | UpRTypes '*' { // Pointer type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 331 | *$1.newTy += '*'; |
| 332 | $1.oldTy = PointerTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 333 | $$ = $1; |
| 334 | }; |
| 335 | |
| 336 | // TypeList - Used for struct declarations and as a basis for function type |
| 337 | // declaration type lists |
| 338 | // |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 339 | TypeListI |
| 340 | : UpRTypes { |
| 341 | $$ = $1.newTy; |
| 342 | } |
| 343 | | TypeListI ',' UpRTypes { |
| 344 | *$1 += ", " + *$3.newTy; |
| 345 | delete $3.newTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 346 | $$ = $1; |
| 347 | }; |
| 348 | |
| 349 | // ArgTypeList - List of types for a function type declaration... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 350 | ArgTypeListI |
| 351 | : TypeListI |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 352 | | TypeListI ',' DOTDOTDOT { |
| 353 | *$1 += ", ..."; |
| 354 | delete $3; |
| 355 | $$ = $1; |
| 356 | } |
| 357 | | DOTDOTDOT { |
| 358 | $$ = $1; |
| 359 | } |
| 360 | | /*empty*/ { |
| 361 | $$ = new std::string(); |
| 362 | }; |
| 363 | |
| 364 | // ConstVal - The various declarations that go into the constant pool. This |
| 365 | // production is used ONLY to represent constants that show up AFTER a 'const', |
| 366 | // 'constant' or 'global' token at global scope. Constants that can be inlined |
| 367 | // into other expressions (such as integers and constexprs) are handled by the |
| 368 | // ResolvedVal, ValueRef and ConstValueRef productions. |
| 369 | // |
| 370 | ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 371 | $$.type = $1; |
| 372 | $$.cnst = new std::string(*$1.newTy); |
| 373 | *$$.cnst += " [ " + *$3 + " ]"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 374 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 375 | } |
| 376 | | Types '[' ']' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 377 | $$.type = $1; |
| 378 | $$.cnst = new std::string(*$1.newTy); |
| 379 | *$$.cnst += "[ ]"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 380 | } |
| 381 | | Types 'c' STRINGCONSTANT { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 382 | $$.type = $1; |
| 383 | $$.cnst = new std::string(*$1.newTy); |
| 384 | *$$.cnst += " c" + *$3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 385 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 386 | } |
| 387 | | Types '<' ConstVector '>' { // Nonempty unsized arr |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 388 | $$.type = $1; |
| 389 | $$.cnst = new std::string(*$1.newTy); |
| 390 | *$$.cnst += " < " + *$3 + " >"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 391 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 392 | } |
| 393 | | Types '{' ConstVector '}' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 394 | $$.type = $1; |
| 395 | $$.cnst = new std::string(*$1.newTy); |
| 396 | *$$.cnst += " { " + *$3 + " }"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 397 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 398 | } |
| 399 | | Types '{' '}' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 400 | $$.type = $1; |
| 401 | $$.cnst = new std::string(*$1.newTy); |
| 402 | *$$.cnst += " [ ]"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 403 | } |
| 404 | | Types NULL_TOK { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 405 | $$.type = $1; |
| 406 | $$.cnst = new std::string(*$1.newTy); |
| 407 | *$$.cnst += " " + *$2.cnst; |
| 408 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 409 | } |
| 410 | | Types UNDEF { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 411 | $$.type = $1; |
| 412 | $$.cnst = new std::string(*$1.newTy); |
| 413 | *$$.cnst += " " + *$2.cnst; |
| 414 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 415 | } |
| 416 | | Types SymbolicValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 417 | $$.type = $1; |
| 418 | $$.cnst = new std::string(*$1.newTy); |
| 419 | *$$.cnst += " " + *$2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 420 | delete $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 421 | } |
| 422 | | Types ConstExpr { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 423 | $$.type = $1; |
| 424 | $$.cnst = new std::string(*$1.newTy); |
| 425 | *$$.cnst += " " + *$2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 426 | delete $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 427 | } |
| 428 | | Types ZEROINITIALIZER { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 429 | $$.type = $1; |
| 430 | $$.cnst = new std::string(*$1.newTy); |
| 431 | *$$.cnst += " " + *$2.cnst; |
| 432 | $2.destroy(); |
| 433 | } |
| 434 | | SIntType EInt64Val { // integral constants |
| 435 | $$.type = $1; |
| 436 | $$.cnst = new std::string(*$1.newTy); |
| 437 | *$$.cnst += " " + *$2.cnst; |
| 438 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 439 | } |
| 440 | | UIntType EUINT64VAL { // integral constants |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 441 | $$.type = $1; |
| 442 | $$.cnst = new std::string(*$1.newTy); |
| 443 | *$$.cnst += " " + *$2.cnst; |
| 444 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 445 | } |
| 446 | | BOOL TRUETOK { // Boolean constants |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 447 | $$.type = $1; |
| 448 | $$.cnst = new std::string(*$1.newTy); |
| 449 | *$$.cnst += " " + *$2.cnst; |
| 450 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 451 | } |
| 452 | | BOOL FALSETOK { // Boolean constants |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 453 | $$.type = $1; |
| 454 | $$.cnst = new std::string(*$1.newTy); |
| 455 | *$$.cnst += " " + *$2.cnst; |
| 456 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 457 | } |
| 458 | | FPType FPVAL { // Float & Double constants |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 459 | $$.type = $1; |
| 460 | $$.cnst = new std::string(*$1.newTy); |
| 461 | *$$.cnst += " " + *$2.cnst; |
| 462 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 463 | }; |
| 464 | |
| 465 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 466 | ConstExpr: CAST '(' ConstVal TO Types ')' { |
| 467 | // We must infer the cast opcode from the types of the operands. |
| 468 | const char *opcode = getCastOpcode($3.type, $5); |
| 469 | $$ = new std::string(opcode); |
| 470 | *$$ += "(" + *$3.cnst + " " + *$4 + " " + *$5.newTy + ")"; |
| 471 | delete $1; $3.destroy(); delete $4; $5.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 472 | } |
| 473 | | GETELEMENTPTR '(' ConstVal IndexList ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 474 | *$1 += "(" + *$3.cnst + " " + *$4 + ")"; |
| 475 | $$ = $1; |
| 476 | $3.destroy(); |
| 477 | delete $4; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 478 | } |
| 479 | | SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 480 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")"; |
| 481 | $3.destroy(); $5.destroy(); $7.destroy(); |
| 482 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 483 | } |
| 484 | | ArithmeticOps '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 485 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 486 | $3.destroy(); $5.destroy(); |
| 487 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 488 | } |
| 489 | | LogicalOps '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 490 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 491 | $3.destroy(); $5.destroy(); |
| 492 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 493 | } |
| 494 | | SetCondOps '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 495 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 496 | $3.destroy(); $5.destroy(); |
| 497 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 498 | } |
| 499 | | ShiftOps '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 500 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 501 | $3.destroy(); $5.destroy(); |
| 502 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 503 | } |
| 504 | | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 505 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 506 | $3.destroy(); $5.destroy(); |
| 507 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 508 | } |
| 509 | | INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 510 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")"; |
| 511 | $3.destroy(); $5.destroy(); $7.destroy(); |
| 512 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 513 | } |
| 514 | | SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 515 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")"; |
| 516 | $3.destroy(); $5.destroy(); $7.destroy(); |
| 517 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | |
| 521 | // ConstVector - A list of comma separated constants. |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 522 | |
| 523 | ConstVector |
| 524 | : ConstVector ',' ConstVal { |
| 525 | *$1 += ", " + *$3.cnst; |
| 526 | $3.destroy(); |
| 527 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 528 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 529 | | ConstVal { $$ = new std::string(*$1.cnst); $1.destroy(); } |
| 530 | ; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 531 | |
| 532 | |
| 533 | // GlobalType - Match either GLOBAL or CONSTANT for global declarations... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 534 | GlobalType : GLOBAL | CONSTANT ; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 535 | |
| 536 | |
| 537 | //===----------------------------------------------------------------------===// |
| 538 | // Rules to match Modules |
| 539 | //===----------------------------------------------------------------------===// |
| 540 | |
| 541 | // Module rule: Capture the result of parsing the whole file into a result |
| 542 | // variable... |
| 543 | // |
| 544 | Module : DefinitionList { |
| 545 | }; |
| 546 | |
| 547 | // DefinitionList - Top level definitions |
| 548 | // |
| 549 | DefinitionList : DefinitionList Function { |
| 550 | $$ = 0; |
| 551 | } |
| 552 | | DefinitionList FunctionProto { |
| 553 | *O << *$2 << "\n"; |
| 554 | delete $2; |
| 555 | $$ = 0; |
| 556 | } |
| 557 | | DefinitionList MODULE ASM_TOK AsmBlock { |
| 558 | *O << "module asm " << " " << *$4 << "\n"; |
Reid Spencer | d154b57 | 2006-12-01 20:36:40 +0000 | [diff] [blame] | 559 | $$ = 0; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 560 | } |
| 561 | | DefinitionList IMPLEMENTATION { |
| 562 | *O << "implementation\n"; |
Reid Spencer | d154b57 | 2006-12-01 20:36:40 +0000 | [diff] [blame] | 563 | $$ = 0; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 564 | } |
Reid Spencer | d154b57 | 2006-12-01 20:36:40 +0000 | [diff] [blame] | 565 | | ConstPool; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 566 | |
| 567 | // ConstPool - Constants with optional names assigned to them. |
| 568 | ConstPool : ConstPool OptAssign TYPE TypesV { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 569 | *O << *$2 << " " << *$3 << " " << *$4.newTy << "\n"; |
| 570 | // delete $2; delete $3; $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 571 | $$ = 0; |
| 572 | } |
| 573 | | ConstPool FunctionProto { // Function prototypes can be in const pool |
| 574 | *O << *$2 << "\n"; |
| 575 | delete $2; |
| 576 | $$ = 0; |
| 577 | } |
| 578 | | ConstPool MODULE ASM_TOK AsmBlock { // Asm blocks can be in the const pool |
| 579 | *O << *$2 << " " << *$3 << " " << *$4 << "\n"; |
| 580 | delete $2; delete $3; delete $4; |
| 581 | $$ = 0; |
| 582 | } |
| 583 | | ConstPool OptAssign OptLinkage GlobalType ConstVal GlobalVarAttributes { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 584 | *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.cnst << " " |
| 585 | << *$6 << "\n"; |
| 586 | delete $2; delete $3; delete $4; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 587 | $$ = 0; |
| 588 | } |
| 589 | | ConstPool OptAssign EXTERNAL GlobalType Types GlobalVarAttributes { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 590 | *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy |
| 591 | << " " << *$6 << "\n"; |
| 592 | delete $2; delete $3; delete $4; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 593 | $$ = 0; |
| 594 | } |
| 595 | | ConstPool OptAssign DLLIMPORT GlobalType Types GlobalVarAttributes { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 596 | *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy |
| 597 | << " " << *$6 << "\n"; |
| 598 | delete $2; delete $3; delete $4; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 599 | $$ = 0; |
| 600 | } |
| 601 | | ConstPool OptAssign EXTERN_WEAK GlobalType Types GlobalVarAttributes { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 602 | *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy |
| 603 | << " " << *$6 << "\n"; |
| 604 | delete $2; delete $3; delete $4; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 605 | $$ = 0; |
| 606 | } |
| 607 | | ConstPool TARGET TargetDefinition { |
| 608 | *O << *$2 << " " << *$3 << "\n"; |
| 609 | delete $2; delete $3; |
| 610 | $$ = 0; |
| 611 | } |
| 612 | | ConstPool DEPLIBS '=' LibrariesDefinition { |
| 613 | *O << *$2 << " = " << *$4 << "\n"; |
| 614 | delete $2; delete $4; |
| 615 | $$ = 0; |
| 616 | } |
| 617 | | /* empty: end of list */ { |
| 618 | $$ = 0; |
| 619 | }; |
| 620 | |
| 621 | |
| 622 | AsmBlock : STRINGCONSTANT ; |
| 623 | |
| 624 | BigOrLittle : BIG | LITTLE |
| 625 | |
| 626 | TargetDefinition |
| 627 | : ENDIAN '=' BigOrLittle { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 628 | *$1 += " = " + *$3; |
| 629 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 630 | $$ = $1; |
| 631 | } |
| 632 | | POINTERSIZE '=' EUINT64VAL { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 633 | *$1 += " = " + *$3.cnst; |
| 634 | if (*$3.cnst == "64") |
| 635 | SizeOfPointer = 64; |
| 636 | $3.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 637 | $$ = $1; |
| 638 | } |
| 639 | | TRIPLE '=' STRINGCONSTANT { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 640 | *$1 += " = " + *$3; |
| 641 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 642 | $$ = $1; |
| 643 | } |
| 644 | | DATALAYOUT '=' STRINGCONSTANT { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 645 | *$1 += " = " + *$3; |
| 646 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 647 | $$ = $1; |
| 648 | }; |
| 649 | |
| 650 | LibrariesDefinition |
| 651 | : '[' LibList ']' { |
| 652 | $2->insert(0, "[ "); |
| 653 | *$2 += " ]"; |
| 654 | $$ = $2; |
| 655 | }; |
| 656 | |
| 657 | LibList |
| 658 | : LibList ',' STRINGCONSTANT { |
| 659 | *$1 += ", " + *$3; |
| 660 | delete $3; |
| 661 | $$ = $1; |
| 662 | } |
| 663 | | STRINGCONSTANT |
| 664 | | /* empty: end of list */ { |
| 665 | $$ = new std::string(); |
| 666 | }; |
| 667 | |
| 668 | //===----------------------------------------------------------------------===// |
| 669 | // Rules to match Function Headers |
| 670 | //===----------------------------------------------------------------------===// |
| 671 | |
| 672 | Name : VAR_ID | STRINGCONSTANT; |
| 673 | OptName : Name | /*empty*/ { $$ = new std::string(); }; |
| 674 | |
| 675 | ArgVal : Types OptName { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 676 | $$ = $1.newTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 677 | if (!$2->empty()) |
| 678 | *$$ += " " + *$2; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 679 | delete $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 680 | }; |
| 681 | |
| 682 | ArgListH : ArgListH ',' ArgVal { |
| 683 | *$1 += ", " + *$3; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 684 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 685 | } |
| 686 | | ArgVal { |
| 687 | $$ = $1; |
| 688 | }; |
| 689 | |
| 690 | ArgList : ArgListH { |
| 691 | $$ = $1; |
| 692 | } |
| 693 | | ArgListH ',' DOTDOTDOT { |
| 694 | *$1 += ", ..."; |
| 695 | $$ = $1; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 696 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 697 | } |
| 698 | | DOTDOTDOT { |
| 699 | $$ = $1; |
| 700 | } |
Reid Spencer | d154b57 | 2006-12-01 20:36:40 +0000 | [diff] [blame] | 701 | | /* empty */ { $$ = new std::string(); }; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 702 | |
| 703 | FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')' |
| 704 | OptSection OptAlign { |
| 705 | if (!$1->empty()) { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 706 | *$1 += " "; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 707 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 708 | *$1 += *$2.newTy + " " + *$3 + "(" + *$5 + ")"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 709 | if (!$7->empty()) { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 710 | *$1 += " " + *$7; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 711 | } |
| 712 | if (!$8->empty()) { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 713 | *$1 += " " + *$8; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 714 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 715 | $2.destroy(); |
| 716 | delete $3; |
| 717 | delete $5; |
| 718 | delete $7; |
| 719 | delete $8; |
| 720 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 721 | }; |
| 722 | |
| 723 | BEGIN : BEGINTOK { |
| 724 | $$ = new std::string("begin"); |
| 725 | } |
| 726 | | '{' { |
| 727 | $$ = new std::string ("{"); |
| 728 | } |
| 729 | |
| 730 | FunctionHeader : OptLinkage FunctionHeaderH BEGIN { |
| 731 | if (!$1->empty()) { |
| 732 | *O << *$1 << " "; |
| 733 | } |
| 734 | *O << *$2 << " " << *$3 << "\n"; |
| 735 | delete $1; delete $2; delete $3; |
| 736 | $$ = 0; |
| 737 | }; |
| 738 | |
| 739 | END : ENDTOK { $$ = new std::string("end"); } |
| 740 | | '}' { $$ = new std::string("}"); }; |
| 741 | |
| 742 | Function : FunctionHeader BasicBlockList END { |
| 743 | if ($2) |
| 744 | *O << *$2; |
| 745 | *O << '\n' << *$3 << "\n"; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 746 | $$ = 0; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 747 | }; |
| 748 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 749 | FnDeclareLinkage |
| 750 | : /*default*/ { $$ = new std::string(); } |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 751 | | DLLIMPORT |
| 752 | | EXTERN_WEAK |
| 753 | ; |
| 754 | |
| 755 | FunctionProto |
| 756 | : DECLARE FnDeclareLinkage FunctionHeaderH { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 757 | if (!$2->empty()) |
| 758 | *$1 += " " + *$2; |
| 759 | *$1 += " " + *$3; |
| 760 | delete $2; |
| 761 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 762 | $$ = $1; |
| 763 | }; |
| 764 | |
| 765 | //===----------------------------------------------------------------------===// |
| 766 | // Rules to match Basic Blocks |
| 767 | //===----------------------------------------------------------------------===// |
| 768 | |
Reid Spencer | d154b57 | 2006-12-01 20:36:40 +0000 | [diff] [blame] | 769 | OptSideEffect : /* empty */ { $$ = new std::string(); } |
| 770 | | SIDEEFFECT; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 771 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 772 | ConstValueRef |
| 773 | : ESINT64VAL { $$ = $1.cnst; } |
| 774 | | EUINT64VAL { $$ = $1.cnst; } |
| 775 | | FPVAL { $$ = $1.cnst; } |
| 776 | | TRUETOK { $$ = $1.cnst; } |
| 777 | | FALSETOK { $$ = $1.cnst; } |
| 778 | | NULL_TOK { $$ = $1.cnst; } |
| 779 | | UNDEF { $$ = $1.cnst; } |
| 780 | | ZEROINITIALIZER { $$ = $1.cnst; } |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 781 | | '<' ConstVector '>' { |
| 782 | $2->insert(0, "<"); |
| 783 | *$2 += ">"; |
| 784 | $$ = $2; |
| 785 | } |
| 786 | | ConstExpr |
| 787 | | ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT { |
| 788 | if (!$2->empty()) { |
| 789 | *$1 += " " + *$2; |
| 790 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 791 | *$1 += " " + *$3 + ", " + *$5; |
| 792 | delete $2; delete $3; delete $5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 793 | $$ = $1; |
| 794 | }; |
| 795 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 796 | SymbolicValueRef : IntVal { $$ = $1.cnst; } | Name ; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 797 | |
| 798 | // ValueRef - A reference to a definition... either constant or symbolic |
| 799 | ValueRef : SymbolicValueRef | ConstValueRef; |
| 800 | |
| 801 | |
| 802 | // ResolvedVal - a <type> <value> pair. This is used only in cases where the |
| 803 | // type immediately preceeds the value reference, and allows complex constant |
| 804 | // pool references (for things like: 'ret [2 x int] [ int 12, int 42]') |
| 805 | ResolvedVal : Types ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 806 | $$.type = $1; |
| 807 | $$.val = new std::string(*$1.newTy + " "); |
| 808 | *$$.val += *$2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 809 | delete $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 810 | }; |
| 811 | |
| 812 | BasicBlockList : BasicBlockList BasicBlock { |
| 813 | } |
| 814 | | BasicBlock { // Do not allow functions with 0 basic blocks |
| 815 | }; |
| 816 | |
| 817 | |
| 818 | // Basic blocks are terminated by branching instructions: |
| 819 | // br, br/cc, switch, ret |
| 820 | // |
Reid Spencer | 16244f4 | 2006-12-01 21:10:07 +0000 | [diff] [blame^] | 821 | BasicBlock : InstructionList BBTerminatorInst { |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 822 | *O << *$2 ; |
| 823 | }; |
| 824 | |
| 825 | InstructionList : InstructionList Inst { |
| 826 | *O << " " << *$2 << "\n"; |
| 827 | delete $2; |
| 828 | $$ = 0; |
| 829 | } |
| 830 | | /* empty */ { |
| 831 | $$ = 0; |
| 832 | } |
| 833 | | LABELSTR { |
| 834 | *O << *$1 << "\n"; |
| 835 | delete $1; |
| 836 | $$ = 0; |
| 837 | }; |
| 838 | |
| 839 | BBTerminatorInst : RET ResolvedVal { // Return with a result... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 840 | *O << " " << *$1 << " " << *$2.val << "\n"; |
| 841 | delete $1; $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 842 | $$ = 0; |
| 843 | } |
| 844 | | RET VOID { // Return with no result... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 845 | *O << " " << *$1 << " " << *$2.newTy << "\n"; |
| 846 | delete $1; $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 847 | $$ = 0; |
| 848 | } |
| 849 | | BR LABEL ValueRef { // Unconditional Branch... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 850 | *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << "\n"; |
| 851 | delete $1; $2.destroy(); delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 852 | $$ = 0; |
| 853 | } // Conditional Branch... |
| 854 | | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 855 | *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", " |
| 856 | << *$5.newTy << " " << *$6 << ", " << *$8.newTy << " " << *$9 << "\n"; |
| 857 | delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6; |
| 858 | $8.destroy(); delete $9; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 859 | $$ = 0; |
| 860 | } |
| 861 | | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 862 | *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", " << *$5.newTy |
| 863 | << " " << *$6 << " [" << *$8 << " ]\n"; |
| 864 | delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6; delete $8; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 865 | $$ = 0; |
| 866 | } |
| 867 | | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 868 | *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", " |
| 869 | << *$5.newTy << " " << *$6 << "[]\n"; |
| 870 | delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 871 | $$ = 0; |
| 872 | } |
Reid Spencer | 16244f4 | 2006-12-01 21:10:07 +0000 | [diff] [blame^] | 873 | | OptAssign INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')' |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 874 | TO LABEL ValueRef UNWIND LABEL ValueRef { |
Reid Spencer | 16244f4 | 2006-12-01 21:10:07 +0000 | [diff] [blame^] | 875 | *O << " "; |
| 876 | if (!$1->empty()) |
| 877 | *O << *$1; |
| 878 | *O << *$2 << " " << *$3 << " " << *$4.newTy << " " << *$5 << " (" |
| 879 | << *$7 << ") " << *$9 << " " << *$10.newTy << " " << *$11 << " " |
| 880 | << *$12 << " " << *$13.newTy << " " << *$14 << "\n"; |
| 881 | delete $1; delete $2; delete $3; $4.destroy(); delete $5; delete $7; |
| 882 | delete $9; $10.destroy(); delete $11; delete $12; $13.destroy(); |
| 883 | delete $14; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 884 | $$ = 0; |
| 885 | } |
| 886 | | UNWIND { |
| 887 | *O << " " << *$1 << "\n"; |
| 888 | delete $1; |
| 889 | $$ = 0; |
| 890 | } |
| 891 | | UNREACHABLE { |
| 892 | *O << " " << *$1 << "\n"; |
| 893 | delete $1; |
| 894 | $$ = 0; |
| 895 | }; |
| 896 | |
| 897 | JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { |
Reid Spencer | 16244f4 | 2006-12-01 21:10:07 +0000 | [diff] [blame^] | 898 | *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5.newTy + " " + *$6; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 899 | $2.destroy(); delete $3; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 900 | $$ = $1; |
| 901 | } |
| 902 | | IntType ConstValueRef ',' LABEL ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 903 | $2->insert(0, *$1.newTy + " " ); |
| 904 | *$2 += ", " + *$4.newTy + " " + *$5; |
| 905 | $1.destroy(); $4.destroy(); delete $5; |
| 906 | $$ = $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 907 | }; |
| 908 | |
| 909 | Inst |
| 910 | : OptAssign InstVal { |
| 911 | *$1 += *$2; |
| 912 | delete $2; |
| 913 | $$ = $1; |
| 914 | }; |
| 915 | |
| 916 | PHIList |
| 917 | : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 918 | $3->insert(0, *$1.newTy + "["); |
| 919 | *$3 += "," + *$5 + "]"; |
| 920 | $1.destroy(); delete $5; |
| 921 | $$ = $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 922 | } |
| 923 | | PHIList ',' '[' ValueRef ',' ValueRef ']' { |
| 924 | *$1 += ", [" + *$4 + "," + *$6 + "]"; |
| 925 | delete $4; delete $6; |
| 926 | $$ = $1; |
| 927 | }; |
| 928 | |
| 929 | |
| 930 | ValueRefList |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 931 | : ResolvedVal { $$ = new std::string(*$1.val); $1.destroy(); } |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 932 | | ValueRefList ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 933 | *$1 += ", " + *$3.val; |
| 934 | $3.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 935 | $$ = $1; |
| 936 | }; |
| 937 | |
| 938 | // ValueRefListE - Just like ValueRefList, except that it may also be empty! |
| 939 | ValueRefListE |
| 940 | : ValueRefList |
| 941 | | /*empty*/ { $$ = new std::string(); } |
| 942 | ; |
| 943 | |
| 944 | OptTailCall |
| 945 | : TAIL CALL { |
| 946 | *$1 += " " + *$2; |
| 947 | delete $2; |
| 948 | $$ = $1; |
| 949 | } |
| 950 | | CALL |
| 951 | ; |
| 952 | |
| 953 | InstVal : ArithmeticOps Types ValueRef ',' ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 954 | *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5; |
| 955 | $2.destroy(); delete $3; delete $5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 956 | $$ = $1; |
| 957 | } |
| 958 | | LogicalOps Types ValueRef ',' ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 959 | *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5; |
| 960 | $2.destroy(); delete $3; delete $5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 961 | $$ = $1; |
| 962 | } |
| 963 | | SetCondOps Types ValueRef ',' ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 964 | *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5; |
| 965 | $2.destroy(); delete $3; delete $5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 966 | $$ = $1; |
| 967 | } |
| 968 | | NOT ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 969 | *$1 += " " + *$2.val; |
| 970 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 971 | $$ = $1; |
| 972 | } |
| 973 | | ShiftOps ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 974 | *$1 += " " + *$2.val + ", " + *$4.val; |
| 975 | $2.destroy(); $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 976 | $$ = $1; |
| 977 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 978 | | CAST ResolvedVal TO Types { |
| 979 | const char *opcode = getCastOpcode($2.type, $4); |
| 980 | $$ = new std::string(opcode); |
| 981 | *$$ += *$2.val + " " + *$3 + " " + *$4.newTy; |
| 982 | delete $1; $2.destroy(); |
| 983 | delete $3; $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 984 | } |
| 985 | | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 986 | *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val; |
| 987 | $2.destroy(); $4.destroy(); $6.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 988 | $$ = $1; |
| 989 | } |
| 990 | | VAARG ResolvedVal ',' Types { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 991 | *$1 += " " + *$2.val + ", " + *$4.newTy; |
| 992 | $2.destroy(); $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 993 | $$ = $1; |
| 994 | } |
| 995 | | EXTRACTELEMENT ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 996 | *$1 += " " + *$2.val + ", " + *$4.val; |
| 997 | $2.destroy(); $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 998 | $$ = $1; |
| 999 | } |
| 1000 | | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1001 | *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val; |
| 1002 | $2.destroy(); $4.destroy(); $6.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1003 | $$ = $1; |
| 1004 | } |
| 1005 | | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1006 | *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val; |
| 1007 | $2.destroy(); $4.destroy(); $6.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1008 | $$ = $1; |
| 1009 | } |
| 1010 | | PHI_TOK PHIList { |
| 1011 | *$1 += " " + *$2; |
| 1012 | delete $2; |
| 1013 | $$ = $1; |
| 1014 | } |
| 1015 | | OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' { |
| 1016 | if (!$2->empty()) |
| 1017 | *$1 += " " + *$2; |
| 1018 | if (!$1->empty()) |
| 1019 | *$1 += " "; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1020 | *$1 += *$3.newTy + " " + *$4 + "(" + *$6 + ")"; |
| 1021 | delete $2; $3.destroy(); delete $4; delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1022 | $$ = $1; |
| 1023 | } |
| 1024 | | MemoryInst ; |
| 1025 | |
| 1026 | |
| 1027 | // IndexList - List of indices for GEP based instructions... |
| 1028 | IndexList |
| 1029 | : ',' ValueRefList { |
| 1030 | $2->insert(0, ", "); |
| 1031 | $$ = $2; |
| 1032 | } |
| 1033 | | /* empty */ { $$ = new std::string(); } |
| 1034 | ; |
| 1035 | |
| 1036 | OptVolatile |
| 1037 | : VOLATILE |
| 1038 | | /* empty */ { $$ = new std::string(); } |
| 1039 | ; |
| 1040 | |
| 1041 | MemoryInst : MALLOC Types OptCAlign { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1042 | *$1 += " " + *$2.newTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1043 | if (!$3->empty()) |
| 1044 | *$1 += " " + *$3; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1045 | $2.destroy(); delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1046 | $$ = $1; |
| 1047 | } |
| 1048 | | MALLOC Types ',' UINT ValueRef OptCAlign { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1049 | *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1050 | if (!$6->empty()) |
| 1051 | *$1 += " " + *$6; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1052 | $2.destroy(); $4.destroy(); delete $5; delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1053 | $$ = $1; |
| 1054 | } |
| 1055 | | ALLOCA Types OptCAlign { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1056 | *$1 += " " + *$2.newTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1057 | if (!$3->empty()) |
| 1058 | *$1 += " " + *$3; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1059 | $2.destroy(); delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1060 | $$ = $1; |
| 1061 | } |
| 1062 | | ALLOCA Types ',' UINT ValueRef OptCAlign { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1063 | *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1064 | if (!$6->empty()) |
| 1065 | *$1 += " " + *$6; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1066 | $2.destroy(); $4.destroy(); delete $5; delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1067 | $$ = $1; |
| 1068 | } |
| 1069 | | FREE ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1070 | *$1 += " " + *$2.val; |
| 1071 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1072 | $$ = $1; |
| 1073 | } |
| 1074 | | OptVolatile LOAD Types ValueRef { |
| 1075 | if (!$1->empty()) |
| 1076 | *$1 += " "; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1077 | *$1 += *$2 + " " + *$3.newTy + " " + *$4; |
| 1078 | delete $2; $3.destroy(); delete $4; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1079 | $$ = $1; |
| 1080 | } |
| 1081 | | OptVolatile STORE ResolvedVal ',' Types ValueRef { |
| 1082 | if (!$1->empty()) |
| 1083 | *$1 += " "; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1084 | *$1 += *$2 + " " + *$3.val + ", " + *$5.newTy + " " + *$6; |
| 1085 | delete $2; $3.destroy(); $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1086 | $$ = $1; |
| 1087 | } |
| 1088 | | GETELEMENTPTR Types ValueRef IndexList { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 1089 | *$1 += *$2.newTy + " " + *$3 + " " + *$4; |
| 1090 | $2.destroy(); delete $3; delete $4; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1091 | $$ = $1; |
| 1092 | }; |
| 1093 | |
| 1094 | %% |
| 1095 | |
| 1096 | int yyerror(const char *ErrorMsg) { |
| 1097 | std::string where |
| 1098 | = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename) |
| 1099 | + ":" + llvm::utostr((unsigned) Upgradelineno) + ": "; |
| 1100 | std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading "; |
| 1101 | if (yychar == YYEMPTY || yychar == 0) |
| 1102 | errMsg += "end-of-file."; |
| 1103 | else |
| 1104 | errMsg += "token: '" + std::string(Upgradetext, Upgradeleng) + "'"; |
| 1105 | std::cerr << errMsg << '\n'; |
| 1106 | exit(1); |
| 1107 | } |