Added "show -colorattr"
authorClifford Wolf <clifford@clifford.at>
Tue, 23 Dec 2014 11:29:29 +0000 (12:29 +0100)
committerClifford Wolf <clifford@clifford.at>
Tue, 23 Dec 2014 11:29:29 +0000 (12:29 +0100)
passes/cmds/show.cc

index 715c1de56d5e0f579dd631b016578253ff49c95e..f61f195be7fa11b85e5b2934c740b793403eee96 100644 (file)
@@ -64,6 +64,10 @@ struct ShowWorker
        const std::vector<std::pair<std::string, RTLIL::Selection>> &color_selections;
        const std::vector<std::pair<std::string, RTLIL::Selection>> &label_selections;
 
+       std::map<RTLIL::Const, int> colorattr_cache;
+       RTLIL::IdString colorattr;
+
+
        static uint32_t xorshift32(uint32_t x) {
                x ^= x << 13;
                x ^= x >> 17;
@@ -128,7 +132,25 @@ struct ShowWorker
                                dot_escape_store.push_back(stringf(", color=\"%s\"", s.first.c_str()));
                                return dot_escape_store.back().c_str();
                        }
-               return "";
+
+               RTLIL::Const colorattr_value;
+               RTLIL::Cell *cell = module->cell(member_name);
+               RTLIL::Wire *wire = module->wire(member_name);
+
+               if (cell && cell->attributes.count(colorattr))
+                       colorattr_value = cell->attributes.at(colorattr);
+               else if (wire && wire->attributes.count(colorattr))
+                       colorattr_value = wire->attributes.at(colorattr);
+               else
+                       return "";
+
+               if (colorattr_cache.count(colorattr_value) == 0) {
+                       int next_id = GetSize(colorattr_cache);
+                       colorattr_cache[colorattr_value] = (next_id % 8) + 1;
+               }
+
+               dot_escape_store.push_back(stringf(", colorscheme=\"dark28\", color=\"%d\", fontcolor=\"%d\"", colorattr_cache.at(colorattr_value), colorattr_cache.at(colorattr_value)));
+               return dot_escape_store.back().c_str();
        }
 
        const char *findLabel(std::string member_name)
@@ -507,10 +529,10 @@ struct ShowWorker
        ShowWorker(FILE *f, RTLIL::Design *design, std::vector<RTLIL::Design*> &libs, uint32_t colorSeed, bool genWidthLabels,
                        bool genSignedLabels, bool stretchIO, bool enumerateIds, bool abbreviateIds, bool notitle,
                        const std::vector<std::pair<std::string, RTLIL::Selection>> &color_selections,
-                       const std::vector<std::pair<std::string, RTLIL::Selection>> &label_selections) :
+                       const std::vector<std::pair<std::string, RTLIL::Selection>> &label_selections, RTLIL::IdString colorattr) :
                        f(f), design(design), currentColor(colorSeed), genWidthLabels(genWidthLabels),
                        genSignedLabels(genSignedLabels), stretchIO(stretchIO), enumerateIds(enumerateIds), abbreviateIds(abbreviateIds),
-                       notitle(notitle), color_selections(color_selections), label_selections(label_selections)
+                       notitle(notitle), color_selections(color_selections), label_selections(label_selections), colorattr(colorattr)
        {
                ct.setup_internals();
                ct.setup_internals_mem();
@@ -586,6 +608,10 @@ struct ShowPass : public Pass {
                log("        for the random number generator. Change the seed value if the colored\n");
                log("        graph still is ambigous. A seed of zero deactivates the coloring.\n");
                log("\n");
+               log("    -colorattr <attribute_name>\n");
+               log("        Use the specified attribute to assign colors. A unique color is\n");
+               log("        assigned to each unique value of this attribute.\n");
+               log("\n");
                log("    -width\n");
                log("        annotate busses with a label indicating the width of the bus.\n");
                log("\n");
@@ -637,6 +663,7 @@ struct ShowPass : public Pass {
                bool flag_enum = false;
                bool flag_abbeviate = true;
                bool flag_notitle = false;
+               RTLIL::IdString colorattr;
 
                size_t argidx;
                for (argidx = 1; argidx < args.size(); argidx++)
@@ -678,6 +705,10 @@ struct ShowPass : public Pass {
                                        colorSeed = ShowWorker::xorshift32(colorSeed);
                                continue;
                        }
+                       if (arg == "-colorattr" && argidx+1 < args.size()) {
+                               colorattr = RTLIL::escape_id(args[++argidx]);
+                               continue;
+                       }
                        if (arg == "-format" && argidx+1 < args.size()) {
                                format = args[++argidx];
                                continue;
@@ -753,7 +784,7 @@ struct ShowPass : public Pass {
                                delete lib;
                        log_cmd_error("Can't open dot file `%s' for writing.\n", dot_file.c_str());
                }
-               ShowWorker worker(f, design, libs, colorSeed, flag_width, flag_signed, flag_stretch, flag_enum, flag_abbeviate, flag_notitle, color_selections, label_selections);
+               ShowWorker worker(f, design, libs, colorSeed, flag_width, flag_signed, flag_stretch, flag_enum, flag_abbeviate, flag_notitle, color_selections, label_selections, colorattr);
                fclose(f);
 
                for (auto lib : libs)