X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTableGen%2FTGParser.cpp;h=2a6b3f40492ad0e945cb2ad16f390959359f5808;hb=2becaaf3a15a8815f93e65f768038427051ee004;hp=8ee3a7b4ec7513692131d33bd1e4f801ac28097f;hpb=b50df4a3df6db2ace3c011267934d3d10bdcc8db;p=oota-llvm.git diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index 8ee3a7b4ec7..2a6b3f40492 100644 --- a/lib/TableGen/TGParser.cpp +++ b/lib/TableGen/TGParser.cpp @@ -380,9 +380,11 @@ static bool isObjectStart(tgtok::TokKind K) { K == tgtok::MultiClass || K == tgtok::Foreach; } -static std::string GetNewAnonymousName() { - static unsigned AnonCounter = 0; - return "anonymous."+utostr(AnonCounter++); +/// GetNewAnonymousName - Generate a unique anonymous name that can be used as +/// an identifier. +std::string TGParser::GetNewAnonymousName() { + unsigned Tmp = AnonCounter++; // MSVC2012 ICEs without this. + return "anonymous_" + utostr(Tmp); } /// ParseObjectName - If an object name is specified, return it. Otherwise, @@ -912,6 +914,7 @@ Init *TGParser::ParseOperation(Record *CurRec) { } case tgtok::XConcat: + case tgtok::XADD: case tgtok::XSRA: case tgtok::XSRL: case tgtok::XSHL: @@ -927,6 +930,7 @@ Init *TGParser::ParseOperation(Record *CurRec) { switch (OpTok) { default: llvm_unreachable("Unhandled code!"); case tgtok::XConcat: Code = BinOpInit::CONCAT;Type = DagRecTy::get(); break; + case tgtok::XADD: Code = BinOpInit::ADD; Type = IntRecTy::get(); break; case tgtok::XSRA: Code = BinOpInit::SRA; Type = IntRecTy::get(); break; case tgtok::XSRL: Code = BinOpInit::SRL; Type = IntRecTy::get(); break; case tgtok::XSHL: Code = BinOpInit::SHL; Type = IntRecTy::get(); break; @@ -1142,6 +1146,7 @@ RecTy *TGParser::ParseOperatorType() { /// SimpleValue ::= '[' ValueList ']' /// SimpleValue ::= '(' IDValue DagArgList ')' /// SimpleValue ::= CONCATTOK '(' Value ',' Value ')' +/// SimpleValue ::= ADDTOK '(' Value ',' Value ')' /// SimpleValue ::= SHLTOK '(' Value ',' Value ')' /// SimpleValue ::= SRATOK '(' Value ',' Value ')' /// SimpleValue ::= SRLTOK '(' Value ',' Value ')' @@ -1211,10 +1216,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, SMLoc EndLoc = Lex.getLoc(); // Create the new record, set it as CurRec temporarily. - static unsigned AnonCounter = 0; - Record *NewRec = new Record("anonymous.val."+utostr(AnonCounter++), - NameLoc, - Records, + Record *NewRec = new Record(GetNewAnonymousName(), NameLoc, Records, /*IsAnonymous=*/true); SubClassReference SCRef; SCRef.RefRange = SMRange(NameLoc, EndLoc); @@ -1223,8 +1225,36 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, // Add info about the subclass to NewRec. if (AddSubClass(NewRec, SCRef)) return 0; - NewRec->resolveReferences(); - Records.addDef(NewRec); + if (!CurMultiClass) { + NewRec->resolveReferences(); + Records.addDef(NewRec); + } else { + // Otherwise, we're inside a multiclass, add it to the multiclass. + CurMultiClass->DefPrototypes.push_back(NewRec); + + // Copy the template arguments for the multiclass into the def. + const std::vector &TArgs = + CurMultiClass->Rec.getTemplateArgs(); + + for (unsigned i = 0, e = TArgs.size(); i != e; ++i) { + const RecordVal *RV = CurMultiClass->Rec.getValue(TArgs[i]); + assert(RV && "Template arg doesn't exist?"); + NewRec->addValue(*RV); + } + + // We can't return the prototype def here, instead return: + // !cast(!strconcat(NAME, AnonName)). + const RecordVal *MCNameRV = CurMultiClass->Rec.getValue("NAME"); + assert(MCNameRV && "multiclass record must have a NAME"); + + return UnOpInit::get(UnOpInit::CAST, + BinOpInit::get(BinOpInit::STRCONCAT, + VarInit::get(MCNameRV->getName(), + MCNameRV->getType()), + NewRec->getNameInit(), + StringRecTy::get()), + Class->getDefInit()->getType()); + } // The result of the expression is a reference to the new record. return DefInit::get(NewRec); @@ -1267,10 +1297,11 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, if (ItemType != 0) { ListRecTy *ListType = dyn_cast(ItemType); if (ListType == 0) { - std::stringstream s; - s << "Type mismatch for list, expected list type, got " - << ItemType->getAsString(); - TokError(s.str()); + std::string s; + raw_string_ostream ss(s); + ss << "Type mismatch for list, expected list type, got " + << ItemType->getAsString(); + TokError(ss.str()); return 0; } GivenListTy = ListType; @@ -1397,6 +1428,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, case tgtok::XEmpty: case tgtok::XCast: // Value ::= !unop '(' Value ')' case tgtok::XConcat: + case tgtok::XADD: case tgtok::XSRA: case tgtok::XSRL: case tgtok::XSHL: @@ -1542,29 +1574,39 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) { /// ParseDagArgList - Parse the argument list for a dag literal expression. /// -/// ParseDagArgList ::= Value (':' VARNAME)? -/// ParseDagArgList ::= ParseDagArgList ',' Value (':' VARNAME)? +/// DagArg ::= Value (':' VARNAME)? +/// DagArg ::= VARNAME +/// DagArgList ::= DagArg +/// DagArgList ::= DagArgList ',' DagArg std::vector > TGParser::ParseDagArgList(Record *CurRec) { std::vector > Result; while (1) { - Init *Val = ParseValue(CurRec); - if (Val == 0) return std::vector >(); - - // If the variable name is present, add it. - std::string VarName; - if (Lex.getCode() == tgtok::colon) { - if (Lex.Lex() != tgtok::VarName) { // eat the ':' - TokError("expected variable name in dag literal"); + // DagArg ::= VARNAME + if (Lex.getCode() == tgtok::VarName) { + // A missing value is treated like '?'. + Result.push_back(std::make_pair(UnsetInit::get(), Lex.getCurStrVal())); + Lex.Lex(); + } else { + // DagArg ::= Value (':' VARNAME)? + Init *Val = ParseValue(CurRec); + if (Val == 0) return std::vector >(); - } - VarName = Lex.getCurStrVal(); - Lex.Lex(); // eat the VarName. - } - Result.push_back(std::make_pair(Val, VarName)); + // If the variable name is present, add it. + std::string VarName; + if (Lex.getCode() == tgtok::colon) { + if (Lex.Lex() != tgtok::VarName) { // eat the ':' + TokError("expected variable name in dag literal"); + return std::vector >(); + } + VarName = Lex.getCurStrVal(); + Lex.Lex(); // eat the VarName. + } + Result.push_back(std::make_pair(Val, VarName)); + } if (Lex.getCode() != tgtok::comma) break; Lex.Lex(); // eat the ',' } @@ -1948,7 +1990,18 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) { return true; } Records.addDef(CurRec); + + if (ParseObjectBody(CurRec)) + return true; } else if (CurMultiClass) { + // Parse the body before adding this prototype to the DefPrototypes vector. + // That way implicit definitions will be added to the DefPrototypes vector + // before this object, instantiated prior to defs derived from this object, + // and this available for indirect name resolution when defs derived from + // this object are instantiated. + if (ParseObjectBody(CurRec)) + return true; + // Otherwise, a def inside a multiclass, add it to the multiclass. for (unsigned i = 0, e = CurMultiClass->DefPrototypes.size(); i != e; ++i) if (CurMultiClass->DefPrototypes[i]->getNameInit() @@ -1958,9 +2011,7 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) { return true; } CurMultiClass->DefPrototypes.push_back(CurRec); - } - - if (ParseObjectBody(CurRec)) + } else if (ParseObjectBody(CurRec)) return true; if (CurMultiClass == 0) // Def's in multiclasses aren't really defs. @@ -2255,7 +2306,7 @@ bool TGParser::ParseMultiClass() { Record *TGParser:: InstantiateMulticlassDef(MultiClass &MC, Record *DefProto, - Init *DefmPrefix, + Init *&DefmPrefix, SMRange DefmPrefixRange) { // We need to preserve DefProto so it can be reused for later // instantiations, so create a new Record to inherit from it. @@ -2480,6 +2531,9 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) { if (Lex.getCode() != tgtok::comma) break; Lex.Lex(); // eat ','. + if (Lex.getCode() != tgtok::Id) + return TokError("expected identifier"); + SubClassLoc = Lex.getLoc(); // A defm can inherit from regular classes (non-multiclass) as