2014-07-31 07:11:39 -05:00
|
|
|
#include "kernel/yosys.h"
|
2014-06-22 05:50:29 -05:00
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
|
2014-11-08 03:59:48 -06:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
2014-06-22 05:50:29 -05:00
|
|
|
struct MyPass : public Pass {
|
|
|
|
MyPass() : Pass("my_cmd", "just a simple test") { }
|
2018-07-21 01:41:18 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
2014-06-22 05:50:29 -05:00
|
|
|
{
|
|
|
|
log("Arguments to my_cmd:\n");
|
|
|
|
for (auto &arg : args)
|
|
|
|
log(" %s\n", arg.c_str());
|
|
|
|
|
|
|
|
log("Modules in current design:\n");
|
2014-07-31 07:11:39 -05:00
|
|
|
for (auto mod : design->modules())
|
|
|
|
log(" %s (%zd wires, %zd cells)\n", log_id(mod),
|
2014-10-10 09:59:44 -05:00
|
|
|
GetSize(mod->wires()), GetSize(mod->cells()));
|
2014-06-22 05:50:29 -05:00
|
|
|
}
|
|
|
|
} MyPass;
|
|
|
|
|
|
|
|
|
|
|
|
struct Test1Pass : public Pass {
|
|
|
|
Test1Pass() : Pass("test1", "creating the absval module") { }
|
2018-07-21 01:41:18 -05:00
|
|
|
void execute(std::vector<std::string>, RTLIL::Design *design) YS_OVERRIDE
|
2014-06-22 05:50:29 -05:00
|
|
|
{
|
2014-07-31 07:11:39 -05:00
|
|
|
if (design->has("\\absval") != 0)
|
|
|
|
log_error("A module with the name absval already exists!\n");
|
2014-06-22 05:50:29 -05:00
|
|
|
|
2014-07-31 07:11:39 -05:00
|
|
|
RTLIL::Module *module = design->addModule("\\absval");
|
2014-11-08 03:59:48 -06:00
|
|
|
log("Name of this module: %s\n", log_id(module));
|
2014-07-31 07:11:39 -05:00
|
|
|
|
|
|
|
RTLIL::Wire *a = module->addWire("\\a", 4);
|
2014-06-22 05:50:29 -05:00
|
|
|
a->port_input = true;
|
|
|
|
a->port_id = 1;
|
|
|
|
|
2014-07-31 07:11:39 -05:00
|
|
|
RTLIL::Wire *y = module->addWire("\\y", 4);
|
2014-06-22 05:50:29 -05:00
|
|
|
y->port_output = true;
|
|
|
|
y->port_id = 2;
|
|
|
|
|
2014-07-31 07:11:39 -05:00
|
|
|
RTLIL::Wire *a_inv = module->addWire(NEW_ID, 4);
|
2014-06-22 05:50:29 -05:00
|
|
|
module->addNeg(NEW_ID, a, a_inv, true);
|
2014-07-31 07:11:39 -05:00
|
|
|
module->addMux(NEW_ID, a, a_inv, RTLIL::SigSpec(a, 3), y);
|
2014-06-22 05:50:29 -05:00
|
|
|
|
2014-11-08 03:59:48 -06:00
|
|
|
module->fixup_ports();
|
2014-06-22 05:50:29 -05:00
|
|
|
}
|
|
|
|
} Test1Pass;
|
|
|
|
|
|
|
|
|
|
|
|
struct Test2Pass : public Pass {
|
|
|
|
Test2Pass() : Pass("test2", "demonstrating sigmap on test module") { }
|
2018-07-21 01:41:18 -05:00
|
|
|
void execute(std::vector<std::string>, RTLIL::Design *design) YS_OVERRIDE
|
2014-06-22 05:50:29 -05:00
|
|
|
{
|
|
|
|
if (design->selection_stack.back().empty())
|
|
|
|
log_cmd_error("This command can't operator on an empty selection!\n");
|
|
|
|
|
2014-07-27 03:18:00 -05:00
|
|
|
RTLIL::Module *module = design->modules_.at("\\test");
|
2014-06-22 05:50:29 -05:00
|
|
|
|
2014-07-31 07:11:39 -05:00
|
|
|
RTLIL::SigSpec a(module->wire("\\a")), x(module->wire("\\x")), y(module->wire("\\y"));
|
2014-06-22 05:50:29 -05:00
|
|
|
log("%d %d %d\n", a == x, x == y, y == a); // will print "0 0 0"
|
|
|
|
|
|
|
|
SigMap sigmap(module);
|
|
|
|
log("%d %d %d\n", sigmap(a) == sigmap(x), sigmap(x) == sigmap(y),
|
|
|
|
sigmap(y) == sigmap(a)); // will print "1 1 1"
|
|
|
|
|
|
|
|
log("Mapped signal x: %s\n", log_signal(sigmap(x)));
|
|
|
|
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Doing important stuff!\n");
|
2014-06-22 05:50:29 -05:00
|
|
|
log_push();
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
log("Log message #%d.\n", i);
|
|
|
|
log_pop();
|
|
|
|
}
|
|
|
|
} Test2Pass;
|
|
|
|
|
2014-11-08 03:59:48 -06:00
|
|
|
PRIVATE_NAMESPACE_END
|