From 23acca48ff57b301251000e8a2d52d7224720405 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 25 Aug 1999 22:22:41 +0000 Subject: [PATCH] elaborate some aspects of functions. --- PFunction.cc | 37 ++++++++++++++++++++++++++++++++++++- PTask.h | 22 +++++++++++++++++----- design_dump.cc | 11 ++++++++++- elaborate.cc | 24 +++++++++++++++++++++++- netlist.cc | 19 ++++++++++++++++++- netlist.h | 24 +++++++++++++++++++++++- parse.y | 17 +++++++++-------- pform.cc | 15 +++++++++++++-- pform.h | 7 +++++-- pform_dump.cc | 8 ++++++-- 10 files changed, 160 insertions(+), 24 deletions(-) diff --git a/PFunction.cc b/PFunction.cc index bd7ab8447..775570937 100644 --- a/PFunction.cc +++ b/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*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. + * + */ diff --git a/PTask.h b/PTask.h index 8c3c29fcd..69d964878 100644 --- a/PTask.h +++ b/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 *p, Statement *s); + + public: + explicit PFunction(svector*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 *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) * diff --git a/design_dump.cc b/design_dump.cc index c608c0a16..2658fe9d1 100644 --- a/design_dump.cc +++ b/design_dump.cc @@ -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 diff --git a/elaborate.cc b/elaborate.cc index 871878845..1dd8d271c 100644 --- a/elaborate.cc +++ b/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*overrides_ (*wt)->elaborate(des, path); } + // Elaborate functions. + typedef map::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&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. diff --git a/netlist.cc b/netlist.cc index 9bb230676..df50fba4b 100644 --- a/netlist.cc +++ b/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 @@ -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(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. * diff --git a/netlist.h b/netlist.h index 827db7d4b..582c0d54f 100644 --- a/netlist.h +++ b/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 memories_; + // List the function definitions in the design. + map funcs_; + // List the task definitions in the design. map 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. * diff --git a/parse.y b/parse.y index b7c29bdda..98e40b488 100644 --- a/parse.y +++ b/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_body %type func_body +%type range_or_type_opt %type event_expression %type event_control %type 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 diff --git a/pform.cc b/pform.cc index e55023b5b..44c72b2e9 100644 --- a/pform.cc +++ b/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*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&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. diff --git a/pform.h b/pform.h index d2cb54f0f..1944e7bfb 100644 --- a/pform.h +++ b/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*names, const svector*); extern void pform_set_reg_idx(const string&name, PExpr*l, PExpr*r); extern void pform_set_reg_integer(list*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*, 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. diff --git a/pform_dump.cc b/pform_dump.cc index a1a2f9324..5d81cca7a 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -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.