1998-11-04 00:28:49 +01:00
|
|
|
/*
|
2008-03-04 05:49:52 +01:00
|
|
|
* Copyright (c) 1998-2008 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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
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"
|
2000-01-09 21:37:57 +01:00
|
|
|
# include <assert.h>
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2003-03-06 05:37:12 +01:00
|
|
|
/* n is a permallocated string. */
|
2004-02-18 18:11:54 +01:00
|
|
|
Module::Module(perm_string n)
|
2008-02-16 06:20:24 +01:00
|
|
|
: PScope(n, 0)
|
1999-08-03 06:14:49 +02:00
|
|
|
{
|
2007-04-19 04:52:53 +02:00
|
|
|
library_flag = false;
|
2004-06-13 06:56:53 +02:00
|
|
|
default_nettype = NetNet::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);
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-18 18:11:54 +01:00
|
|
|
void Module::add_task(perm_string name, PTask*task)
|
1999-07-03 04:12:51 +02:00
|
|
|
{
|
|
|
|
|
tasks_[name] = task;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-18 18:11:54 +01:00
|
|
|
void Module::add_function(perm_string name, PFunction *func)
|
1999-07-31 21:14:47 +02:00
|
|
|
{
|
|
|
|
|
funcs_[name] = func;
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-03 06:14:49 +02:00
|
|
|
unsigned Module::port_count() const
|
|
|
|
|
{
|
2002-05-20 01:37:28 +02:00
|
|
|
return ports.count();
|
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
|
|
|
*/
|
2000-05-16 06:05:15 +02:00
|
|
|
const svector<PEIdent*>& Module::get_port(unsigned idx) const
|
1999-08-03 06:14:49 +02:00
|
|
|
{
|
2002-05-20 01:37:28 +02:00
|
|
|
assert(idx < ports.count());
|
2000-11-15 21:31:05 +01:00
|
|
|
static svector<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);
|
2003-04-02 05:00:14 +02:00
|
|
|
for (unsigned idx = 0 ; idx < ports.count() ; 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;
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2002-05-20 01:37:28 +02:00
|
|
|
return ports.count();
|
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()
|
|
|
|
|
; cur != gates_.end()
|
|
|
|
|
; cur ++ ) {
|
|
|
|
|
|
|
|
|
|
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_;
|
|
|
|
|
}
|
|
|
|
|
|