1998-11-04 00:28:49 +01:00
|
|
|
/*
|
2017-11-05 18:50:05 +01:00
|
|
|
* Copyright (c) 1998-2017 Stephen Williams (steve@icarus.com)
|
1998-11-04 00:28:49 +01: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-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1998-11-04 00:28:49 +01:00
|
|
|
*/
|
|
|
|
|
|
2001-07-25 05:10:48 +02:00
|
|
|
# include "config.h"
|
|
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
# include "Module.h"
|
1999-12-11 06:45:41 +01:00
|
|
|
# include "PGate.h"
|
1998-11-04 00:28:49 +01:00
|
|
|
# include "PWire.h"
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cassert>
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2009-08-06 23:42:13 +02:00
|
|
|
list<Module::named_expr_t> Module::user_defparms;
|
|
|
|
|
|
2003-03-06 05:37:12 +01:00
|
|
|
/* n is a permallocated string. */
|
2012-05-10 04:35:11 +02:00
|
|
|
Module::Module(LexicalScope*parent, perm_string n)
|
|
|
|
|
: PScopeExtra(n, parent)
|
1999-08-03 06:14:49 +02:00
|
|
|
{
|
2007-04-19 04:52:53 +02:00
|
|
|
library_flag = false;
|
2009-05-21 23:41:58 +02:00
|
|
|
is_cell = false;
|
2015-12-20 02:18:15 +01:00
|
|
|
is_interface = false;
|
2012-05-01 06:12:59 +02:00
|
|
|
program_block = false;
|
2009-05-27 22:41:54 +02:00
|
|
|
uc_drive = UCD_NONE;
|
1999-08-03 06:14:49 +02:00
|
|
|
}
|
|
|
|
|
|
2001-10-20 07:21:51 +02:00
|
|
|
Module::~Module()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
void Module::add_gate(PGate*gate)
|
|
|
|
|
{
|
|
|
|
|
gates_.push_back(gate);
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-03 06:14:49 +02:00
|
|
|
unsigned Module::port_count() const
|
|
|
|
|
{
|
2008-11-03 05:08:38 +01:00
|
|
|
return ports.size();
|
1999-08-03 06:14:49 +02:00
|
|
|
}
|
|
|
|
|
|
2000-11-05 07:05:59 +01: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 03:10:51 +02:00
|
|
|
* array.
|
2000-11-05 07:05:59 +01:00
|
|
|
*/
|
2008-11-03 05:08:38 +01:00
|
|
|
const vector<PEIdent*>& Module::get_port(unsigned idx) const
|
1999-08-03 06:14:49 +02:00
|
|
|
{
|
2008-11-03 05:08:38 +01:00
|
|
|
assert(idx < ports.size());
|
|
|
|
|
static const vector<PEIdent*> zero;
|
2000-11-05 07:05:59 +01:00
|
|
|
|
2002-05-20 01:37:28 +02:00
|
|
|
if (ports[idx])
|
|
|
|
|
return ports[idx]->expr;
|
2000-11-05 07:05:59 +01:00
|
|
|
else
|
2000-11-15 21:31:05 +01:00
|
|
|
return zero;
|
1999-08-03 06:14:49 +02:00
|
|
|
}
|
|
|
|
|
|
2004-02-20 07:22:56 +01:00
|
|
|
unsigned Module::find_port(const char*name) const
|
1999-08-03 06:14:49 +02:00
|
|
|
{
|
2007-09-21 02:20:48 +02:00
|
|
|
assert(name != 0);
|
2008-11-03 05:08:38 +01:00
|
|
|
for (unsigned idx = 0 ; idx < ports.size() ; idx += 1) {
|
2003-04-02 05:00:14 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
assert(ports[idx]);
|
2002-05-20 01:37:28 +02:00
|
|
|
if (ports[idx]->name == name)
|
1999-08-03 06:14:49 +02:00
|
|
|
return idx;
|
2003-04-02 05:00:14 +02:00
|
|
|
}
|
1999-08-03 06:14:49 +02:00
|
|
|
|
2008-11-03 05:08:38 +01:00
|
|
|
return ports.size();
|
1999-08-03 06:14:49 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-04 21:43:33 +02:00
|
|
|
perm_string Module::get_port_name(unsigned idx) const
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
assert(idx < ports.size());
|
2015-07-11 00:02:27 +02:00
|
|
|
if (ports[idx] == 0 || ports[idx]->name.str() == 0) {
|
2012-06-04 21:43:33 +02:00
|
|
|
/* 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
|
2015-07-11 00:02:27 +02:00
|
|
|
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");
|
2012-06-04 21:43:33 +02:00
|
|
|
}
|
|
|
|
|
return ports[idx]->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-08-03 06:14:49 +02:00
|
|
|
|
2004-02-18 18:11:54 +01:00
|
|
|
PGate* Module::get_gate(perm_string name)
|
1999-12-11 06:45:41 +01:00
|
|
|
{
|
|
|
|
|
for (list<PGate*>::iterator cur = gates_.begin()
|
2010-10-23 23:57:59 +02:00
|
|
|
; cur != gates_.end() ; ++ cur ) {
|
1999-12-11 06:45:41 +01:00
|
|
|
|
|
|
|
|
if ((*cur)->get_name() == name)
|
|
|
|
|
return *cur;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-12 18:09:40 +01:00
|
|
|
const list<PGate*>& Module::get_gates() const
|
|
|
|
|
{
|
|
|
|
|
return gates_;
|
|
|
|
|
}
|