ast, rpc: record original name of $paramod\* as \hdlname attribute.
authorwhitequark <whitequark@whitequark.org>
Sat, 18 Apr 2020 03:43:15 +0000 (03:43 +0000)
committerwhitequark <whitequark@whitequark.org>
Sat, 18 Apr 2020 03:47:28 +0000 (03:47 +0000)
The $paramod name mangling is not invertible (the \ character, which
separates the module name from the parameters, is valid in the module
name itself), which does not stop people from trying to invert it.

This commit makes it easy to invert the name mangling by storing
the original name explicitly, and fixes the firrtl backend to use
the newly introduced attribute.

backends/firrtl/firrtl.cc
frontends/ast/ast.cc
frontends/rpc/rpc_frontend.cc

index fd7f20cc6403daf4668cb1c21a9ce4a16542582b..40d05a03654639f66f7c43fe192ab40b93e5e661 100644 (file)
@@ -306,17 +306,8 @@ struct FirrtlWorker
                // If this is a parameterized module, its parent module is encoded in the cell type
                if (cell->type.begins_with("$paramod"))
                {
-                       std::string::iterator it;
-                       for (it = cell_type.begin(); it < cell_type.end(); it++)
-                       {
-                               switch (*it) {
-                                       case '\\': /* FALL_THROUGH */
-                                       case '=': /* FALL_THROUGH */
-                                       case '\'': /* FALL_THROUGH */
-                                       case '$': instanceOf.append("_"); break;
-                                       default: instanceOf.append(1, *it); break;
-                               }
-                       }
+                       log_assert(cell->has_attribute(ID::hdlname));
+                       instanceOf = cell->get_string_attribute(ID::hdlname);
                }
                else
                {
index 245a53611ac578d141b93ec22f4363438640e228..de741a50618a52d3803bd14af00d34164494c9e0 100644 (file)
@@ -1565,6 +1565,9 @@ std::string AstModule::derive_common(RTLIL::Design *design, const dict<RTLIL::Id
        rewritten.reserve(GetSize(parameters));
 
        AstNode *new_ast = ast->clone();
+       if (!new_ast->attributes.count(ID::hdlname))
+               new_ast->attributes[ID::hdlname] = AstNode::mkconst_str(stripped_name);
+
        para_counter = 0;
        for (auto child : new_ast->children) {
                if (child->type != AST_PARAMETER)
index a23f7548e5fb66ae9a0b3391bbf9aa3e7f5c29c2..46ee6a73327a496bec751c7c0e5cffa9212bf283 100644 (file)
@@ -217,6 +217,8 @@ struct RpcModule : RTLIL::Module {
                                module.second->name = mangled_name;
                                module.second->design = design;
                                module.second->attributes.erase(ID::top);
+                               if (!module.second->has_attribute(ID::hdlname))
+                                       module.second->set_string_attribute(ID::hdlname, module.first.str());
                                design->modules_[mangled_name] = module.second;
                                derived_design->modules_.erase(module.first);
                        }