@@ -34,6 +34,7 @@ struct JsonWriter
3434 bool use_selection;
3535 bool aig_mode;
3636 bool compat_int_mode;
37+ bool scopeinfo_mode;
3738
3839 Design *design;
3940 Module *module ;
@@ -43,9 +44,9 @@ struct JsonWriter
4344 dict<SigBit, string> sigids;
4445 pool<Aig> aig_models;
4546
46- JsonWriter (std::ostream &f, bool use_selection, bool aig_mode, bool compat_int_mode) :
47+ JsonWriter (std::ostream &f, bool use_selection, bool aig_mode, bool compat_int_mode, bool scopeinfo_mode ) :
4748 f (f), use_selection(use_selection), aig_mode(aig_mode),
48- compat_int_mode (compat_int_mode) { }
49+ compat_int_mode (compat_int_mode), scopeinfo_mode(scopeinfo_mode) { }
4950
5051 string get_string (string str)
5152 {
@@ -192,9 +193,7 @@ struct JsonWriter
192193 for (auto c : module ->cells ()) {
193194 if (use_selection && !module ->selected (c))
194195 continue ;
195- // Eventually we will want to emit $scopeinfo, but currently this
196- // will break JSON netlist consumers like nextpnr
197- if (c->type == ID ($scopeinfo))
196+ if (!scopeinfo_mode && c->type == ID ($scopeinfo))
198197 continue ;
199198 f << stringf (" %s\n " , first ? " " : " ," );
200199 f << stringf (" %s: {\n " , get_name (c->name ).c_str ());
@@ -356,6 +355,9 @@ struct JsonBackend : public Backend {
356355 log (" -selected\n " );
357356 log (" output only select module\n " );
358357 log (" \n " );
358+ log (" -noscopeinfo\n " );
359+ log (" don't include $scopeinfo cells in the output\n " );
360+ log (" \n " );
359361 log (" \n " );
360362 log (" The general syntax of the JSON output created by this command is as follows:\n " );
361363 log (" \n " );
@@ -601,6 +603,7 @@ struct JsonBackend : public Backend {
601603 bool aig_mode = false ;
602604 bool compat_int_mode = false ;
603605 bool use_selection = false ;
606+ bool scopeinfo_mode = true ;
604607
605608 size_t argidx;
606609 for (argidx = 1 ; argidx < args.size (); argidx++)
@@ -617,13 +620,17 @@ struct JsonBackend : public Backend {
617620 use_selection = true ;
618621 continue ;
619622 }
623+ if (args[argidx] == " -noscopeinfo" ) {
624+ scopeinfo_mode = false ;
625+ continue ;
626+ }
620627 break ;
621628 }
622629 extra_args (f, filename, args, argidx);
623630
624631 log_header (design, " Executing JSON backend.\n " );
625632
626- JsonWriter json_writer (*f, use_selection, aig_mode, compat_int_mode);
633+ JsonWriter json_writer (*f, use_selection, aig_mode, compat_int_mode, scopeinfo_mode );
627634 json_writer.write_design (design);
628635 }
629636} JsonBackend;
@@ -648,6 +655,9 @@ struct JsonPass : public Pass {
648655 log (" emit 32-bit or smaller fully-defined parameter values directly\n " );
649656 log (" as JSON numbers (for compatibility with old parsers)\n " );
650657 log (" \n " );
658+ log (" -noscopeinfo\n " );
659+ log (" don't include $scopeinfo cells in the output\n " );
660+ log (" \n " );
651661 log (" See 'help write_json' for a description of the JSON format used.\n " );
652662 log (" \n " );
653663 }
@@ -656,6 +666,7 @@ struct JsonPass : public Pass {
656666 std::string filename;
657667 bool aig_mode = false ;
658668 bool compat_int_mode = false ;
669+ bool scopeinfo_mode = true ;
659670
660671 size_t argidx;
661672 for (argidx = 1 ; argidx < args.size (); argidx++)
@@ -672,6 +683,10 @@ struct JsonPass : public Pass {
672683 compat_int_mode = true ;
673684 continue ;
674685 }
686+ if (args[argidx] == " -noscopeinfo" ) {
687+ scopeinfo_mode = false ;
688+ continue ;
689+ }
675690 break ;
676691 }
677692 extra_args (args, argidx, design);
@@ -693,7 +708,7 @@ struct JsonPass : public Pass {
693708 f = &buf;
694709 }
695710
696- JsonWriter json_writer (*f, true , aig_mode, compat_int_mode);
711+ JsonWriter json_writer (*f, true , aig_mode, compat_int_mode, scopeinfo_mode );
697712 json_writer.write_design (design);
698713
699714 if (!empty) {
0 commit comments