21#define DEBUG_TYPE "json-emitter"
34 explicit JSONEmitter(
const RecordKeeper &R) : Records(R) {}
45 if (isa<UnsetInit>(&
I))
47 if (
const auto *Bit = dyn_cast<BitInit>(&
I))
48 return Bit->getValue() ? 1 : 0;
49 if (
const auto *Bits = dyn_cast<BitsInit>(&
I)) {
51 for (
unsigned Idx = 0, E =
Bits->getNumBits();
Idx < E; ++
Idx)
53 return std::move(Array);
55 if (
const auto *
Int = dyn_cast<IntInit>(&
I))
56 return Int->getValue();
57 if (
const auto *Str = dyn_cast<StringInit>(&
I))
58 return Str->getValue();
59 if (
const auto *List = dyn_cast<ListInit>(&
I)) {
61 for (
const auto *Val : *List)
62 Array.push_back(translateInit(*Val));
63 return std::move(Array);
72 Obj[
"printable"] =
I.getAsString();
74 if (
const auto *Def = dyn_cast<DefInit>(&
I)) {
76 Obj[
"def"] =
Def->getDef()->getName();
77 return std::move(Obj);
79 if (
const auto *Var = dyn_cast<VarInit>(&
I)) {
81 Obj[
"var"] = Var->getName();
82 return std::move(Obj);
84 if (
const auto *VarBit = dyn_cast<VarBitInit>(&
I)) {
85 if (
const auto *Var = dyn_cast<VarInit>(VarBit->getBitVar())) {
86 Obj[
"kind"] =
"varbit";
87 Obj[
"var"] = Var->getName();
88 Obj[
"index"] = VarBit->getBitNum();
89 return std::move(Obj);
92 if (
const auto *Dag = dyn_cast<DagInit>(&
I)) {
94 Obj[
"operator"] = translateInit(*
Dag->getOperator());
96 Obj[
"name"] =
name->getAsUnquotedString();
98 for (
unsigned Idx = 0, E =
Dag->getNumArgs();
Idx < E; ++
Idx) {
101 if (
const auto ArgName =
Dag->getArgName(
Idx))
102 Arg.
push_back(ArgName->getAsUnquotedString());
105 Args.push_back(std::move(Arg));
107 Obj[
"args"] = std::move(Args);
108 return std::move(Obj);
115 Obj[
"kind"] =
"complex";
116 return std::move(Obj);
122 Root[
"!tablegen_json_version"] = 1;
130 std::map<std::string, json::Array> InstanceLists;
131 for (
const auto &[ClassName, ClassRec] :
Records.getClasses())
132 InstanceLists.emplace(ClassRec->getNameInitAsString(),
json::Array());
135 for (
const auto &[DefName, Def] :
Records.getDefs()) {
136 const std::string
Name =
Def->getNameInitAsString();
142 if (!
Def->isTemplateArg(RV.getNameInit())) {
143 auto Name = RV.getNameInitAsString();
144 if (RV.isNonconcreteOK())
146 Obj[
Name] = translateInit(*RV.getValue());
150 Obj[
"!fields"] = std::move(Fields);
154 for (
const auto &[
SuperClass, Loc] :
Def->getSuperClasses()) {
155 std::string SuperName =
SuperClass->getNameInitAsString();
157 InstanceLists[SuperName].push_back(
Name);
160 Obj[
"!superclasses"] = std::move(SuperClasses);
163 Obj[
"!anonymous"] =
Def->isAnonymous();
166 for (
const SMLoc Loc :
Def->getLoc())
168 Obj[
"!locs"] = std::move(Locs);
170 Root[
Name] = std::move(Obj);
175 for (
auto &[ClassName, Instances] : InstanceLists)
176 InstanceOf[ClassName] = std::move(Instances);
177 Root[
"!instanceof"] = std::move(InstanceOf);
184 JSONEmitter(RK).run(
OS);
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file supports working with JSON data.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents a field in a record, including its name, type, value, and source location.
Represents a location in source code.
std::string getFormattedLocationNoOffset(SMLoc Loc, bool IncludePath=false) const
Get a string with the SMLoc filename and line number formatted in the standard style.
An Array is a JSON array, which contains heterogeneous JSON values.
void push_back(const Value &E)
An Object is a JSON object, which maps strings to heterogenous JSON values.
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.
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
NodeAddr< DefNode * > Def
This is an optimization pass for GlobalISel generic memory operations.
void EmitJSON(const RecordKeeper &RK, raw_ostream &OS)