(*it)->str = (*it)->str.substr(1);
if (defer)
(*it)->str = "$abstract" + (*it)->str;
- if (design->modules_.count((*it)->str)) {
+ if (design->has((*it)->str)) {
if (!ignore_redef)
log_error("Re-definition of module `%s' at %s:%d!\n",
(*it)->str.c_str(), (*it)->filename.c_str(), (*it)->linenum);
(*it)->str.c_str(), (*it)->filename.c_str(), (*it)->linenum);
continue;
}
- design->modules_[(*it)->str] = process_module(*it, defer);
+ design->add(process_module(*it, defer));
}
}
modname = "$paramod" + stripped_name + para_info;
}
- if (design->modules_.count(modname) == 0) {
+ if (!design->has(modname)) {
new_ast->str = modname;
- design->modules_[modname] = process_module(new_ast, false);
- design->modules_[modname]->check();
+ design->add(process_module(new_ast, false));
+ design->module(modname)->check();
} else {
log("Found cached RTLIL representation for module `%s'.\n", modname.c_str());
}
module:
TOK_MODULE TOK_ID EOL {
- if (current_design->modules_.count($2) != 0)
+ if (current_design->has($2))
rtlil_frontend_ilang_yyerror(stringf("ilang error: redefinition of module %s.", $2).c_str());
current_module = new RTLIL::Module;
current_module->name = $2;
current_module->attributes = attrbuf;
- current_design->modules_[$2] = current_module;
+ current_design->add(current_module);
attrbuf.clear();
free($2);
} module_body TOK_END {
std::string cell_name = RTLIL::escape_id(cell->args.at(0));
- if (design->modules_.count(cell_name)) {
+ if (design->has(cell_name)) {
if (flag_ignore_redef)
continue;
log_error("Duplicate definition of cell/module %s.\n", RTLIL::id2cstr(cell_name));
}
module->fixup_ports();
- design->modules_[module->name] = module;
+ design->add(module);
cell_count++;
skip_cell:;
}
{
std::string module_name = nl->IsOperator() ? std::string("$verific$") + nl->Owner()->Name() : RTLIL::escape_id(nl->Owner()->Name());
- if (design->modules_.count(module_name)) {
+ if (design->has(module_name)) {
if (!nl->IsOperator())
log_cmd_error("Re-definition of module `%s'.\n", nl->Owner()->Name());
return;
RTLIL::Module *module = new RTLIL::Module;
module->name = module_name;
- design->modules_[module->name] = module;
+ design->add(module);
log("Importing module %s.\n", RTLIL::id2cstr(module->name));
log_assert(modules_.count(module->name) == 0);
log_assert(refcount_modules_ == 0);
modules_[module->name] = module;
+ module->design = this;
}
RTLIL::Module *RTLIL::Design::addModule(RTLIL::IdString name)
log_assert(modules_.count(name) == 0);
log_assert(refcount_modules_ == 0);
modules_[name] = new RTLIL::Module;
+ modules_[name]->design = this;
modules_[name]->name = name;
return modules_[name];
}
{
#ifndef NDEBUG
for (auto &it : modules_) {
+ log_assert(this == it.second->design);
log_assert(it.first == it.second->name);
log_assert(it.first.size() > 0 && (it.first[0] == '\\' || it.first[0] == '$'));
it.second->check();
return selected_whole_module(mod->name);
}
+std::vector<RTLIL::Module*> RTLIL::Design::selected_modules() const
+{
+ std::vector<RTLIL::Module*> result;
+ result.reserve(modules_.size());
+ for (auto &it : modules_)
+ if (selected_module(it.first))
+ result.push_back(it.second);
+ return result;
+}
+
+std::vector<RTLIL::Module*> RTLIL::Design::selected_whole_modules() const
+{
+ std::vector<RTLIL::Module*> result;
+ result.reserve(modules_.size());
+ for (auto &it : modules_)
+ if (selected_whole_module(it.first))
+ result.push_back(it.second);
+ return result;
+}
+
+std::vector<RTLIL::Module*> RTLIL::Design::selected_whole_modules_warn() const
+{
+ std::vector<RTLIL::Module*> result;
+ result.reserve(modules_.size());
+ for (auto &it : modules_)
+ if (selected_whole_module(it.first))
+ result.push_back(it.second);
+ else if (selected_module(it.first))
+ log("Warning: Ignoring partially selected module %s.\n", log_id(it.first));
+ return result;
+}
+
RTLIL::Module::Module()
{
refcount_wires_ = 0;
{
#ifndef NDEBUG
for (auto &it : wires_) {
+ log_assert(this == it.second->module);
log_assert(it.first == it.second->name);
log_assert(it.first.size() > 0 && (it.first[0] == '\\' || it.first[0] == '$'));
log_assert(it.second->width >= 0);
}
for (auto &it : cells_) {
+ log_assert(this == it.second->module);
log_assert(it.first == it.second->name);
log_assert(it.first.size() > 0 && (it.first[0] == '\\' || it.first[0] == '$'));
log_assert(it.second->type.size() > 0 && (it.second->type[0] == '\\' || it.second->type[0] == '$'));
return new_mod;
}
+bool RTLIL::Module::has_memories() const
+{
+ return !memories.empty();
+}
+
+bool RTLIL::Module::has_processes() const
+{
+ return !processes.empty();
+}
+
+bool RTLIL::Module::has_memories_warn() const
+{
+ if (!memories.empty())
+ log("Warning: Ignoring module %s because it contains memories (run 'memory' command first).\n", log_id(this));
+ return !memories.empty();
+}
+
+bool RTLIL::Module::has_processes_warn() const
+{
+ if (!processes.empty())
+ log("Warning: Ignoring module %s because it contains processes (run 'proc' command first).\n", log_id(this));
+ return !processes.empty();
+}
+
+std::vector<RTLIL::Wire*> RTLIL::Module::selected_wires() const
+{
+ std::vector<RTLIL::Wire*> result;
+ result.reserve(wires_.size());
+ for (auto &it : wires_)
+ if (design->selected(this, it.second))
+ result.push_back(it.second);
+ return result;
+}
+
+std::vector<RTLIL::Cell*> RTLIL::Module::selected_cells() const
+{
+ std::vector<RTLIL::Cell*> result;
+ result.reserve(wires_.size());
+ for (auto &it : cells_)
+ if (design->selected(this, it.second))
+ result.push_back(it.second);
+ return result;
+}
+
void RTLIL::Module::add(RTLIL::Wire *wire)
{
log_assert(!wire->name.empty());
log_assert(count_id(wire->name) == 0);
log_assert(refcount_wires_ == 0);
wires_[wire->name] = wire;
+ wire->module = this;
}
void RTLIL::Module::add(RTLIL::Cell *cell)
log_assert(count_id(cell->name) == 0);
log_assert(refcount_cells_ == 0);
cells_[cell->name] = cell;
+ cell->module = this;
}
namespace {
RTLIL::ObjIterator<T> begin() { return RTLIL::ObjIterator<T>(list_p, refcount_p); }
RTLIL::ObjIterator<T> end() { return RTLIL::ObjIterator<T>(); }
+ size_t size() const {
+ return list_p->size();
+ }
+
operator std::set<T>() const {
std::set<T> result;
for (auto &it : *list_p)
sel.select(module, member);
}
}
+
+ std::vector<RTLIL::Module*> selected_modules() const;
+ std::vector<RTLIL::Module*> selected_whole_modules() const;
+ std::vector<RTLIL::Module*> selected_whole_modules_warn() const;
};
#define RTLIL_ATTRIBUTE_MEMBERS \
void add(RTLIL::Cell *cell);
public:
+ RTLIL::Design *design;
int refcount_wires_;
int refcount_cells_;
void cloneInto(RTLIL::Module *new_mod) const;
virtual RTLIL::Module *clone() const;
+ bool has_memories() const;
+ bool has_processes() const;
+
+ bool has_memories_warn() const;
+ bool has_processes_warn() const;
+
+ std::vector<RTLIL::Wire*> selected_wires() const;
+ std::vector<RTLIL::Cell*> selected_cells() const;
+
RTLIL::Wire* wire(RTLIL::IdString id) { return wires_.count(id) ? wires_.at(id) : nullptr; }
RTLIL::Cell* cell(RTLIL::IdString id) { return cells_.count(id) ? cells_.at(id) : nullptr; }
Wire(RTLIL::Wire &other) = delete;
void operator=(RTLIL::Wire &other) = delete;
+ RTLIL::Module *module;
RTLIL::IdString name;
int width, start_offset, port_id;
bool port_input, port_output, upto;
Cell(RTLIL::Cell &other) = delete;
void operator=(RTLIL::Cell &other) = delete;
+ RTLIL::Module *module;
RTLIL::IdString name;
RTLIL::IdString type;
std::map<RTLIL::IdString, RTLIL::SigSpec> connections_;
../../yosys-config --exec --cxx --cxxflags --ldflags -o my_cmd.so -shared my_cmd.cc --ldlibs
test0.log: my_cmd.so
- ../../yosys -l test0.log_new -m ./my_cmd.so -p 'my_cmd foo bar' absval_ref.v
+ ../../yosys -Ql test0.log_new -m ./my_cmd.so -p 'my_cmd foo bar' absval_ref.v
mv test0.log_new test0.log
test1.log: my_cmd.so
- ../../yosys -l test1.log_new -m ./my_cmd.so -p 'clean; test1; dump' absval_ref.v
+ ../../yosys -Ql test1.log_new -m ./my_cmd.so -p 'clean; test1; dump' absval_ref.v
mv test1.log_new test1.log
test2.log: my_cmd.so
- ../../yosys -l test2.log_new -m ./my_cmd.so -p 'test2' sigmap_test.v
+ ../../yosys -Ql test2.log_new -m ./my_cmd.so -p 'test2' sigmap_test.v
mv test2.log_new test2.log
-#include "kernel/rtlil.h"
-#include "kernel/register.h"
-#include "kernel/log.h"
+#include "kernel/yosys.h"
#include "kernel/sigtools.h"
struct MyPass : public Pass {
log(" %s\n", arg.c_str());
log("Modules in current design:\n");
- for (auto &mod : design->modules_)
- log(" %s (%zd wires, %zd cells)\n", RTLIL::id2cstr(mod.first),
- mod.second->wires_.size(), mod.second->cells_.size());
+ for (auto mod : design->modules())
+ log(" %s (%zd wires, %zd cells)\n", log_id(mod),
+ SIZE(mod->wires()), SIZE(mod->cells()));
}
} MyPass;
Test1Pass() : Pass("test1", "creating the absval module") { }
virtual void execute(std::vector<std::string>, RTLIL::Design *design)
{
- RTLIL::Module *module = new RTLIL::Module;
- module->name = "\\absval";
+ if (design->has("\\absval") != 0)
+ log_error("A module with the name absval already exists!\n");
- RTLIL::Wire *a = module->new_wire(4, "\\a");
+ RTLIL::Module *module = design->addModule("\\absval");
+
+ RTLIL::Wire *a = module->addWire("\\a", 4);
a->port_input = true;
a->port_id = 1;
- RTLIL::Wire *y = module->new_wire(4, "\\y");
+ RTLIL::Wire *y = module->addWire("\\y", 4);
y->port_output = true;
y->port_id = 2;
- RTLIL::Wire *a_inv = module->new_wire(4, NEW_ID);
+ RTLIL::Wire *a_inv = module->addWire(NEW_ID, 4);
module->addNeg(NEW_ID, a, a_inv, true);
- module->addMux(NEW_ID, a, a_inv, RTLIL::SigSpec(a, 1, 3), y);
-
- log("Name of this module: %s\n", RTLIL::id2cstr(module->name));
-
- if (design->modules_.count(module->name) != 0)
- log_error("A module with the name %s already exists!\n",
- RTLIL::id2cstr(module->name));
+ module->addMux(NEW_ID, a, a_inv, RTLIL::SigSpec(a, 3), y);
- design->modules_[module->name] = module;
+ log("Name of this module: %s\n", log_id(module));
}
} Test1Pass;
RTLIL::Module *module = design->modules_.at("\\test");
- RTLIL::SigSpec a(module->wires_.at("\\a")), x(module->wires_.at("\\x")),
- y(module->wires_.at("\\y"));
+ RTLIL::SigSpec a(module->wire("\\a")), x(module->wire("\\x")), y(module->wire("\\y"));
log("%d %d %d\n", a == x, x == y, y == a); // will print "0 0 0"
SigMap sigmap(module);
int port_count = 0;
module->name = "\\netlist";
- design->modules_[module->name] = module;
+ design->add(module);
size_t buffer_size = 4096;
char *buffer = (char*)malloc(buffer_size);
if (design->modules_.count(trg_name) != 0)
log_cmd_error("Target module name %s already exists.\n", trg_name.c_str());
- design->modules_[trg_name] = design->modules_.at(src_name)->clone();
- design->modules_[trg_name]->name = trg_name;
+ RTLIL::Module *new_mod = design->module(src_name)->clone();
+ new_mod->name = trg_name;
+ design->add(new_mod);
}
} CopyPass;
delete copy_to_design->modules_.at(trg_name);
copy_to_design->modules_[trg_name] = mod->clone();
copy_to_design->modules_[trg_name]->name = trg_name;
+ copy_to_design->modules_[trg_name]->design = copy_to_design;
}
}
RTLIL::Design *design_copy = new RTLIL::Design;
for (auto &it : design->modules_)
- design_copy->modules_[it.first] = it.second->clone();
+ design_copy->add(it.second->clone());
design_copy->selection_stack = design->selection_stack;
design_copy->selection_vars = design->selection_vars;
pushed_designs.pop_back();
for (auto &it : saved_design->modules_)
- design->modules_[it.first] = it.second->clone();
+ design->add(it.second->clone());
design->selection_stack = saved_design->selection_stack;
design->selection_vars = saved_design->selection_vars;
RTLIL::Module *mod = new RTLIL::Module;
mod->name = celltype;
mod->attributes["\\blackbox"] = RTLIL::Const(1);
- design->modules_[mod->name] = mod;
+ design->add(mod);
for (auto &decl : ports) {
RTLIL::Wire *wire = mod->addWire(decl.portname, portwidths.at(decl.portname));
RTLIL::Module *new_mod = new RTLIL::Module;
new_mod->name = submod.full_name;
- design->modules_[new_mod->name] = new_mod;
+ design->add(new_mod);
int port_counter = 1, auto_name_counter = 1;
std::set<std::string> all_wire_names;
RTLIL::Module *miter_module = new RTLIL::Module;
miter_module->name = miter_name;
- design->modules_[miter_name] = miter_module;
+ design->add(miter_module);
RTLIL::Cell *gold_cell = miter_module->addCell("\\gold", gold_name);
RTLIL::Cell *gate_cell = miter_module->addCell("\\gate", gate_name);
RTLIL::Module *newMod = new RTLIL::Module;
newMod->name = stringf("\\needle%05d_%s_%dx", needleCounter++, id2cstr(haystack_map.at(result.graphId)->name), result.totalMatchesAfterLimits);
- map->modules_[newMod->name] = newMod;
+ map->add(newMod);
int portCounter = 1;
for (auto wire : wires) {