39 void add_port(std::string celltype, std::string portname, std::string widthparam, std::string signparam)
45 log_cmd_error(
"Duplicate port decl: %s %s\n", celltype.c_str(), portname.c_str());
54 void add_port(std::string celltype, std::string portname, std::string widthparam,
bool is_signed)
60 log_cmd_error(
"Duplicate port decl: %s %s\n", celltype.c_str(), portname.c_str());
70 std::map<RTLIL::SigBit, std::pair<bool, RTLIL::SigSpec>> extend_map;
73 for (
auto &it : module->
cells_)
82 std::pair<RTLIL::IdString, RTLIL::IdString> key(cell->
type, conn.first);
84 if (!
decls.count(key))
96 int outer_width = conn.second.size();
99 if (inner_width >= outer_width)
103 extend_map[sig.
extract(inner_width - 1, 1)] = std::pair<bool, RTLIL::SigSpec>(is_signed,
104 sig.
extract(inner_width, outer_width - inner_width));
108 for (
auto &it : module->
cells_)
112 if (!design->
selected(module, cell))
117 std::vector<RTLIL::SigBit> sigbits = sigmap(conn.second).to_sigbit_vector();
120 for (
size_t i = 0; i < sigbits.size(); i++)
122 if (!extend_map.count(sigbits[i]))
125 bool is_signed = extend_map.at(sigbits[i]).first;
128 int extend_width = 0;
130 while (extend_width < extend_sig.
size() && i + extend_width + 1 < sigbits.size() &&
131 sigbits[i + extend_width + 1] == extend_bit) extend_width++;
133 if (extend_width == 0)
136 if (old_sig.
size() == 0)
137 old_sig = conn.second;
157 log(
" connwrappers [options] [selection]\n");
159 log(
"Wrappers are used in coarse-grain synthesis to wrap cells with smaller ports\n");
160 log(
"in wrapper cells with a (larger) constant port size. I.e. the upper bits\n");
161 log(
"of the wrapper outut are signed/unsigned bit extended. This command uses this\n");
162 log(
"knowlege to rewire the inputs of the driven cells to match the output of\n");
163 log(
"the driving cell.\n");
165 log(
" -signed <cell_type> <port_name> <width_param>\n");
166 log(
" -unsigned <cell_type> <port_name> <width_param>\n");
167 log(
" consider the specified signed/unsigned wrapper output\n");
169 log(
" -port <cell_type> <port_name> <width_param> <sign_param>\n");
170 log(
" use the specified parameter to decide if signed or unsigned\n");
172 log(
"The options -signed, -unsigned, and -port can be specified multiple times.\n");
180 for (argidx = 1; argidx < args.size(); argidx++)
182 if (args[argidx] ==
"-signed" && argidx+3 < args.size()) {
183 worker.
add_port(args[argidx+1], args[argidx+2], args[argidx+3],
true);
187 if (args[argidx] ==
"-unsigned" && argidx+3 < args.size()) {
188 worker.
add_port(args[argidx+1], args[argidx+2], args[argidx+3],
false);
192 if (args[argidx] ==
"-port" && argidx+4 < args.size()) {
193 worker.
add_port(args[argidx+1], args[argidx+2], args[argidx+3], args[argidx+4]);
201 log_header(
"Executing CONNWRAPPERS pass (connect extended ports of wrapper cells).\n");
203 for (
auto &mod_it : design->
modules_)
204 if (design->
selected(mod_it.second))
205 worker.
work(design, mod_it.second);
bool selected(T1 *module) const
std::set< RTLIL::IdString > decl_celltypes
void log_header(const char *format,...)
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
std::map< RTLIL::IdString, RTLIL::Const > parameters
void work(RTLIL::Design *design, RTLIL::Module *module)
static std::string escape_id(std::string str)
#define PRIVATE_NAMESPACE_BEGIN
void add_port(std::string celltype, std::string portname, std::string widthparam, bool is_signed)
std::map< std::pair< RTLIL::IdString, RTLIL::IdString >, portdecl_t > decls
#define PRIVATE_NAMESPACE_END
static const char * id2cstr(const RTLIL::IdString &str)
void log_cmd_error(const char *format,...)
#define USING_YOSYS_NAMESPACE
void add_port(std::string celltype, std::string portname, std::string widthparam, std::string signparam)
std::map< RTLIL::IdString, RTLIL::Module * > modules_
void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with)
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
void log(const char *format,...)
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
ConnwrappersPass ConnwrappersPass
std::map< RTLIL::IdString, RTLIL::SigSpec > connections_
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const