22 #define DEBUG_TYPE "json-emitter" 43 JSONEmitter::JSONEmitter(
RecordKeeper &R) : Records(R) {}
50 if (isa<UnsetInit>(&I)) {
52 }
else if (
auto *
Bit = dyn_cast<BitInit>(&I)) {
53 return Bit->getValue() ? 1 : 0;
54 }
else if (
auto *
Bits = dyn_cast<BitsInit>(&I)) {
56 for (
unsigned i = 0, limit =
Bits->getNumBits(); i < limit; i++)
58 return std::move(array);
59 }
else if (
auto *Int = dyn_cast<IntInit>(&I)) {
60 return Int->getValue();
61 }
else if (
auto *Str = dyn_cast<StringInit>(&I)) {
62 return Str->getValue();
63 }
else if (
auto *Code = dyn_cast<CodeInit>(&I)) {
64 return Code->getValue();
65 }
else if (
auto *
List = dyn_cast<ListInit>(&I)) {
67 for (
auto val : *
List)
69 return std::move(array);
80 if (
auto *
Def = dyn_cast<DefInit>(&I)) {
82 obj[
"def"] =
Def->getDef()->getName();
83 return std::move(obj);
84 }
else if (
auto *Var = dyn_cast<VarInit>(&I)) {
86 obj[
"var"] = Var->getName();
87 return std::move(obj);
88 }
else if (
auto *VarBit = dyn_cast<VarBitInit>(&I)) {
89 if (
auto *Var = dyn_cast<VarInit>(VarBit->getBitVar())) {
90 obj[
"kind"] =
"varbit";
91 obj[
"var"] = Var->getName();
92 obj[
"index"] = VarBit->getBitNum();
93 return std::move(obj);
95 }
else if (
auto *
Dag = dyn_cast<DagInit>(&I)) {
97 obj[
"operator"] = translateInit(*
Dag->getOperator());
99 obj[
"name"] =
name->getAsUnquotedString();
101 for (
unsigned i = 0, limit =
Dag->getNumArgs(); i < limit; ++i) {
104 if (
auto argname =
Dag->getArgName(i))
105 arg.
push_back(argname->getAsUnquotedString());
110 obj[
"args"] = std::move(args);
111 return std::move(obj);
119 obj[
"kind"] =
"complex";
120 return std::move(obj);
126 root[
"!tablegen_json_version"] = 1;
134 std::map<std::string, json::Array> instance_lists;
135 for (
const auto &
C : Records.getClasses()) {
136 auto &
Name =
C.second->getNameInitAsString();
137 (void)instance_lists[
Name];
141 for (
const auto &
D : Records.getDefs()) {
142 auto &
Name =
D.second->getNameInitAsString();
143 auto &
Def = *
D.second;
149 if (!
Def.isTemplateArg(RV.getNameInit())) {
150 auto Name = RV.getNameInitAsString();
153 obj[
Name] = translateInit(*RV.getValue());
157 obj[
"!fields"] = std::move(fields);
160 for (
const auto &SuperPair :
Def.getSuperClasses())
161 superclasses.
push_back(SuperPair.first->getNameInitAsString());
162 obj[
"!superclasses"] = std::move(superclasses);
165 obj[
"!anonymous"] =
Def.isAnonymous();
167 root[
Name] = std::move(obj);
170 for (
const auto &SuperPair :
Def.getSuperClasses()) {
171 auto SuperName = SuperPair.first->getNameInitAsString();
172 instance_lists[SuperName].push_back(
Name);
178 for (
auto kv: instance_lists)
179 instanceof[kv.first] = std::move(kv.second);
180 root[
"!instanceof"] = std::move(instanceof);
An Object is a JSON object, which maps strings to heterogenous JSON values.
This class represents lattice values for constants.
An Array is a JSON array, which contains heterogeneous JSON values.
void push_back(const Value &E)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
A Value is an JSON value of unknown type.
virtual bool isConcrete() const
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
void EmitJSON(RecordKeeper &RK, raw_ostream &OS)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file supports working with JSON data.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual std::string getAsString() const =0
Convert this value to a string form.
This class implements an extremely fast bulk output stream that can only output to a stream...