elaborate some aspects of functions.

This commit is contained in:
steve 1999-08-25 22:22:41 +00:00
parent 648e4c68e4
commit 23acca48ff
10 changed files with 160 additions and 24 deletions

View File

@ -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" #include "PTask.h"
PFunction::PFunction(svector<PWire*>*p, Statement*s) PFunction::PFunction(svector<PWire*>*p, Statement*s)
: ports_(p), statement_(s) : out_(0), ports_(p), statement_(s)
{ {
} }
PFunction::~PFunction() 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
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) #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 #endif
# include "LineInfo.h" # include "LineInfo.h"
@ -50,21 +50,33 @@ class PTask : public LineInfo {
PTask& operator=(const PTask&); 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 { class PFunction : public LineInfo {
public:
explicit PFunction(svector<PWire *> *p, Statement *s); public:
explicit PFunction(svector<PWire *>*p, Statement *s);
~PFunction(); ~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; void dump(ostream&, unsigned) const;
private: private:
PWire*out_;
svector<PWire *> *ports_; svector<PWire *> *ports_;
Statement *statement_; Statement *statement_;
}; };
/* /*
* $Log: PTask.h,v $ * $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 * Revision 1.3 1999/07/31 19:14:47 steve
* Add functions up to elaboration (Ed Carter) * Add functions up to elaboration (Ed Carter)
* *

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) #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 #endif
/* /*
@ -423,6 +423,12 @@ void NetForever::dump(ostream&o, unsigned ind) const
statement_->dump(o, ind+2); 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 void NetPDelay::dump(ostream&o, unsigned ind) const
{ {
o << setw(ind) << "" << "#" << delay_; o << setw(ind) << "" << "#" << delay_;
@ -690,6 +696,9 @@ void Design::dump(ostream&o) const
/* /*
* $Log: design_dump.cc,v $ * $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 * Revision 1.34 1999/08/01 16:34:50 steve
* Parse and elaborate rise/fall/decay times * Parse and elaborate rise/fall/decay times
* for gates, and handle the rules for partial * for gates, and handle the rules for partial

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) #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 #endif
/* /*
@ -1866,6 +1866,17 @@ NetProc* PForStatement::elaborate(Design*des, const string&path) const
return top; 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 NetProc* PRepeat::elaborate(Design*des, const string&path) const
{ {
NetExpr*expr = expr_->elaborate_expr(des, path); 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); (*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 // Elaborate the task definitions. This is done before the
// behaviors so that task calls may reference these, and after // behaviors so that task calls may reference these, and after
// the signals so that the tasks can reference them. // the signals so that the tasks can reference them.
@ -2070,6 +2089,9 @@ Design* elaborate(const map<string,Module*>&modules,
/* /*
* $Log: elaborate.cc,v $ * $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 * Revision 1.72 1999/08/23 16:48:39 steve
* Parameter overrides support from Peter Monta * Parameter overrides support from Peter Monta
* AND and XOR support wide expressions. * AND and XOR support wide expressions.

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) #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 #endif
# include <cassert> # include <cassert>
@ -482,6 +482,15 @@ NetProc* NetCondit::else_clause()
return else_; 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) NetNEvent::NetNEvent(const string&ev, unsigned wid, Type e, NetPEvent*pe)
: NetNode(ev, wid), sref<NetPEvent,NetNEvent>(pe), edge_(e) : NetNode(ev, wid), sref<NetPEvent,NetNEvent>(pe), edge_(e)
{ {
@ -1439,6 +1448,11 @@ NetMemory* Design::find_memory(const string&key)
return (*cur).second; return (*cur).second;
} }
void Design::add_function(const string&key, NetFuncDef*def)
{
funcs_[key] = def;
}
void Design::add_task(const string&key, NetTaskDef*def) void Design::add_task(const string&key, NetTaskDef*def)
{ {
tasks_[key] = def; tasks_[key] = def;
@ -1571,6 +1585,9 @@ NetNet* Design::find_signal(bool (*func)(const NetNet*))
/* /*
* $Log: netlist.cc,v $ * $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 * Revision 1.52 1999/08/06 04:05:28 steve
* Handle scope of parameters. * Handle scope of parameters.
* *

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) #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 #endif
/* /*
@ -758,6 +758,19 @@ class NetForever : public NetProc {
NetProc*statement_; 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 { class NetPDelay : public NetProc {
public: public:
@ -1339,6 +1352,9 @@ class Design {
void add_memory(NetMemory*); void add_memory(NetMemory*);
NetMemory* find_memory(const string&name); NetMemory* find_memory(const string&name);
// Functions
void add_function(const string&n, NetFuncDef*);
// Tasks // Tasks
void add_task(const string&n, NetTaskDef*); void add_task(const string&n, NetTaskDef*);
NetTaskDef* find_task(const string&key); NetTaskDef* find_task(const string&key);
@ -1379,6 +1395,9 @@ class Design {
map<string,NetMemory*> memories_; map<string,NetMemory*> memories_;
// List the function definitions in the design.
map<string,NetFuncDef*> funcs_;
// List the task definitions in the design. // List the task definitions in the design.
map<string,NetTaskDef*> tasks_; map<string,NetTaskDef*> tasks_;
@ -1440,6 +1459,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
/* /*
* $Log: netlist.h,v $ * $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 * Revision 1.56 1999/08/18 04:00:02 steve
* Fixup spelling and some error messages. <LRDoolittle@lbl.gov> * Fixup spelling and some error messages. <LRDoolittle@lbl.gov>
* *

17
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) #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 #endif
# include "parse_misc.h" # include "parse_misc.h"
@ -137,6 +137,7 @@ extern void lex_end_table();
%type <task> task_body %type <task> task_body
%type <function> func_body %type <function> func_body
%type <exprs> range_or_type_opt
%type <event_expr> event_expression %type <event_expr> event_expression
%type <event_statement> event_control %type <event_statement> event_control
%type <statement> statement statement_opt %type <statement> statement statement_opt
@ -1028,7 +1029,7 @@ module_item
{ PFunction *tmp = $6; { PFunction *tmp = $6;
tmp->set_file(@1.text); tmp->set_file(@1.text);
tmp->set_lineno(@1.first_line); tmp->set_lineno(@1.first_line);
pform_set_function($3, $6); pform_set_function($3, $2, $6);
delete $3; delete $3;
} }
| K_specify specify_item_list K_endspecify | K_specify specify_item_list K_endspecify
@ -1284,12 +1285,12 @@ range_opt
; ;
range_or_type_opt range_or_type_opt
: range { } : range { $$ = $1; }
| K_integer | K_integer { $$ = 0; }
| K_real | K_real { $$ = 0; }
| K_realtime | K_realtime { $$ = 0; }
| K_time | K_time { $$ = 0; }
| | { $$ = 0; }
; ;
/* The register_variable rule is matched only when I am parsing /* The register_variable rule is matched only when I am parsing
variables in a "reg" definition. I therefore know that I am variables in a "reg" definition. I therefore know that I am

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) #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 #endif
# include "compiler.h" # include "compiler.h"
@ -504,8 +504,16 @@ void pform_set_task(const string&name, PTask*task)
pform_cur_module->add_task(name, 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); 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 $ * $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 * Revision 1.38 1999/08/23 16:48:39 steve
* Parameter overrides support from Peter Monta * Parameter overrides support from Peter Monta
* AND and XOR support wide expressions. * AND and XOR support wide expressions.

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) #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 #endif
# include "netlist.h" # 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_idx(const string&name, PExpr*l, PExpr*r);
extern void pform_set_reg_integer(list<string>*names); extern void pform_set_reg_integer(list<string>*names);
extern void pform_set_task(const string&, PTask*); 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, extern void pform_set_attrib(const string&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,
@ -169,6 +169,9 @@ extern void pform_dump(ostream&out, Module*mod);
/* /*
* $Log: pform.h,v $ * $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 * Revision 1.28 1999/08/23 16:48:39 steve
* Parameter overrides support from Peter Monta * Parameter overrides support from Peter Monta
* AND and XOR support wide expressions. * AND and XOR support wide expressions.

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) #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 #endif
/* /*
@ -65,7 +65,7 @@ void PECallFunction::dump(ostream &out) const
{ {
out << name_ << "("; out << name_ << "(";
parms_[0]->dump(out); parms_[0]->dump(out);
for (unsigned idx = 0; idx < parms_.count(); ++idx) { for (unsigned idx = 1; idx < parms_.count(); ++idx) {
out << ", "; out << ", ";
parms_[idx]->dump(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 void PFunction::dump(ostream&out, unsigned ind) const
{ {
out << setw(ind) << "" << "output " << out_->name() << ";" << endl;
for (unsigned idx = 0 ; idx < ports_->count() ; idx += 1) { for (unsigned idx = 0 ; idx < ports_->count() ; idx += 1) {
out << setw(ind) << ""; out << setw(ind) << "";
out << "input "; out << "input ";
@ -628,6 +629,9 @@ void PUdp::dump(ostream&out) const
/* /*
* $Log: pform_dump.cc,v $ * $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 * Revision 1.35 1999/08/23 16:48:39 steve
* Parameter overrides support from Peter Monta * Parameter overrides support from Peter Monta
* AND and XOR support wide expressions. * AND and XOR support wide expressions.