From 9f4448a26ef8f7e8be847bf7bce4b6e525743af1 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sun, 19 Nov 2006 23:07:00 +0000 Subject: [PATCH] For PR950: Retain the signedness of the old integer types in a new TypeInfo structure so that it can be used in the grammar to implement auto-upgrade of things that depended on signedness of types. This doesn't implement any new functionality in the AsmParser, its just plumbing for future changes. llvm-svn: 31866 --- llvm/lib/AsmParser/Lexer.l | 37 ++- llvm/lib/AsmParser/ParserInternals.h | 26 ++ llvm/lib/AsmParser/llvmAsmParser.y | 429 ++++++++++++++------------- 3 files changed, 277 insertions(+), 215 deletions(-) diff --git a/llvm/lib/AsmParser/Lexer.l b/llvm/lib/AsmParser/Lexer.l index 1226f018cd4b..717e583291c3 100644 --- a/llvm/lib/AsmParser/Lexer.l +++ b/llvm/lib/AsmParser/Lexer.l @@ -51,6 +51,17 @@ void set_scan_string (const char * str) { llvmAsmlval.type.obsolete = true; \ return sym +// Construct a token value for a non-obsolete type +#define RET_TY(CType, sym) \ + llvmAsmlval.TypeVal.type = new PATypeHolder(CType); \ + llvmAsmlval.TypeVal.signedness = isSignless; \ + return sym + +// Construct a token value for an obsolete token +#define RET_TY_OBSOLETE(CType, sign, sym) \ + llvmAsmlval.TypeVal.type = new PATypeHolder(CType); \ + llvmAsmlval.TypeVal.signedness = sign; \ + return sym namespace llvm { @@ -238,19 +249,19 @@ coldcc { return COLDCC_TOK; } x86_stdcallcc { return X86_STDCALLCC_TOK; } x86_fastcallcc { return X86_FASTCALLCC_TOK; } -void { llvmAsmlval.PrimType = Type::VoidTy ; return VOID; } -bool { llvmAsmlval.PrimType = Type::BoolTy ; return BOOL; } -sbyte { llvmAsmlval.PrimType = Type::SByteTy ; return SBYTE; } -ubyte { llvmAsmlval.PrimType = Type::UByteTy ; return UBYTE; } -short { llvmAsmlval.PrimType = Type::ShortTy ; return SHORT; } -ushort { llvmAsmlval.PrimType = Type::UShortTy; return USHORT; } -int { llvmAsmlval.PrimType = Type::IntTy ; return INT; } -uint { llvmAsmlval.PrimType = Type::UIntTy ; return UINT; } -long { llvmAsmlval.PrimType = Type::LongTy ; return LONG; } -ulong { llvmAsmlval.PrimType = Type::ULongTy ; return ULONG; } -float { llvmAsmlval.PrimType = Type::FloatTy ; return FLOAT; } -double { llvmAsmlval.PrimType = Type::DoubleTy; return DOUBLE; } -label { llvmAsmlval.PrimType = Type::LabelTy ; return LABEL; } +void { RET_TY(Type::VoidTy, VOID); } +bool { RET_TY(Type::BoolTy, BOOL); } +sbyte { RET_TY_OBSOLETE(Type::SByteTy, isSigned, SBYTE); } +ubyte { RET_TY_OBSOLETE(Type::UByteTy, isUnsigned, UBYTE); } +short { RET_TY_OBSOLETE(Type::ShortTy, isSigned, SHORT); } +ushort { RET_TY_OBSOLETE(Type::UShortTy,isUnsigned, USHORT); } +int { RET_TY_OBSOLETE(Type::IntTy, isSigned, INT); } +uint { RET_TY_OBSOLETE(Type::UIntTy, isUnsigned, UINT); } +long { RET_TY_OBSOLETE(Type::LongTy, isSigned, LONG); } +ulong { RET_TY_OBSOLETE(Type::ULongTy, isUnsigned, ULONG); } +float { RET_TY(Type::FloatTy, FLOAT); } +double { RET_TY(Type::DoubleTy, DOUBLE); } +label { RET_TY(Type::LabelTy, LABEL); } type { return TYPE; } opaque { return OPAQUE; } diff --git a/llvm/lib/AsmParser/ParserInternals.h b/llvm/lib/AsmParser/ParserInternals.h index 9c94505bf820..c26c5f4ffb50 100644 --- a/llvm/lib/AsmParser/ParserInternals.h +++ b/llvm/lib/AsmParser/ParserInternals.h @@ -217,4 +217,30 @@ typedef OpcodeInfo TermOpInfo; typedef OpcodeInfo MemOpInfo; typedef OpcodeInfo OtherOpInfo; +/// This enumeration is used to indicate if a type is signed, signless or +/// unsigned. It is used for backwards compatibility with assembly code that +/// pre-dates the signless types conversion. +enum Signedness { + isSigned, + isUnsigned, + isSignless +}; + +/// This structure is used to keep track of the signedness of the obsolete +/// integer types. Instead of creating an llvm::Type directly, the Lexer will +/// create instances of TypeInfo which retains the signedness indication so +/// it can be used by the parser for upgrade decisions. +/// For example if "uint" is encountered then the type will be set "int32" +/// and the "signedness" will be "isUnsigned". If the type is not obsolete +/// then "signedness" will be "isSignless". +struct TypeInfo { + llvm::PATypeHolder *type; + Signedness signedness; +}; + +struct ValueInfo { + std::vector valuelist; + std::vector signlist; +}; + #endif diff --git a/llvm/lib/AsmParser/llvmAsmParser.y b/llvm/lib/AsmParser/llvmAsmParser.y index f9a090a1634d..806372ae879a 100644 --- a/llvm/lib/AsmParser/llvmAsmParser.y +++ b/llvm/lib/AsmParser/llvmAsmParser.y @@ -83,8 +83,8 @@ static struct PerModuleInfo { Module *CurrentModule; std::map Values; // Module level numbered definitions std::map LateResolveValues; - std::vector Types; - std::map LateResolveTypes; + std::vector Types; + std::map LateResolveTypes; /// PlaceHolderInfo - When temporary placeholder objects are created, remember /// how they were referenced and on which line of the input they came from so @@ -217,7 +217,7 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) { case ValID::NumberVal: // Is it a numbered definition? // Module constants occupy the lowest numbered slots... if ((unsigned)D.Num < CurModule.Types.size()) - return CurModule.Types[(unsigned)D.Num]; + return CurModule.Types[(unsigned)D.Num].type->get(); break; case ValID::NameVal: // Is it a named definition? if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) { @@ -247,13 +247,15 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) { } } - std::map::iterator I =CurModule.LateResolveTypes.find(D); + std::map::iterator I =CurModule.LateResolveTypes.find(D); if (I != CurModule.LateResolveTypes.end()) - return I->second; + return I->second.type->get(); - Type *Typ = OpaqueType::get(); - CurModule.LateResolveTypes.insert(std::make_pair(D, Typ)); - return Typ; + TypeInfo TI; + TI.type = new PATypeHolder(OpaqueType::get()); + TI.signedness = isSignless; + CurModule.LateResolveTypes.insert(std::make_pair(D, TI)); + return TI.type->get(); } static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) { @@ -557,10 +559,10 @@ static void ResolveTypeTo(char *Name, const Type *ToTy) { if (Name) D = ValID::create(Name); else D = ValID::create((int)CurModule.Types.size()); - std::map::iterator I = + std::map::iterator I = CurModule.LateResolveTypes.find(D); if (I != CurModule.LateResolveTypes.end()) { - ((DerivedType*)I->second.get())->refineAbstractTypeTo(ToTy); + ((DerivedType*)I->second.type->get())->refineAbstractTypeTo(ToTy); CurModule.LateResolveTypes.erase(I); } } @@ -822,14 +824,13 @@ static PATypeHolder HandleUpRefs(const Type *ty) { /// instruction. This function handles converting div -> [usf]div appropriately. /// @brief Convert obsolete BinaryOps opcodes to new values static void -sanitizeOpCode(OpcodeInfo &OI, const PATypeHolder& PATy) +sanitizeOpCode(OpcodeInfo &OI, const Type *Ty) { // If its not obsolete, don't do anything if (!OI.obsolete) return; // If its a packed type we want to use the element type - const Type* Ty = PATy; if (const PackedType* PTy = dyn_cast(Ty)) Ty = PTy->getElementType(); @@ -860,13 +861,12 @@ sanitizeOpCode(OpcodeInfo &OI, const PATypeHolder& PATy) /// operates on Instruction::OtherOps instead of Instruction::BinaryOps. /// @brief Convert obsolete OtherOps opcodes to new values static void -sanitizeOpCode(OpcodeInfo &OI, const PATypeHolder& PATy) +sanitizeOpCode(OpcodeInfo &OI, const Type *Ty) { // If its not obsolete, don't do anything if (!OI.obsolete) return; - const Type* Ty = PATy; // type conversion switch (OI.opcode) { default: GenerateError("Invalid obsolete opcode (check Lexer.l)"); @@ -1040,19 +1040,18 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %union { llvm::Module *ModuleVal; llvm::Function *FunctionVal; - std::pair *ArgVal; + std::pair *ArgVal; llvm::BasicBlock *BasicBlockVal; llvm::TerminatorInst *TermInstVal; llvm::Instruction *InstVal; llvm::Constant *ConstVal; - const llvm::Type *PrimType; - llvm::PATypeHolder *TypeVal; + TypeInfo TypeVal; llvm::Value *ValueVal; - std::vector > *ArgList; + std::vector >*ArgList; std::vector *ValueList; - std::list *TypeList; + std::list *TypeList; // Represent the RHS of PHI node std::list > *PHIList; @@ -1117,9 +1116,9 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { // Built in types... %type Types TypesV UpRTypes UpRTypesV -%type SIntType UIntType IntType FPType PrimType // Classifications -%token VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG -%token FLOAT DOUBLE TYPE LABEL +%type SIntType UIntType IntType FPType PrimType // Classifications +%token VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG +%token FLOAT DOUBLE TYPE LABEL %token VAR_ID LABELSTR STRINGCONSTANT %type Name OptName OptAssign @@ -1279,15 +1278,22 @@ GlobalVarAttribute : SectionString { // // TypesV includes all of 'Types', but it also includes the void type. -TypesV : Types | VOID { $$ = new PATypeHolder($1); }; -UpRTypesV : UpRTypes | VOID { $$ = new PATypeHolder($1); }; +TypesV : Types | VOID { + $$.type = new PATypeHolder($1.type->get()); + $$.signedness = $1.signedness; +}; +UpRTypesV : UpRTypes | VOID { + $$.type = new PATypeHolder($1.type->get()); + $$.signedness = $1.signedness; +}; Types : UpRTypes { if (!UpRefs.empty()) - GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription()); + GEN_ERROR("Invalid upreference in type: " + + ($1.type->get())->getDescription()); $$ = $1; CHECK_FOR_ERROR - }; +}; // Derived types are added later... @@ -1295,17 +1301,19 @@ Types : UpRTypes { PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ; PrimType : LONG | ULONG | FLOAT | DOUBLE | TYPE | LABEL; UpRTypes : OPAQUE { - $$ = new PATypeHolder(OpaqueType::get()); + $$.type = new PATypeHolder(OpaqueType::get()); + $$.signedness = isSignless; CHECK_FOR_ERROR } | PrimType { - $$ = new PATypeHolder($1); + $$ = $1; CHECK_FOR_ERROR }; UpRTypes : SymbolicValueRef { // Named types are also simple types... const Type* tmp = getTypeVal($1); CHECK_FOR_ERROR - $$ = new PATypeHolder(tmp); + $$.type = new PATypeHolder(tmp); + $$.signedness = isSignless; }; // Include derived types in the Types production. @@ -1314,59 +1322,69 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference if ($2 > (uint64_t)~0U) GEN_ERROR("Value out of range!"); OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder UpRefs.push_back(UpRefRecord((unsigned)$2, OT)); // Add to vector... - $$ = new PATypeHolder(OT); + $$.type = new PATypeHolder(OT); + $$.signedness = isSignless; UR_OUT("New Upreference!\n"); CHECK_FOR_ERROR } | UpRTypesV '(' ArgTypeListI ')' { // Function derived type? std::vector Params; - for (std::list::iterator I = $3->begin(), + for (std::list::iterator I = $3->begin(), E = $3->end(); I != E; ++I) - Params.push_back(*I); + Params.push_back(I->type->get()); bool isVarArg = Params.size() && Params.back() == Type::VoidTy; if (isVarArg) Params.pop_back(); - $$ = new PATypeHolder(HandleUpRefs(FunctionType::get(*$1,Params,isVarArg))); + $$.type = new PATypeHolder(HandleUpRefs( + FunctionType::get($1.type->get(),Params,isVarArg))); + $$.signedness = isSignless; delete $3; // Delete the argument list - delete $1; // Delete the return type handle + delete $1.type; CHECK_FOR_ERROR } | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type? - $$ = new PATypeHolder(HandleUpRefs(ArrayType::get(*$4, (unsigned)$2))); - delete $4; + $$.type = new PATypeHolder(HandleUpRefs( + ArrayType::get($4.type->get(), (unsigned)$2))); + $$.signedness = isSignless; + delete $4.type; CHECK_FOR_ERROR } | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type? - const llvm::Type* ElemTy = $4->get(); - if ((unsigned)$2 != $2) - GEN_ERROR("Unsigned result not equal to signed result"); - if (!ElemTy->isPrimitiveType()) - GEN_ERROR("Elemental type of a PackedType must be primitive"); - if (!isPowerOf2_32($2)) - GEN_ERROR("Vector length should be a power of 2!"); - $$ = new PATypeHolder(HandleUpRefs(PackedType::get(*$4, (unsigned)$2))); - delete $4; - CHECK_FOR_ERROR + const llvm::Type* ElemTy = $4.type->get(); + if ((unsigned)$2 != $2) + GEN_ERROR("Unsigned result not equal to signed result"); + if (!ElemTy->isPrimitiveType()) + GEN_ERROR("Elemental type of a PackedType must be primitive"); + if (!isPowerOf2_32($2)) + GEN_ERROR("Vector length should be a power of 2!"); + $$.type = new PATypeHolder(HandleUpRefs( + PackedType::get($4.type->get(), (unsigned)$2))); + $$.signedness = isSignless; + delete $4.type; + CHECK_FOR_ERROR } | '{' TypeListI '}' { // Structure type? std::vector Elements; - for (std::list::iterator I = $2->begin(), + for (std::list::iterator I = $2->begin(), E = $2->end(); I != E; ++I) - Elements.push_back(*I); + Elements.push_back(I->type->get()); - $$ = new PATypeHolder(HandleUpRefs(StructType::get(Elements))); + $$.type = new PATypeHolder(HandleUpRefs(StructType::get(Elements))); + $$.signedness = isSignless; delete $2; CHECK_FOR_ERROR } | '{' '}' { // Empty structure type? - $$ = new PATypeHolder(StructType::get(std::vector())); + $$.type = new PATypeHolder(StructType::get(std::vector())); + $$.signedness = isSignless; CHECK_FOR_ERROR } | UpRTypes '*' { // Pointer type? - if (*$1 == Type::LabelTy) + if ($1.type->get() == Type::LabelTy) GEN_ERROR("Cannot form a pointer to a basic block"); - $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1))); - delete $1; + $$.type = new PATypeHolder(HandleUpRefs(PointerType::get($1.type->get()))); + $$.signedness = $1.signedness; + delete $1.type; CHECK_FOR_ERROR }; @@ -1374,27 +1392,31 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference // declaration type lists // TypeListI : UpRTypes { - $$ = new std::list(); - $$->push_back(*$1); delete $1; + $$ = new std::list(); + $$->push_back($1); CHECK_FOR_ERROR } | TypeListI ',' UpRTypes { - ($$=$1)->push_back(*$3); delete $3; + ($$=$1)->push_back($3); CHECK_FOR_ERROR }; // ArgTypeList - List of types for a function type declaration... ArgTypeListI : TypeListI | TypeListI ',' DOTDOTDOT { - ($$=$1)->push_back(Type::VoidTy); + TypeInfo TI; + TI.type = new PATypeHolder(Type::VoidTy); TI.signedness = isSignless; + ($$=$1)->push_back(TI); CHECK_FOR_ERROR } | DOTDOTDOT { - ($$ = new std::list())->push_back(Type::VoidTy); + TypeInfo TI; + TI.type = new PATypeHolder(Type::VoidTy); TI.signedness = isSignless; + ($$ = new std::list())->push_back(TI); CHECK_FOR_ERROR } | /*empty*/ { - $$ = new std::list(); + $$ = new std::list(); CHECK_FOR_ERROR }; @@ -1405,10 +1427,10 @@ ArgTypeListI : TypeListI // ResolvedVal, ValueRef and ConstValueRef productions. // ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr - const ArrayType *ATy = dyn_cast($1->get()); + const ArrayType *ATy = dyn_cast($1.type->get()); if (ATy == 0) GEN_ERROR("Cannot make array constant with type: '" + - (*$1)->getDescription() + "'!"); + ($1.type->get())->getDescription() + "'!"); const Type *ETy = ATy->getElementType(); int NumElements = ATy->getNumElements(); @@ -1427,28 +1449,28 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr } $$ = ConstantArray::get(ATy, *$3); - delete $1; delete $3; + delete $1.type; delete $3; CHECK_FOR_ERROR } | Types '[' ']' { - const ArrayType *ATy = dyn_cast($1->get()); + const ArrayType *ATy = dyn_cast($1.type->get()); if (ATy == 0) GEN_ERROR("Cannot make array constant with type: '" + - (*$1)->getDescription() + "'!"); + ($1.type->get())->getDescription() + "'!"); int NumElements = ATy->getNumElements(); if (NumElements != -1 && NumElements != 0) GEN_ERROR("Type mismatch: constant sized array initialized with 0" " arguments, but has size of " + itostr(NumElements) +"!"); $$ = ConstantArray::get(ATy, std::vector()); - delete $1; + delete $1.type; CHECK_FOR_ERROR } | Types 'c' STRINGCONSTANT { - const ArrayType *ATy = dyn_cast($1->get()); + const ArrayType *ATy = dyn_cast($1.type->get()); if (ATy == 0) GEN_ERROR("Cannot make array constant with type: '" + - (*$1)->getDescription() + "'!"); + ($1.type->get())->getDescription() + "'!"); int NumElements = ATy->getNumElements(); const Type *ETy = ATy->getElementType(); @@ -1471,14 +1493,14 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr } free($3); $$ = ConstantArray::get(ATy, Vals); - delete $1; + delete $1.type; CHECK_FOR_ERROR } | Types '<' ConstVector '>' { // Nonempty unsized arr - const PackedType *PTy = dyn_cast($1->get()); + const PackedType *PTy = dyn_cast($1.type->get()); if (PTy == 0) GEN_ERROR("Cannot make packed constant with type: '" + - (*$1)->getDescription() + "'!"); + $1.type->get()->getDescription() + "'!"); const Type *ETy = PTy->getElementType(); int NumElements = PTy->getNumElements(); @@ -1497,14 +1519,14 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr } $$ = ConstantPacked::get(PTy, *$3); - delete $1; delete $3; + delete $1.type; delete $3; CHECK_FOR_ERROR } | Types '{' ConstVector '}' { - const StructType *STy = dyn_cast($1->get()); + const StructType *STy = dyn_cast($1.type->get()); if (STy == 0) GEN_ERROR("Cannot make struct constant with type: '" + - (*$1)->getDescription() + "'!"); + $1.type->get()->getDescription() + "'!"); if ($3->size() != STy->getNumContainedTypes()) GEN_ERROR("Illegal number of initializers for structure type!"); @@ -1518,39 +1540,39 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr " of structure initializer!"); $$ = ConstantStruct::get(STy, *$3); - delete $1; delete $3; + delete $1.type; delete $3; CHECK_FOR_ERROR } | Types '{' '}' { - const StructType *STy = dyn_cast($1->get()); + const StructType *STy = dyn_cast($1.type->get()); if (STy == 0) GEN_ERROR("Cannot make struct constant with type: '" + - (*$1)->getDescription() + "'!"); + $1.type->get()->getDescription() + "'!"); if (STy->getNumContainedTypes() != 0) GEN_ERROR("Illegal number of initializers for structure type!"); $$ = ConstantStruct::get(STy, std::vector()); - delete $1; + delete $1.type; CHECK_FOR_ERROR } | Types NULL_TOK { - const PointerType *PTy = dyn_cast($1->get()); + const PointerType *PTy = dyn_cast($1.type->get()); if (PTy == 0) GEN_ERROR("Cannot make null pointer constant with type: '" + - (*$1)->getDescription() + "'!"); + $1.type->get()->getDescription() + "'!"); $$ = ConstantPointerNull::get(PTy); - delete $1; + delete $1.type; CHECK_FOR_ERROR } | Types UNDEF { - $$ = UndefValue::get($1->get()); - delete $1; + $$ = UndefValue::get($1.type->get()); + delete $1.type; CHECK_FOR_ERROR } | Types SymbolicValueRef { - const PointerType *Ty = dyn_cast($1->get()); + const PointerType *Ty = dyn_cast($1.type->get()); if (Ty == 0) GEN_ERROR("Global const reference must be a pointer type!"); @@ -1607,35 +1629,35 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr } $$ = cast(V); - delete $1; // Free the type handle + delete $1.type; // Free the type handle CHECK_FOR_ERROR } | Types ConstExpr { - if ($1->get() != $2->getType()) + if ($1.type->get() != $2->getType()) GEN_ERROR("Mismatched types for constant expression!"); $$ = $2; - delete $1; + delete $1.type; CHECK_FOR_ERROR } | Types ZEROINITIALIZER { - const Type *Ty = $1->get(); + const Type *Ty = $1.type->get(); if (isa(Ty) || Ty == Type::LabelTy || isa(Ty)) GEN_ERROR("Cannot create a null initialized value of this type!"); $$ = Constant::getNullValue(Ty); - delete $1; + delete $1.type; CHECK_FOR_ERROR }; ConstVal : SIntType EINT64VAL { // integral constants - if (!ConstantInt::isValueValidForType($1, $2)) + if (!ConstantInt::isValueValidForType($1.type->get(), $2)) GEN_ERROR("Constant value doesn't fit in type!"); - $$ = ConstantInt::get($1, $2); + $$ = ConstantInt::get($1.type->get(), $2); CHECK_FOR_ERROR } | UIntType EUINT64VAL { // integral constants - if (!ConstantInt::isValueValidForType($1, $2)) + if (!ConstantInt::isValueValidForType($1.type->get(), $2)) GEN_ERROR("Constant value doesn't fit in type!"); - $$ = ConstantInt::get($1, $2); + $$ = ConstantInt::get($1.type->get(), $2); CHECK_FOR_ERROR } | BOOL TRUETOK { // Boolean constants @@ -1647,9 +1669,9 @@ ConstVal : SIntType EINT64VAL { // integral constants CHECK_FOR_ERROR } | FPType FPVAL { // Float & Double constants - if (!ConstantFP::isValueValidForType($1, $2)) + if (!ConstantFP::isValueValidForType($1.type->get(), $2)) GEN_ERROR("Floating point constant invalid for type!!"); - $$ = ConstantFP::get($1, $2); + $$ = ConstantFP::get($1.type->get(), $2); CHECK_FOR_ERROR }; @@ -1658,11 +1680,11 @@ ConstExpr: CAST '(' ConstVal TO Types ')' { if (!$3->getType()->isFirstClassType()) GEN_ERROR("cast constant expression from a non-primitive type: '" + $3->getType()->getDescription() + "'!"); - if (!$5->get()->isFirstClassType()) + if (!$5.type->get()->isFirstClassType()) GEN_ERROR("cast constant expression to a non-primitive type: '" + - $5->get()->getDescription() + "'!"); - $$ = ConstantExpr::getCast($3, $5->get()); - delete $5; + $5.type->get()->getDescription() + "'!"); + $$ = ConstantExpr::getCast($3, $5.type->get()); + delete $5.type; CHECK_FOR_ERROR } | GETELEMENTPTR '(' ConstVal IndexList ')' { @@ -1853,16 +1875,16 @@ ConstPool : ConstPool OptAssign TYPE TypesV { // If types are not resolved eagerly, then the two types will not be // determined to be the same type! // - ResolveTypeTo($2, *$4); + ResolveTypeTo($2, $4.type->get()); - if (!setTypeName(*$4, $2) && !$2) { + if (!setTypeName($4.type->get(), $2) && !$2) { CHECK_FOR_ERROR // If this is a named type that is not a redefinition, add it to the slot // table. - CurModule.Types.push_back(*$4); + CurModule.Types.push_back($4); + } else { + delete $4.type; } - - delete $4; CHECK_FOR_ERROR } | ConstPool FunctionProto { // Function prototypes can be in const pool @@ -1880,26 +1902,29 @@ ConstPool : ConstPool OptAssign TYPE TypesV { CurGV = 0; } | ConstPool OptAssign EXTERNAL GlobalType Types { - CurGV = ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, *$5, 0); + CurGV = ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, + $5.type->get(), 0); CHECK_FOR_ERROR - delete $5; + delete $5.type; } GlobalVarAttributes { CurGV = 0; CHECK_FOR_ERROR } | ConstPool OptAssign DLLIMPORT GlobalType Types { - CurGV = ParseGlobalVariable($2, GlobalValue::DLLImportLinkage, $4, *$5, 0); + CurGV = ParseGlobalVariable($2, GlobalValue::DLLImportLinkage, $4, + $5.type->get(), 0); CHECK_FOR_ERROR - delete $5; + delete $5.type; } GlobalVarAttributes { CurGV = 0; CHECK_FOR_ERROR } | ConstPool OptAssign EXTERN_WEAK GlobalType Types { CurGV = - ParseGlobalVariable($2, GlobalValue::ExternalWeakLinkage, $4, *$5, 0); + ParseGlobalVariable($2, GlobalValue::ExternalWeakLinkage, $4, + $5.type->get(), 0); CHECK_FOR_ERROR - delete $5; + delete $5.type; } GlobalVarAttributes { CurGV = 0; CHECK_FOR_ERROR @@ -1977,9 +2002,9 @@ Name : VAR_ID | STRINGCONSTANT; OptName : Name | /*empty*/ { $$ = 0; }; ArgVal : Types OptName { - if (*$1 == Type::VoidTy) + if ($1.type->get() == Type::VoidTy) GEN_ERROR("void typed arguments are invalid!"); - $$ = new std::pair($1, $2); + $$ = new std::pair($1, $2); CHECK_FOR_ERROR }; @@ -1990,7 +2015,7 @@ ArgListH : ArgListH ',' ArgVal { CHECK_FOR_ERROR } | ArgVal { - $$ = new std::vector >(); + $$ = new std::vector >(); $$->push_back(*$1); delete $1; CHECK_FOR_ERROR @@ -2002,13 +2027,18 @@ ArgList : ArgListH { } | ArgListH ',' DOTDOTDOT { $$ = $1; - $$->push_back(std::pair(new PATypeHolder(Type::VoidTy), 0)); + TypeInfo TI; + TI.type = new PATypeHolder(Type::VoidTy); + TI.signedness = isSignless; + $$->push_back(std::pair(TI,(char*)0)); CHECK_FOR_ERROR } | DOTDOTDOT { - $$ = new std::vector >(); - $$->push_back(std::make_pair(new PATypeHolder(Type::VoidTy), (char*)0)); + $$ = new std::vector >(); + TypeInfo TI; + TI.type = new PATypeHolder(Type::VoidTy); + TI.signedness = isSignless; + $$->push_back(std::make_pair(TI, (char*)0)); CHECK_FOR_ERROR } | /* empty */ { @@ -2022,22 +2052,23 @@ FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')' std::string FunctionName($3); free($3); // Free strdup'd memory! - if (!(*$2)->isFirstClassType() && *$2 != Type::VoidTy) + if (!($2.type->get())->isFirstClassType() && $2.type->get() != Type::VoidTy) GEN_ERROR("LLVM functions cannot return aggregate types!"); std::vector ParamTypeList; if ($5) { // If there are arguments... - for (std::vector >::iterator I = $5->begin(); + for (std::vector >::iterator I = $5->begin(); I != $5->end(); ++I) - ParamTypeList.push_back(I->first->get()); + ParamTypeList.push_back(I->first.type->get()); } bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy; if (isVarArg) ParamTypeList.pop_back(); - const FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg); + const FunctionType *FT = FunctionType::get($2.type->get(), ParamTypeList, + isVarArg); const PointerType *PFT = PointerType::get(FT); - delete $2; + delete $2.type; ValID ID; if (!FunctionName.empty()) { @@ -2091,21 +2122,19 @@ FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')' // Add all of the arguments we parsed to the function... if ($5) { // Is null if empty... if (isVarArg) { // Nuke the last entry - assert($5->back().first->get() == Type::VoidTy && $5->back().second == 0&& - "Not a varargs marker!"); - delete $5->back().first; + assert($5->back().first.type->get() == Type::VoidTy && + $5->back().second == 0 && "Not a varargs marker!"); + delete $5->back().first.type; $5->pop_back(); // Delete the last entry } Function::arg_iterator ArgIt = Fn->arg_begin(); - for (std::vector >::iterator I = $5->begin(); + for (std::vector >::iterator I = $5->begin(); I != $5->end(); ++I, ++ArgIt) { - delete I->first; // Delete the typeholder... - + delete I->first.type; // Delete the typeholder... setValueName(ArgIt, I->second); // Insert arg into symtab... CHECK_FOR_ERROR InsertValue(ArgIt); } - delete $5; // We're now done with the argument list } CHECK_FOR_ERROR @@ -2189,12 +2218,7 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant PackedType* pt = PackedType::get(ETy, NumElements); PATypeHolder* PTy = new PATypeHolder( - HandleUpRefs( - PackedType::get( - ETy, - NumElements) - ) - ); + HandleUpRefs(PackedType::get( ETy, NumElements))); // Verify all elements are correct type! for (unsigned i = 0; i < $2->size(); i++) { @@ -2243,7 +2267,7 @@ ValueRef : SymbolicValueRef | ConstValueRef; // type immediately preceeds the value reference, and allows complex constant // pool references (for things like: 'ret [2 x int] [ int 12, int 42]') ResolvedVal : Types ValueRef { - $$ = getVal(*$1, $2); delete $1; + $$ = getVal($1.type->get(), $2); delete $1.type; CHECK_FOR_ERROR }; @@ -2324,7 +2348,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... $$ = new BranchInst(tmpBBA, tmpBBB, tmpVal); } | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' { - Value* tmpVal = getVal($2, $3); + Value* tmpVal = getVal($2.type->get(), $3); CHECK_FOR_ERROR BasicBlock* tmpBB = getBBVal($6); CHECK_FOR_ERROR @@ -2343,7 +2367,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... CHECK_FOR_ERROR } | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' { - Value* tmpVal = getVal($2, $3); + Value* tmpVal = getVal($2.type->get(), $3); CHECK_FOR_ERROR BasicBlock* tmpBB = getBBVal($6); CHECK_FOR_ERROR @@ -2356,7 +2380,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... const PointerType *PFTy; const FunctionType *Ty; - if (!(PFTy = dyn_cast($3->get())) || + if (!(PFTy = dyn_cast($3.type->get())) || !(Ty = dyn_cast(PFTy->getElementType()))) { // Pull out the types of all of the arguments... std::vector ParamTypes; @@ -2369,7 +2393,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy; if (isVarArg) ParamTypes.pop_back(); - Ty = FunctionType::get($3->get(), ParamTypes, isVarArg); + Ty = FunctionType::get($3.type->get(), ParamTypes, isVarArg); PFTy = PointerType::get(Ty); } @@ -2403,7 +2427,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... } cast($$)->setCallingConv($2); - delete $3; + delete $3.type; delete $6; CHECK_FOR_ERROR } @@ -2420,7 +2444,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { $$ = $1; - Constant *V = cast(getValNonImprovising($2, $3)); + Constant *V = cast(getValNonImprovising($2.type->get(), $3)); CHECK_FOR_ERROR if (V == 0) GEN_ERROR("May only switch on a constant pool value!"); @@ -2431,7 +2455,7 @@ JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { } | IntType ConstValueRef ',' LABEL ValueRef { $$ = new std::vector >(); - Constant *V = cast(getValNonImprovising($1, $2)); + Constant *V = cast(getValNonImprovising($1.type->get(), $2)); CHECK_FOR_ERROR if (V == 0) @@ -2453,12 +2477,12 @@ Inst : OptAssign InstVal { PHIList : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes $$ = new std::list >(); - Value* tmpVal = getVal(*$1, $3); + Value* tmpVal = getVal($1.type->get(), $3); CHECK_FOR_ERROR BasicBlock* tmpBB = getBBVal($5); CHECK_FOR_ERROR $$->push_back(std::make_pair(tmpVal, tmpBB)); - delete $1; + delete $1.type; } | PHIList ',' '[' ValueRef ',' ValueRef ']' { $$ = $1; @@ -2493,55 +2517,55 @@ OptTailCall : TAIL CALL { }; InstVal : ArithmeticOps Types ValueRef ',' ValueRef { - if (!(*$2)->isInteger() && !(*$2)->isFloatingPoint() && - !isa((*$2).get())) + if (!$2.type->get()->isInteger() && !$2.type->get()->isFloatingPoint() && + !isa($2.type->get())) GEN_ERROR( "Arithmetic operator requires integer, FP, or packed operands!"); - if (isa((*$2).get()) && + if (isa($2.type->get()) && ($1.opcode == Instruction::URem || $1.opcode == Instruction::SRem || $1.opcode == Instruction::FRem)) GEN_ERROR("U/S/FRem not supported on packed types!"); // Upgrade the opcode from obsolete versions before we do anything with it. - sanitizeOpCode($1,*$2); + sanitizeOpCode($1,$2.type->get()); CHECK_FOR_ERROR; - Value* val1 = getVal(*$2, $3); + Value* val1 = getVal($2.type->get(), $3); CHECK_FOR_ERROR - Value* val2 = getVal(*$2, $5); + Value* val2 = getVal($2.type->get(), $5); CHECK_FOR_ERROR $$ = BinaryOperator::create($1.opcode, val1, val2); if ($$ == 0) GEN_ERROR("binary operator returned null!"); - delete $2; + delete $2.type; } | LogicalOps Types ValueRef ',' ValueRef { - if (!(*$2)->isIntegral()) { - if (!isa($2->get()) || - !cast($2->get())->getElementType()->isIntegral()) + if (!$2.type->get()->isIntegral()) { + if (!isa($2.type->get()) || + !cast($2.type->get())->getElementType()->isIntegral()) GEN_ERROR("Logical operator requires integral operands!"); } - Value* tmpVal1 = getVal(*$2, $3); + Value* tmpVal1 = getVal($2.type->get(), $3); CHECK_FOR_ERROR - Value* tmpVal2 = getVal(*$2, $5); + Value* tmpVal2 = getVal($2.type->get(), $5); CHECK_FOR_ERROR $$ = BinaryOperator::create($1.opcode, tmpVal1, tmpVal2); if ($$ == 0) GEN_ERROR("binary operator returned null!"); - delete $2; + delete $2.type; } | SetCondOps Types ValueRef ',' ValueRef { - if(isa((*$2).get())) { + if(isa($2.type->get())) { GEN_ERROR( "PackedTypes currently not supported in setcc instructions!"); } - Value* tmpVal1 = getVal(*$2, $3); + Value* tmpVal1 = getVal($2.type->get(), $3); CHECK_FOR_ERROR - Value* tmpVal2 = getVal(*$2, $5); + Value* tmpVal2 = getVal($2.type->get(), $5); CHECK_FOR_ERROR $$ = new SetCondInst($1.opcode, tmpVal1, tmpVal2); if ($$ == 0) GEN_ERROR("binary operator returned null!"); - delete $2; + delete $2.type; } | NOT ResolvedVal { std::cerr << "WARNING: Use of eliminated 'not' instruction:" @@ -2568,11 +2592,11 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { CHECK_FOR_ERROR } | CAST ResolvedVal TO Types { - if (!$4->get()->isFirstClassType()) + if (!$4.type->get()->isFirstClassType()) GEN_ERROR("cast instruction to a non-primitive type: '" + - $4->get()->getDescription() + "'!"); - $$ = new CastInst($2, *$4); - delete $4; + $4.type->get()->getDescription() + "'!"); + $$ = new CastInst($2, $4.type->get()); + delete $4.type; CHECK_FOR_ERROR } | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal { @@ -2585,8 +2609,8 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { } | VAARG ResolvedVal ',' Types { NewVarArgs = true; - $$ = new VAArgInst($2, *$4); - delete $4; + $$ = new VAArgInst($2, $4.type->get()); + delete $4.type; CHECK_FOR_ERROR } | VAARG_old ResolvedVal ',' Types { @@ -2605,8 +2629,8 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { CallInst* bar = new CallInst(NF, $2); CurBB->getInstList().push_back(bar); CurBB->getInstList().push_back(new StoreInst(bar, foo)); - $$ = new VAArgInst(foo, *$4); - delete $4; + $$ = new VAArgInst(foo, $4.type->get()); + delete $4.type; CHECK_FOR_ERROR } | VANEXT_old ResolvedVal ',' Types { @@ -2626,10 +2650,10 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { CallInst* bar = new CallInst(NF, $2); CurBB->getInstList().push_back(bar); CurBB->getInstList().push_back(new StoreInst(bar, foo)); - Instruction* tmp = new VAArgInst(foo, *$4); + Instruction* tmp = new VAArgInst(foo, $4.type->get()); CurBB->getInstList().push_back(tmp); $$ = new LoadInst(foo); - delete $4; + delete $4.type; CHECK_FOR_ERROR } | EXTRACTELEMENT ResolvedVal ',' ResolvedVal { @@ -2669,7 +2693,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { const PointerType *PFTy = 0; const FunctionType *Ty = 0; - if (!(PFTy = dyn_cast($3->get())) || + if (!(PFTy = dyn_cast($3.type->get())) || !(Ty = dyn_cast(PFTy->getElementType()))) { // Pull out the types of all of the arguments... std::vector ParamTypes; @@ -2682,10 +2706,11 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy; if (isVarArg) ParamTypes.pop_back(); - if (!(*$3)->isFirstClassType() && *$3 != Type::VoidTy) + if (!$3.type->get()->isFirstClassType() && + $3.type->get() != Type::VoidTy) GEN_ERROR("LLVM functions cannot return aggregate types!"); - Ty = FunctionType::get($3->get(), ParamTypes, isVarArg); + Ty = FunctionType::get($3.type->get(), ParamTypes, isVarArg); PFTy = PointerType::get(Ty); } @@ -2720,7 +2745,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { } cast($$)->setTailCall($1); cast($$)->setCallingConv($2); - delete $3; + delete $3.type; delete $6; CHECK_FOR_ERROR } @@ -2751,26 +2776,26 @@ OptVolatile : VOLATILE { MemoryInst : MALLOC Types OptCAlign { - $$ = new MallocInst(*$2, 0, $3); - delete $2; + $$ = new MallocInst($2.type->get(), 0, $3); + delete $2.type; CHECK_FOR_ERROR } | MALLOC Types ',' UINT ValueRef OptCAlign { - Value* tmpVal = getVal($4, $5); + Value* tmpVal = getVal($4.type->get(), $5); CHECK_FOR_ERROR - $$ = new MallocInst(*$2, tmpVal, $6); - delete $2; + $$ = new MallocInst($2.type->get(), tmpVal, $6); + delete $2.type; } | ALLOCA Types OptCAlign { - $$ = new AllocaInst(*$2, 0, $3); - delete $2; + $$ = new AllocaInst($2.type->get(), 0, $3); + delete $2.type; CHECK_FOR_ERROR } | ALLOCA Types ',' UINT ValueRef OptCAlign { - Value* tmpVal = getVal($4, $5); + Value* tmpVal = getVal($4.type->get(), $5); CHECK_FOR_ERROR - $$ = new AllocaInst(*$2, tmpVal, $6); - delete $2; + $$ = new AllocaInst($2.type->get(), tmpVal, $6); + delete $2.type; } | FREE ResolvedVal { if (!isa($2->getType())) @@ -2781,54 +2806,54 @@ MemoryInst : MALLOC Types OptCAlign { } | OptVolatile LOAD Types ValueRef { - if (!isa($3->get())) + if (!isa($3.type->get())) GEN_ERROR("Can't load from nonpointer type: " + - (*$3)->getDescription()); - if (!cast($3->get())->getElementType()->isFirstClassType()) + $3.type->get()->getDescription()); + if (!cast($3.type->get())->getElementType()->isFirstClassType()) GEN_ERROR("Can't load from pointer of non-first-class type: " + - (*$3)->getDescription()); - Value* tmpVal = getVal(*$3, $4); + $3.type->get()->getDescription()); + Value* tmpVal = getVal($3.type->get(), $4); CHECK_FOR_ERROR $$ = new LoadInst(tmpVal, "", $1); - delete $3; + delete $3.type; } | OptVolatile STORE ResolvedVal ',' Types ValueRef { - const PointerType *PT = dyn_cast($5->get()); + const PointerType *PT = dyn_cast($5.type->get()); if (!PT) GEN_ERROR("Can't store to a nonpointer type: " + - (*$5)->getDescription()); + ($5.type->get())->getDescription()); const Type *ElTy = PT->getElementType(); if (ElTy != $3->getType()) GEN_ERROR("Can't store '" + $3->getType()->getDescription() + "' into space of type '" + ElTy->getDescription() + "'!"); - Value* tmpVal = getVal(*$5, $6); + Value* tmpVal = getVal($5.type->get(), $6); CHECK_FOR_ERROR $$ = new StoreInst($3, tmpVal, $1); - delete $5; + delete $5.type; } | GETELEMENTPTR Types ValueRef IndexList { - if (!isa($2->get())) + if (!isa($2.type->get())) GEN_ERROR("getelementptr insn requires pointer operand!"); // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct // indices to uint struct indices for compatibility. generic_gep_type_iterator::iterator> - GTI = gep_type_begin($2->get(), $4->begin(), $4->end()), - GTE = gep_type_end($2->get(), $4->begin(), $4->end()); + GTI = gep_type_begin($2.type->get(), $4->begin(), $4->end()), + GTE = gep_type_end($2.type->get(), $4->begin(), $4->end()); for (unsigned i = 0, e = $4->size(); i != e && GTI != GTE; ++i, ++GTI) if (isa(*GTI)) // Only change struct indices if (ConstantInt *CUI = dyn_cast((*$4)[i])) if (CUI->getType() == Type::UByteTy) (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy); - if (!GetElementPtrInst::getIndexedType(*$2, *$4, true)) + if (!GetElementPtrInst::getIndexedType($2.type->get(), *$4, true)) GEN_ERROR("Invalid getelementptr indices for type '" + - (*$2)->getDescription()+ "'!"); - Value* tmpVal = getVal(*$2, $3); + $2.type->get()->getDescription()+ "'!"); + Value* tmpVal = getVal($2.type->get(), $3); CHECK_FOR_ERROR $$ = new GetElementPtrInst(tmpVal, *$4); - delete $2; + delete $2.type; delete $4; };