Skip to content

Commit 2b86a87

Browse files
committed
TableGen: Some more std::string->StringInit* replacements
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288653 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 53cf984 commit 2b86a87

File tree

4 files changed

+28
-38
lines changed

4 files changed

+28
-38
lines changed

include/llvm/TableGen/Record.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ class RecordVal {
12311231
RecordVal(StringRef N, RecTy *T, bool P);
12321232

12331233
StringRef getName() const;
1234-
const Init *getNameInit() const { return Name; }
1234+
Init *getNameInit() const { return Name; }
12351235

12361236
std::string getNameInitAsString() const {
12371237
return getNameInit()->getAsUnquotedString();

lib/TableGen/Record.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,10 +1702,10 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const Record &R) {
17021702
OS << "\n";
17031703

17041704
for (const RecordVal &Val : R.getValues())
1705-
if (Val.getPrefix() && !R.isTemplateArg(Val.getName()))
1705+
if (Val.getPrefix() && !R.isTemplateArg(Val.getNameInit()))
17061706
OS << Val;
17071707
for (const RecordVal &Val : R.getValues())
1708-
if (!Val.getPrefix() && !R.isTemplateArg(Val.getName()))
1708+
if (!Val.getPrefix() && !R.isTemplateArg(Val.getNameInit()))
17091709
OS << Val;
17101710

17111711
return OS << "}\n";

lib/TableGen/TGParser.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ bool TGParser::ProcessForeachDefs(Record *CurRec, SMLoc Loc, IterSet &IterVals){
339339

340340
IterRec->addValue(RecordVal(IterVar->getName(), IVal->getType(), false));
341341

342-
if (SetValue(IterRec.get(), Loc, IterVar->getName(), None, IVal))
342+
if (SetValue(IterRec.get(), Loc, IterVar->getNameInit(), None, IVal))
343343
return Error(Loc, "when instantiating this def");
344344

345345
// Resolve it next.
346-
IterRec->resolveReferencesTo(IterRec->getValue(IterVar->getName()));
346+
IterRec->resolveReferencesTo(IterRec->getValue(IterVar->getNameInit()));
347347

348348
// Remove it.
349-
IterRec->removeValue(IterVar->getName());
349+
IterRec->removeValue(IterVar->getNameInit());
350350
}
351351

352352
if (Records.getDef(IterRec->getNameInitAsString())) {
@@ -716,31 +716,27 @@ RecTy *TGParser::ParseType() {
716716

717717
/// ParseIDValue - This is just like ParseIDValue above, but it assumes the ID
718718
/// has already been read.
719-
Init *TGParser::ParseIDValue(Record *CurRec, StringRef Name, SMLoc NameLoc,
719+
Init *TGParser::ParseIDValue(Record *CurRec, StringInit *Name, SMLoc NameLoc,
720720
IDParseMode Mode) {
721-
StringInit *NameInit;
722721
if (CurRec) {
723722
if (const RecordVal *RV = CurRec->getValue(Name))
724723
return VarInit::get(Name, RV->getType());
725724

726-
NameInit = StringInit::get(Name);
727-
Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, NameInit, ":");
725+
Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, Name, ":");
728726

729727
if (CurMultiClass)
730-
TemplateArgName = QualifyName(CurMultiClass->Rec, CurMultiClass, NameInit,
728+
TemplateArgName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name,
731729
"::");
732730

733731
if (CurRec->isTemplateArg(TemplateArgName)) {
734732
const RecordVal *RV = CurRec->getValue(TemplateArgName);
735733
assert(RV && "Template arg doesn't exist??");
736734
return VarInit::get(TemplateArgName, RV->getType());
737735
}
738-
} else
739-
NameInit = StringInit::get(Name);
736+
}
740737

741738
if (CurMultiClass) {
742-
Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, NameInit,
743-
"::");
739+
Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name, "::");
744740

745741
if (CurMultiClass->Rec.isTemplateArg(MCName)) {
746742
const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
@@ -752,22 +748,22 @@ Init *TGParser::ParseIDValue(Record *CurRec, StringRef Name, SMLoc NameLoc,
752748
// If this is in a foreach loop, make sure it's not a loop iterator
753749
for (const auto &L : Loops) {
754750
VarInit *IterVar = dyn_cast<VarInit>(L.IterVar);
755-
if (IterVar && IterVar->getNameInit() == NameInit)
751+
if (IterVar && IterVar->getNameInit() == Name)
756752
return IterVar;
757753
}
758754

759755
if (Mode == ParseNameMode)
760-
return NameInit;
756+
return Name;
761757

762-
if (Record *D = Records.getDef(Name))
758+
if (Record *D = Records.getDef(Name->getValue()))
763759
return DefInit::get(D);
764760

765761
if (Mode == ParseValueMode) {
766-
Error(NameLoc, "Variable not defined: '" + Name + "'");
762+
Error(NameLoc, "Variable not defined: '" + Name->getValue() + "'");
767763
return nullptr;
768764
}
769765

770-
return NameInit;
766+
return Name;
771767
}
772768

773769
/// ParseOperation - Parse an operator. This returns null on error.
@@ -1187,7 +1183,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
11871183
break;
11881184
case tgtok::Id: {
11891185
SMLoc NameLoc = Lex.getLoc();
1190-
std::string Name = Lex.getCurStrVal();
1186+
StringInit *Name = StringInit::get(Lex.getCurStrVal());
11911187
if (Lex.Lex() != tgtok::less) // consume the Id.
11921188
return ParseIDValue(CurRec, Name, NameLoc, Mode); // Value ::= IDValue
11931189

@@ -1200,9 +1196,9 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
12001196
// This is a CLASS<initvalslist> expression. This is supposed to synthesize
12011197
// a new anonymous definition, deriving from CLASS<initvalslist> with no
12021198
// body.
1203-
Record *Class = Records.getClass(Name);
1199+
Record *Class = Records.getClass(Name->getValue());
12041200
if (!Class) {
1205-
Error(NameLoc, "Expected a class name, got '" + Name + "'");
1201+
Error(NameLoc, "Expected a class name, got '" + Name->getValue() + "'");
12061202
return nullptr;
12071203
}
12081204

@@ -1891,7 +1887,7 @@ bool TGParser::ParseBodyItem(Record *CurRec) {
18911887
return TokError("expected field identifier after let");
18921888

18931889
SMLoc IdLoc = Lex.getLoc();
1894-
std::string FieldName = Lex.getCurStrVal();
1890+
StringInit *FieldName = StringInit::get(Lex.getCurStrVal());
18951891
Lex.Lex(); // eat the field name.
18961892

18971893
SmallVector<unsigned, 16> BitList;
@@ -1905,7 +1901,7 @@ bool TGParser::ParseBodyItem(Record *CurRec) {
19051901

19061902
RecordVal *Field = CurRec->getValue(FieldName);
19071903
if (!Field)
1908-
return TokError("Value '" + FieldName + "' unknown!");
1904+
return TokError("Value '" + FieldName->getValue() + "' unknown!");
19091905

19101906
RecTy *Type = Field->getType();
19111907

@@ -2169,7 +2165,7 @@ void TGParser::ParseLetList(SmallVectorImpl<LetRecord> &Result) {
21692165
return;
21702166
}
21712167

2172-
std::string Name = Lex.getCurStrVal();
2168+
StringInit *Name = StringInit::get(Lex.getCurStrVal());
21732169
SMLoc NameLoc = Lex.getLoc();
21742170
Lex.Lex(); // Eat the identifier.
21752171

@@ -2195,7 +2191,7 @@ void TGParser::ParseLetList(SmallVectorImpl<LetRecord> &Result) {
21952191
}
21962192

21972193
// Now that we have everything, add the record.
2198-
Result.emplace_back(std::move(Name), Bits, Val, NameLoc);
2194+
Result.emplace_back(Name, Bits, Val, NameLoc);
21992195

22002196
if (Lex.getCode() != tgtok::comma)
22012197
return;
@@ -2382,8 +2378,8 @@ Record *TGParser::InstantiateMulticlassDef(MultiClass &MC, Record *DefProto,
23822378
// Set the value for NAME. We don't resolve references to it 'til later,
23832379
// though, so that uses in nested multiclass names don't get
23842380
// confused.
2385-
if (SetValue(CurRec.get(), Ref.RefRange.Start, "NAME", None, DefmPrefix,
2386-
/*AllowSelfAssignment*/true)) {
2381+
if (SetValue(CurRec.get(), Ref.RefRange.Start, StringInit::get("NAME"), None,
2382+
DefmPrefix, /*AllowSelfAssignment*/true)) {
23872383
Error(DefmPrefixRange.Start, "Could not resolve " +
23882384
CurRec->getNameInitAsString() + ":NAME to '" +
23892385
DefmPrefix->getAsUnquotedString() + "'");

lib/TableGen/TGParser.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ namespace llvm {
3232
struct SubMultiClassReference;
3333

3434
struct LetRecord {
35-
std::string Name;
35+
StringInit *Name;
3636
std::vector<unsigned> Bits;
3737
Init *Value;
3838
SMLoc Loc;
39-
LetRecord(StringRef N, ArrayRef<unsigned> B, Init *V, SMLoc L)
39+
LetRecord(StringInit *N, ArrayRef<unsigned> B, Init *V, SMLoc L)
4040
: Name(N), Bits(B), Value(V), Loc(L) {
4141
}
4242
};
@@ -106,12 +106,6 @@ class TGParser {
106106
bool SetValue(Record *TheRec, SMLoc Loc, Init *ValName,
107107
ArrayRef<unsigned> BitList, Init *V,
108108
bool AllowSelfAssignment = false);
109-
bool SetValue(Record *TheRec, SMLoc Loc, StringRef ValName,
110-
ArrayRef<unsigned> BitList, Init *V,
111-
bool AllowSelfAssignment = false) {
112-
return SetValue(TheRec, Loc, StringInit::get(ValName), BitList, V,
113-
AllowSelfAssignment);
114-
}
115109
bool AddSubClass(Record *Rec, SubClassReference &SubClass);
116110
bool AddSubMultiClass(MultiClass *CurMC,
117111
SubMultiClassReference &SubMultiClass);
@@ -166,7 +160,7 @@ class TGParser {
166160
SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
167161
SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
168162

169-
Init *ParseIDValue(Record *CurRec, StringRef Name, SMLoc NameLoc,
163+
Init *ParseIDValue(Record *CurRec, StringInit *Name, SMLoc NameLoc,
170164
IDParseMode Mode = ParseValueMode);
171165
Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = nullptr,
172166
IDParseMode Mode = ParseValueMode);

0 commit comments

Comments
 (0)