Added proper Design->addModule interface

This commit is contained in:
Clifford Wolf 2014-07-27 21:12:09 +02:00
parent 5da343b7de
commit c4bdba78cb
3 changed files with 43 additions and 4 deletions

View File

@ -1051,6 +1051,7 @@ RTLIL::IdString AstModule::derive(RTLIL::Design *design, std::map<RTLIL::IdStrin
RTLIL::Module *AstModule::clone() const RTLIL::Module *AstModule::clone() const
{ {
AstModule *new_mod = new AstModule; AstModule *new_mod = new AstModule;
new_mod->name = name;
cloneInto(new_mod); cloneInto(new_mod);
new_mod->ast = ast->clone(); new_mod->ast = ast->clone();

View File

@ -226,6 +226,39 @@ RTLIL::Design::~Design()
delete it->second; delete it->second;
} }
RTLIL::ObjRange<RTLIL::Module*> RTLIL::Design::modules()
{
return RTLIL::ObjRange<RTLIL::Module*>(&modules_, &refcount_modules_);
}
RTLIL::Module *RTLIL::Design::module(RTLIL::IdString name)
{
return modules_.count(name) ? modules_.at(name) : NULL;
}
void RTLIL::Design::add(RTLIL::Module *module)
{
assert(modules_.count(module->name) == 0);
assert(refcount_modules_ == 0);
modules_[module->name] = module;
}
RTLIL::Module *RTLIL::Design::addModule(RTLIL::IdString name)
{
assert(modules_.count(name) == 0);
assert(refcount_modules_ == 0);
modules_[name] = new RTLIL::Module;
modules_[name]->name = name;
return modules_[name];
}
void RTLIL::Design::remove(RTLIL::Module *module)
{
assert(modules_.at(module->name) == module);
modules_.erase(module->name);
delete module;
}
void RTLIL::Design::check() void RTLIL::Design::check()
{ {
#ifndef NDEBUG #ifndef NDEBUG
@ -412,7 +445,7 @@ namespace {
void check() void check()
{ {
if (cell->type[0] != '$' || cell->type.substr(0, 3) == "$__" || cell->type.substr(0, 8) == "$paramod" || if (cell->type[0] != '$' || cell->type.substr(0, 3) == "$__" || cell->type.substr(0, 8) == "$paramod" ||
cell->type.substr(0, 9) == "$verific$" || cell->type.substr(0, 7) == "$array:") cell->type.substr(0, 9) == "$verific$" || cell->type.substr(0, 7) == "$array:" || cell->type.substr(0, 8) == "$extern:")
return; return;
if (cell->type == "$not" || cell->type == "$pos" || cell->type == "$bu0" || cell->type == "$neg") { if (cell->type == "$not" || cell->type == "$pos" || cell->type == "$bu0" || cell->type == "$neg") {
@ -791,7 +824,6 @@ void RTLIL::Module::cloneInto(RTLIL::Module *new_mod) const
log_assert(new_mod->refcount_wires_ == 0); log_assert(new_mod->refcount_wires_ == 0);
log_assert(new_mod->refcount_cells_ == 0); log_assert(new_mod->refcount_cells_ == 0);
new_mod->name = name;
new_mod->connections_ = connections_; new_mod->connections_ = connections_;
new_mod->attributes = attributes; new_mod->attributes = attributes;
@ -828,6 +860,7 @@ void RTLIL::Module::cloneInto(RTLIL::Module *new_mod) const
RTLIL::Module *RTLIL::Module::clone() const RTLIL::Module *RTLIL::Module::clone() const
{ {
RTLIL::Module *new_mod = new RTLIL::Module; RTLIL::Module *new_mod = new RTLIL::Module;
new_mod->name = name;
cloneInto(new_mod); cloneInto(new_mod);
return new_mod; return new_mod;
} }
@ -1455,7 +1488,7 @@ void RTLIL::Cell::check()
void RTLIL::Cell::fixup_parameters(bool set_a_signed, bool set_b_signed) void RTLIL::Cell::fixup_parameters(bool set_a_signed, bool set_b_signed)
{ {
if (type[0] != '$' || type.substr(0, 2) == "$_" || type.substr(0, 8) == "$paramod" || if (type[0] != '$' || type.substr(0, 2) == "$_" || type.substr(0, 8) == "$paramod" ||
type.substr(0, 9) == "$verific$" || type.substr(0, 7) == "$array:") type.substr(0, 9) == "$verific$" || type.substr(0, 7) == "$array:" || type.substr(0, 8) == "$extern:")
return; return;
if (type == "$mux" || type == "$pmux" || type == "$safe_pmux") if (type == "$mux" || type == "$pmux" || type == "$safe_pmux")

View File

@ -350,7 +350,12 @@ struct RTLIL::Design
~Design(); ~Design();
RTLIL::ObjRange<RTLIL::Module*> modules() { return RTLIL::ObjRange<RTLIL::Module*>(&modules_, &refcount_modules_); } RTLIL::ObjRange<RTLIL::Module*> modules();
RTLIL::Module *module(RTLIL::IdString name);
void add(RTLIL::Module *module);
RTLIL::Module *addModule(RTLIL::IdString name);
void remove(RTLIL::Module *module);
void check(); void check();
void optimize(); void optimize();