From: Matthias Braun Date: Mon, 5 Dec 2016 07:35:13 +0000 (+0000) Subject: TableGen: Some more std::string->StringInit* replacements X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=215ff84b4082bea94dbf065d5fbac3cdd7f69516;p=platform%2Fupstream%2Fllvm.git TableGen: Some more std::string->StringInit* replacements llvm-svn: 288653 --- diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index 7830ba6..5a100f0 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -1231,7 +1231,7 @@ public: RecordVal(StringRef N, RecTy *T, bool P); StringRef getName() const; - const Init *getNameInit() const { return Name; } + Init *getNameInit() const { return Name; } std::string getNameInitAsString() const { return getNameInit()->getAsUnquotedString(); diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 2e69ed7..ea9c9a1 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -1702,10 +1702,10 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const Record &R) { OS << "\n"; for (const RecordVal &Val : R.getValues()) - if (Val.getPrefix() && !R.isTemplateArg(Val.getName())) + if (Val.getPrefix() && !R.isTemplateArg(Val.getNameInit())) OS << Val; for (const RecordVal &Val : R.getValues()) - if (!Val.getPrefix() && !R.isTemplateArg(Val.getName())) + if (!Val.getPrefix() && !R.isTemplateArg(Val.getNameInit())) OS << Val; return OS << "}\n"; diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 3cc8633..1a91b37 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -339,14 +339,14 @@ bool TGParser::ProcessForeachDefs(Record *CurRec, SMLoc Loc, IterSet &IterVals){ IterRec->addValue(RecordVal(IterVar->getName(), IVal->getType(), false)); - if (SetValue(IterRec.get(), Loc, IterVar->getName(), None, IVal)) + if (SetValue(IterRec.get(), Loc, IterVar->getNameInit(), None, IVal)) return Error(Loc, "when instantiating this def"); // Resolve it next. - IterRec->resolveReferencesTo(IterRec->getValue(IterVar->getName())); + IterRec->resolveReferencesTo(IterRec->getValue(IterVar->getNameInit())); // Remove it. - IterRec->removeValue(IterVar->getName()); + IterRec->removeValue(IterVar->getNameInit()); } if (Records.getDef(IterRec->getNameInitAsString())) { @@ -716,18 +716,16 @@ RecTy *TGParser::ParseType() { /// ParseIDValue - This is just like ParseIDValue above, but it assumes the ID /// has already been read. -Init *TGParser::ParseIDValue(Record *CurRec, StringRef Name, SMLoc NameLoc, +Init *TGParser::ParseIDValue(Record *CurRec, StringInit *Name, SMLoc NameLoc, IDParseMode Mode) { - StringInit *NameInit; if (CurRec) { if (const RecordVal *RV = CurRec->getValue(Name)) return VarInit::get(Name, RV->getType()); - NameInit = StringInit::get(Name); - Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, NameInit, ":"); + Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, Name, ":"); if (CurMultiClass) - TemplateArgName = QualifyName(CurMultiClass->Rec, CurMultiClass, NameInit, + TemplateArgName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name, "::"); if (CurRec->isTemplateArg(TemplateArgName)) { @@ -735,12 +733,10 @@ Init *TGParser::ParseIDValue(Record *CurRec, StringRef Name, SMLoc NameLoc, assert(RV && "Template arg doesn't exist??"); return VarInit::get(TemplateArgName, RV->getType()); } - } else - NameInit = StringInit::get(Name); + } if (CurMultiClass) { - Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, NameInit, - "::"); + Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name, "::"); if (CurMultiClass->Rec.isTemplateArg(MCName)) { const RecordVal *RV = CurMultiClass->Rec.getValue(MCName); @@ -752,22 +748,22 @@ Init *TGParser::ParseIDValue(Record *CurRec, StringRef Name, SMLoc NameLoc, // If this is in a foreach loop, make sure it's not a loop iterator for (const auto &L : Loops) { VarInit *IterVar = dyn_cast(L.IterVar); - if (IterVar && IterVar->getNameInit() == NameInit) + if (IterVar && IterVar->getNameInit() == Name) return IterVar; } if (Mode == ParseNameMode) - return NameInit; + return Name; - if (Record *D = Records.getDef(Name)) + if (Record *D = Records.getDef(Name->getValue())) return DefInit::get(D); if (Mode == ParseValueMode) { - Error(NameLoc, "Variable not defined: '" + Name + "'"); + Error(NameLoc, "Variable not defined: '" + Name->getValue() + "'"); return nullptr; } - return NameInit; + return Name; } /// ParseOperation - Parse an operator. This returns null on error. @@ -1187,7 +1183,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, break; case tgtok::Id: { SMLoc NameLoc = Lex.getLoc(); - std::string Name = Lex.getCurStrVal(); + StringInit *Name = StringInit::get(Lex.getCurStrVal()); if (Lex.Lex() != tgtok::less) // consume the Id. return ParseIDValue(CurRec, Name, NameLoc, Mode); // Value ::= IDValue @@ -1200,9 +1196,9 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, // This is a CLASS expression. This is supposed to synthesize // a new anonymous definition, deriving from CLASS with no // body. - Record *Class = Records.getClass(Name); + Record *Class = Records.getClass(Name->getValue()); if (!Class) { - Error(NameLoc, "Expected a class name, got '" + Name + "'"); + Error(NameLoc, "Expected a class name, got '" + Name->getValue() + "'"); return nullptr; } @@ -1891,7 +1887,7 @@ bool TGParser::ParseBodyItem(Record *CurRec) { return TokError("expected field identifier after let"); SMLoc IdLoc = Lex.getLoc(); - std::string FieldName = Lex.getCurStrVal(); + StringInit *FieldName = StringInit::get(Lex.getCurStrVal()); Lex.Lex(); // eat the field name. SmallVector BitList; @@ -1905,7 +1901,7 @@ bool TGParser::ParseBodyItem(Record *CurRec) { RecordVal *Field = CurRec->getValue(FieldName); if (!Field) - return TokError("Value '" + FieldName + "' unknown!"); + return TokError("Value '" + FieldName->getValue() + "' unknown!"); RecTy *Type = Field->getType(); @@ -2169,7 +2165,7 @@ void TGParser::ParseLetList(SmallVectorImpl &Result) { return; } - std::string Name = Lex.getCurStrVal(); + StringInit *Name = StringInit::get(Lex.getCurStrVal()); SMLoc NameLoc = Lex.getLoc(); Lex.Lex(); // Eat the identifier. @@ -2195,7 +2191,7 @@ void TGParser::ParseLetList(SmallVectorImpl &Result) { } // Now that we have everything, add the record. - Result.emplace_back(std::move(Name), Bits, Val, NameLoc); + Result.emplace_back(Name, Bits, Val, NameLoc); if (Lex.getCode() != tgtok::comma) return; @@ -2382,8 +2378,8 @@ Record *TGParser::InstantiateMulticlassDef(MultiClass &MC, Record *DefProto, // Set the value for NAME. We don't resolve references to it 'til later, // though, so that uses in nested multiclass names don't get // confused. - if (SetValue(CurRec.get(), Ref.RefRange.Start, "NAME", None, DefmPrefix, - /*AllowSelfAssignment*/true)) { + if (SetValue(CurRec.get(), Ref.RefRange.Start, StringInit::get("NAME"), None, + DefmPrefix, /*AllowSelfAssignment*/true)) { Error(DefmPrefixRange.Start, "Could not resolve " + CurRec->getNameInitAsString() + ":NAME to '" + DefmPrefix->getAsUnquotedString() + "'"); diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h index 8396e9d..76f7d8f 100644 --- a/llvm/lib/TableGen/TGParser.h +++ b/llvm/lib/TableGen/TGParser.h @@ -32,11 +32,11 @@ namespace llvm { struct SubMultiClassReference; struct LetRecord { - std::string Name; + StringInit *Name; std::vector Bits; Init *Value; SMLoc Loc; - LetRecord(StringRef N, ArrayRef B, Init *V, SMLoc L) + LetRecord(StringInit *N, ArrayRef B, Init *V, SMLoc L) : Name(N), Bits(B), Value(V), Loc(L) { } }; @@ -106,12 +106,6 @@ private: // Semantic analysis methods. bool SetValue(Record *TheRec, SMLoc Loc, Init *ValName, ArrayRef BitList, Init *V, bool AllowSelfAssignment = false); - bool SetValue(Record *TheRec, SMLoc Loc, StringRef ValName, - ArrayRef BitList, Init *V, - bool AllowSelfAssignment = false) { - return SetValue(TheRec, Loc, StringInit::get(ValName), BitList, V, - AllowSelfAssignment); - } bool AddSubClass(Record *Rec, SubClassReference &SubClass); bool AddSubMultiClass(MultiClass *CurMC, SubMultiClassReference &SubMultiClass); @@ -166,7 +160,7 @@ private: // Parser methods. SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm); SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC); - Init *ParseIDValue(Record *CurRec, StringRef Name, SMLoc NameLoc, + Init *ParseIDValue(Record *CurRec, StringInit *Name, SMLoc NameLoc, IDParseMode Mode = ParseValueMode); Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = nullptr, IDParseMode Mode = ParseValueMode);