20#define DEBUG_TYPE "json-emitter"
33 explicit JSONEmitter(
const RecordKeeper &R) : Records(R) {}
47 return Bit->getValue() ? 1 : 0;
50 for (
unsigned Idx = 0,
E =
Bits->getNumBits(); Idx <
E; ++Idx)
51 Array.push_back(translateInit(*
Bits->getBit(Idx)));
52 return std::move(Array);
55 return Int->getValue();
57 return Str->getValue();
60 for (
const auto *Val : *
List)
61 Array.push_back(translateInit(*Val));
62 return std::move(Array);
71 Obj[
"printable"] =
I.getAsString();
75 Obj[
"def"] =
Def->getDef()->getName();
76 return std::move(Obj);
80 Obj[
"var"] = Var->getName();
81 return std::move(Obj);
85 Obj[
"kind"] =
"varbit";
86 Obj[
"var"] = Var->getName();
87 Obj[
"index"] = VarBit->getBitNum();
88 return std::move(Obj);
93 Obj[
"operator"] = translateInit(*
Dag->getOperator());
95 Obj[
"name"] =
name->getAsUnquotedString();
97 for (
unsigned Idx = 0,
E =
Dag->getNumArgs(); Idx <
E; ++Idx) {
100 if (
const auto ArgName =
Dag->getArgName(Idx))
101 Arg.
push_back(ArgName->getAsUnquotedString());
104 Args.push_back(std::move(Arg));
106 Obj[
"args"] = std::move(Args);
107 return std::move(Obj);
114 Obj[
"kind"] =
"complex";
115 return std::move(Obj);
118void JSONEmitter::run(raw_ostream &OS) {
121 Root[
"!tablegen_json_version"] = 1;
129 std::map<std::string, json::Array> InstanceLists;
130 for (
const auto &[ClassName, ClassRec] : Records.
getClasses())
131 InstanceLists.emplace(ClassRec->getNameInitAsString(), json::Array());
134 for (
const auto &[DefName, Def] : Records.
getDefs()) {
135 const std::string
Name =
Def->getNameInitAsString();
140 for (
const RecordVal &RV :
Def->getValues()) {
141 if (!
Def->isTemplateArg(RV.getNameInit())) {
142 auto Name = RV.getNameInitAsString();
143 if (RV.isNonconcreteOK())
145 Obj[
Name] = translateInit(*RV.getValue());
149 Obj[
"!fields"] = std::move(Fields);
151 json::Array SuperClasses;
153 for (
const Record *SuperClass :
Def->getSuperClasses()) {
154 std::string SuperName = SuperClass->getNameInitAsString();
156 InstanceLists[SuperName].push_back(Name);
159 Obj[
"!superclasses"] = std::move(SuperClasses);
162 Obj[
"!anonymous"] =
Def->isAnonymous();
165 for (
const SMLoc Loc :
Def->getLoc())
167 Obj[
"!locs"] = std::move(Locs);
169 Root[
Name] = std::move(Obj);
173 json::Object InstanceOf;
174 for (
auto &[ClassName, Instances] : InstanceLists)
175 InstanceOf[ClassName] = std::move(Instances);
176 Root[
"!instanceof"] = std::move(InstanceOf);
179 OS << json::Value(std::move(Root)) <<
"\n";
183 JSONEmitter(RK).run(OS);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file supports working with JSON data.
const RecordMap & getClasses() const
Get the map of classes.
const RecordMap & getDefs() const
Get the map of records (defs).
LLVM_ABI std::string getFormattedLocationNoOffset(SMLoc Loc, bool IncludePath=false) const
Get a string with the SMLoc filename and line number formatted in the standard style.
void push_back(const Value &E)
A Value is an JSON value of unknown type.
This class implements an extremely fast bulk output stream that can only output to a stream.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
NodeAddr< DefNode * > Def
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
void EmitJSON(const RecordKeeper &RK, raw_ostream &OS)