Make sure that types go in the constant pool if they are used.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2001-07-09 19:38:36 +00:00
parent 282072869e
commit 8896eda9a9
2 changed files with 199 additions and 141 deletions

View File

@ -82,6 +82,7 @@
#include "llvm/iMemory.h" #include "llvm/iMemory.h"
#include <list> #include <list>
#include <utility> // Get definition of pair class #include <utility> // Get definition of pair class
#include <algorithm> // Get definition of find_if
#include <stdio.h> // This embarasment is due to our flex lexer... #include <stdio.h> // This embarasment is due to our flex lexer...
int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit
@ -371,6 +372,41 @@ static ConstPoolVal *addConstValToConstantPool(ConstPoolVal *C) {
} }
} }
struct EqualsType {
const Type *T;
inline EqualsType(const Type *t) { T = t; }
inline bool operator()(const ConstPoolVal *CPV) const {
return static_cast<const ConstPoolType*>(CPV)->getValue() == T;
}
};
// checkNewType - We have to be careful to add all types referenced by the
// program to the constant pool of the method or module. Because of this, we
// often want to check to make sure that types used are in the constant pool,
// and add them if they aren't. That's what this function does.
//
static const Type *checkNewType(const Type *Ty) {
ConstantPool &CP = CurMeth.CurrentMethod ?
CurMeth.CurrentMethod->getConstantPool() :
CurModule.CurrentModule->getConstantPool();
// Get the type type plane...
ConstantPool::PlaneType &P = CP.getPlane(Type::TypeTy);
ConstantPool::PlaneType::const_iterator PI = find_if(P.begin(), P.end(),
EqualsType(Ty));
if (PI == P.end()) {
vector<ValueList> &ValTab = CurMeth.CurrentMethod ?
CurMeth.Values : CurModule.Values;
ConstPoolVal *CPT = new ConstPoolType(Ty);
CP.insert(CPT);
InsertValue(CPT, ValTab);
}
return Ty;
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// RunVMAsmParser - Define an interface to this parser // RunVMAsmParser - Define an interface to this parser
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -391,7 +427,7 @@ Module *RunVMAsmParser(const ToolCommandLine &Opts, FILE *F) {
} }
#line 337 "llvmAsmParser.y" #line 373 "llvmAsmParser.y"
typedef union { typedef union {
Module *ModuleVal; Module *ModuleVal;
Method *MethodVal; Method *MethodVal;
@ -540,19 +576,19 @@ static const short yyrhs[] = { 5,
#if YYDEBUG != 0 #if YYDEBUG != 0
static const short yyrline[] = { 0, static const short yyrline[] = { 0,
434, 435, 442, 443, 454, 454, 454, 454, 454, 454, 470, 471, 478, 479, 490, 490, 490, 490, 490, 490,
454, 455, 455, 455, 455, 455, 455, 455, 458, 458, 490, 491, 491, 491, 491, 491, 491, 491, 494, 494,
463, 464, 464, 464, 464, 464, 465, 465, 465, 465, 499, 500, 500, 500, 500, 500, 501, 501, 501, 501,
465, 465, 466, 466, 470, 470, 470, 470, 471, 471, 501, 501, 502, 502, 506, 506, 506, 506, 507, 507,
471, 471, 472, 472, 474, 477, 481, 486, 491, 494, 507, 507, 508, 508, 510, 513, 517, 522, 527, 530,
497, 503, 506, 519, 523, 541, 548, 556, 570, 573, 533, 539, 542, 555, 559, 577, 584, 592, 606, 609,
579, 587, 598, 603, 608, 617, 617, 619, 627, 631, 615, 623, 634, 639, 644, 653, 653, 655, 663, 667,
636, 639, 643, 670, 674, 683, 686, 689, 692, 695, 672, 675, 679, 706, 710, 719, 722, 725, 728, 731,
700, 703, 706, 713, 721, 726, 730, 733, 736, 741, 736, 739, 742, 749, 757, 762, 766, 769, 772, 777,
744, 749, 753, 758, 762, 771, 776, 785, 789, 793, 780, 785, 789, 794, 798, 807, 812, 821, 825, 829,
796, 799, 802, 807, 818, 826, 836, 844, 849, 856, 832, 835, 838, 843, 854, 862, 872, 880, 885, 892,
860, 866, 866, 868, 873, 878, 882, 885, 896, 933, 896, 902, 902, 904, 909, 914, 918, 921, 932, 969,
938, 940, 944, 949, 958, 963, 972, 978, 987, 999 974, 976, 980, 983, 990, 993, 1001, 1007, 1016, 1028
}; };
#endif #endif
@ -1339,7 +1375,7 @@ yyreduce:
switch (yyn) { switch (yyn) {
case 2: case 2:
#line 435 "llvmAsmParser.y" #line 471 "llvmAsmParser.y"
{ {
if (yyvsp[0].UIntVal > (uint32_t)INT32_MAX) // Outside of my range! if (yyvsp[0].UIntVal > (uint32_t)INT32_MAX) // Outside of my range!
ThrowException("Value too large for type!"); ThrowException("Value too large for type!");
@ -1347,7 +1383,7 @@ case 2:
; ;
break;} break;}
case 4: case 4:
#line 443 "llvmAsmParser.y" #line 479 "llvmAsmParser.y"
{ {
if (yyvsp[0].UInt64Val > (uint64_t)INT64_MAX) // Outside of my range! if (yyvsp[0].UInt64Val > (uint64_t)INT64_MAX) // Outside of my range!
ThrowException("Value too large for type!"); ThrowException("Value too large for type!");
@ -1355,19 +1391,19 @@ case 4:
; ;
break;} break;}
case 45: case 45:
#line 474 "llvmAsmParser.y" #line 510 "llvmAsmParser.y"
{ {
yyval.StrVal = yyvsp[-1].StrVal; yyval.StrVal = yyvsp[-1].StrVal;
; ;
break;} break;}
case 46: case 46:
#line 477 "llvmAsmParser.y" #line 513 "llvmAsmParser.y"
{ {
yyval.StrVal = 0; yyval.StrVal = 0;
; ;
break;} break;}
case 47: case 47:
#line 481 "llvmAsmParser.y" #line 517 "llvmAsmParser.y"
{ // integral constants { // integral constants
if (!ConstPoolSInt::isValueValidForType(yyvsp[-1].TypeVal, yyvsp[0].SInt64Val)) if (!ConstPoolSInt::isValueValidForType(yyvsp[-1].TypeVal, yyvsp[0].SInt64Val))
ThrowException("Constant value doesn't fit in type!"); ThrowException("Constant value doesn't fit in type!");
@ -1375,7 +1411,7 @@ case 47:
; ;
break;} break;}
case 48: case 48:
#line 486 "llvmAsmParser.y" #line 522 "llvmAsmParser.y"
{ // integral constants { // integral constants
if (!ConstPoolUInt::isValueValidForType(yyvsp[-1].TypeVal, yyvsp[0].UInt64Val)) if (!ConstPoolUInt::isValueValidForType(yyvsp[-1].TypeVal, yyvsp[0].UInt64Val))
ThrowException("Constant value doesn't fit in type!"); ThrowException("Constant value doesn't fit in type!");
@ -1383,19 +1419,19 @@ case 48:
; ;
break;} break;}
case 49: case 49:
#line 491 "llvmAsmParser.y" #line 527 "llvmAsmParser.y"
{ // Boolean constants { // Boolean constants
yyval.ConstVal = new ConstPoolBool(true); yyval.ConstVal = new ConstPoolBool(true);
; ;
break;} break;}
case 50: case 50:
#line 494 "llvmAsmParser.y" #line 530 "llvmAsmParser.y"
{ // Boolean constants { // Boolean constants
yyval.ConstVal = new ConstPoolBool(false); yyval.ConstVal = new ConstPoolBool(false);
; ;
break;} break;}
case 51: case 51:
#line 497 "llvmAsmParser.y" #line 533 "llvmAsmParser.y"
{ // String constants { // String constants
cerr << "FIXME: TODO: String constants [sbyte] not implemented yet!\n"; cerr << "FIXME: TODO: String constants [sbyte] not implemented yet!\n";
abort(); abort();
@ -1404,13 +1440,13 @@ case 51:
; ;
break;} break;}
case 52: case 52:
#line 503 "llvmAsmParser.y" #line 539 "llvmAsmParser.y"
{ // Type constants { // Type constants
yyval.ConstVal = new ConstPoolType(yyvsp[0].TypeVal); yyval.ConstVal = new ConstPoolType(yyvsp[0].TypeVal);
; ;
break;} break;}
case 53: case 53:
#line 506 "llvmAsmParser.y" #line 542 "llvmAsmParser.y"
{ // Nonempty array constant { // Nonempty array constant
// Verify all elements are correct type! // Verify all elements are correct type!
const ArrayType *AT = ArrayType::getArrayType(yyvsp[-4].TypeVal); const ArrayType *AT = ArrayType::getArrayType(yyvsp[-4].TypeVal);
@ -1426,14 +1462,14 @@ case 53:
; ;
break;} break;}
case 54: case 54:
#line 519 "llvmAsmParser.y" #line 555 "llvmAsmParser.y"
{ // Empty array constant { // Empty array constant
vector<ConstPoolVal*> Empty; vector<ConstPoolVal*> Empty;
yyval.ConstVal = new ConstPoolArray(ArrayType::getArrayType(yyvsp[-3].TypeVal), Empty); yyval.ConstVal = new ConstPoolArray(ArrayType::getArrayType(yyvsp[-3].TypeVal), Empty);
; ;
break;} break;}
case 55: case 55:
#line 523 "llvmAsmParser.y" #line 559 "llvmAsmParser.y"
{ {
// Verify all elements are correct type! // Verify all elements are correct type!
const ArrayType *AT = ArrayType::getArrayType(yyvsp[-4].TypeVal, (int)yyvsp[-6].UInt64Val); const ArrayType *AT = ArrayType::getArrayType(yyvsp[-4].TypeVal, (int)yyvsp[-6].UInt64Val);
@ -1454,7 +1490,7 @@ case 55:
; ;
break;} break;}
case 56: case 56:
#line 541 "llvmAsmParser.y" #line 577 "llvmAsmParser.y"
{ {
if (yyvsp[-5].UInt64Val != 0) if (yyvsp[-5].UInt64Val != 0)
ThrowException("Type mismatch: constant sized array initialized with 0" ThrowException("Type mismatch: constant sized array initialized with 0"
@ -1464,7 +1500,7 @@ case 56:
; ;
break;} break;}
case 57: case 57:
#line 548 "llvmAsmParser.y" #line 584 "llvmAsmParser.y"
{ {
StructType::ElementTypes Types(yyvsp[-4].TypeList->begin(), yyvsp[-4].TypeList->end()); StructType::ElementTypes Types(yyvsp[-4].TypeList->begin(), yyvsp[-4].TypeList->end());
delete yyvsp[-4].TypeList; delete yyvsp[-4].TypeList;
@ -1475,7 +1511,7 @@ case 57:
; ;
break;} break;}
case 58: case 58:
#line 556 "llvmAsmParser.y" #line 592 "llvmAsmParser.y"
{ {
const StructType *St = const StructType *St =
StructType::getStructType(StructType::ElementTypes()); StructType::getStructType(StructType::ElementTypes());
@ -1484,20 +1520,20 @@ case 58:
; ;
break;} break;}
case 59: case 59:
#line 570 "llvmAsmParser.y" #line 606 "llvmAsmParser.y"
{ {
(yyval.ConstVector = yyvsp[-2].ConstVector)->push_back(addConstValToConstantPool(yyvsp[0].ConstVal)); (yyval.ConstVector = yyvsp[-2].ConstVector)->push_back(addConstValToConstantPool(yyvsp[0].ConstVal));
; ;
break;} break;}
case 60: case 60:
#line 573 "llvmAsmParser.y" #line 609 "llvmAsmParser.y"
{ {
yyval.ConstVector = new vector<ConstPoolVal*>(); yyval.ConstVector = new vector<ConstPoolVal*>();
yyval.ConstVector->push_back(addConstValToConstantPool(yyvsp[0].ConstVal)); yyval.ConstVector->push_back(addConstValToConstantPool(yyvsp[0].ConstVal));
; ;
break;} break;}
case 61: case 61:
#line 579 "llvmAsmParser.y" #line 615 "llvmAsmParser.y"
{ {
if (yyvsp[-1].StrVal) { if (yyvsp[-1].StrVal) {
yyvsp[0].ConstVal->setName(yyvsp[-1].StrVal); yyvsp[0].ConstVal->setName(yyvsp[-1].StrVal);
@ -1508,19 +1544,19 @@ case 61:
; ;
break;} break;}
case 62: case 62:
#line 587 "llvmAsmParser.y" #line 623 "llvmAsmParser.y"
{ {
; ;
break;} break;}
case 63: case 63:
#line 598 "llvmAsmParser.y" #line 634 "llvmAsmParser.y"
{ {
yyval.ModuleVal = ParserResult = yyvsp[0].ModuleVal; yyval.ModuleVal = ParserResult = yyvsp[0].ModuleVal;
CurModule.ModuleDone(); CurModule.ModuleDone();
; ;
break;} break;}
case 64: case 64:
#line 603 "llvmAsmParser.y" #line 639 "llvmAsmParser.y"
{ {
yyvsp[-1].ModuleVal->getMethodList().push_back(yyvsp[0].MethodVal); yyvsp[-1].ModuleVal->getMethodList().push_back(yyvsp[0].MethodVal);
CurMeth.MethodDone(); CurMeth.MethodDone();
@ -1528,17 +1564,17 @@ case 64:
; ;
break;} break;}
case 65: case 65:
#line 608 "llvmAsmParser.y" #line 644 "llvmAsmParser.y"
{ {
yyval.ModuleVal = CurModule.CurrentModule; yyval.ModuleVal = CurModule.CurrentModule;
; ;
break;} break;}
case 67: case 67:
#line 617 "llvmAsmParser.y" #line 653 "llvmAsmParser.y"
{ yyval.StrVal = 0; ; { yyval.StrVal = 0; ;
break;} break;}
case 68: case 68:
#line 619 "llvmAsmParser.y" #line 655 "llvmAsmParser.y"
{ {
yyval.MethArgVal = new MethodArgument(yyvsp[-1].TypeVal); yyval.MethArgVal = new MethodArgument(yyvsp[-1].TypeVal);
if (yyvsp[0].StrVal) { // Was the argument named? if (yyvsp[0].StrVal) { // Was the argument named?
@ -1548,33 +1584,33 @@ case 68:
; ;
break;} break;}
case 69: case 69:
#line 627 "llvmAsmParser.y" #line 663 "llvmAsmParser.y"
{ {
yyval.MethodArgList = yyvsp[0].MethodArgList; yyval.MethodArgList = yyvsp[0].MethodArgList;
yyvsp[0].MethodArgList->push_front(yyvsp[-2].MethArgVal); yyvsp[0].MethodArgList->push_front(yyvsp[-2].MethArgVal);
; ;
break;} break;}
case 70: case 70:
#line 631 "llvmAsmParser.y" #line 667 "llvmAsmParser.y"
{ {
yyval.MethodArgList = new list<MethodArgument*>(); yyval.MethodArgList = new list<MethodArgument*>();
yyval.MethodArgList->push_front(yyvsp[0].MethArgVal); yyval.MethodArgList->push_front(yyvsp[0].MethArgVal);
; ;
break;} break;}
case 71: case 71:
#line 636 "llvmAsmParser.y" #line 672 "llvmAsmParser.y"
{ {
yyval.MethodArgList = yyvsp[0].MethodArgList; yyval.MethodArgList = yyvsp[0].MethodArgList;
; ;
break;} break;}
case 72: case 72:
#line 639 "llvmAsmParser.y" #line 675 "llvmAsmParser.y"
{ {
yyval.MethodArgList = 0; yyval.MethodArgList = 0;
; ;
break;} break;}
case 73: case 73:
#line 643 "llvmAsmParser.y" #line 679 "llvmAsmParser.y"
{ {
MethodType::ParamTypes ParamTypeList; MethodType::ParamTypes ParamTypeList;
if (yyvsp[-1].MethodArgList) if (yyvsp[-1].MethodArgList)
@ -1603,67 +1639,67 @@ case 73:
; ;
break;} break;}
case 74: case 74:
#line 670 "llvmAsmParser.y" #line 706 "llvmAsmParser.y"
{ {
yyval.MethodVal = CurMeth.CurrentMethod; yyval.MethodVal = CurMeth.CurrentMethod;
; ;
break;} break;}
case 75: case 75:
#line 674 "llvmAsmParser.y" #line 710 "llvmAsmParser.y"
{ {
yyval.MethodVal = yyvsp[-1].MethodVal; yyval.MethodVal = yyvsp[-1].MethodVal;
; ;
break;} break;}
case 76: case 76:
#line 683 "llvmAsmParser.y" #line 719 "llvmAsmParser.y"
{ // A reference to a direct constant { // A reference to a direct constant
yyval.ValIDVal = ValID::create(yyvsp[0].SInt64Val); yyval.ValIDVal = ValID::create(yyvsp[0].SInt64Val);
; ;
break;} break;}
case 77: case 77:
#line 686 "llvmAsmParser.y" #line 722 "llvmAsmParser.y"
{ {
yyval.ValIDVal = ValID::create(yyvsp[0].UInt64Val); yyval.ValIDVal = ValID::create(yyvsp[0].UInt64Val);
; ;
break;} break;}
case 78: case 78:
#line 689 "llvmAsmParser.y" #line 725 "llvmAsmParser.y"
{ {
yyval.ValIDVal = ValID::create((int64_t)1); yyval.ValIDVal = ValID::create((int64_t)1);
; ;
break;} break;}
case 79: case 79:
#line 692 "llvmAsmParser.y" #line 728 "llvmAsmParser.y"
{ {
yyval.ValIDVal = ValID::create((int64_t)0); yyval.ValIDVal = ValID::create((int64_t)0);
; ;
break;} break;}
case 80: case 80:
#line 695 "llvmAsmParser.y" #line 731 "llvmAsmParser.y"
{ // Quoted strings work too... especially for methods { // Quoted strings work too... especially for methods
yyval.ValIDVal = ValID::create_conststr(yyvsp[0].StrVal); yyval.ValIDVal = ValID::create_conststr(yyvsp[0].StrVal);
; ;
break;} break;}
case 81: case 81:
#line 700 "llvmAsmParser.y" #line 736 "llvmAsmParser.y"
{ // Is it an integer reference...? { // Is it an integer reference...?
yyval.ValIDVal = ValID::create(yyvsp[0].SIntVal); yyval.ValIDVal = ValID::create(yyvsp[0].SIntVal);
; ;
break;} break;}
case 82: case 82:
#line 703 "llvmAsmParser.y" #line 739 "llvmAsmParser.y"
{ // It must be a named reference then... { // It must be a named reference then...
yyval.ValIDVal = ValID::create(yyvsp[0].StrVal); yyval.ValIDVal = ValID::create(yyvsp[0].StrVal);
; ;
break;} break;}
case 83: case 83:
#line 706 "llvmAsmParser.y" #line 742 "llvmAsmParser.y"
{ {
yyval.ValIDVal = yyvsp[0].ValIDVal; yyval.ValIDVal = yyvsp[0].ValIDVal;
; ;
break;} break;}
case 84: case 84:
#line 713 "llvmAsmParser.y" #line 749 "llvmAsmParser.y"
{ {
Value *D = getVal(Type::TypeTy, yyvsp[0].ValIDVal, true); Value *D = getVal(Type::TypeTy, yyvsp[0].ValIDVal, true);
if (D == 0) ThrowException("Invalid user defined type: " + yyvsp[0].ValIDVal.getName()); if (D == 0) ThrowException("Invalid user defined type: " + yyvsp[0].ValIDVal.getName());
@ -1674,81 +1710,81 @@ case 84:
; ;
break;} break;}
case 85: case 85:
#line 721 "llvmAsmParser.y" #line 757 "llvmAsmParser.y"
{ // Method derived type? { // Method derived type?
MethodType::ParamTypes Params(yyvsp[-1].TypeList->begin(), yyvsp[-1].TypeList->end()); MethodType::ParamTypes Params(yyvsp[-1].TypeList->begin(), yyvsp[-1].TypeList->end());
delete yyvsp[-1].TypeList; delete yyvsp[-1].TypeList;
yyval.TypeVal = MethodType::getMethodType(yyvsp[-3].TypeVal, Params); yyval.TypeVal = checkNewType(MethodType::getMethodType(yyvsp[-3].TypeVal, Params));
; ;
break;} break;}
case 86: case 86:
#line 726 "llvmAsmParser.y" #line 762 "llvmAsmParser.y"
{ // Method derived type? { // Method derived type?
MethodType::ParamTypes Params; // Empty list MethodType::ParamTypes Params; // Empty list
yyval.TypeVal = MethodType::getMethodType(yyvsp[-2].TypeVal, Params); yyval.TypeVal = checkNewType(MethodType::getMethodType(yyvsp[-2].TypeVal, Params));
; ;
break;} break;}
case 87: case 87:
#line 730 "llvmAsmParser.y" #line 766 "llvmAsmParser.y"
{ {
yyval.TypeVal = ArrayType::getArrayType(yyvsp[-1].TypeVal); yyval.TypeVal = checkNewType(ArrayType::getArrayType(yyvsp[-1].TypeVal));
; ;
break;} break;}
case 88: case 88:
#line 733 "llvmAsmParser.y" #line 769 "llvmAsmParser.y"
{ {
yyval.TypeVal = ArrayType::getArrayType(yyvsp[-1].TypeVal, (int)yyvsp[-3].UInt64Val); yyval.TypeVal = checkNewType(ArrayType::getArrayType(yyvsp[-1].TypeVal, (int)yyvsp[-3].UInt64Val));
; ;
break;} break;}
case 89: case 89:
#line 736 "llvmAsmParser.y" #line 772 "llvmAsmParser.y"
{ {
StructType::ElementTypes Elements(yyvsp[-1].TypeList->begin(), yyvsp[-1].TypeList->end()); StructType::ElementTypes Elements(yyvsp[-1].TypeList->begin(), yyvsp[-1].TypeList->end());
delete yyvsp[-1].TypeList; delete yyvsp[-1].TypeList;
yyval.TypeVal = StructType::getStructType(Elements); yyval.TypeVal = checkNewType(StructType::getStructType(Elements));
; ;
break;} break;}
case 90: case 90:
#line 741 "llvmAsmParser.y" #line 777 "llvmAsmParser.y"
{ {
yyval.TypeVal = StructType::getStructType(StructType::ElementTypes()); yyval.TypeVal = checkNewType(StructType::getStructType(StructType::ElementTypes()));
; ;
break;} break;}
case 91: case 91:
#line 744 "llvmAsmParser.y" #line 780 "llvmAsmParser.y"
{ {
yyval.TypeVal = PointerType::getPointerType(yyvsp[-1].TypeVal); yyval.TypeVal = checkNewType(PointerType::getPointerType(yyvsp[-1].TypeVal));
; ;
break;} break;}
case 92: case 92:
#line 749 "llvmAsmParser.y" #line 785 "llvmAsmParser.y"
{ {
yyval.TypeList = new list<const Type*>(); yyval.TypeList = new list<const Type*>();
yyval.TypeList->push_back(yyvsp[0].TypeVal); yyval.TypeList->push_back(yyvsp[0].TypeVal);
; ;
break;} break;}
case 93: case 93:
#line 753 "llvmAsmParser.y" #line 789 "llvmAsmParser.y"
{ {
(yyval.TypeList=yyvsp[-2].TypeList)->push_back(yyvsp[0].TypeVal); (yyval.TypeList=yyvsp[-2].TypeList)->push_back(yyvsp[0].TypeVal);
; ;
break;} break;}
case 94: case 94:
#line 758 "llvmAsmParser.y" #line 794 "llvmAsmParser.y"
{ {
yyvsp[-1].MethodVal->getBasicBlocks().push_back(yyvsp[0].BasicBlockVal); yyvsp[-1].MethodVal->getBasicBlocks().push_back(yyvsp[0].BasicBlockVal);
yyval.MethodVal = yyvsp[-1].MethodVal; yyval.MethodVal = yyvsp[-1].MethodVal;
; ;
break;} break;}
case 95: case 95:
#line 762 "llvmAsmParser.y" #line 798 "llvmAsmParser.y"
{ // Do not allow methods with 0 basic blocks { // Do not allow methods with 0 basic blocks
yyval.MethodVal = yyvsp[-1].MethodVal; // in them... yyval.MethodVal = yyvsp[-1].MethodVal; // in them...
yyvsp[-1].MethodVal->getBasicBlocks().push_back(yyvsp[0].BasicBlockVal); yyvsp[-1].MethodVal->getBasicBlocks().push_back(yyvsp[0].BasicBlockVal);
; ;
break;} break;}
case 96: case 96:
#line 771 "llvmAsmParser.y" #line 807 "llvmAsmParser.y"
{ {
yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal); yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal);
InsertValue(yyvsp[-1].BasicBlockVal); InsertValue(yyvsp[-1].BasicBlockVal);
@ -1756,7 +1792,7 @@ case 96:
; ;
break;} break;}
case 97: case 97:
#line 776 "llvmAsmParser.y" #line 812 "llvmAsmParser.y"
{ {
yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal); yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal);
yyvsp[-1].BasicBlockVal->setName(yyvsp[-2].StrVal); yyvsp[-1].BasicBlockVal->setName(yyvsp[-2].StrVal);
@ -1767,38 +1803,38 @@ case 97:
; ;
break;} break;}
case 98: case 98:
#line 785 "llvmAsmParser.y" #line 821 "llvmAsmParser.y"
{ {
yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].InstVal); yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].InstVal);
yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal; yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal;
; ;
break;} break;}
case 99: case 99:
#line 789 "llvmAsmParser.y" #line 825 "llvmAsmParser.y"
{ {
yyval.BasicBlockVal = new BasicBlock(); yyval.BasicBlockVal = new BasicBlock();
; ;
break;} break;}
case 100: case 100:
#line 793 "llvmAsmParser.y" #line 829 "llvmAsmParser.y"
{ // Return with a result... { // Return with a result...
yyval.TermInstVal = new ReturnInst(getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal)); yyval.TermInstVal = new ReturnInst(getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal));
; ;
break;} break;}
case 101: case 101:
#line 796 "llvmAsmParser.y" #line 832 "llvmAsmParser.y"
{ // Return with no result... { // Return with no result...
yyval.TermInstVal = new ReturnInst(); yyval.TermInstVal = new ReturnInst();
; ;
break;} break;}
case 102: case 102:
#line 799 "llvmAsmParser.y" #line 835 "llvmAsmParser.y"
{ // Unconditional Branch... { // Unconditional Branch...
yyval.TermInstVal = new BranchInst((BasicBlock*)getVal(Type::LabelTy, yyvsp[0].ValIDVal)); yyval.TermInstVal = new BranchInst((BasicBlock*)getVal(Type::LabelTy, yyvsp[0].ValIDVal));
; ;
break;} break;}
case 103: case 103:
#line 802 "llvmAsmParser.y" #line 838 "llvmAsmParser.y"
{ {
yyval.TermInstVal = new BranchInst((BasicBlock*)getVal(Type::LabelTy, yyvsp[-3].ValIDVal), yyval.TermInstVal = new BranchInst((BasicBlock*)getVal(Type::LabelTy, yyvsp[-3].ValIDVal),
(BasicBlock*)getVal(Type::LabelTy, yyvsp[0].ValIDVal), (BasicBlock*)getVal(Type::LabelTy, yyvsp[0].ValIDVal),
@ -1806,7 +1842,7 @@ case 103:
; ;
break;} break;}
case 104: case 104:
#line 807 "llvmAsmParser.y" #line 843 "llvmAsmParser.y"
{ {
SwitchInst *S = new SwitchInst(getVal(yyvsp[-7].TypeVal, yyvsp[-6].ValIDVal), SwitchInst *S = new SwitchInst(getVal(yyvsp[-7].TypeVal, yyvsp[-6].ValIDVal),
(BasicBlock*)getVal(Type::LabelTy, yyvsp[-3].ValIDVal)); (BasicBlock*)getVal(Type::LabelTy, yyvsp[-3].ValIDVal));
@ -1819,7 +1855,7 @@ case 104:
; ;
break;} break;}
case 105: case 105:
#line 818 "llvmAsmParser.y" #line 854 "llvmAsmParser.y"
{ {
yyval.JumpTable = yyvsp[-5].JumpTable; yyval.JumpTable = yyvsp[-5].JumpTable;
ConstPoolVal *V = (ConstPoolVal*)getVal(yyvsp[-4].TypeVal, yyvsp[-3].ValIDVal, true); ConstPoolVal *V = (ConstPoolVal*)getVal(yyvsp[-4].TypeVal, yyvsp[-3].ValIDVal, true);
@ -1830,7 +1866,7 @@ case 105:
; ;
break;} break;}
case 106: case 106:
#line 826 "llvmAsmParser.y" #line 862 "llvmAsmParser.y"
{ {
yyval.JumpTable = new list<pair<ConstPoolVal*, BasicBlock*> >(); yyval.JumpTable = new list<pair<ConstPoolVal*, BasicBlock*> >();
ConstPoolVal *V = (ConstPoolVal*)getVal(yyvsp[-4].TypeVal, yyvsp[-3].ValIDVal, true); ConstPoolVal *V = (ConstPoolVal*)getVal(yyvsp[-4].TypeVal, yyvsp[-3].ValIDVal, true);
@ -1842,7 +1878,7 @@ case 106:
; ;
break;} break;}
case 107: case 107:
#line 836 "llvmAsmParser.y" #line 872 "llvmAsmParser.y"
{ {
if (yyvsp[-1].StrVal) // Is this definition named?? if (yyvsp[-1].StrVal) // Is this definition named??
yyvsp[0].InstVal->setName(yyvsp[-1].StrVal); // if so, assign the name... yyvsp[0].InstVal->setName(yyvsp[-1].StrVal); // if so, assign the name...
@ -1852,7 +1888,7 @@ case 107:
; ;
break;} break;}
case 108: case 108:
#line 844 "llvmAsmParser.y" #line 880 "llvmAsmParser.y"
{ // Used for PHI nodes { // Used for PHI nodes
yyval.PHIList = new list<pair<Value*, BasicBlock*> >(); yyval.PHIList = new list<pair<Value*, BasicBlock*> >();
yyval.PHIList->push_back(make_pair(getVal(yyvsp[-5].TypeVal, yyvsp[-3].ValIDVal), yyval.PHIList->push_back(make_pair(getVal(yyvsp[-5].TypeVal, yyvsp[-3].ValIDVal),
@ -1860,7 +1896,7 @@ case 108:
; ;
break;} break;}
case 109: case 109:
#line 849 "llvmAsmParser.y" #line 885 "llvmAsmParser.y"
{ {
yyval.PHIList = yyvsp[-6].PHIList; yyval.PHIList = yyvsp[-6].PHIList;
yyvsp[-6].PHIList->push_back(make_pair(getVal(yyvsp[-6].PHIList->front().first->getType(), yyvsp[-3].ValIDVal), yyvsp[-6].PHIList->push_back(make_pair(getVal(yyvsp[-6].PHIList->front().first->getType(), yyvsp[-3].ValIDVal),
@ -1868,25 +1904,25 @@ case 109:
; ;
break;} break;}
case 110: case 110:
#line 856 "llvmAsmParser.y" #line 892 "llvmAsmParser.y"
{ // Used for call statements... { // Used for call statements...
yyval.ValueList = new list<Value*>(); yyval.ValueList = new list<Value*>();
yyval.ValueList->push_back(getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal)); yyval.ValueList->push_back(getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal));
; ;
break;} break;}
case 111: case 111:
#line 860 "llvmAsmParser.y" #line 896 "llvmAsmParser.y"
{ {
yyval.ValueList = yyvsp[-3].ValueList; yyval.ValueList = yyvsp[-3].ValueList;
yyvsp[-3].ValueList->push_back(getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal)); yyvsp[-3].ValueList->push_back(getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal));
; ;
break;} break;}
case 113: case 113:
#line 866 "llvmAsmParser.y" #line 902 "llvmAsmParser.y"
{ yyval.ValueList = 0; ; { yyval.ValueList = 0; ;
break;} break;}
case 114: case 114:
#line 868 "llvmAsmParser.y" #line 904 "llvmAsmParser.y"
{ {
yyval.InstVal = BinaryOperator::create(yyvsp[-4].BinaryOpVal, getVal(yyvsp[-3].TypeVal, yyvsp[-2].ValIDVal), getVal(yyvsp[-3].TypeVal, yyvsp[0].ValIDVal)); yyval.InstVal = BinaryOperator::create(yyvsp[-4].BinaryOpVal, getVal(yyvsp[-3].TypeVal, yyvsp[-2].ValIDVal), getVal(yyvsp[-3].TypeVal, yyvsp[0].ValIDVal));
if (yyval.InstVal == 0) if (yyval.InstVal == 0)
@ -1894,7 +1930,7 @@ case 114:
; ;
break;} break;}
case 115: case 115:
#line 873 "llvmAsmParser.y" #line 909 "llvmAsmParser.y"
{ {
yyval.InstVal = UnaryOperator::create(yyvsp[-2].UnaryOpVal, getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal)); yyval.InstVal = UnaryOperator::create(yyvsp[-2].UnaryOpVal, getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal));
if (yyval.InstVal == 0) if (yyval.InstVal == 0)
@ -1902,20 +1938,20 @@ case 115:
; ;
break;} break;}
case 116: case 116:
#line 878 "llvmAsmParser.y" #line 914 "llvmAsmParser.y"
{ {
if (yyvsp[-1].TypeVal != Type::UByteTy) ThrowException("Shift amount must be ubyte!"); if (yyvsp[-1].TypeVal != Type::UByteTy) ThrowException("Shift amount must be ubyte!");
yyval.InstVal = new ShiftInst(yyvsp[-5].OtherOpVal, getVal(yyvsp[-4].TypeVal, yyvsp[-3].ValIDVal), getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal)); yyval.InstVal = new ShiftInst(yyvsp[-5].OtherOpVal, getVal(yyvsp[-4].TypeVal, yyvsp[-3].ValIDVal), getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal));
; ;
break;} break;}
case 117: case 117:
#line 882 "llvmAsmParser.y" #line 918 "llvmAsmParser.y"
{ {
yyval.InstVal = new CastInst(getVal(yyvsp[-3].TypeVal, yyvsp[-2].ValIDVal), yyvsp[0].TypeVal); yyval.InstVal = new CastInst(getVal(yyvsp[-3].TypeVal, yyvsp[-2].ValIDVal), yyvsp[0].TypeVal);
; ;
break;} break;}
case 118: case 118:
#line 885 "llvmAsmParser.y" #line 921 "llvmAsmParser.y"
{ {
const Type *Ty = yyvsp[0].PHIList->front().first->getType(); const Type *Ty = yyvsp[0].PHIList->front().first->getType();
yyval.InstVal = new PHINode(Ty); yyval.InstVal = new PHINode(Ty);
@ -1929,7 +1965,7 @@ case 118:
; ;
break;} break;}
case 119: case 119:
#line 896 "llvmAsmParser.y" #line 932 "llvmAsmParser.y"
{ {
if (!yyvsp[-4].TypeVal->isMethodType()) if (!yyvsp[-4].TypeVal->isMethodType())
ThrowException("Can only call methods: invalid type '" + ThrowException("Can only call methods: invalid type '" +
@ -1969,65 +2005,58 @@ case 119:
; ;
break;} break;}
case 120: case 120:
#line 933 "llvmAsmParser.y" #line 969 "llvmAsmParser.y"
{ {
yyval.InstVal = yyvsp[0].InstVal; yyval.InstVal = yyvsp[0].InstVal;
; ;
break;} break;}
case 121: case 121:
#line 938 "llvmAsmParser.y" #line 974 "llvmAsmParser.y"
{ {
yyval.ConstVector = yyvsp[0].ConstVector; yyval.ConstVector = yyvsp[0].ConstVector;
; ;
break;} break;}
case 122: case 122:
#line 940 "llvmAsmParser.y" #line 976 "llvmAsmParser.y"
{ {
yyval.ConstVector = new vector<ConstPoolVal*>(); yyval.ConstVector = new vector<ConstPoolVal*>();
; ;
break;} break;}
case 123: case 123:
#line 944 "llvmAsmParser.y" #line 980 "llvmAsmParser.y"
{ {
const Type *Ty = PointerType::getPointerType(yyvsp[0].TypeVal); yyval.InstVal = new MallocInst(checkNewType(PointerType::getPointerType(yyvsp[0].TypeVal)));
addConstValToConstantPool(new ConstPoolType(Ty));
yyval.InstVal = new MallocInst(Ty);
; ;
break;} break;}
case 124: case 124:
#line 949 "llvmAsmParser.y" #line 983 "llvmAsmParser.y"
{ {
if (!yyvsp[-3].TypeVal->isArrayType() || ((const ArrayType*)yyvsp[-3].TypeVal)->isSized()) if (!yyvsp[-3].TypeVal->isArrayType() || ((const ArrayType*)yyvsp[-3].TypeVal)->isSized())
ThrowException("Trying to allocate " + yyvsp[-3].TypeVal->getName() + ThrowException("Trying to allocate " + yyvsp[-3].TypeVal->getName() +
" as unsized array!"); " as unsized array!");
const Type *Ty = PointerType::getPointerType(yyvsp[-3].TypeVal); const Type *Ty = checkNewType(PointerType::getPointerType(yyvsp[-3].TypeVal));
addConstValToConstantPool(new ConstPoolType(Ty)); yyval.InstVal = new MallocInst(Ty, getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal));
Value *ArrSize = getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal);
yyval.InstVal = new MallocInst(Ty, ArrSize);
; ;
break;} break;}
case 125: case 125:
#line 958 "llvmAsmParser.y" #line 990 "llvmAsmParser.y"
{ {
const Type *Ty = PointerType::getPointerType(yyvsp[0].TypeVal); yyval.InstVal = new AllocaInst(checkNewType(PointerType::getPointerType(yyvsp[0].TypeVal)));
addConstValToConstantPool(new ConstPoolType(Ty));
yyval.InstVal = new AllocaInst(Ty);
; ;
break;} break;}
case 126: case 126:
#line 963 "llvmAsmParser.y" #line 993 "llvmAsmParser.y"
{ {
if (!yyvsp[-3].TypeVal->isArrayType() || ((const ArrayType*)yyvsp[-3].TypeVal)->isSized()) if (!yyvsp[-3].TypeVal->isArrayType() || ((const ArrayType*)yyvsp[-3].TypeVal)->isSized())
ThrowException("Trying to allocate " + yyvsp[-3].TypeVal->getName() + ThrowException("Trying to allocate " + yyvsp[-3].TypeVal->getName() +
" as unsized array!"); " as unsized array!");
const Type *Ty = PointerType::getPointerType(yyvsp[-3].TypeVal); const Type *Ty = checkNewType(PointerType::getPointerType(yyvsp[-3].TypeVal));
addConstValToConstantPool(new ConstPoolType(Ty));
Value *ArrSize = getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal); Value *ArrSize = getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal);
yyval.InstVal = new AllocaInst(Ty, ArrSize); yyval.InstVal = new AllocaInst(Ty, ArrSize);
; ;
break;} break;}
case 127: case 127:
#line 972 "llvmAsmParser.y" #line 1001 "llvmAsmParser.y"
{ {
if (!yyvsp[-1].TypeVal->isPointerType()) if (!yyvsp[-1].TypeVal->isPointerType())
ThrowException("Trying to free nonpointer type " + yyvsp[-1].TypeVal->getName() + "!"); ThrowException("Trying to free nonpointer type " + yyvsp[-1].TypeVal->getName() + "!");
@ -2035,7 +2064,7 @@ case 127:
; ;
break;} break;}
case 128: case 128:
#line 978 "llvmAsmParser.y" #line 1007 "llvmAsmParser.y"
{ {
if (!yyvsp[-2].TypeVal->isPointerType()) if (!yyvsp[-2].TypeVal->isPointerType())
ThrowException("Can't load from nonpointer type: " + yyvsp[-2].TypeVal->getName()); ThrowException("Can't load from nonpointer type: " + yyvsp[-2].TypeVal->getName());
@ -2047,7 +2076,7 @@ case 128:
; ;
break;} break;}
case 129: case 129:
#line 987 "llvmAsmParser.y" #line 1016 "llvmAsmParser.y"
{ {
if (!yyvsp[-2].TypeVal->isPointerType()) if (!yyvsp[-2].TypeVal->isPointerType())
ThrowException("Can't store to a nonpointer type: " + yyvsp[-2].TypeVal->getName()); ThrowException("Can't store to a nonpointer type: " + yyvsp[-2].TypeVal->getName());
@ -2062,7 +2091,7 @@ case 129:
; ;
break;} break;}
case 130: case 130:
#line 999 "llvmAsmParser.y" #line 1028 "llvmAsmParser.y"
{ {
if (!yyvsp[-2].TypeVal->isPointerType()) if (!yyvsp[-2].TypeVal->isPointerType())
ThrowException("getelementptr insn requires pointer operand!"); ThrowException("getelementptr insn requires pointer operand!");
@ -2070,7 +2099,7 @@ case 130:
ThrowException("Can't get element ptr '" + yyvsp[-2].TypeVal->getName() + "'!"); ThrowException("Can't get element ptr '" + yyvsp[-2].TypeVal->getName() + "'!");
yyval.InstVal = new GetElementPtrInst(getVal(yyvsp[-2].TypeVal, yyvsp[-1].ValIDVal), *yyvsp[0].ConstVector); yyval.InstVal = new GetElementPtrInst(getVal(yyvsp[-2].TypeVal, yyvsp[-1].ValIDVal), *yyvsp[0].ConstVector);
delete yyvsp[0].ConstVector; delete yyvsp[0].ConstVector;
addConstValToConstantPool(new ConstPoolType(yyval.InstVal->getType())); checkNewType(yyval.InstVal->getType());
; ;
break;} break;}
} }
@ -2295,7 +2324,7 @@ yyerrhandle:
} }
return 1; return 1;
} }
#line 1009 "llvmAsmParser.y" #line 1038 "llvmAsmParser.y"
int yyerror(const char *ErrorMsg) { int yyerror(const char *ErrorMsg) {
ThrowException(string("Parse error: ") + ErrorMsg); ThrowException(string("Parse error: ") + ErrorMsg);

View File

@ -24,6 +24,7 @@
#include "llvm/iMemory.h" #include "llvm/iMemory.h"
#include <list> #include <list>
#include <utility> // Get definition of pair class #include <utility> // Get definition of pair class
#include <algorithm> // Get definition of find_if
#include <stdio.h> // This embarasment is due to our flex lexer... #include <stdio.h> // This embarasment is due to our flex lexer...
int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit
@ -313,6 +314,41 @@ static ConstPoolVal *addConstValToConstantPool(ConstPoolVal *C) {
} }
} }
struct EqualsType {
const Type *T;
inline EqualsType(const Type *t) { T = t; }
inline bool operator()(const ConstPoolVal *CPV) const {
return static_cast<const ConstPoolType*>(CPV)->getValue() == T;
}
};
// checkNewType - We have to be careful to add all types referenced by the
// program to the constant pool of the method or module. Because of this, we
// often want to check to make sure that types used are in the constant pool,
// and add them if they aren't. That's what this function does.
//
static const Type *checkNewType(const Type *Ty) {
ConstantPool &CP = CurMeth.CurrentMethod ?
CurMeth.CurrentMethod->getConstantPool() :
CurModule.CurrentModule->getConstantPool();
// Get the type type plane...
ConstantPool::PlaneType &P = CP.getPlane(Type::TypeTy);
ConstantPool::PlaneType::const_iterator PI = find_if(P.begin(), P.end(),
EqualsType(Ty));
if (PI == P.end()) {
vector<ValueList> &ValTab = CurMeth.CurrentMethod ?
CurMeth.Values : CurModule.Values;
ConstPoolVal *CPT = new ConstPoolType(Ty);
CP.insert(CPT);
InsertValue(CPT, ValTab);
}
return Ty;
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// RunVMAsmParser - Define an interface to this parser // RunVMAsmParser - Define an interface to this parser
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -721,28 +757,28 @@ Types : ValueRef {
| TypesV '(' TypeList ')' { // Method derived type? | TypesV '(' TypeList ')' { // Method derived type?
MethodType::ParamTypes Params($3->begin(), $3->end()); MethodType::ParamTypes Params($3->begin(), $3->end());
delete $3; delete $3;
$$ = MethodType::getMethodType($1, Params); $$ = checkNewType(MethodType::getMethodType($1, Params));
} }
| TypesV '(' ')' { // Method derived type? | TypesV '(' ')' { // Method derived type?
MethodType::ParamTypes Params; // Empty list MethodType::ParamTypes Params; // Empty list
$$ = MethodType::getMethodType($1, Params); $$ = checkNewType(MethodType::getMethodType($1, Params));
} }
| '[' Types ']' { | '[' Types ']' {
$$ = ArrayType::getArrayType($2); $$ = checkNewType(ArrayType::getArrayType($2));
} }
| '[' EUINT64VAL 'x' Types ']' { | '[' EUINT64VAL 'x' Types ']' {
$$ = ArrayType::getArrayType($4, (int)$2); $$ = checkNewType(ArrayType::getArrayType($4, (int)$2));
} }
| '{' TypeList '}' { | '{' TypeList '}' {
StructType::ElementTypes Elements($2->begin(), $2->end()); StructType::ElementTypes Elements($2->begin(), $2->end());
delete $2; delete $2;
$$ = StructType::getStructType(Elements); $$ = checkNewType(StructType::getStructType(Elements));
} }
| '{' '}' { | '{' '}' {
$$ = StructType::getStructType(StructType::ElementTypes()); $$ = checkNewType(StructType::getStructType(StructType::ElementTypes()));
} }
| Types '*' { | Types '*' {
$$ = PointerType::getPointerType($1); $$ = checkNewType(PointerType::getPointerType($1));
} }
@ -942,30 +978,23 @@ UByteList : ',' ConstVector {
} }
MemoryInst : MALLOC Types { MemoryInst : MALLOC Types {
const Type *Ty = PointerType::getPointerType($2); $$ = new MallocInst(checkNewType(PointerType::getPointerType($2)));
addConstValToConstantPool(new ConstPoolType(Ty));
$$ = new MallocInst(Ty);
} }
| MALLOC Types ',' UINT ValueRef { | MALLOC Types ',' UINT ValueRef {
if (!$2->isArrayType() || ((const ArrayType*)$2)->isSized()) if (!$2->isArrayType() || ((const ArrayType*)$2)->isSized())
ThrowException("Trying to allocate " + $2->getName() + ThrowException("Trying to allocate " + $2->getName() +
" as unsized array!"); " as unsized array!");
const Type *Ty = PointerType::getPointerType($2); const Type *Ty = checkNewType(PointerType::getPointerType($2));
addConstValToConstantPool(new ConstPoolType(Ty)); $$ = new MallocInst(Ty, getVal($4, $5));
Value *ArrSize = getVal($4, $5);
$$ = new MallocInst(Ty, ArrSize);
} }
| ALLOCA Types { | ALLOCA Types {
const Type *Ty = PointerType::getPointerType($2); $$ = new AllocaInst(checkNewType(PointerType::getPointerType($2)));
addConstValToConstantPool(new ConstPoolType(Ty));
$$ = new AllocaInst(Ty);
} }
| ALLOCA Types ',' UINT ValueRef { | ALLOCA Types ',' UINT ValueRef {
if (!$2->isArrayType() || ((const ArrayType*)$2)->isSized()) if (!$2->isArrayType() || ((const ArrayType*)$2)->isSized())
ThrowException("Trying to allocate " + $2->getName() + ThrowException("Trying to allocate " + $2->getName() +
" as unsized array!"); " as unsized array!");
const Type *Ty = PointerType::getPointerType($2); const Type *Ty = checkNewType(PointerType::getPointerType($2));
addConstValToConstantPool(new ConstPoolType(Ty));
Value *ArrSize = getVal($4, $5); Value *ArrSize = getVal($4, $5);
$$ = new AllocaInst(Ty, ArrSize); $$ = new AllocaInst(Ty, ArrSize);
} }
@ -1003,7 +1032,7 @@ MemoryInst : MALLOC Types {
ThrowException("Can't get element ptr '" + $2->getName() + "'!"); ThrowException("Can't get element ptr '" + $2->getName() + "'!");
$$ = new GetElementPtrInst(getVal($2, $3), *$4); $$ = new GetElementPtrInst(getVal($2, $3), *$4);
delete $4; delete $4;
addConstValToConstantPool(new ConstPoolType($$->getType())); checkNewType($$->getType());
} }
%% %%