Support integer for function return value.

This commit is contained in:
steve 2001-12-07 05:03:13 +00:00
parent 4b174fd996
commit c200c0c20e
3 changed files with 46 additions and 15 deletions

22
parse.y
View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) && !defined(macintosh) #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 #endif
# include "config.h" # include "config.h"
@ -80,6 +80,8 @@ static struct str_pair_t decl_strength = { PGate::STRONG, PGate::STRONG };
Statement*statement; Statement*statement;
svector<Statement*>*statement_list; svector<Statement*>*statement_list;
struct { svector<PExpr*>*range; NetNet::Type ntype; } range_type;
struct { svector<PExpr*>*range; svector<PExpr*>*delay; } range_delay; struct { svector<PExpr*>*range; svector<PExpr*>*delay; } range_delay;
net_decl_assign_t*net_decl_assign; 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 <porttype> port_type
%type <parmvalue> parameter_value_opt %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_list
%type <event_expr> event_expression %type <event_expr> event_expression
%type <event_statement> event_control %type <event_statement> event_control
@ -1331,7 +1333,7 @@ module_item
tmp->set_lineno(@1.first_line); tmp->set_lineno(@1.first_line);
tmp->set_ports($6); tmp->set_ports($6);
tmp->set_statement($7); tmp->set_statement($7);
pform_set_function($3, $2, tmp); pform_set_function($3, $2.ntype, $2.range, tmp);
pform_pop_scope(); pform_pop_scope();
delete $3; delete $3;
} }
@ -1791,14 +1793,14 @@ range_opt
| { $$ = 0; } | { $$ = 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_or_type_opt
: range { $$ = $1; } : range { $$.range = $1; $$.ntype = NetNet::REG; }
| K_integer { $$ = 0; } | K_integer { $$.range = 0; $$.ntype = NetNet::IMPLICIT_REG; }
| K_real { $$ = 0; } | K_real { $$.range = 0; $$.ntype = NetNet::IMPLICIT; }
| K_realtime { $$ = 0; } | K_realtime { $$.range = 0; $$.ntype = NetNet::IMPLICIT; }
| K_time { $$ = 0; } | K_time { $$.range = 0; $$.ntype = NetNet::IMPLICIT; }
| { $$ = 0; } | { $$.range = 0; $$.ntype = NetNet::IMPLICIT; }
; ;
/* The register_variable rule is matched only when I am parsing /* The register_variable rule is matched only when I am parsing

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) && !defined(macintosh) #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 #endif
# include "config.h" # 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 * with the trappings that are discovered after the basic function
* name is parsed. * 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); hname_t path_return (name);
path_return.append(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) { if (ra) {
assert(ra->count() == 2); assert(ra->count() == 2);
out->set_range((*ra)[0], (*ra)[1]); out->set_range((*ra)[0], (*ra)[1]);
delete ra; 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); pform_cur_module->add_wire(out);
func->set_output(out); func->set_output(out);
pform_cur_module->add_function(name, func); pform_cur_module->add_function(name, func);
@ -1136,6 +1158,9 @@ int pform_parse(const char*path, FILE*file)
/* /*
* $Log: pform.cc,v $ * $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 * Revision 1.86 2001/12/03 04:47:15 steve
* Parser and pform use hierarchical names as hname_t * Parser and pform use hierarchical names as hname_t
* objects instead of encoded strings. * objects instead of encoded strings.

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) && !defined(macintosh) #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 #endif
# include "netlist.h" # 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_integer(list<char*>*names);
extern void pform_set_reg_time(list<char*>*names); extern void pform_set_reg_time(list<char*>*names);
extern void pform_set_task(const string&, PTask*); 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, extern void pform_set_attrib(const char*name, const string&key,
const string&value); const string&value);
extern void pform_set_type_attrib(const string&name, const string&key, 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 $ * $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 * Revision 1.53 2001/12/03 04:47:15 steve
* Parser and pform use hierarchical names as hname_t * Parser and pform use hierarchical names as hname_t
* objects instead of encoded strings. * objects instead of encoded strings.