mirror of https://github.com/YosysHQ/yosys.git
write_json: add option to include $scopeinfo cells
This commit is contained in:
parent
17a53b8385
commit
dab7905cbe
|
@ -34,6 +34,7 @@ struct JsonWriter
|
||||||
bool use_selection;
|
bool use_selection;
|
||||||
bool aig_mode;
|
bool aig_mode;
|
||||||
bool compat_int_mode;
|
bool compat_int_mode;
|
||||||
|
bool scopeinfo_mode;
|
||||||
|
|
||||||
Design *design;
|
Design *design;
|
||||||
Module *module;
|
Module *module;
|
||||||
|
@ -43,9 +44,9 @@ struct JsonWriter
|
||||||
dict<SigBit, string> sigids;
|
dict<SigBit, string> sigids;
|
||||||
pool<Aig> aig_models;
|
pool<Aig> aig_models;
|
||||||
|
|
||||||
JsonWriter(std::ostream &f, bool use_selection, bool aig_mode, bool compat_int_mode) :
|
JsonWriter(std::ostream &f, bool use_selection, bool aig_mode, bool compat_int_mode, bool scopeinfo_mode) :
|
||||||
f(f), use_selection(use_selection), aig_mode(aig_mode),
|
f(f), use_selection(use_selection), aig_mode(aig_mode),
|
||||||
compat_int_mode(compat_int_mode) { }
|
compat_int_mode(compat_int_mode), scopeinfo_mode(scopeinfo_mode) { }
|
||||||
|
|
||||||
string get_string(string str)
|
string get_string(string str)
|
||||||
{
|
{
|
||||||
|
@ -194,7 +195,7 @@ struct JsonWriter
|
||||||
continue;
|
continue;
|
||||||
// Eventually we will want to emit $scopeinfo, but currently this
|
// Eventually we will want to emit $scopeinfo, but currently this
|
||||||
// will break JSON netlist consumers like nextpnr
|
// will break JSON netlist consumers like nextpnr
|
||||||
if (c->type == ID($scopeinfo))
|
if (!scopeinfo_mode && c->type == ID($scopeinfo))
|
||||||
continue;
|
continue;
|
||||||
f << stringf("%s\n", first ? "" : ",");
|
f << stringf("%s\n", first ? "" : ",");
|
||||||
f << stringf(" %s: {\n", get_name(c->name).c_str());
|
f << stringf(" %s: {\n", get_name(c->name).c_str());
|
||||||
|
@ -356,6 +357,9 @@ struct JsonBackend : public Backend {
|
||||||
log(" -selected\n");
|
log(" -selected\n");
|
||||||
log(" output only select module\n");
|
log(" output only select module\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
|
log(" -scopeinfo\n");
|
||||||
|
log(" include $scopeinfo cells in the output\n");
|
||||||
|
log("\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
log("The general syntax of the JSON output created by this command is as follows:\n");
|
log("The general syntax of the JSON output created by this command is as follows:\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
|
@ -601,6 +605,7 @@ struct JsonBackend : public Backend {
|
||||||
bool aig_mode = false;
|
bool aig_mode = false;
|
||||||
bool compat_int_mode = false;
|
bool compat_int_mode = false;
|
||||||
bool use_selection = false;
|
bool use_selection = false;
|
||||||
|
bool scopeinfo_mode = false;
|
||||||
|
|
||||||
size_t argidx;
|
size_t argidx;
|
||||||
for (argidx = 1; argidx < args.size(); argidx++)
|
for (argidx = 1; argidx < args.size(); argidx++)
|
||||||
|
@ -617,13 +622,17 @@ struct JsonBackend : public Backend {
|
||||||
use_selection = true;
|
use_selection = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (args[argidx] == "-scopeinfo") {
|
||||||
|
scopeinfo_mode = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
extra_args(f, filename, args, argidx);
|
extra_args(f, filename, args, argidx);
|
||||||
|
|
||||||
log_header(design, "Executing JSON backend.\n");
|
log_header(design, "Executing JSON backend.\n");
|
||||||
|
|
||||||
JsonWriter json_writer(*f, use_selection, aig_mode, compat_int_mode);
|
JsonWriter json_writer(*f, use_selection, aig_mode, compat_int_mode, scopeinfo_mode);
|
||||||
json_writer.write_design(design);
|
json_writer.write_design(design);
|
||||||
}
|
}
|
||||||
} JsonBackend;
|
} JsonBackend;
|
||||||
|
@ -648,6 +657,9 @@ struct JsonPass : public Pass {
|
||||||
log(" emit 32-bit or smaller fully-defined parameter values directly\n");
|
log(" emit 32-bit or smaller fully-defined parameter values directly\n");
|
||||||
log(" as JSON numbers (for compatibility with old parsers)\n");
|
log(" as JSON numbers (for compatibility with old parsers)\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
|
log(" -scopeinfo\n");
|
||||||
|
log(" include $scopeinfo cells in the output\n");
|
||||||
|
log("\n");
|
||||||
log("See 'help write_json' for a description of the JSON format used.\n");
|
log("See 'help write_json' for a description of the JSON format used.\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
}
|
}
|
||||||
|
@ -656,6 +668,7 @@ struct JsonPass : public Pass {
|
||||||
std::string filename;
|
std::string filename;
|
||||||
bool aig_mode = false;
|
bool aig_mode = false;
|
||||||
bool compat_int_mode = false;
|
bool compat_int_mode = false;
|
||||||
|
bool scopeinfo_mode = false;
|
||||||
|
|
||||||
size_t argidx;
|
size_t argidx;
|
||||||
for (argidx = 1; argidx < args.size(); argidx++)
|
for (argidx = 1; argidx < args.size(); argidx++)
|
||||||
|
@ -672,6 +685,10 @@ struct JsonPass : public Pass {
|
||||||
compat_int_mode = true;
|
compat_int_mode = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (args[argidx] == "-scopeinfo") {
|
||||||
|
scopeinfo_mode = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
extra_args(args, argidx, design);
|
extra_args(args, argidx, design);
|
||||||
|
@ -693,7 +710,7 @@ struct JsonPass : public Pass {
|
||||||
f = &buf;
|
f = &buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonWriter json_writer(*f, true, aig_mode, compat_int_mode);
|
JsonWriter json_writer(*f, true, aig_mode, compat_int_mode, scopeinfo_mode);
|
||||||
json_writer.write_design(design);
|
json_writer.write_design(design);
|
||||||
|
|
||||||
if (!empty) {
|
if (!empty) {
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
read_verilog <<EOT
|
||||||
|
module top(input in, output out);
|
||||||
|
wire [1:0] w1, w2;
|
||||||
|
f1_test u1 (.in(in), .out(w1[0]));
|
||||||
|
f2_test u2 (.in(w1), .out(w2));
|
||||||
|
f3_test u3 (.in(w2[0]), .out(out));
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
module f1_test(input in, output out);
|
||||||
|
assign out = in;
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
module f2_test(input [1:0] in, output [1:0] out);
|
||||||
|
assign out[0] = in[0];
|
||||||
|
assign out[1] = in[1];
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
module f3_test(input in, output [1:0] out);
|
||||||
|
assign out[0] = in;
|
||||||
|
assign out[1] = in;
|
||||||
|
endmodule
|
||||||
|
EOT
|
||||||
|
|
||||||
|
hierarchy -top top
|
||||||
|
flatten -scopename
|
||||||
|
prep
|
||||||
|
|
||||||
|
write_json json_scopeinfo.out
|
||||||
|
!grep -qvF '$scopeinfo' json_scopeinfo.out
|
||||||
|
|
||||||
|
write_json -scopeinfo json_scopeinfo.out
|
||||||
|
!grep -qF '$scopeinfo' json_scopeinfo.out
|
||||||
|
|
||||||
|
json -o json_scopeinfo.out
|
||||||
|
!grep -qvF '$scopeinfo' json_scopeinfo.out
|
||||||
|
|
||||||
|
json -scopeinfo -o json_scopeinfo.out
|
||||||
|
!grep -qF '$scopeinfo' json_scopeinfo.out
|
Loading…
Reference in New Issue