Add support for module parameters.
This commit is contained in:
parent
9d0a266705
commit
e2a37a8ccd
12
Module.h
12
Module.h
|
|
@ -19,12 +19,14 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: Module.h,v 1.2 1999/01/25 05:45:56 steve Exp $"
|
||||
#ident "$Id: Module.h,v 1.3 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include <list>
|
||||
# include <map>
|
||||
# include <vector>
|
||||
# include <string>
|
||||
class PExpr;
|
||||
class PGate;
|
||||
class PWire;
|
||||
class PProcess;
|
||||
|
|
@ -43,6 +45,11 @@ class Module {
|
|||
|
||||
vector<PWire*> ports;
|
||||
|
||||
/* The module has parameters that are evaluated when the
|
||||
module is elaborated. During parsing, I put the parameters
|
||||
into this map. */
|
||||
map<string,PExpr*>parameters;
|
||||
|
||||
const string&get_name() const { return name_; }
|
||||
|
||||
void add_gate(PGate*gate);
|
||||
|
|
@ -74,6 +81,9 @@ class Module {
|
|||
|
||||
/*
|
||||
* $Log: Module.h,v $
|
||||
* Revision 1.3 1999/02/21 17:01:57 steve
|
||||
* Add support for module parameters.
|
||||
*
|
||||
* Revision 1.2 1999/01/25 05:45:56 steve
|
||||
* Add the LineInfo class to carry the source file
|
||||
* location of things. PGate, Statement and PProcess.
|
||||
|
|
|
|||
|
|
@ -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.13 1999/02/15 02:06:15 steve Exp $"
|
||||
#ident "$Id: design_dump.cc,v 1.14 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -473,6 +473,15 @@ void NetEUnary::dump(ostream&o) const
|
|||
|
||||
void Design::dump(ostream&o) const
|
||||
{
|
||||
o << "ELABORATED PARAMETERS:" << endl;
|
||||
{
|
||||
map<string,NetExpr*>::const_iterator pp;
|
||||
for (pp = parameters_.begin()
|
||||
; pp != parameters_.end() ; pp ++) {
|
||||
o << " " << (*pp).first << " = " <<
|
||||
*(*pp).second << ";" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
o << "ELABORATED SIGNALS:" << endl;
|
||||
|
||||
|
|
@ -506,6 +515,9 @@ void Design::dump(ostream&o) const
|
|||
|
||||
/*
|
||||
* $Log: design_dump.cc,v $
|
||||
* Revision 1.14 1999/02/21 17:01:57 steve
|
||||
* Add support for module parameters.
|
||||
*
|
||||
* Revision 1.13 1999/02/15 02:06:15 steve
|
||||
* Elaborate gate ranges.
|
||||
*
|
||||
|
|
|
|||
36
elaborate.cc
36
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.15 1999/02/15 02:06:15 steve Exp $"
|
||||
#ident "$Id: elaborate.cc,v 1.16 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -640,15 +640,22 @@ NetExpr* PEString::elaborate_expr(Design*des, const string&path) const
|
|||
|
||||
NetExpr*PEIdent::elaborate_expr(Design*des, const string&path) const
|
||||
{
|
||||
if (text_[0] == '$')
|
||||
if (text_[0] == '$') {
|
||||
return new NetEIdent(text_, 64);
|
||||
else {
|
||||
|
||||
} else {
|
||||
string name = path+"."+text_;
|
||||
NetNet*net = des->find_signal(name);
|
||||
assert(net);
|
||||
NetESignal*node = new NetESignal(net);
|
||||
des->add_node(node);
|
||||
return node;
|
||||
|
||||
if (NetExpr*ex = des->get_parameter(name))
|
||||
return ex;
|
||||
|
||||
if (NetNet*net = des->find_signal(name)) {
|
||||
NetESignal*node = new NetESignal(net);
|
||||
des->add_node(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -861,6 +868,16 @@ bool Module::elaborate(Design*des, const string&path) const
|
|||
{
|
||||
bool result_flag = true;
|
||||
|
||||
// Generate all the parameters that this instance of this
|
||||
// module introduce to the design.
|
||||
typedef map<string,PExpr*>::const_iterator mparm_it_t;
|
||||
for (mparm_it_t cur = parameters.begin()
|
||||
; cur != parameters.end() ; cur ++) {
|
||||
string pname = path + "." + (*cur).first;
|
||||
NetExpr*expr = (*cur).second->elaborate_expr(des, path);
|
||||
des->set_parameter(pname, expr);
|
||||
}
|
||||
|
||||
// Get all the explicitly declared wires of the module and
|
||||
// start the signals list with them.
|
||||
const list<PWire*>&wl = get_wires();
|
||||
|
|
@ -947,6 +964,9 @@ Design* elaborate(const map<string,Module*>&modules,
|
|||
|
||||
/*
|
||||
* $Log: elaborate.cc,v $
|
||||
* Revision 1.16 1999/02/21 17:01:57 steve
|
||||
* Add support for module parameters.
|
||||
*
|
||||
* Revision 1.15 1999/02/15 02:06:15 steve
|
||||
* Elaborate gate ranges.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: lexor.lex,v 1.8 1999/02/15 05:52:08 steve Exp $"
|
||||
#ident "$Id: lexor.lex,v 1.9 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
//# define YYSTYPE lexval
|
||||
|
|
@ -237,6 +237,7 @@ static const struct { const char*name; int code; } key_table[] = {
|
|||
{ "notif1", K_notif1 },
|
||||
{ "or", K_or },
|
||||
{ "output", K_output },
|
||||
{ "parameter", K_parameter },
|
||||
{ "pmos", K_pmos },
|
||||
{ "posedge", K_posedge },
|
||||
{ "primitive", K_primitive },
|
||||
|
|
|
|||
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.16 1999/02/08 02:49:56 steve Exp $"
|
||||
#ident "$Id: netlist.cc,v 1.17 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include <cassert>
|
||||
|
|
@ -729,6 +729,20 @@ void NetUDP::set_initial(char val)
|
|||
init_ = val;
|
||||
}
|
||||
|
||||
void Design::set_parameter(const string&key, NetExpr*expr)
|
||||
{
|
||||
parameters_[key] = expr;
|
||||
}
|
||||
|
||||
NetExpr* Design::get_parameter(const string&key) const
|
||||
{
|
||||
map<string,NetExpr*>::const_iterator cur = parameters_.find(key);
|
||||
if (cur == parameters_.end())
|
||||
return 0;
|
||||
else
|
||||
return (*cur).second;
|
||||
}
|
||||
|
||||
string Design::get_flag(const string&key) const
|
||||
{
|
||||
map<string,string>::const_iterator tmp = flags_.find(key);
|
||||
|
|
@ -881,6 +895,9 @@ NetNet* Design::find_signal(bool (*func)(const NetNet*))
|
|||
|
||||
/*
|
||||
* $Log: netlist.cc,v $
|
||||
* Revision 1.17 1999/02/21 17:01:57 steve
|
||||
* Add support for module parameters.
|
||||
*
|
||||
* Revision 1.16 1999/02/08 02:49:56 steve
|
||||
* Turn the NetESignal into a NetNode so
|
||||
* that it can connect to the netlist.
|
||||
|
|
|
|||
11
netlist.h
11
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.19 1999/02/15 02:06:15 steve Exp $"
|
||||
#ident "$Id: netlist.h,v 1.20 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -869,6 +869,10 @@ class Design {
|
|||
string get_flag(const string&key) const;
|
||||
|
||||
|
||||
// PARAMETERS
|
||||
void set_parameter(const string&, NetExpr*);
|
||||
NetExpr*get_parameter(const string&name) const;
|
||||
|
||||
// SIGNALS
|
||||
|
||||
void add_signal(NetNet*);
|
||||
|
|
@ -900,6 +904,8 @@ class Design {
|
|||
string local_symbol(const string&path);
|
||||
|
||||
private:
|
||||
map<string,NetExpr*> parameters_;
|
||||
|
||||
// List all the signals in the design.
|
||||
NetNet*signals_;
|
||||
|
||||
|
|
@ -960,6 +966,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
|
|||
|
||||
/*
|
||||
* $Log: netlist.h,v $
|
||||
* Revision 1.20 1999/02/21 17:01:57 steve
|
||||
* Add support for module parameters.
|
||||
*
|
||||
* Revision 1.19 1999/02/15 02:06:15 steve
|
||||
* Elaborate gate ranges.
|
||||
*
|
||||
|
|
|
|||
19
parse.y
19
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.13 1999/02/15 02:06:15 steve Exp $"
|
||||
#ident "$Id: parse.y,v 1.14 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "parse_misc.h"
|
||||
|
|
@ -67,8 +67,8 @@ extern void lex_end_table();
|
|||
%token K_force K_forever K_fork K_function K_highz0 K_highz1 K_if
|
||||
%token K_initial K_inout K_input K_integer K_join K_large K_macromodule
|
||||
%token K_medium K_module K_nand K_negedge K_nmos K_nor K_not K_notif0
|
||||
%token K_notif1 K_or K_output K_pmos K_posedge K_primitive K_pull0
|
||||
%token K_pull1 K_pulldown K_pullup K_rcmos K_reg K_release K_repeat
|
||||
%token K_notif1 K_or K_output K_parameter K_pmos K_posedge K_primitive
|
||||
%token K_pull0 K_pull1 K_pulldown K_pullup K_rcmos K_reg K_release K_repeat
|
||||
%token K_rnmos K_rpmos K_rtran K_rtranif0 K_rtranif1 K_scalered
|
||||
%token K_small K_specify
|
||||
%token K_specparam K_strong0 K_strong1 K_supply0 K_supply1 K_table K_task
|
||||
|
|
@ -483,6 +483,7 @@ module_item
|
|||
}
|
||||
delete $3;
|
||||
}
|
||||
| K_parameter parameter_assign_list ';'
|
||||
| gatetype delay_opt gate_instance_list ';'
|
||||
{ pform_makegates($1, $2, $3);
|
||||
}
|
||||
|
|
@ -542,6 +543,18 @@ net_type
|
|||
| K_trior { $$ = NetNet::TRIOR; }
|
||||
;
|
||||
|
||||
parameter_assign
|
||||
: IDENTIFIER '=' const_expression
|
||||
{ pform_set_parameter(*$1, $3);
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
parameter_assign_list
|
||||
: parameter_assign
|
||||
| parameter_assign_list ',' parameter_assign
|
||||
;
|
||||
|
||||
port
|
||||
: IDENTIFIER
|
||||
{ $$ = new PWire(*$1, NetNet::IMPLICIT);
|
||||
|
|
|
|||
10
pform.cc
10
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.9 1999/02/15 02:06:15 steve Exp $"
|
||||
#ident "$Id: pform.cc,v 1.10 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "pform.h"
|
||||
|
|
@ -412,6 +412,11 @@ static void pform_set_net_range(const string&name, list<PExpr*>*range)
|
|||
}
|
||||
}
|
||||
|
||||
void pform_set_parameter(const string&name, PExpr*expr)
|
||||
{
|
||||
cur_module->parameters[name] = expr;
|
||||
}
|
||||
|
||||
void pform_set_port_type(list<string>*names, NetNet::PortType pt)
|
||||
{
|
||||
for (list<string>::const_iterator cur = names->begin()
|
||||
|
|
@ -509,6 +514,9 @@ int pform_parse(const char*path, map<string,Module*>&modules,
|
|||
|
||||
/*
|
||||
* $Log: pform.cc,v $
|
||||
* Revision 1.10 1999/02/21 17:01:57 steve
|
||||
* Add support for module parameters.
|
||||
*
|
||||
* Revision 1.9 1999/02/15 02:06:15 steve
|
||||
* Elaborate gate ranges.
|
||||
*
|
||||
|
|
|
|||
6
pform.h
6
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.7 1999/02/15 02:06:15 steve Exp $"
|
||||
#ident "$Id: pform.h,v 1.8 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "netlist.h"
|
||||
|
|
@ -105,6 +105,7 @@ 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,
|
||||
const string&value);
|
||||
extern void pform_set_parameter(const string&name, PExpr*expr);
|
||||
extern PProcess* pform_make_behavior(PProcess::Type, Statement*);
|
||||
extern Statement* pform_make_block(PBlock::BL_TYPE, list<Statement*>*);
|
||||
extern Statement* pform_make_assignment(string*t, PExpr*e);
|
||||
|
|
@ -138,6 +139,9 @@ extern void pform_dump(ostream&out, Module*mod);
|
|||
|
||||
/*
|
||||
* $Log: pform.h,v $
|
||||
* Revision 1.8 1999/02/21 17:01:57 steve
|
||||
* Add support for module parameters.
|
||||
*
|
||||
* Revision 1.7 1999/02/15 02:06:15 steve
|
||||
* Elaborate gate ranges.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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.10 1999/02/15 02:06:15 steve Exp $"
|
||||
#ident "$Id: pform_dump.cc,v 1.11 1999/02/21 17:01:57 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -334,6 +334,13 @@ void pform_dump(ostream&out, Module*mod)
|
|||
{
|
||||
out << "module " << mod->get_name() << ";" << endl;
|
||||
|
||||
typedef map<string,PExpr*>::const_iterator parm_iter_t;
|
||||
for (parm_iter_t cur = mod->parameters.begin()
|
||||
; cur != mod->parameters.end() ; cur ++) {
|
||||
out << " parameter " << (*cur).first << " = " <<
|
||||
*(*cur).second << ";" << endl;
|
||||
}
|
||||
|
||||
// Iterate through and display all the wires.
|
||||
const list<PWire*>&wires = mod->get_wires();
|
||||
for (list<PWire*>::const_iterator wire = wires.begin()
|
||||
|
|
@ -407,6 +414,9 @@ void PUdp::dump(ostream&out) const
|
|||
|
||||
/*
|
||||
* $Log: pform_dump.cc,v $
|
||||
* Revision 1.11 1999/02/21 17:01:57 steve
|
||||
* Add support for module parameters.
|
||||
*
|
||||
* Revision 1.10 1999/02/15 02:06:15 steve
|
||||
* Elaborate gate ranges.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue