2014-01-19 14:58:58 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2014-01-19 14:58:58 -06:00
|
|
|
* 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.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2014-01-19 14:58:58 -06:00
|
|
|
* 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
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/rtlil.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
2014-01-19 14:58:58 -06:00
|
|
|
static std::string hicell_celltype, hicell_portname;
|
|
|
|
static std::string locell_celltype, locell_portname;
|
|
|
|
static bool singleton_mode;
|
|
|
|
|
|
|
|
static RTLIL::Module *module;
|
2014-07-23 08:36:09 -05:00
|
|
|
static RTLIL::SigBit last_hi, last_lo;
|
2014-01-19 14:58:58 -06:00
|
|
|
|
|
|
|
void hilomap_worker(RTLIL::SigSpec &sig)
|
|
|
|
{
|
2014-07-23 08:36:09 -05:00
|
|
|
for (auto &bit : sig) {
|
|
|
|
if (bit == RTLIL::State::S1 && !hicell_celltype.empty()) {
|
|
|
|
if (!singleton_mode || last_hi == RTLIL::State::Sm) {
|
|
|
|
last_hi = module->addWire(NEW_ID);
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *cell = module->addCell(NEW_ID, RTLIL::escape_id(hicell_celltype));
|
2014-07-31 09:38:54 -05:00
|
|
|
cell->setPort(RTLIL::escape_id(hicell_portname), last_hi);
|
2014-01-19 14:58:58 -06:00
|
|
|
}
|
2014-07-23 08:36:09 -05:00
|
|
|
bit = last_hi;
|
2014-01-19 14:58:58 -06:00
|
|
|
}
|
2014-07-23 08:36:09 -05:00
|
|
|
if (bit == RTLIL::State::S0 && !locell_celltype.empty()) {
|
|
|
|
if (!singleton_mode || last_lo == RTLIL::State::Sm) {
|
|
|
|
last_lo = module->addWire(NEW_ID);
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *cell = module->addCell(NEW_ID, RTLIL::escape_id(locell_celltype));
|
2014-07-31 09:38:54 -05:00
|
|
|
cell->setPort(RTLIL::escape_id(locell_portname), last_lo);
|
2014-01-19 14:58:58 -06:00
|
|
|
}
|
2014-07-23 08:36:09 -05:00
|
|
|
bit = last_lo;
|
2014-01-19 14:58:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct HilomapPass : public Pass {
|
|
|
|
HilomapPass() : Pass("hilomap", "technology mapping of constant hi- and/or lo-drivers") { }
|
2018-07-21 01:41:18 -05:00
|
|
|
void help() YS_OVERRIDE
|
2014-01-19 14:58:58 -06:00
|
|
|
{
|
|
|
|
log("\n");
|
|
|
|
log(" hilomap [options] [selection]\n");
|
|
|
|
log("\n");
|
2014-10-08 14:38:37 -05:00
|
|
|
log("Map constants to 'tielo' and 'tiehi' driver cells.\n");
|
2014-01-19 14:58:58 -06:00
|
|
|
log("\n");
|
|
|
|
log(" -hicell <celltype> <portname>\n");
|
|
|
|
log(" Replace constant hi bits with this cell.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -locell <celltype> <portname>\n");
|
|
|
|
log(" Replace constant lo bits with this cell.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -singleton\n");
|
|
|
|
log(" Create only one hi/lo cell and connect all constant bits\n");
|
|
|
|
log(" to that cell. Per default a separate cell is created for\n");
|
|
|
|
log(" each constant bit.\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
2018-07-21 01:41:18 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
2014-01-19 14:58:58 -06:00
|
|
|
{
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Executing HILOMAP pass (mapping to constant drivers).\n");
|
2014-01-19 14:58:58 -06:00
|
|
|
|
|
|
|
hicell_celltype = std::string();
|
|
|
|
hicell_portname = std::string();
|
|
|
|
locell_celltype = std::string();
|
|
|
|
locell_portname = std::string();
|
|
|
|
singleton_mode = false;
|
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
if (args[argidx] == "-hicell" && argidx+2 < args.size()) {
|
|
|
|
hicell_celltype = args[++argidx];
|
|
|
|
hicell_portname = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-locell" && argidx+2 < args.size()) {
|
|
|
|
locell_celltype = args[++argidx];
|
|
|
|
locell_portname = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-singleton") {
|
|
|
|
singleton_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
2020-04-09 00:24:37 -05:00
|
|
|
for (auto mod : design->selected_modules())
|
2014-01-19 14:58:58 -06:00
|
|
|
{
|
2020-04-09 00:24:37 -05:00
|
|
|
module = mod;
|
2014-07-23 08:36:09 -05:00
|
|
|
last_hi = RTLIL::State::Sm;
|
|
|
|
last_lo = RTLIL::State::Sm;
|
2014-01-19 14:58:58 -06:00
|
|
|
|
|
|
|
module->rewrite_sigspecs(hilomap_worker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} HilomapPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|