2 * Copyright (c) 2002-2004 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 # include "compiler.h"
27 * To make a NetUserFunc device, make as many pins as there are ports
28 * in the function. Get the port count from the function definition,
29 * which accounts for all the inputs, plus one for the phantom output
32 NetUserFunc::NetUserFunc(NetScope
*s
, perm_string n
, NetScope
*d
)
33 : NetNode(s
, n
, d
->func_def()->port_count()+1),
36 pin(0).set_dir(Link::OUTPUT
);
37 pin(0).set_name(def_
->basename(), 0);
39 for (unsigned idx
= 1 ; idx
< pin_count() ; idx
+= 1) {
41 pin(idx
).set_dir(Link::INPUT
);
42 pin(idx
).set_name(perm_string::literal("D"), idx
-1);
43 pin(idx
).drive0(Link::HIGHZ
);
44 pin(idx
).drive1(Link::HIGHZ
);
48 NetUserFunc::~NetUserFunc()
52 ivl_variable_type_t
NetUserFunc::data_type(unsigned port
) const
54 NetFuncDef
*def
= def_
->func_def();
56 /* Port 0 is the return port. */
58 const NetNet
*sig
= def
->return_sig();
60 return sig
->data_type();
64 assert(port
< def
->port_count());
65 const NetNet
*port_sig
= def
->port(port
);
67 return port_sig
->data_type();
70 unsigned NetUserFunc::port_width(unsigned port
) const
72 NetFuncDef
*def
= def_
->func_def();
74 /* Port 0 is the return port. */
76 const NetNet
*sig
= def
->return_sig();
78 return sig
->vector_width();
82 assert(port
< def
->port_count());
83 const NetNet
*port_sig
= def
->port(port
);
85 return port_sig
->vector_width();
88 const NetScope
* NetUserFunc::def() const
94 * This method of the PECallFunction class checks that the parameters
95 * of the PECallFunction match the function definition. This is used
96 * during elaboration to validate the parameters before using them.
98 bool PECallFunction::check_call_matches_definition_(Design
*des
, NetScope
*dscope
) const
102 /* How many parameters have I got? Normally the size of the
103 list is correct, but there is the special case of a list of
104 1 nil pointer. This is how the parser tells me of no
105 parameter. In other words, ``func()'' is 1 nil parameter. */
107 unsigned parms_count
= parms_
.count();
108 if ((parms_count
== 1) && (parms_
[0] == 0))
111 if (dscope
->type() != NetScope::FUNC
) {
112 cerr
<< get_fileline() << ": error: Attempt to call scope "
113 << scope_path(dscope
) << " as a function." << endl
;
118 if (parms_count
!= dscope
->func_def()->port_count()) {
119 cerr
<< get_fileline() << ": error: Function " << scope_path(dscope
)
120 << " expects " << (dscope
->func_def()->port_count())
121 << " arguments, you passed " << parms_count
<< "."
131 NetSysFunc::NetSysFunc(NetScope
*s
, perm_string n
,
132 const struct sfunc_return_type
*def
,
134 : NetNode(s
, n
, ports
)
138 pin(0).set_dir(Link::OUTPUT
);
139 pin(0).set_name(perm_string::literal("Q"), 0);
141 for (unsigned idx
= 1 ; idx
< pin_count() ; idx
+= 1) {
143 pin(idx
).set_dir(Link::INPUT
);
144 pin(idx
).set_name(perm_string::literal("D"), idx
-1);
145 pin(idx
).drive0(Link::HIGHZ
);
146 pin(idx
).drive1(Link::HIGHZ
);
150 NetSysFunc::~NetSysFunc()
154 const char*NetSysFunc::func_name() const
159 ivl_variable_type_t
NetSysFunc::data_type() const
164 unsigned NetSysFunc::vector_width() const