Support integer for function return value.
This commit is contained in:
parent
4b174fd996
commit
c200c0c20e
22
parse.y
22
parse.y
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT) && !defined(macintosh)
|
||||
#ident "$Id: parse.y,v 1.139 2001/12/03 04:47:15 steve Exp $"
|
||||
#ident "$Id: parse.y,v 1.140 2001/12/07 05:03:13 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "config.h"
|
||||
|
|
@ -80,6 +80,8 @@ static struct str_pair_t decl_strength = { PGate::STRONG, PGate::STRONG };
|
|||
Statement*statement;
|
||||
svector<Statement*>*statement_list;
|
||||
|
||||
struct { svector<PExpr*>*range; NetNet::Type ntype; } range_type;
|
||||
|
||||
struct { svector<PExpr*>*range; svector<PExpr*>*delay; } range_delay;
|
||||
net_decl_assign_t*net_decl_assign;
|
||||
|
||||
|
|
@ -159,7 +161,7 @@ static struct str_pair_t decl_strength = { PGate::STRONG, PGate::STRONG };
|
|||
%type <porttype> port_type
|
||||
%type <parmvalue> parameter_value_opt
|
||||
|
||||
%type <exprs> range_or_type_opt
|
||||
%type <range_type> range_or_type_opt
|
||||
%type <event_expr> event_expression_list
|
||||
%type <event_expr> event_expression
|
||||
%type <event_statement> event_control
|
||||
|
|
@ -1331,7 +1333,7 @@ module_item
|
|||
tmp->set_lineno(@1.first_line);
|
||||
tmp->set_ports($6);
|
||||
tmp->set_statement($7);
|
||||
pform_set_function($3, $2, tmp);
|
||||
pform_set_function($3, $2.ntype, $2.range, tmp);
|
||||
pform_pop_scope();
|
||||
delete $3;
|
||||
}
|
||||
|
|
@ -1791,14 +1793,14 @@ range_opt
|
|||
| { $$ = 0; }
|
||||
;
|
||||
|
||||
/* This is used to express the retur type of a function. */
|
||||
/* This is used to express the return type of a function. */
|
||||
range_or_type_opt
|
||||
: range { $$ = $1; }
|
||||
| K_integer { $$ = 0; }
|
||||
| K_real { $$ = 0; }
|
||||
| K_realtime { $$ = 0; }
|
||||
| K_time { $$ = 0; }
|
||||
| { $$ = 0; }
|
||||
: range { $$.range = $1; $$.ntype = NetNet::REG; }
|
||||
| K_integer { $$.range = 0; $$.ntype = NetNet::IMPLICIT_REG; }
|
||||
| K_real { $$.range = 0; $$.ntype = NetNet::IMPLICIT; }
|
||||
| K_realtime { $$.range = 0; $$.ntype = NetNet::IMPLICIT; }
|
||||
| K_time { $$.range = 0; $$.ntype = NetNet::IMPLICIT; }
|
||||
| { $$.range = 0; $$.ntype = NetNet::IMPLICIT; }
|
||||
;
|
||||
|
||||
/* The register_variable rule is matched only when I am parsing
|
||||
|
|
|
|||
31
pform.cc
31
pform.cc
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT) && !defined(macintosh)
|
||||
#ident "$Id: pform.cc,v 1.86 2001/12/03 04:47:15 steve Exp $"
|
||||
#ident "$Id: pform.cc,v 1.87 2001/12/07 05:03:13 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "config.h"
|
||||
|
|
@ -907,16 +907,38 @@ void pform_set_task(const string&name, PTask*task)
|
|||
* with the trappings that are discovered after the basic function
|
||||
* name is parsed.
|
||||
*/
|
||||
void pform_set_function(const char*name, svector<PExpr*>*ra, PFunction *func)
|
||||
void pform_set_function(const char*name, NetNet::Type ntype,
|
||||
svector<PExpr*>*ra, PFunction *func)
|
||||
{
|
||||
if (ntype == NetNet::IMPLICIT)
|
||||
ntype = NetNet::REG;
|
||||
|
||||
/* Form into path_return a hierarchical name for the synthetic
|
||||
return value for the function. The return value is the same
|
||||
name as the function, so if the function name is "foo", the
|
||||
wire is "foo.foo". */
|
||||
hname_t path_return (name);
|
||||
path_return.append(name);
|
||||
PWire*out = new PWire(path_return, NetNet::REG, NetNet::POUTPUT);
|
||||
|
||||
PWire*out = new PWire(path_return, ntype, NetNet::POUTPUT);
|
||||
if (ra) {
|
||||
assert(ra->count() == 2);
|
||||
out->set_range((*ra)[0], (*ra)[1]);
|
||||
delete ra;
|
||||
}
|
||||
|
||||
/* If the return type of the function is INTEGER, then convert
|
||||
it to a signed reg, and generate a range for it. The
|
||||
parse.y uses IMPLICIT_REG as a signal that this is an
|
||||
integer, because there is no such thing as
|
||||
NetNet::INTEGER. */
|
||||
if (ntype == NetNet::IMPLICIT_REG) {
|
||||
out->set_wire_type(NetNet::REG);
|
||||
out->set_signed(true);
|
||||
out->set_range(new PENumber(new verinum(INTEGER_WIDTH-1, INTEGER_WIDTH)),
|
||||
new PENumber(new verinum(0UL, INTEGER_WIDTH)));
|
||||
}
|
||||
|
||||
pform_cur_module->add_wire(out);
|
||||
func->set_output(out);
|
||||
pform_cur_module->add_function(name, func);
|
||||
|
|
@ -1136,6 +1158,9 @@ int pform_parse(const char*path, FILE*file)
|
|||
|
||||
/*
|
||||
* $Log: pform.cc,v $
|
||||
* Revision 1.87 2001/12/07 05:03:13 steve
|
||||
* Support integer for function return value.
|
||||
*
|
||||
* Revision 1.86 2001/12/03 04:47:15 steve
|
||||
* Parser and pform use hierarchical names as hname_t
|
||||
* objects instead of encoded strings.
|
||||
|
|
|
|||
8
pform.h
8
pform.h
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT) && !defined(macintosh)
|
||||
#ident "$Id: pform.h,v 1.53 2001/12/03 04:47:15 steve Exp $"
|
||||
#ident "$Id: pform.h,v 1.54 2001/12/07 05:03:13 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "netlist.h"
|
||||
|
|
@ -159,7 +159,8 @@ extern void pform_set_reg_idx(const char*name, PExpr*l, PExpr*r);
|
|||
extern void pform_set_reg_integer(list<char*>*names);
|
||||
extern void pform_set_reg_time(list<char*>*names);
|
||||
extern void pform_set_task(const string&, PTask*);
|
||||
extern void pform_set_function(const char*, svector<PExpr*>*, PFunction*);
|
||||
extern void pform_set_function(const char*, NetNet::Type,
|
||||
svector<PExpr*>*, PFunction*);
|
||||
extern void pform_set_attrib(const char*name, const string&key,
|
||||
const string&value);
|
||||
extern void pform_set_type_attrib(const string&name, const string&key,
|
||||
|
|
@ -217,6 +218,9 @@ extern void pform_dump(ostream&out, Module*mod);
|
|||
|
||||
/*
|
||||
* $Log: pform.h,v $
|
||||
* Revision 1.54 2001/12/07 05:03:13 steve
|
||||
* Support integer for function return value.
|
||||
*
|
||||
* Revision 1.53 2001/12/03 04:47:15 steve
|
||||
* Parser and pform use hierarchical names as hname_t
|
||||
* objects instead of encoded strings.
|
||||
|
|
|
|||
Loading…
Reference in New Issue