elaborate some aspects of functions.
This commit is contained in:
parent
648e4c68e4
commit
23acca48ff
37
PFunction.cc
37
PFunction.cc
|
|
@ -1,10 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 1999 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: PFunction.cc,v 1.2 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
#include "PTask.h"
|
||||
|
||||
PFunction::PFunction(svector<PWire*>*p, Statement*s)
|
||||
: ports_(p), statement_(s)
|
||||
: out_(0), ports_(p), statement_(s)
|
||||
{
|
||||
}
|
||||
|
||||
PFunction::~PFunction()
|
||||
{
|
||||
}
|
||||
|
||||
void PFunction::set_output(PWire*o)
|
||||
{
|
||||
assert(out_ == 0);
|
||||
out_ = o;
|
||||
}
|
||||
|
||||
/*
|
||||
* $Log: PFunction.cc,v $
|
||||
* Revision 1.2 1999/08/25 22:22:41 steve
|
||||
* elaborate some aspects of functions.
|
||||
*
|
||||
*/
|
||||
|
|
|
|||
22
PTask.h
22
PTask.h
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: PTask.h,v 1.3 1999/07/31 19:14:47 steve Exp $"
|
||||
#ident "$Id: PTask.h,v 1.4 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "LineInfo.h"
|
||||
|
|
@ -50,21 +50,33 @@ class PTask : public LineInfo {
|
|||
PTask& operator=(const PTask&);
|
||||
};
|
||||
|
||||
/*
|
||||
* The function is similar to a task (in this context) but there is a
|
||||
* single output port and a set of input ports. The output port is the
|
||||
* function return value.
|
||||
*/
|
||||
class PFunction : public LineInfo {
|
||||
public:
|
||||
explicit PFunction(svector<PWire *> *p, Statement *s);
|
||||
|
||||
public:
|
||||
explicit PFunction(svector<PWire *>*p, Statement *s);
|
||||
~PFunction();
|
||||
|
||||
//virtual void elaborate(Design *des, const string &path) const {}
|
||||
void set_output(PWire*);
|
||||
|
||||
virtual void elaborate(Design *des, const string &path) const;
|
||||
void dump(ostream&, unsigned) const;
|
||||
|
||||
private:
|
||||
private:
|
||||
PWire*out_;
|
||||
svector<PWire *> *ports_;
|
||||
Statement *statement_;
|
||||
};
|
||||
|
||||
/*
|
||||
* $Log: PTask.h,v $
|
||||
* Revision 1.4 1999/08/25 22:22:41 steve
|
||||
* elaborate some aspects of functions.
|
||||
*
|
||||
* Revision 1.3 1999/07/31 19:14:47 steve
|
||||
* Add functions up to elaboration (Ed Carter)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: design_dump.cc,v 1.34 1999/08/01 16:34:50 steve Exp $"
|
||||
#ident "$Id: design_dump.cc,v 1.35 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -423,6 +423,12 @@ void NetForever::dump(ostream&o, unsigned ind) const
|
|||
statement_->dump(o, ind+2);
|
||||
}
|
||||
|
||||
void NetFuncDef::dump(ostream&o, unsigned ind) const
|
||||
{
|
||||
o << setw(ind) << "" << "function " << name_ << endl;
|
||||
statement_->dump(o, ind+2);
|
||||
}
|
||||
|
||||
void NetPDelay::dump(ostream&o, unsigned ind) const
|
||||
{
|
||||
o << setw(ind) << "" << "#" << delay_;
|
||||
|
|
@ -690,6 +696,9 @@ void Design::dump(ostream&o) const
|
|||
|
||||
/*
|
||||
* $Log: design_dump.cc,v $
|
||||
* Revision 1.35 1999/08/25 22:22:41 steve
|
||||
* elaborate some aspects of functions.
|
||||
*
|
||||
* Revision 1.34 1999/08/01 16:34:50 steve
|
||||
* Parse and elaborate rise/fall/decay times
|
||||
* for gates, and handle the rules for partial
|
||||
|
|
|
|||
24
elaborate.cc
24
elaborate.cc
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: elaborate.cc,v 1.72 1999/08/23 16:48:39 steve Exp $"
|
||||
#ident "$Id: elaborate.cc,v 1.73 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -1866,6 +1866,17 @@ NetProc* PForStatement::elaborate(Design*des, const string&path) const
|
|||
return top;
|
||||
}
|
||||
|
||||
void PFunction::elaborate(Design*des, const string&path) const
|
||||
{
|
||||
NetProc*st = statement_->elaborate(des, path);
|
||||
NetFuncDef*def = new NetFuncDef(path, st);
|
||||
des->add_function(path, def);
|
||||
|
||||
cerr << get_line() << ": Sorry, unable to elaborate "
|
||||
"function definitions." << endl;
|
||||
des->errors += 1;
|
||||
}
|
||||
|
||||
NetProc* PRepeat::elaborate(Design*des, const string&path) const
|
||||
{
|
||||
NetExpr*expr = expr_->elaborate_expr(des, path);
|
||||
|
|
@ -1985,6 +1996,14 @@ bool Module::elaborate(Design*des, const string&path, svector<PExpr*>*overrides_
|
|||
(*wt)->elaborate(des, path);
|
||||
}
|
||||
|
||||
// Elaborate functions.
|
||||
typedef map<string,PFunction*>::const_iterator mfunc_it_t;
|
||||
for (mfunc_it_t cur = funcs_.begin()
|
||||
; cur != funcs_.end() ; cur ++) {
|
||||
string pname = path + "." + (*cur).first;
|
||||
(*cur).second->elaborate(des, pname);
|
||||
}
|
||||
|
||||
// Elaborate the task definitions. This is done before the
|
||||
// behaviors so that task calls may reference these, and after
|
||||
// the signals so that the tasks can reference them.
|
||||
|
|
@ -2070,6 +2089,9 @@ Design* elaborate(const map<string,Module*>&modules,
|
|||
|
||||
/*
|
||||
* $Log: elaborate.cc,v $
|
||||
* Revision 1.73 1999/08/25 22:22:41 steve
|
||||
* elaborate some aspects of functions.
|
||||
*
|
||||
* Revision 1.72 1999/08/23 16:48:39 steve
|
||||
* Parameter overrides support from Peter Monta
|
||||
* AND and XOR support wide expressions.
|
||||
|
|
|
|||
19
netlist.cc
19
netlist.cc
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: netlist.cc,v 1.52 1999/08/06 04:05:28 steve Exp $"
|
||||
#ident "$Id: netlist.cc,v 1.53 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include <cassert>
|
||||
|
|
@ -482,6 +482,15 @@ NetProc* NetCondit::else_clause()
|
|||
return else_;
|
||||
}
|
||||
|
||||
NetFuncDef::NetFuncDef(const string&n, NetProc*st)
|
||||
: name_(n), statement_(st)
|
||||
{
|
||||
}
|
||||
|
||||
NetFuncDef::~NetFuncDef()
|
||||
{
|
||||
}
|
||||
|
||||
NetNEvent::NetNEvent(const string&ev, unsigned wid, Type e, NetPEvent*pe)
|
||||
: NetNode(ev, wid), sref<NetPEvent,NetNEvent>(pe), edge_(e)
|
||||
{
|
||||
|
|
@ -1439,6 +1448,11 @@ NetMemory* Design::find_memory(const string&key)
|
|||
return (*cur).second;
|
||||
}
|
||||
|
||||
void Design::add_function(const string&key, NetFuncDef*def)
|
||||
{
|
||||
funcs_[key] = def;
|
||||
}
|
||||
|
||||
void Design::add_task(const string&key, NetTaskDef*def)
|
||||
{
|
||||
tasks_[key] = def;
|
||||
|
|
@ -1571,6 +1585,9 @@ NetNet* Design::find_signal(bool (*func)(const NetNet*))
|
|||
|
||||
/*
|
||||
* $Log: netlist.cc,v $
|
||||
* Revision 1.53 1999/08/25 22:22:41 steve
|
||||
* elaborate some aspects of functions.
|
||||
*
|
||||
* Revision 1.52 1999/08/06 04:05:28 steve
|
||||
* Handle scope of parameters.
|
||||
*
|
||||
|
|
|
|||
24
netlist.h
24
netlist.h
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: netlist.h,v 1.56 1999/08/18 04:00:02 steve Exp $"
|
||||
#ident "$Id: netlist.h,v 1.57 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -758,6 +758,19 @@ class NetForever : public NetProc {
|
|||
NetProc*statement_;
|
||||
};
|
||||
|
||||
class NetFuncDef {
|
||||
|
||||
public:
|
||||
explicit NetFuncDef(const string&, NetProc*st);
|
||||
~NetFuncDef();
|
||||
|
||||
virtual void dump(ostream&, unsigned ind) const;
|
||||
|
||||
private:
|
||||
string name_;
|
||||
NetProc*statement_;
|
||||
};
|
||||
|
||||
class NetPDelay : public NetProc {
|
||||
|
||||
public:
|
||||
|
|
@ -1339,6 +1352,9 @@ class Design {
|
|||
void add_memory(NetMemory*);
|
||||
NetMemory* find_memory(const string&name);
|
||||
|
||||
// Functions
|
||||
void add_function(const string&n, NetFuncDef*);
|
||||
|
||||
// Tasks
|
||||
void add_task(const string&n, NetTaskDef*);
|
||||
NetTaskDef* find_task(const string&key);
|
||||
|
|
@ -1379,6 +1395,9 @@ class Design {
|
|||
|
||||
map<string,NetMemory*> memories_;
|
||||
|
||||
// List the function definitions in the design.
|
||||
map<string,NetFuncDef*> funcs_;
|
||||
|
||||
// List the task definitions in the design.
|
||||
map<string,NetTaskDef*> tasks_;
|
||||
|
||||
|
|
@ -1440,6 +1459,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
|
|||
|
||||
/*
|
||||
* $Log: netlist.h,v $
|
||||
* Revision 1.57 1999/08/25 22:22:41 steve
|
||||
* elaborate some aspects of functions.
|
||||
*
|
||||
* Revision 1.56 1999/08/18 04:00:02 steve
|
||||
* Fixup spelling and some error messages. <LRDoolittle@lbl.gov>
|
||||
*
|
||||
|
|
|
|||
17
parse.y
17
parse.y
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: parse.y,v 1.59 1999/08/23 16:48:39 steve Exp $"
|
||||
#ident "$Id: parse.y,v 1.60 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "parse_misc.h"
|
||||
|
|
@ -137,6 +137,7 @@ extern void lex_end_table();
|
|||
|
||||
%type <task> task_body
|
||||
%type <function> func_body
|
||||
%type <exprs> range_or_type_opt
|
||||
%type <event_expr> event_expression
|
||||
%type <event_statement> event_control
|
||||
%type <statement> statement statement_opt
|
||||
|
|
@ -1028,7 +1029,7 @@ module_item
|
|||
{ PFunction *tmp = $6;
|
||||
tmp->set_file(@1.text);
|
||||
tmp->set_lineno(@1.first_line);
|
||||
pform_set_function($3, $6);
|
||||
pform_set_function($3, $2, $6);
|
||||
delete $3;
|
||||
}
|
||||
| K_specify specify_item_list K_endspecify
|
||||
|
|
@ -1284,12 +1285,12 @@ range_opt
|
|||
;
|
||||
|
||||
range_or_type_opt
|
||||
: range { }
|
||||
| K_integer
|
||||
| K_real
|
||||
| K_realtime
|
||||
| K_time
|
||||
|
|
||||
: range { $$ = $1; }
|
||||
| K_integer { $$ = 0; }
|
||||
| K_real { $$ = 0; }
|
||||
| K_realtime { $$ = 0; }
|
||||
| K_time { $$ = 0; }
|
||||
| { $$ = 0; }
|
||||
;
|
||||
/* The register_variable rule is matched only when I am parsing
|
||||
variables in a "reg" definition. I therefore know that I am
|
||||
|
|
|
|||
15
pform.cc
15
pform.cc
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: pform.cc,v 1.38 1999/08/23 16:48:39 steve Exp $"
|
||||
#ident "$Id: pform.cc,v 1.39 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "compiler.h"
|
||||
|
|
@ -504,8 +504,16 @@ void pform_set_task(const string&name, PTask*task)
|
|||
pform_cur_module->add_task(name, task);
|
||||
}
|
||||
|
||||
void pform_set_function(const string&name, PFunction *func)
|
||||
void pform_set_function(const string&name, svector<PExpr*>*ra, PFunction *func)
|
||||
{
|
||||
PWire*out = new PWire(name+"."+name, NetNet::REG, NetNet::POUTPUT);
|
||||
if (ra) {
|
||||
assert(ra->count() == 2);
|
||||
out->set_range((*ra)[0], (*ra)[1]);
|
||||
delete ra;
|
||||
}
|
||||
pform_cur_module->add_wire(out);
|
||||
func->set_output(out);
|
||||
pform_cur_module->add_function(name, func);
|
||||
}
|
||||
|
||||
|
|
@ -660,6 +668,9 @@ int pform_parse(const char*path, map<string,Module*>&modules,
|
|||
|
||||
/*
|
||||
* $Log: pform.cc,v $
|
||||
* Revision 1.39 1999/08/25 22:22:41 steve
|
||||
* elaborate some aspects of functions.
|
||||
*
|
||||
* Revision 1.38 1999/08/23 16:48:39 steve
|
||||
* Parameter overrides support from Peter Monta
|
||||
* AND and XOR support wide expressions.
|
||||
|
|
|
|||
7
pform.h
7
pform.h
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: pform.h,v 1.28 1999/08/23 16:48:39 steve Exp $"
|
||||
#ident "$Id: pform.h,v 1.29 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "netlist.h"
|
||||
|
|
@ -121,7 +121,7 @@ extern void pform_set_net_range(list<string>*names, const svector<PExpr*>*);
|
|||
extern void pform_set_reg_idx(const string&name, PExpr*l, PExpr*r);
|
||||
extern void pform_set_reg_integer(list<string>*names);
|
||||
extern void pform_set_task(const string&, PTask*);
|
||||
extern void pform_set_function(const string&, PFunction*);
|
||||
extern void pform_set_function(const string&, svector<PExpr*>*, PFunction*);
|
||||
extern void pform_set_attrib(const string&name, const string&key,
|
||||
const string&value);
|
||||
extern void pform_set_type_attrib(const string&name, const string&key,
|
||||
|
|
@ -169,6 +169,9 @@ extern void pform_dump(ostream&out, Module*mod);
|
|||
|
||||
/*
|
||||
* $Log: pform.h,v $
|
||||
* Revision 1.29 1999/08/25 22:22:41 steve
|
||||
* elaborate some aspects of functions.
|
||||
*
|
||||
* Revision 1.28 1999/08/23 16:48:39 steve
|
||||
* Parameter overrides support from Peter Monta
|
||||
* AND and XOR support wide expressions.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: pform_dump.cc,v 1.35 1999/08/23 16:48:39 steve Exp $"
|
||||
#ident "$Id: pform_dump.cc,v 1.36 1999/08/25 22:22:41 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -65,7 +65,7 @@ void PECallFunction::dump(ostream &out) const
|
|||
{
|
||||
out << name_ << "(";
|
||||
parms_[0]->dump(out);
|
||||
for (unsigned idx = 0; idx < parms_.count(); ++idx) {
|
||||
for (unsigned idx = 1; idx < parms_.count(); ++idx) {
|
||||
out << ", ";
|
||||
parms_[idx]->dump(out);
|
||||
}
|
||||
|
|
@ -439,6 +439,7 @@ void PForStatement::dump(ostream&out, unsigned ind) const
|
|||
|
||||
void PFunction::dump(ostream&out, unsigned ind) const
|
||||
{
|
||||
out << setw(ind) << "" << "output " << out_->name() << ";" << endl;
|
||||
for (unsigned idx = 0 ; idx < ports_->count() ; idx += 1) {
|
||||
out << setw(ind) << "";
|
||||
out << "input ";
|
||||
|
|
@ -628,6 +629,9 @@ void PUdp::dump(ostream&out) const
|
|||
|
||||
/*
|
||||
* $Log: pform_dump.cc,v $
|
||||
* Revision 1.36 1999/08/25 22:22:41 steve
|
||||
* elaborate some aspects of functions.
|
||||
*
|
||||
* Revision 1.35 1999/08/23 16:48:39 steve
|
||||
* Parameter overrides support from Peter Monta
|
||||
* AND and XOR support wide expressions.
|
||||
|
|
|
|||
Loading…
Reference in New Issue