Author: Timm Bäder Date: 2024-01-28T16:15:21+01:00 New Revision: 354548621fdbaead4832361d26922b91488e401a
URL: https://github.com/llvm/llvm-project/commit/354548621fdbaead4832361d26922b91488e401a DIFF: https://github.com/llvm/llvm-project/commit/354548621fdbaead4832361d26922b91488e401a.diff LOG: [clang][Interp][NFC] Make some variables in the opcode emitter const Added: Modified: clang/utils/TableGen/ClangOpcodesEmitter.cpp Removed: ################################################################################ diff --git a/clang/utils/TableGen/ClangOpcodesEmitter.cpp b/clang/utils/TableGen/ClangOpcodesEmitter.cpp index db88c990d5f9bd..e624cb4d8cc6a5 100644 --- a/clang/utils/TableGen/ClangOpcodesEmitter.cpp +++ b/clang/utils/TableGen/ClangOpcodesEmitter.cpp @@ -60,7 +60,7 @@ class ClangOpcodesEmitter { void Enumerate(const Record *R, StringRef N, std::function<void(ArrayRef<const Record *>, Twine)> &&F) { llvm::SmallVector<const Record *, 2> TypePath; - auto *Types = R->getValueAsListInit("Types"); + const auto *Types = R->getValueAsListInit("Types"); std::function<void(size_t, const Twine &)> Rec; Rec = [&TypePath, Types, &Rec, &F](size_t I, const Twine &ID) { @@ -69,8 +69,9 @@ void Enumerate(const Record *R, StringRef N, return; } - if (auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) { - for (auto *Type : TypeClass->getDef()->getValueAsListOfDefs("Types")) { + if (const auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) { + for (const auto *Type : + TypeClass->getDef()->getValueAsListOfDefs("Types")) { TypePath.push_back(Type); Rec(I + 1, ID + Type->getName()); TypePath.pop_back(); @@ -85,7 +86,7 @@ void Enumerate(const Record *R, StringRef N, } // namespace void ClangOpcodesEmitter::run(raw_ostream &OS) { - for (auto *Opcode : Records.getAllDerivedDefinitions(Root.getName())) { + for (const auto *Opcode : Records.getAllDerivedDefinitions(Root.getName())) { // The name is the record name, unless overriden. StringRef N = Opcode->getValueAsString("Name"); if (N.empty()) @@ -118,7 +119,7 @@ void ClangOpcodesEmitter::EmitInterp(raw_ostream &OS, StringRef N, [this, R, &OS, &N](ArrayRef<const Record *> TS, const Twine &ID) { bool CanReturn = R->getValueAsBit("CanReturn"); bool ChangesPC = R->getValueAsBit("ChangesPC"); - auto Args = R->getValueAsListOfDefs("Args"); + const auto &Args = R->getValueAsListOfDefs("Args"); OS << "case OP_" << ID << ": {\n"; @@ -171,7 +172,7 @@ void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N, OS << " PrintName(\"" << ID << "\");\n"; OS << " OS << \"\\t\""; - for (auto *Arg : R->getValueAsListOfDefs("Args")) { + for (const auto *Arg : R->getValueAsListOfDefs("Args")) { OS << " << ReadArg<" << Arg->getValueAsString("Name") << ">(P, PC)"; OS << " << \" \""; } @@ -189,7 +190,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N, OS << "#ifdef GET_LINK_IMPL\n"; Enumerate(R, N, [R, &OS](ArrayRef<const Record *>, const Twine &ID) { - auto Args = R->getValueAsListOfDefs("Args"); + const auto &Args = R->getValueAsListOfDefs("Args"); // Emit the list of arguments. OS << "bool ByteCodeEmitter::emit" << ID << "("; @@ -236,7 +237,7 @@ void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N, } OS << ">\n"; OS << "bool emit" << N << "("; - for (auto *Arg : Args) + for (const auto *Arg : Args) OS << Arg->getValueAsString("Name") << ", "; OS << "const SourceInfo &);\n"; OS << "#endif\n"; @@ -250,8 +251,8 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N, if (!R->getValueAsBit("HasGroup")) return; - auto *Types = R->getValueAsListInit("Types"); - auto Args = R->getValueAsListOfDefs("Args"); + const auto *Types = R->getValueAsListInit("Types"); + const auto &Args = R->getValueAsListOfDefs("Args"); Twine EmitFuncName = "emit" + N; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits