2002-03-09 03:10:22 +01:00
|
|
|
/*
|
2010-05-13 03:53:56 +02:00
|
|
|
* Copyright (c) 2002-2010 Stephen Williams (steve@icarus.com)
|
2002-03-09 03:10:22 +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.
|
2002-03-09 03:10:22 +01:00
|
|
|
*/
|
|
|
|
|
|
2002-03-31 06:07:40 +02:00
|
|
|
# include "config.h"
|
2002-03-09 03:10:22 +01:00
|
|
|
# include "netlist.h"
|
2003-03-06 01:28:41 +01:00
|
|
|
# include "compiler.h"
|
2002-03-09 03:10:22 +01:00
|
|
|
# include "PExpr.h"
|
2002-03-31 06:07:40 +02:00
|
|
|
# include <iostream>
|
2002-03-09 03:10:22 +01:00
|
|
|
|
2005-03-18 03:56:03 +01:00
|
|
|
/*
|
|
|
|
|
* To make a NetUserFunc device, make as many pins as there are ports
|
|
|
|
|
* in the function. Get the port count from the function definition,
|
|
|
|
|
* which accounts for all the inputs, plus one for the phantom output
|
|
|
|
|
* that is the result.
|
|
|
|
|
*/
|
2010-05-13 03:53:56 +02:00
|
|
|
NetUserFunc::NetUserFunc(NetScope*s, perm_string n, NetScope*d,
|
|
|
|
|
NetEvWait*trigger__)
|
2005-03-18 03:56:03 +01:00
|
|
|
: NetNode(s, n, d->func_def()->port_count()+1),
|
2010-05-13 03:53:56 +02:00
|
|
|
def_(d), trigger_(trigger__)
|
2002-03-09 03:10:22 +01:00
|
|
|
{
|
2005-03-18 03:56:03 +01:00
|
|
|
pin(0).set_dir(Link::OUTPUT);
|
2002-03-09 03:10:22 +01:00
|
|
|
|
2005-03-18 03:56:03 +01:00
|
|
|
for (unsigned idx = 1 ; idx < pin_count() ; idx += 1) {
|
2002-03-09 03:10:22 +01:00
|
|
|
|
2005-03-18 03:56:03 +01:00
|
|
|
pin(idx).set_dir(Link::INPUT);
|
2010-03-16 23:16:53 +01:00
|
|
|
pin(idx).drive0(IVL_DR_HiZ);
|
|
|
|
|
pin(idx).drive1(IVL_DR_HiZ);
|
2002-03-09 03:10:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetUserFunc::~NetUserFunc()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-29 03:57:55 +01:00
|
|
|
ivl_variable_type_t NetUserFunc::data_type(unsigned port) const
|
|
|
|
|
{
|
2008-10-13 18:51:05 +02:00
|
|
|
NetFuncDef*fdef = def_->func_def();
|
2008-01-29 03:57:55 +01:00
|
|
|
|
|
|
|
|
/* Port 0 is the return port. */
|
|
|
|
|
if (port == 0) {
|
2008-10-13 18:51:05 +02:00
|
|
|
const NetNet*sig = fdef->return_sig();
|
2008-01-29 03:57:55 +01:00
|
|
|
assert(sig);
|
|
|
|
|
return sig->data_type();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port -= 1;
|
2008-10-13 18:51:05 +02:00
|
|
|
assert(port < fdef->port_count());
|
|
|
|
|
const NetNet*port_sig = fdef->port(port);
|
2008-01-29 03:57:55 +01:00
|
|
|
|
|
|
|
|
return port_sig->data_type();
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-09 03:10:22 +01:00
|
|
|
unsigned NetUserFunc::port_width(unsigned port) const
|
|
|
|
|
{
|
2008-10-13 18:51:05 +02:00
|
|
|
NetFuncDef*fdef = def_->func_def();
|
2002-03-09 03:10:22 +01:00
|
|
|
|
2004-06-01 01:34:36 +02:00
|
|
|
/* Port 0 is the return port. */
|
|
|
|
|
if (port == 0) {
|
2008-10-13 18:51:05 +02:00
|
|
|
const NetNet*sig = fdef->return_sig();
|
2004-06-01 01:34:36 +02:00
|
|
|
assert(sig);
|
2005-03-18 03:56:03 +01:00
|
|
|
return sig->vector_width();
|
2004-06-01 01:34:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port -= 1;
|
2008-10-13 18:51:05 +02:00
|
|
|
assert(port < fdef->port_count());
|
|
|
|
|
const NetNet*port_sig = fdef->port(port);
|
2002-03-09 03:10:22 +01:00
|
|
|
|
2005-03-18 03:56:03 +01:00
|
|
|
return port_sig->vector_width();
|
2002-03-09 03:10:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetScope* NetUserFunc::def() const
|
|
|
|
|
{
|
|
|
|
|
return def_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This method of the PECallFunction class checks that the parameters
|
|
|
|
|
* of the PECallFunction match the function definition. This is used
|
|
|
|
|
* during elaboration to validate the parameters before using them.
|
|
|
|
|
*/
|
|
|
|
|
bool PECallFunction::check_call_matches_definition_(Design*des, NetScope*dscope) const
|
|
|
|
|
{
|
|
|
|
|
assert(dscope);
|
|
|
|
|
|
|
|
|
|
/* How many parameters have I got? Normally the size of the
|
|
|
|
|
list is correct, but there is the special case of a list of
|
|
|
|
|
1 nil pointer. This is how the parser tells me of no
|
|
|
|
|
parameter. In other words, ``func()'' is 1 nil parameter. */
|
|
|
|
|
|
2008-07-27 23:22:19 +02:00
|
|
|
unsigned parms_count = parms_.size();
|
2002-03-09 03:10:22 +01:00
|
|
|
if ((parms_count == 1) && (parms_[0] == 0))
|
|
|
|
|
parms_count = 0;
|
|
|
|
|
|
|
|
|
|
if (dscope->type() != NetScope::FUNC) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: Attempt to call scope "
|
2007-06-02 05:42:12 +02:00
|
|
|
<< scope_path(dscope) << " as a function." << endl;
|
2002-03-09 03:10:22 +01:00
|
|
|
des->errors += 1;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
|
|
|
|
|
NetSysFunc::NetSysFunc(NetScope*s, perm_string n,
|
|
|
|
|
const struct sfunc_return_type*def,
|
2010-05-13 03:53:56 +02:00
|
|
|
unsigned ports, NetEvWait*trigger__)
|
|
|
|
|
: NetNode(s, n, ports), def_(def), trigger_(trigger__)
|
2006-06-18 06:15:50 +02:00
|
|
|
{
|
2008-09-11 04:34:28 +02:00
|
|
|
pin(0).set_dir(Link::OUTPUT); // Q
|
2006-06-18 06:15:50 +02:00
|
|
|
|
|
|
|
|
for (unsigned idx = 1 ; idx < pin_count() ; idx += 1) {
|
|
|
|
|
|
|
|
|
|
pin(idx).set_dir(Link::INPUT);
|
2010-03-16 23:16:53 +01:00
|
|
|
pin(idx).drive0(IVL_DR_HiZ);
|
|
|
|
|
pin(idx).drive1(IVL_DR_HiZ);
|
2006-06-18 06:15:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetSysFunc::~NetSysFunc()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char*NetSysFunc::func_name() const
|
|
|
|
|
{
|
|
|
|
|
return def_->name;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-09 03:54:55 +01:00
|
|
|
ivl_variable_type_t NetSysFunc::data_type() const
|
|
|
|
|
{
|
|
|
|
|
return def_->type;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
unsigned NetSysFunc::vector_width() const
|
|
|
|
|
{
|
|
|
|
|
return def_->wid;
|
|
|
|
|
}
|