[llvm] r288653 - TableGen: Some more std::string->StringInit* replacements
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 4 23:35:13 PST 2016
Author: matze
Date: Mon Dec 5 01:35:13 2016
New Revision: 288653
URL: http://llvm.org/viewvc/llvm-project?rev=288653&view=rev
Log:
TableGen: Some more std::string->StringInit* replacements
Modified:
llvm/trunk/include/llvm/TableGen/Record.h
llvm/trunk/lib/TableGen/Record.cpp
llvm/trunk/lib/TableGen/TGParser.cpp
llvm/trunk/lib/TableGen/TGParser.h
Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=288653&r1=288652&r2=288653&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Mon Dec 5 01:35:13 2016
@@ -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();
Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=288653&r1=288652&r2=288653&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Mon Dec 5 01:35:13 2016
@@ -1702,10 +1702,10 @@ raw_ostream &llvm::operator<<(raw_ostrea
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";
Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=288653&r1=288652&r2=288653&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Mon Dec 5 01:35:13 2016
@@ -339,14 +339,14 @@ bool TGParser::ProcessForeachDefs(Record
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 *Cur
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 *Cur
// If this is in a foreach loop, make sure it's not a loop iterator
for (const auto &L : Loops) {
VarInit *IterVar = dyn_cast<VarInit>(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
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
// This is a CLASS<initvalslist> expression. This is supposed to synthesize
// a new anonymous definition, deriving from CLASS<initvalslist> 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 *Cur
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<unsigned, 16> BitList;
@@ -1905,7 +1901,7 @@ bool TGParser::ParseBodyItem(Record *Cur
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(SmallVectorI
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(SmallVectorI
}
// 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::InstantiateMulticlassD
// 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() + "'");
Modified: llvm/trunk/lib/TableGen/TGParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.h?rev=288653&r1=288652&r2=288653&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.h (original)
+++ llvm/trunk/lib/TableGen/TGParser.h Mon Dec 5 01:35:13 2016
@@ -32,11 +32,11 @@ namespace llvm {
struct SubMultiClassReference;
struct LetRecord {
- std::string Name;
+ StringInit *Name;
std::vector<unsigned> Bits;
Init *Value;
SMLoc Loc;
- LetRecord(StringRef N, ArrayRef<unsigned> B, Init *V, SMLoc L)
+ LetRecord(StringInit *N, ArrayRef<unsigned> 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<unsigned> BitList, Init *V,
bool AllowSelfAssignment = false);
- bool SetValue(Record *TheRec, SMLoc Loc, StringRef ValName,
- ArrayRef<unsigned> 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);
More information about the llvm-commits
mailing list