abc9_ops: still emit delay table even box has no timing
[yosys.git] / passes / techmap / extract.cc
index 27689663e97e1755d97f9155becbc6560ed3676f..f8798eea50857e7a4c9012380cbc17cc24168774 100644 (file)
@@ -2,11 +2,11 @@
  *  yosys -- Yosys Open SYnthesis Suite
  *
  *  Copyright (C) 2012  Clifford Wolf <clifford@clifford.at>
- *  
+ *
  *  Permission to use, copy, modify, and/or distribute this software for any
  *  purpose with or without fee is hereby granted, provided that the above
  *  copyright notice and this permission notice appear in all copies.
- *  
+ *
  *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@@ -54,40 +54,40 @@ public:
 
        RTLIL::Const unified_param(RTLIL::IdString cell_type, RTLIL::IdString param, RTLIL::Const value)
        {
-               if (cell_type.substr(0, 1) != "$" || cell_type.substr(0, 2) == "$_")
+               if (!cell_type.begins_with("$") || cell_type.begins_with("$_"))
                        return value;
 
        #define param_bool(_n) if (param == _n) return value.as_bool();
-               param_bool("\\ARST_POLARITY");
-               param_bool("\\A_SIGNED");
-               param_bool("\\B_SIGNED");
-               param_bool("\\CLK_ENABLE");
-               param_bool("\\CLK_POLARITY");
-               param_bool("\\CLR_POLARITY");
-               param_bool("\\EN_POLARITY");
-               param_bool("\\SET_POLARITY");
-               param_bool("\\TRANSPARENT");
+               param_bool(ID(ARST_POLARITY));
+               param_bool(ID(A_SIGNED));
+               param_bool(ID(B_SIGNED));
+               param_bool(ID(CLK_ENABLE));
+               param_bool(ID(CLK_POLARITY));
+               param_bool(ID(CLR_POLARITY));
+               param_bool(ID(EN_POLARITY));
+               param_bool(ID(SET_POLARITY));
+               param_bool(ID(TRANSPARENT));
        #undef param_bool
 
        #define param_int(_n) if (param == _n) return value.as_int();
-               param_int("\\ABITS")
-               param_int("\\A_WIDTH")
-               param_int("\\B_WIDTH")
-               param_int("\\CTRL_IN_WIDTH")
-               param_int("\\CTRL_OUT_WIDTH")
-               param_int("\\OFFSET")
-               param_int("\\PRIORITY")
-               param_int("\\RD_PORTS")
-               param_int("\\SIZE")
-               param_int("\\STATE_BITS")
-               param_int("\\STATE_NUM")
-               param_int("\\STATE_NUM_LOG2")
-               param_int("\\STATE_RST")
-               param_int("\\S_WIDTH")
-               param_int("\\TRANS_NUM")
-               param_int("\\WIDTH")
-               param_int("\\WR_PORTS")
-               param_int("\\Y_WIDTH")
+               param_int(ID(ABITS))
+               param_int(ID(A_WIDTH))
+               param_int(ID(B_WIDTH))
+               param_int(ID(CTRL_IN_WIDTH))
+               param_int(ID(CTRL_OUT_WIDTH))
+               param_int(ID(OFFSET))
+               param_int(ID(PRIORITY))
+               param_int(ID(RD_PORTS))
+               param_int(ID(SIZE))
+               param_int(ID(STATE_BITS))
+               param_int(ID(STATE_NUM))
+               param_int(ID(STATE_NUM_LOG2))
+               param_int(ID(STATE_RST))
+               param_int(ID(S_WIDTH))
+               param_int(ID(TRANS_NUM))
+               param_int(ID(WIDTH))
+               param_int(ID(WR_PORTS))
+               param_int(ID(Y_WIDTH))
        #undef param_int
 
                return value;
@@ -130,7 +130,7 @@ public:
                                RTLIL::SigSpec needleSig = conn.second;
                                RTLIL::SigSpec haystackSig = haystackCell->getPort(portMapping.at(conn.first.str()));
 
-                               for (int i = 0; i < std::min(needleSig.size(), haystackSig.size()); i++) {
+                               for (int i = 0; i < min(needleSig.size(), haystackSig.size()); i++) {
                                        RTLIL::Wire *needleWire = needleSig[i].wire, *haystackWire = haystackSig[i].wire;
                                        if (needleWire != lastNeedleWire || haystackWire != lastHaystackWire)
                                                if (!compareAttributes(wire_attr, needleWire ? needleWire->attributes : emptyAttr, haystackWire ? haystackWire->attributes : emptyAttr))
@@ -203,7 +203,7 @@ bool module2graph(SubCircuit::Graph &graph, RTLIL::Module *mod, bool constports,
                        continue;
 
                std::string type = cell->type.str();
-               if (sel == NULL && type.substr(0, 2) == "\\$")
+               if (sel == NULL && type.compare(0, 2, "\\$") == 0)
                        type = type.substr(1);
                graph.createNode(cell->name.str(), type, (void*)cell);
 
@@ -341,10 +341,10 @@ RTLIL::Cell *replace(RTLIL::Module *needle, RTLIL::Module *haystack, SubCircuit:
 bool compareSortNeedleList(RTLIL::Module *left, RTLIL::Module *right)
 {
        int left_idx = 0, right_idx = 0;
-       if (left->attributes.count("\\extract_order") > 0)
-               left_idx = left->attributes.at("\\extract_order").as_int();
-       if (right->attributes.count("\\extract_order") > 0)
-               right_idx = right->attributes.at("\\extract_order").as_int();
+       if (left->attributes.count(ID(extract_order)) > 0)
+               left_idx = left->attributes.at(ID(extract_order)).as_int();
+       if (right->attributes.count(ID(extract_order)) > 0)
+               right_idx = right->attributes.at(ID(extract_order)).as_int();
        if (left_idx != right_idx)
                return left_idx < right_idx;
        return left->name < right->name;
@@ -352,7 +352,7 @@ bool compareSortNeedleList(RTLIL::Module *left, RTLIL::Module *right)
 
 struct ExtractPass : public Pass {
        ExtractPass() : Pass("extract", "find subcircuits and replace them with cells") { }
-       virtual void help()
+       void help() YS_OVERRIDE
        {
                //   |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
                log("\n");
@@ -361,7 +361,7 @@ struct ExtractPass : public Pass {
                log("\n");
                log("This pass looks for subcircuits that are isomorphic to any of the modules\n");
                log("in the given map file and replaces them with instances of this modules. The\n");
-               log("map file can be a verilog source file (*.v) or an ilang file (*.il).\n");
+               log("map file can be a Verilog source file (*.v) or an ilang file (*.il).\n");
                log("\n");
                log("    -map <map_file>\n");
                log("        use the modules in this file as reference. This option can be used\n");
@@ -390,11 +390,11 @@ struct ExtractPass : public Pass {
                log("        match. This option can be used multiple times.\n");
                log("\n");
                log("    -swap <needle_type> <port1>,<port2>[,...]\n");
-               log("        Register a set of swapable ports for a needle cell type.\n");
+               log("        Register a set of swappable ports for a needle cell type.\n");
                log("        This option can be used multiple times.\n");
                log("\n");
                log("    -perm <needle_type> <port1>,<port2>[,...] <portA>,<portB>[,...]\n");
-               log("        Register a valid permutation of swapable ports for a needle\n");
+               log("        Register a valid permutation of swappable ports for a needle\n");
                log("        cell type. This option can be used multiple times.\n");
                log("\n");
                log("    -cell_attr <attribute_name>\n");
@@ -409,7 +409,7 @@ struct ExtractPass : public Pass {
                log("    -ignore_param <cell_type> <parameter_name>\n");
                log("        Do not use this parameter when matching cells.\n");
                log("\n");
-               log("This pass does not operate on modules with uprocessed processes in it.\n");
+               log("This pass does not operate on modules with unprocessed processes in it.\n");
                log("(I.e. the 'proc' pass should be used first to convert processes to netlists.)\n");
                log("\n");
                log("This pass can also be used for mining for frequent subcircuits. In this mode\n");
@@ -440,9 +440,9 @@ struct ExtractPass : public Pass {
                log("See 'help techmap' for a pass that does the opposite thing.\n");
                log("\n");
        }
-       virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
+       void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
        {
-               log_header("Executing EXTRACT pass (map subcircuits to cells).\n");
+               log_header(design, "Executing EXTRACT pass (map subcircuits to cells).\n");
                log_push();
 
                SubCircuitSolver solver;
@@ -594,7 +594,7 @@ struct ExtractPass : public Pass {
                        map = new RTLIL::Design;
                        for (auto &filename : map_filenames)
                        {
-                               if (filename.substr(0, 1) == "%")
+                               if (filename.compare(0, 1, "%") == 0)
                                {
                                        if (!saved_designs.count(filename.substr(1))) {
                                                delete map;
@@ -613,10 +613,10 @@ struct ExtractPass : public Pass {
                                                delete map;
                                                log_cmd_error("Can't open map file `%s'.\n", filename.c_str());
                                        }
-                                       Frontend::frontend_call(map, &f, filename, (filename.size() > 3 && filename.substr(filename.size()-3) == ".il") ? "ilang" : "verilog");
+                                       Frontend::frontend_call(map, &f, filename, (filename.size() > 3 && filename.compare(filename.size()-3, std::string::npos, ".il") == 0 ? "ilang" : "verilog"));
                                        f.close();
 
-                                       if (filename.size() <= 3 || filename.substr(filename.size()-3) != ".il") {
+                                       if (filename.size() <= 3 || filename.compare(filename.size()-3, std::string::npos, ".il") != 0) {
                                                Pass::call(map, "proc");
                                                Pass::call(map, "opt_clean");
                                        }
@@ -627,7 +627,7 @@ struct ExtractPass : public Pass {
                std::map<std::string, RTLIL::Module*> needle_map, haystack_map;
                std::vector<RTLIL::Module*> needle_list;
 
-               log_header("Creating graphs for SubCircuit library.\n");
+               log_header(design, "Creating graphs for SubCircuit library.\n");
 
                if (!mine_mode)
                        for (auto &mod_it : map->modules_) {
@@ -650,11 +650,11 @@ struct ExtractPass : public Pass {
                                haystack_map[graph_name] = mod_it.second;
                        }
                }
-               
+
                if (!mine_mode)
                {
                        std::vector<SubCircuit::Solver::Result> results;
-                       log_header("Running solver from SubCircuit library.\n");
+                       log_header(design, "Running solver from SubCircuit library.\n");
 
                        std::sort(needle_list.begin(), needle_list.end(), compareSortNeedleList);
 
@@ -667,7 +667,7 @@ struct ExtractPass : public Pass {
 
                        if (results.size() > 0)
                        {
-                               log_header("Substitute SubCircuits with cells.\n");
+                               log_header(design, "Substitute SubCircuits with cells.\n");
 
                                for (int i = 0; i < int(results.size()); i++) {
                                        auto &result = results[i];
@@ -688,7 +688,7 @@ struct ExtractPass : public Pass {
                {
                        std::vector<SubCircuit::Solver::MineResult> results;
 
-                       log_header("Running miner from SubCircuit library.\n");
+                       log_header(design, "Running miner from SubCircuit library.\n");
                        solver.mine(results, mine_cells_min, mine_cells_max, mine_min_freq, mine_limit_mod);
 
                        map = new RTLIL::Design;
@@ -737,7 +737,7 @@ struct ExtractPass : public Pass {
                                        RTLIL::Cell *newCell = newMod->addCell(cell->name, cell->type);
                                        newCell->parameters = cell->parameters;
                                        for (auto &conn : cell->connections()) {
-                                               std::vector<RTLIL::SigChunk> chunks = sigmap(conn.second);
+                                               std::vector<SigChunk> chunks = sigmap(conn.second);
                                                for (auto &chunk : chunks)
                                                        if (chunk.wire != NULL)
                                                                chunk.wire = newMod->wires_.at(chunk.wire->name);
@@ -759,5 +759,5 @@ struct ExtractPass : public Pass {
                log_pop();
        }
 } ExtractPass;
+
 PRIVATE_NAMESPACE_END