From: Chris Lattner Date: Thu, 4 Apr 2002 19:23:55 +0000 (+0000) Subject: * Make PATypeHolder not take a type argument X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8b88b3b5bfb84723adeb6491e238f43f88d4b973;p=oota-llvm.git * Make PATypeHolder not take a type argument * Eliminate by inlining the old newTH, newTH, and TypeDone functions * OPAQUE is now just a token that gets returned by the lexer, not a type Parser now creates type, not lexer git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2104 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 3c0bb8f101d..b9f9887ca38 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -60,8 +60,8 @@ static struct PerModuleInfo { Module *CurrentModule; vector Values; // Module level numbered definitions vector LateResolveValues; - vector > Types; - map > LateResolveTypes; + vector Types; + map LateResolveTypes; // GlobalRefs - This maintains a mapping between 's and forward // references to global values. Global values may be referenced before they @@ -140,8 +140,8 @@ static struct PerFunctionInfo { vector Values; // Keep track of numbered definitions vector LateResolveValues; - vector > Types; - map > LateResolveTypes; + vector Types; + map LateResolveTypes; bool isDeclare; // Is this method a forward declararation? inline PerFunctionInfo() { @@ -187,7 +187,7 @@ static int InsertValue(Value *D, vector &ValueTab = CurMeth.Values) { } // TODO: FIXME when Type are not const -static void InsertType(const Type *Ty, vector > &Types) { +static void InsertType(const Type *Ty, vector &Types) { Types.push_back(Ty); } @@ -236,10 +236,10 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) { // if (DoNotImprovise) return 0; // Do we just want a null to be returned? - map > &LateResolver = inFunctionScope() ? + map &LateResolver = inFunctionScope() ? CurMeth.LateResolveTypes : CurModule.LateResolveTypes; - map >::iterator I = LateResolver.find(D); + map::iterator I = LateResolver.find(D); if (I != LateResolver.end()) { return I->second; } @@ -443,17 +443,17 @@ static void ResolveDefinitions(vector &LateResolvers, // refering to the number can be resolved. Do this now. // static void ResolveTypeTo(char *Name, const Type *ToTy) { - vector > &Types = inFunctionScope() ? + vector &Types = inFunctionScope() ? CurMeth.Types : CurModule.Types; ValID D; if (Name) D = ValID::create(Name); else D = ValID::create((int)Types.size()); - map > &LateResolver = inFunctionScope() ? + map &LateResolver = inFunctionScope() ? CurMeth.LateResolveTypes : CurModule.LateResolveTypes; - map >::iterator I = LateResolver.find(D); + map::iterator I = LateResolver.find(D); if (I != LateResolver.end()) { cast(I->second.get())->refineAbstractTypeTo(ToTy); LateResolver.erase(I); @@ -463,7 +463,7 @@ static void ResolveTypeTo(char *Name, const Type *ToTy) { // ResolveTypes - At this point, all types should be resolved. Any that aren't // are errors. // -static void ResolveTypes(map > &LateResolveTypes) { +static void ResolveTypes(map &LateResolveTypes) { if (!LateResolveTypes.empty()) { const ValID &DID = LateResolveTypes.begin()->first; @@ -558,8 +558,8 @@ static bool TypeContains(const Type *Ty, const Type *E) { static vector > UpRefs; -static PATypeHolder HandleUpRefs(const Type *ty) { - PATypeHolder Ty(ty); +static PATypeHolder HandleUpRefs(const Type *ty) { + PATypeHolder Ty(ty); UR_OUT("Type '" << ty->getDescription() << "' newly formed. Resolving upreferences.\n" << UpRefs.size() << " upreferences active!\n"); @@ -588,22 +588,6 @@ static PATypeHolder HandleUpRefs(const Type *ty) { return Ty; } -template -inline static void TypeDone(PATypeHolder *Ty) { - if (UpRefs.size()) - ThrowException("Invalid upreference in type: " + (*Ty)->getDescription()); -} - -// newTH - Allocate a new type holder for the specified type -template -inline static PATypeHolder *newTH(const TypeTy *Ty) { - return new PATypeHolder(Ty); -} -template -inline static PATypeHolder *newTH(const PATypeHolder &TH) { - return new PATypeHolder(TH); -} - //===----------------------------------------------------------------------===// // RunVMAsmParser - Define an interface to this parser @@ -635,12 +619,12 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) { Constant *ConstVal; const Type *PrimType; - PATypeHolder *TypeVal; + PATypeHolder *TypeVal; Value *ValueVal; std::list > *FunctionArgList; std::vector *ValueList; - std::list > *TypeList; + std::list *TypeList; std::list > *PHIList; // Represent the RHS of PHI node std::list > *JumpTable; @@ -699,7 +683,6 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) { // Built in types... %type Types TypesV UpRTypes UpRTypesV %type SIntType UIntType IntType FPType PrimType // Classifications -%token OPAQUE %token VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG %token FLOAT DOUBLE TYPE LABEL @@ -708,7 +691,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) { %token IMPLEMENTATION TRUE FALSE BEGINTOK END DECLARE GLOBAL CONSTANT UNINIT -%token TO EXCEPT DOTDOTDOT STRING NULL_TOK CONST INTERNAL +%token TO EXCEPT DOTDOTDOT STRING NULL_TOK CONST INTERNAL OPAQUE // Basic Block Terminating Operators %token RET BR SWITCH @@ -782,11 +765,13 @@ OptInternal : INTERNAL { $$ = true; } | /*empty*/ { $$ = false; } // // TypesV includes all of 'Types', but it also includes the void type. -TypesV : Types | VOID { $$ = newTH($1); } -UpRTypesV : UpRTypes | VOID { $$ = newTH($1); } +TypesV : Types | VOID { $$ = new PATypeHolder($1); } +UpRTypesV : UpRTypes | VOID { $$ = new PATypeHolder($1); } Types : UpRTypes { - TypeDone($$ = $1); + if (UpRefs.size()) + ThrowException("Invalid upreference in type: " + (*$1)->getDescription()); + $$ = $1; } @@ -794,9 +779,14 @@ Types : UpRTypes { // PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT PrimType : LONG | ULONG | FLOAT | DOUBLE | TYPE | LABEL -UpRTypes : OPAQUE | PrimType { $$ = newTH($1); } +UpRTypes : OPAQUE { + $$ = new PATypeHolder(OpaqueType::get()); + } + | PrimType { + $$ = new PATypeHolder($1); + } UpRTypes : ValueRef { // Named types are also simple types... - $$ = newTH(getTypeVal($1)); + $$ = new PATypeHolder(getTypeVal($1)); } // Include derived types in the Types production. @@ -805,7 +795,7 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference if ($2 > (uint64_t)INT64_MAX) ThrowException("Value out of range!"); OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder UpRefs.push_back(make_pair((unsigned)$2, OT)); // Add to vector... - $$ = newTH(OT); + $$ = new PATypeHolder(OT); UR_OUT("New Upreference!\n"); } | UpRTypesV '(' ArgTypeListI ')' { // Function derived type? @@ -815,12 +805,12 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference bool isVarArg = Params.size() && Params.back() == Type::VoidTy; if (isVarArg) Params.pop_back(); - $$ = newTH(HandleUpRefs(FunctionType::get(*$1, Params, isVarArg))); + $$ = new PATypeHolder(HandleUpRefs(FunctionType::get(*$1,Params,isVarArg))); delete $3; // Delete the argument list delete $1; // Delete the old type handle } | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type? - $$ = newTH(HandleUpRefs(ArrayType::get(*$4, (unsigned)$2))); + $$ = new PATypeHolder(HandleUpRefs(ArrayType::get(*$4, (unsigned)$2))); delete $4; } | '{' TypeListI '}' { // Structure type? @@ -828,14 +818,14 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference mapto($2->begin(), $2->end(), std::back_inserter(Elements), std::mem_fun_ref(&PATypeHandle::get)); - $$ = newTH(HandleUpRefs(StructType::get(Elements))); + $$ = new PATypeHolder(HandleUpRefs(StructType::get(Elements))); delete $2; } | '{' '}' { // Empty structure type? - $$ = newTH(StructType::get(vector())); + $$ = new PATypeHolder(StructType::get(vector())); } | UpRTypes '*' { // Pointer type? - $$ = newTH(HandleUpRefs(PointerType::get(*$1))); + $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1))); delete $1; } @@ -843,7 +833,7 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference // declaration type lists // TypeListI : UpRTypes { - $$ = new list >(); + $$ = new list(); $$->push_back(*$1); delete $1; } | TypeListI ',' UpRTypes { @@ -856,10 +846,10 @@ ArgTypeListI : TypeListI ($$=$1)->push_back(Type::VoidTy); } | DOTDOTDOT { - ($$ = new list >())->push_back(Type::VoidTy); + ($$ = new list())->push_back(Type::VoidTy); } | /*empty*/ { - $$ = new list >(); + $$ = new list(); }