mirror of https://github.com/YosysHQ/yosys.git
Json backend improvements
This commit is contained in:
parent
795a6e1d04
commit
4fc63f27a1
|
@ -43,8 +43,13 @@ struct JsonWriter
|
||||||
|
|
||||||
string get_string(string str)
|
string get_string(string str)
|
||||||
{
|
{
|
||||||
// FIXME: proper string escaping
|
string newstr = "\"";
|
||||||
return stringf("\"%s\"", str.c_str());
|
for (char c : str) {
|
||||||
|
if (c == '\\')
|
||||||
|
newstr += c;
|
||||||
|
newstr += c;
|
||||||
|
}
|
||||||
|
return newstr + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
string get_name(IdString name)
|
string get_name(IdString name)
|
||||||
|
@ -157,7 +162,9 @@ struct JsonWriter
|
||||||
void write_design(Design *design_)
|
void write_design(Design *design_)
|
||||||
{
|
{
|
||||||
design = design_;
|
design = design_;
|
||||||
f << stringf("{\n \"modules\": {\n");
|
f << stringf("{\n");
|
||||||
|
f << stringf(" \"creator\": %s,\n", get_string(yosys_version_str).c_str());
|
||||||
|
f << stringf(" \"modules\": {\n");
|
||||||
vector<Module*> modules = use_selection ? design->selected_modules() : design->modules();
|
vector<Module*> modules = use_selection ? design->selected_modules() : design->modules();
|
||||||
bool first_module = true;
|
bool first_module = true;
|
||||||
for (auto mod : modules) {
|
for (auto mod : modules) {
|
||||||
|
@ -166,7 +173,8 @@ struct JsonWriter
|
||||||
write_module(mod);
|
write_module(mod);
|
||||||
first_module = false;
|
first_module = false;
|
||||||
}
|
}
|
||||||
f << stringf("\n }\n}\n");
|
f << stringf("\n }\n");
|
||||||
|
f << stringf("}\n");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue