21#define DEBUG_TYPE "json-emitter"
48 if (isa<UnsetInit>(&
I)) {
50 }
else if (
auto *Bit = dyn_cast<BitInit>(&
I)) {
51 return Bit->getValue() ? 1 : 0;
52 }
else if (
auto *Bits = dyn_cast<BitsInit>(&
I)) {
54 for (
unsigned i = 0, limit =
Bits->getNumBits(); i < limit; i++)
56 return std::move(array);
57 }
else if (
auto *
Int = dyn_cast<IntInit>(&
I)) {
58 return Int->getValue();
59 }
else if (
auto *Str = dyn_cast<StringInit>(&
I)) {
60 return Str->getValue();
61 }
else if (
auto *List = dyn_cast<ListInit>(&
I)) {
63 for (
auto *val : *List)
65 return std::move(array);
74 obj[
"printable"] =
I.getAsString();
76 if (
auto *Def = dyn_cast<DefInit>(&
I)) {
78 obj[
"def"] =
Def->getDef()->getName();
79 return std::move(obj);
80 }
else if (
auto *Var = dyn_cast<VarInit>(&
I)) {
82 obj[
"var"] = Var->getName();
83 return std::move(obj);
84 }
else if (
auto *VarBit = dyn_cast<VarBitInit>(&
I)) {
85 if (
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);
91 }
else if (
auto *Dag = dyn_cast<DagInit>(&
I)) {
93 obj[
"operator"] = translateInit(*
Dag->getOperator());
95 obj[
"name"] =
name->getAsUnquotedString();
97 for (
unsigned i = 0, limit =
Dag->getNumArgs(); i < limit; ++i) {
100 if (
auto argname =
Dag->getArgName(i))
101 arg.
push_back(argname->getAsUnquotedString());
104 args.push_back(std::move(arg));
106 obj[
"args"] = std::move(
args);
107 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> instance_lists;
131 for (
const auto &
C :
Records.getClasses()) {
132 const auto Name =
C.second->getNameInitAsString();
133 (void)instance_lists[
Name];
137 for (
const auto &
D :
Records.getDefs()) {
138 const auto Name =
D.second->getNameInitAsString();
139 auto &
Def = *
D.second;
145 if (!
Def.isTemplateArg(RV.getNameInit())) {
146 auto Name = RV.getNameInitAsString();
147 if (RV.isNonconcreteOK())
149 obj[
Name] = translateInit(*RV.getValue());
153 obj[
"!fields"] = std::move(fields);
156 for (
const auto &SuperPair :
Def.getSuperClasses())
157 superclasses.
push_back(SuperPair.first->getNameInitAsString());
158 obj[
"!superclasses"] = std::move(superclasses);
161 obj[
"!anonymous"] =
Def.isAnonymous();
164 for (
const SMLoc Loc :
Def.getLoc())
166 obj[
"!locs"] = std::move(locs);
168 root[
Name] = std::move(obj);
171 for (
const auto &SuperPair :
Def.getSuperClasses()) {
172 auto SuperName = SuperPair.first->getNameInitAsString();
173 instance_lists[SuperName].push_back(
Name);
179 for (
auto kv: instance_lists)
180 instanceof[kv.first] = std::move(kv.second);
181 root[
"!instanceof"] = std::move(instanceof);
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())
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.
@ C
The default llvm calling convention, compatible with C.
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
NodeAddr< DefNode * > Def
This is an optimization pass for GlobalISel generic memory operations.
void EmitJSON(RecordKeeper &RK, raw_ostream &OS)