21 #define DEBUG_TYPE "json-emitter" 42 JSONEmitter::JSONEmitter(
RecordKeeper &R) : Records(R) {}
49 if (isa<UnsetInit>(&I)) {
51 }
else if (
auto *
Bit = dyn_cast<BitInit>(&I)) {
52 return Bit->getValue() ? 1 : 0;
53 }
else if (
auto *
Bits = dyn_cast<BitsInit>(&I)) {
55 for (
unsigned i = 0, limit =
Bits->getNumBits(); i < limit; i++)
57 return std::move(array);
58 }
else if (
auto *Int = dyn_cast<IntInit>(&I)) {
59 return Int->getValue();
60 }
else if (
auto *Str = dyn_cast<StringInit>(&I)) {
61 return Str->getValue();
62 }
else if (
auto *Code = dyn_cast<CodeInit>(&I)) {
63 return Code->getValue();
64 }
else if (
auto *
List = dyn_cast<ListInit>(&I)) {
66 for (
auto val : *
List)
68 return std::move(array);
79 if (
auto *
Def = dyn_cast<DefInit>(&I)) {
81 obj[
"def"] =
Def->getDef()->getName();
82 return std::move(obj);
83 }
else if (
auto *Var = dyn_cast<VarInit>(&I)) {
85 obj[
"var"] = Var->getName();
86 return std::move(obj);
87 }
else if (
auto *VarBit = dyn_cast<VarBitInit>(&I)) {
88 if (
auto *Var = dyn_cast<VarInit>(VarBit->getBitVar())) {
89 obj[
"kind"] =
"varbit";
90 obj[
"var"] = Var->getName();
91 obj[
"index"] = VarBit->getBitNum();
92 return std::move(obj);
94 }
else if (
auto *
Dag = dyn_cast<DagInit>(&I)) {
96 obj[
"operator"] = translateInit(*
Dag->getOperator());
98 obj[
"name"] =
name->getAsUnquotedString();
100 for (
unsigned i = 0, limit =
Dag->getNumArgs(); i < limit; ++i) {
103 if (
auto argname =
Dag->getArgName(i))
104 arg.
push_back(argname->getAsUnquotedString());
109 obj[
"args"] = std::move(args);
110 return std::move(obj);
118 obj[
"kind"] =
"complex";
119 return std::move(obj);
125 root[
"!tablegen_json_version"] = 1;
133 std::map<std::string, json::Array> instance_lists;
134 for (
const auto &
C : Records.getClasses()) {
135 auto &
Name =
C.second->getNameInitAsString();
136 (void)instance_lists[
Name];
140 for (
const auto &
D : Records.getDefs()) {
141 auto &
Name =
D.second->getNameInitAsString();
142 auto &
Def = *
D.second;
148 if (!
Def.isTemplateArg(RV.getNameInit())) {
149 auto Name = RV.getNameInitAsString();
152 obj[
Name] = translateInit(*RV.getValue());
156 obj[
"!fields"] = std::move(fields);
159 for (
const auto &SuperPair :
Def.getSuperClasses())
160 superclasses.
push_back(SuperPair.first->getNameInitAsString());
161 obj[
"!superclasses"] = std::move(superclasses);
164 obj[
"!anonymous"] =
Def.isAnonymous();
166 root[
Name] = std::move(obj);
169 for (
const auto &SuperPair :
Def.getSuperClasses()) {
170 auto SuperName = SuperPair.first->getNameInitAsString();
171 instance_lists[SuperName].push_back(
Name);
177 for (
auto kv: instance_lists)
178 instanceof[kv.first] = std::move(kv.second);
179 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.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
An Array is a JSON array, which contains heterogeneous JSON values.
void push_back(const Value &E)
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...