Skip to content

Commit 3545486

Browse files
committed
[clang][Interp][NFC] Make some variables in the opcode emitter const
1 parent 74e5418 commit 3545486

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

clang/utils/TableGen/ClangOpcodesEmitter.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ClangOpcodesEmitter {
6060
void Enumerate(const Record *R, StringRef N,
6161
std::function<void(ArrayRef<const Record *>, Twine)> &&F) {
6262
llvm::SmallVector<const Record *, 2> TypePath;
63-
auto *Types = R->getValueAsListInit("Types");
63+
const auto *Types = R->getValueAsListInit("Types");
6464

6565
std::function<void(size_t, const Twine &)> Rec;
6666
Rec = [&TypePath, Types, &Rec, &F](size_t I, const Twine &ID) {
@@ -69,8 +69,9 @@ void Enumerate(const Record *R, StringRef N,
6969
return;
7070
}
7171

72-
if (auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) {
73-
for (auto *Type : TypeClass->getDef()->getValueAsListOfDefs("Types")) {
72+
if (const auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) {
73+
for (const auto *Type :
74+
TypeClass->getDef()->getValueAsListOfDefs("Types")) {
7475
TypePath.push_back(Type);
7576
Rec(I + 1, ID + Type->getName());
7677
TypePath.pop_back();
@@ -85,7 +86,7 @@ void Enumerate(const Record *R, StringRef N,
8586
} // namespace
8687

8788
void ClangOpcodesEmitter::run(raw_ostream &OS) {
88-
for (auto *Opcode : Records.getAllDerivedDefinitions(Root.getName())) {
89+
for (const auto *Opcode : Records.getAllDerivedDefinitions(Root.getName())) {
8990
// The name is the record name, unless overriden.
9091
StringRef N = Opcode->getValueAsString("Name");
9192
if (N.empty())
@@ -118,7 +119,7 @@ void ClangOpcodesEmitter::EmitInterp(raw_ostream &OS, StringRef N,
118119
[this, R, &OS, &N](ArrayRef<const Record *> TS, const Twine &ID) {
119120
bool CanReturn = R->getValueAsBit("CanReturn");
120121
bool ChangesPC = R->getValueAsBit("ChangesPC");
121-
auto Args = R->getValueAsListOfDefs("Args");
122+
const auto &Args = R->getValueAsListOfDefs("Args");
122123

123124
OS << "case OP_" << ID << ": {\n";
124125

@@ -171,7 +172,7 @@ void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N,
171172
OS << " PrintName(\"" << ID << "\");\n";
172173
OS << " OS << \"\\t\"";
173174

174-
for (auto *Arg : R->getValueAsListOfDefs("Args")) {
175+
for (const auto *Arg : R->getValueAsListOfDefs("Args")) {
175176
OS << " << ReadArg<" << Arg->getValueAsString("Name") << ">(P, PC)";
176177
OS << " << \" \"";
177178
}
@@ -189,7 +190,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N,
189190

190191
OS << "#ifdef GET_LINK_IMPL\n";
191192
Enumerate(R, N, [R, &OS](ArrayRef<const Record *>, const Twine &ID) {
192-
auto Args = R->getValueAsListOfDefs("Args");
193+
const auto &Args = R->getValueAsListOfDefs("Args");
193194

194195
// Emit the list of arguments.
195196
OS << "bool ByteCodeEmitter::emit" << ID << "(";
@@ -236,7 +237,7 @@ void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
236237
}
237238
OS << ">\n";
238239
OS << "bool emit" << N << "(";
239-
for (auto *Arg : Args)
240+
for (const auto *Arg : Args)
240241
OS << Arg->getValueAsString("Name") << ", ";
241242
OS << "const SourceInfo &);\n";
242243
OS << "#endif\n";
@@ -250,8 +251,8 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
250251
if (!R->getValueAsBit("HasGroup"))
251252
return;
252253

253-
auto *Types = R->getValueAsListInit("Types");
254-
auto Args = R->getValueAsListOfDefs("Args");
254+
const auto *Types = R->getValueAsListInit("Types");
255+
const auto &Args = R->getValueAsListOfDefs("Args");
255256

256257
Twine EmitFuncName = "emit" + N;
257258

0 commit comments

Comments
 (0)