[llvm] [NFC][TableGen] Refactor JSON and detailed record emitter (PR #105770)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 12:53:54 PDT 2024
================
@@ -153,38 +147,36 @@ void JSONEmitter::run(raw_ostream &OS) {
obj["!fields"] = std::move(fields);
json::Array superclasses;
- for (const auto &SuperPair : Def.getSuperClasses())
- superclasses.push_back(SuperPair.first->getNameInitAsString());
+ // Add this def to the instance list for each of its superclasses.
+ for (const auto &[SuperClass, Loc] : Def->getSuperClasses()) {
+ std::string SuperName = SuperClass->getNameInitAsString();
+ superclasses.push_back(SuperName);
+ instance_lists[SuperName].push_back(Name);
+ }
+
obj["!superclasses"] = std::move(superclasses);
obj["!name"] = Name;
- obj["!anonymous"] = Def.isAnonymous();
+ obj["!anonymous"] = Def->isAnonymous();
json::Array locs;
- for (const SMLoc Loc : Def.getLoc())
+ for (const SMLoc Loc : Def->getLoc())
locs.push_back(SrcMgr.getFormattedLocationNoOffset(Loc));
obj["!locs"] = std::move(locs);
root[Name] = std::move(obj);
-
- // Add this def to the instance list for each of its superclasses.
- for (const auto &SuperPair : Def.getSuperClasses()) {
- auto SuperName = SuperPair.first->getNameInitAsString();
- instance_lists[SuperName].push_back(Name);
- }
}
// Make a JSON object from the std::map of instance lists.
json::Object instanceof;
- for (auto kv: instance_lists)
- instanceof[kv.first] = std::move(kv.second);
+ for (auto &[ClassName, Instances] : instance_lists)
+ instanceof [ ClassName ] = std::move(Instances);
root["!instanceof"] = std::move(instanceof);
// Done. Write the output.
OS << json::Value(std::move(root)) << "\n";
}
-namespace llvm {
-
-void EmitJSON(RecordKeeper &RK, raw_ostream &OS) { JSONEmitter(RK).run(OS); }
-} // end namespace llvm
+void llvm::EmitJSON(RecordKeeper &RK, raw_ostream &OS) {
----------------
jurahul wrote:
Done.
https://github.com/llvm/llvm-project/pull/105770
More information about the llvm-commits
mailing list