Files
iverilog/Module.cc
T

158 lines
4.0 KiB
C++
Raw Normal View History

1998-11-03 23:28:49 +00:00
/*
2022-12-27 23:59:39 -08:00
* Copyright (c) 1998-2022 Stephen Williams ([email protected])
1998-11-03 23:28:49 +00:00
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2012-08-28 18:41:23 -07:00
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1998-11-03 23:28:49 +00:00
*/
# include "config.h"
1998-11-03 23:28:49 +00:00
# include "Module.h"
# include "PGate.h"
1998-11-03 23:28:49 +00:00
# include "PWire.h"
# include "ivl_assert.h"
1998-11-03 23:28:49 +00:00
using namespace std;
list<Module::named_expr_t> Module::user_defparms;
2003-03-06 04:37:12 +00:00
/* n is a permallocated string. */
Module::Module(LexicalScope*parent, perm_string n)
: PScopeExtra(n, parent)
1999-08-03 04:14:49 +00:00
{
2007-04-19 02:52:53 +00:00
library_flag = false;
is_cell = false;
2015-12-19 17:18:15 -08:00
is_interface = false;
2012-04-30 21:12:59 -07:00
program_block = false;
2009-05-27 13:41:54 -07:00
uc_drive = UCD_NONE;
1999-08-03 04:14:49 +00:00
}
Module::~Module()
{
}
1998-11-03 23:28:49 +00:00
void Module::add_gate(PGate*gate)
{
gates_.push_back(gate);
}
1999-08-03 04:14:49 +00:00
unsigned Module::port_count() const
{
2008-11-02 20:08:38 -08:00
return ports.size();
1999-08-03 04:14:49 +00:00
}
/*
* Return the array of PEIdent object that are at this port of the
* module. If the port is internally unconnected, return an empty
2004-10-04 01:10:51 +00:00
* array.
*/
2008-11-02 20:08:38 -08:00
const vector<PEIdent*>& Module::get_port(unsigned idx) const
1999-08-03 04:14:49 +00:00
{
ivl_assert(*this, idx < ports.size());
2008-11-02 20:08:38 -08:00
static const vector<PEIdent*> zero;
if (ports[idx])
return ports[idx]->expr;
else
2000-11-15 20:31:05 +00:00
return zero;
1999-08-03 04:14:49 +00:00
}
2004-02-20 06:22:56 +00:00
unsigned Module::find_port(const char*name) const
1999-08-03 04:14:49 +00:00
{
ivl_assert(*this, name != 0);
2008-11-02 20:08:38 -08:00
for (unsigned idx = 0 ; idx < ports.size() ; idx += 1) {
if (ports[idx] == 0) {
/* It is possible to have undeclared ports. These
are ports that are skipped in the declaration,
for example like so: module foo(x ,, y); The
port between x and y is unnamed and thus
inaccessible to binding by name. */
continue;
}
ivl_assert(*this, ports[idx]);
if (ports[idx]->name == name)
1999-08-03 04:14:49 +00:00
return idx;
}
1999-08-03 04:14:49 +00:00
2008-11-02 20:08:38 -08:00
return ports.size();
1999-08-03 04:14:49 +00:00
}
perm_string Module::get_port_name(unsigned idx) const
{
ivl_assert(*this, idx < ports.size());
if (ports[idx] == 0 || ports[idx]->name.str() == 0) {
/* It is possible to have undeclared ports. These
are ports that are skipped in the declaration,
for example like so: module foo(x ,, y); The
port between x and y is unnamed and thus
inaccessible to binding by name. Port references
that aren't simple or escaped identifiers are
also inaccessible to binding by name. */
return perm_string::literal("unnamed");
}
return ports[idx]->name;
}
PExpr* Module::get_port_default_value(unsigned idx) const
{
ivl_assert(*this, idx < ports.size());
return ports[idx] ? ports[idx]->default_value : 0;
}
1999-08-03 04:14:49 +00:00
2004-02-18 17:11:54 +00:00
PGate* Module::get_gate(perm_string name)
{
for (list<PGate*>::iterator cur = gates_.begin()
; cur != gates_.end() ; ++ cur ) {
if ((*cur)->get_name() == name)
return *cur;
}
return 0;
}
2000-03-12 17:09:40 +00:00
const list<PGate*>& Module::get_gates() const
{
return gates_;
}
PNamedItem::SymbolType Module::symbol_type() const
{
if (program_block)
return PROGRAM;
if (is_interface)
return INTERFACE;
return MODULE;
}
2022-02-10 14:03:46 +01:00
bool Module::can_be_toplevel() const
{
// Don't choose library modules.
if (library_flag)
return false;
// Don't choose modules with parameters without default value
for (std::map<perm_string,param_expr_t*>::const_iterator cur =
2022-12-27 23:59:39 -08:00
parameters.begin(); cur != parameters.end(); ++cur) {
2022-02-10 14:03:46 +01:00
if (cur->second->expr == 0)
return false;
}
return true;
}