From 994904028524c557873af8a368d746e0f0010248 Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 13 Jun 2004 04:56:53 +0000 Subject: [PATCH] Add support for the default_nettype directive. --- Module.cc | 6 +++- Module.h | 10 ++++-- elab_net.cc | 14 ++++++--- elab_scope.cc | 6 +++- elaborate.cc | 6 +++- lexor.lex | 34 +++++++++++++++++++-- net_scope.cc | 15 ++++++++- netlist.cc | 8 ++++- netlist.h | 85 ++++++--------------------------------------------- pform.cc | 28 +++++++++++++++-- pform.h | 10 +++++- 11 files changed, 129 insertions(+), 93 deletions(-) diff --git a/Module.cc b/Module.cc index 51e031d2c8..7d87e5994b 100644 --- a/Module.cc +++ b/Module.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: Module.cc,v 1.23 2004/02/20 06:22:56 steve Exp $" +#ident "$Id: Module.cc,v 1.24 2004/06/13 04:56:53 steve Exp $" #endif # include "config.h" @@ -31,6 +31,7 @@ Module::Module(perm_string n) : name_(n) { + default_nettype = NetNet::NONE; } Module::~Module() @@ -149,6 +150,9 @@ const list& Module::get_behaviors() const /* * $Log: Module.cc,v $ + * Revision 1.24 2004/06/13 04:56:53 steve + * Add support for the default_nettype directive. + * * Revision 1.23 2004/02/20 06:22:56 steve * parameter keys are per_strings. * diff --git a/Module.h b/Module.h index e2823c934a..aea52e425d 100644 --- a/Module.h +++ b/Module.h @@ -1,7 +1,7 @@ #ifndef __Module_H #define __Module_H /* - * Copyright (c) 1998-2000 Stephen Williams (steve@icarus.com) + * Copyright (c) 1998-2004 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 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: Module.h,v 1.36 2004/05/25 19:21:06 steve Exp $" +#ident "$Id: Module.h,v 1.37 2004/06/13 04:56:53 steve Exp $" #endif # include @@ -29,7 +29,7 @@ # include "HName.h" # include "named.h" # include "LineInfo.h" -# include +# include "netlist.h" class PData; class PEvent; class PExpr; @@ -67,6 +67,7 @@ class Module : public LineInfo { explicit Module(perm_string name); ~Module(); + NetNet::Type default_nettype; /* The module has parameters that are evaluated when the module is elaborated. During parsing, I put the parameters @@ -166,6 +167,9 @@ class Module : public LineInfo { /* * $Log: Module.h,v $ + * Revision 1.37 2004/06/13 04:56:53 steve + * Add support for the default_nettype directive. + * * Revision 1.36 2004/05/25 19:21:06 steve * More identifier lists use perm_strings. * diff --git a/elab_net.cc b/elab_net.cc index 77ea07fd4f..d194cc31a7 100644 --- a/elab_net.cc +++ b/elab_net.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: elab_net.cc,v 1.127 2004/06/01 01:04:57 steve Exp $" +#ident "$Id: elab_net.cc,v 1.128 2004/06/13 04:56:53 steve Exp $" #endif # include "config.h" @@ -1396,11 +1396,11 @@ NetNet* PEIdent::elaborate_net(Design*des, NetScope*scope, /* Fallback, this may be an implicitly declared net. */ if (sig == 0) { - + NetNet::Type nettype = scope->default_nettype(); sig = new NetNet(scope, lex_strings.make(path_.peek_name(0)), - NetNet::IMPLICIT, 1); + nettype, 1); - if (error_implicit) { + if (error_implicit || (nettype == NetNet::NONE)) { cerr << get_line() << ": error: " << scope->name() << "." << path_.peek_name(0) << " not defined in this scope." << endl; @@ -1656,8 +1656,9 @@ NetNet* PEIdent::elaborate_lnet(Design*des, NetScope*scope, } if (sig == 0) { + NetNet::Type nettype = scope->default_nettype(); - if (implicit_net_ok && !error_implicit) { + if (implicit_net_ok && !error_implicit && nettype!=NetNet::NONE) { sig = new NetNet(scope, lex_strings.make(path_.peek_name(0)), NetNet::IMPLICIT, 1); @@ -2432,6 +2433,9 @@ NetNet* PEUnary::elaborate_net(Design*des, NetScope*scope, /* * $Log: elab_net.cc,v $ + * Revision 1.128 2004/06/13 04:56:53 steve + * Add support for the default_nettype directive. + * * Revision 1.127 2004/06/01 01:04:57 steve * Fix synthesis method for logical and/or * diff --git a/elab_scope.cc b/elab_scope.cc index 25a548b071..6fc6dbdb3c 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: elab_scope.cc,v 1.31 2004/05/25 19:21:06 steve Exp $" +#ident "$Id: elab_scope.cc,v 1.32 2004/06/13 04:56:54 steve Exp $" #endif # include "config.h" @@ -290,6 +290,7 @@ void PGModule::elaborate_scope_mod_(Design*des, Module*mod, NetScope*sc) const // Create the new scope as a MODULE with my name. NetScope*my_scope = new NetScope(sc, get_name(), NetScope::MODULE); my_scope->set_module_name(mod->mod_name()); + my_scope->default_nettype(mod->default_nettype); // Set time units and precision. my_scope->time_unit(mod->time_unit); @@ -549,6 +550,9 @@ void PWhile::elaborate_scope(Design*des, NetScope*scope) const /* * $Log: elab_scope.cc,v $ + * Revision 1.32 2004/06/13 04:56:54 steve + * Add support for the default_nettype directive. + * * Revision 1.31 2004/05/25 19:21:06 steve * More identifier lists use perm_strings. * diff --git a/elaborate.cc b/elaborate.cc index 3b65a0f8dd..ed71c8bcc1 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: elaborate.cc,v 1.302 2004/05/31 23:34:37 steve Exp $" +#ident "$Id: elaborate.cc,v 1.303 2004/06/13 04:56:54 steve Exp $" #endif # include "config.h" @@ -2643,6 +2643,7 @@ Design* elaborate(listroots) NetScope*scope = des->make_root_scope(*root); scope->time_unit(rmod->time_unit); scope->time_precision(rmod->time_precision); + scope->default_nettype(rmod->default_nettype); des->set_precision(rmod->time_precision); if (! rmod->elaborate_scope(des, scope)) { delete des; @@ -2708,6 +2709,9 @@ Design* elaborate(listroots) /* * $Log: elaborate.cc,v $ + * Revision 1.303 2004/06/13 04:56:54 steve + * Add support for the default_nettype directive. + * * Revision 1.302 2004/05/31 23:34:37 steve * Rewire/generalize parsing an elaboration of * function return values to allow for better diff --git a/lexor.lex b/lexor.lex index 244f33a577..0d762b0e3a 100644 --- a/lexor.lex +++ b/lexor.lex @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: lexor.lex,v 1.85 2003/08/31 21:14:28 steve Exp $" +#ident "$Id: lexor.lex,v 1.86 2004/06/13 04:56:54 steve Exp $" #endif # include "config.h" @@ -98,6 +98,7 @@ static int comment_enter; %x CSTRING %s UDPTABLE %x PPTIMESCALE +%x PPDEFAULT_NETTYPE W [ \t\b\f\r]+ @@ -269,7 +270,6 @@ W [ \t\b\f\r]+ should handle these, not an external preprocessor. */ ^{W}?`celldefine{W}?.* { } -^{W}?`default_nettype{W}?.* { } ^{W}?`delay_mode_distributed{W}?.* { } ^{W}?`delay_mode_unit{W}?.* { } ^{W}?`delay_mode_path{W}?.* { } @@ -285,6 +285,36 @@ W [ \t\b\f\r]+ ^{W}?`unconnected_drive{W}?.* { } ^{W}?`uselib{W}?.* { } + /* Notice and handle the default_nettype directive. The lexor + detects the default_nettype keyword, and the second part of the + rule collects the rest of the line and processes it. We only need + to look for the first work, and interpret it. */ + +`default_nettype{W}? { BEGIN(PPDEFAULT_NETTYPE); } +.* { + NetNet::Type net_type; + size_t wordlen = strcspn(yytext, " \t\f\r\n"); + yytext[wordlen] = 0; + if (strcmp(yytext,"wire") == 0) { + net_type = NetNet::WIRE; + + } else if (strcmp(yytext,"none") == 0) { + net_type = NetNet::NONE; + + } else { + cerr << yylloc.text << ":" << yylloc.first_line + << " error: Net type " << yytext + << " is not a valid (and supported)" + << " default net type." << endl; + net_type = NetNet::WIRE; + error_count += 1; + } + pform_set_default_nettype(net_type, yylloc.text, yylloc.first_line); + } +\n { + yylloc.first_line += 1; + BEGIN(0); } + /* These are directives that are not supported by me and should have been handled by an external preprocessor such as ivlpp. */ diff --git a/net_scope.cc b/net_scope.cc index 4aa451ca16..d711c2dbe9 100644 --- a/net_scope.cc +++ b/net_scope.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: net_scope.cc,v 1.31 2004/02/20 06:22:56 steve Exp $" +#ident "$Id: net_scope.cc,v 1.32 2004/06/13 04:56:54 steve Exp $" #endif # include "config.h" @@ -223,6 +223,16 @@ int NetScope::time_precision() const return time_prec_; } +void NetScope::default_nettype(NetNet::Type nt) +{ + default_nettype_ = nt; +} + +NetNet::Type NetScope::default_nettype() const +{ + return default_nettype_; +} + perm_string NetScope::basename() const { return name_; @@ -457,6 +467,9 @@ string NetScope::local_hsymbol() /* * $Log: net_scope.cc,v $ + * Revision 1.32 2004/06/13 04:56:54 steve + * Add support for the default_nettype directive. + * * Revision 1.31 2004/02/20 06:22:56 steve * parameter keys are per_strings. * diff --git a/netlist.cc b/netlist.cc index e74d0c2f2f..3bedaae6f2 100644 --- a/netlist.cc +++ b/netlist.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: netlist.cc,v 1.223 2004/05/31 23:34:37 steve Exp $" +#ident "$Id: netlist.cc,v 1.224 2004/06/13 04:56:54 steve Exp $" #endif # include "config.h" @@ -34,6 +34,9 @@ ostream& operator<< (ostream&o, NetNet::Type t) { switch (t) { + case NetNet::NONE: + o << "net_none"; + break; case NetNet::IMPLICIT: o << "wire /*implicit*/"; break; @@ -2254,6 +2257,9 @@ const NetProc*NetTaskDef::proc() const /* * $Log: netlist.cc,v $ + * Revision 1.224 2004/06/13 04:56:54 steve + * Add support for the default_nettype directive. + * * Revision 1.223 2004/05/31 23:34:37 steve * Rewire/generalize parsing an elaboration of * function return values to allow for better diff --git a/netlist.h b/netlist.h index dd0b4ef010..608202a4d7 100644 --- a/netlist.h +++ b/netlist.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: netlist.h,v 1.312 2004/05/31 23:34:38 steve Exp $" +#ident "$Id: netlist.h,v 1.313 2004/06/13 04:56:55 steve Exp $" #endif /* @@ -364,8 +364,8 @@ class NetNode : public NetObj { class NetNet : public NetObj { public: - enum Type { IMPLICIT, IMPLICIT_REG, INTEGER, WIRE, TRI, TRI1, SUPPLY0, - SUPPLY1, WAND, TRIAND, TRI0, WOR, TRIOR, REG }; + enum Type { NONE, IMPLICIT, IMPLICIT_REG, INTEGER, WIRE, TRI, TRI1, + SUPPLY0, SUPPLY1, WAND, TRIAND, TRI0, WOR, TRIOR, REG }; enum PortType { NOT_A_PORT, PIMPLICIT, PINPUT, POUTPUT, PINOUT }; @@ -3097,6 +3097,9 @@ class NetScope : public Attrib { int time_unit() const; int time_precision() const; + void default_nettype(NetNet::Type); + NetNet::Type default_nettype() const; + /* The name of the scope is the fully qualified hierarchical name, whereas the basename is just my name within my parent scope. */ @@ -3145,6 +3148,7 @@ class NetScope : public Attrib { perm_string name_; signed char time_unit_, time_prec_; + NetNet::Type default_nettype_; NetEvent *events_; NetVariable*vars_; @@ -3327,6 +3331,9 @@ extern ostream& operator << (ostream&, NetNet::Type); /* * $Log: netlist.h,v $ + * Revision 1.313 2004/06/13 04:56:55 steve + * Add support for the default_nettype directive. + * * Revision 1.312 2004/05/31 23:34:38 steve * Rewire/generalize parsing an elaboration of * function return values to allow for better @@ -3355,77 +3362,5 @@ extern ostream& operator << (ostream&, NetNet::Type); * * Revision 1.304 2003/10/31 02:47:11 steve * NetEUReduce has its own dup_expr method. - * - * Revision 1.303 2003/10/26 04:51:38 steve - * Output of While is output of while substatement. - * - * Revision 1.302 2003/09/20 01:05:36 steve - * Obsolete find_symbol and find_event from the Design class. - * - * Revision 1.301 2003/09/19 03:50:12 steve - * Remove find_memory method from Design class. - * - * Revision 1.300 2003/09/19 03:30:05 steve - * Fix name search in elab_lval. - * - * Revision 1.299 2003/09/13 01:01:52 steve - * Spelling fixes. - * - * Revision 1.298 2003/08/28 04:11:19 steve - * Spelling patch. - * - * Revision 1.297 2003/08/15 02:23:52 steve - * Add synthesis support for synchronous reset. - * - * Revision 1.296 2003/08/09 03:23:40 steve - * Add support for IVL_LPM_MULT device. - * - * Revision 1.295 2003/07/26 03:34:42 steve - * Start handling pad of expressions in code generators. - * - * Revision 1.294 2003/07/15 03:49:22 steve - * Spelling fixes. - * - * Revision 1.293 2003/07/02 04:19:16 steve - * Elide empty begin-end in conditionals. - * - * Revision 1.292 2003/06/21 01:21:43 steve - * Harmless fixup of warnings. - * - * Revision 1.291 2003/06/20 00:53:19 steve - * Module attributes from the parser - * through to elaborated form. - * - * Revision 1.290 2003/06/18 03:55:18 steve - * Add arithmetic shift operators. - * - * Revision 1.289 2003/06/05 04:28:24 steve - * Evaluate <= with real operands. - * - * Revision 1.288 2003/05/30 02:55:32 steve - * Support parameters in real expressions and - * as real expressions, and fix multiply and - * divide with real results. - * - * Revision 1.287 2003/05/01 01:13:57 steve - * More complete bit range internal error message, - * Better test of part select ranges on non-zero - * signal ranges. - * - * Revision 1.286 2003/04/22 04:48:30 steve - * Support event names as expressions elements. - * - * Revision 1.285 2003/04/11 05:18:08 steve - * Handle signed magnitude compare all the - * way through to the vvp code generator. - * - * Revision 1.284 2003/04/08 04:33:55 steve - * Synthesize shift expressions. - * - * Revision 1.283 2003/03/29 05:51:25 steve - * Sign extend NetMult inputs if result is signed. - * - * Revision 1.282 2003/03/15 18:08:43 steve - * Comparison operators do have defined width. */ #endif diff --git a/pform.cc b/pform.cc index cb0d9016c8..fab56a8b8e 100644 --- a/pform.cc +++ b/pform.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998-2000 Stephen Williams (steve@icarus.com) + * Copyright (c) 1998-2004 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 @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: pform.cc,v 1.126 2004/05/31 23:34:39 steve Exp $" +#ident "$Id: pform.cc,v 1.127 2004/06/13 04:56:55 steve Exp $" #endif # include "config.h" @@ -47,6 +47,8 @@ extern int VLparse(); static Module*pform_cur_module = 0; +static NetNet::Type pform_default_nettype = NetNet::WIRE; + /* * These variables track the current time scale, as well as where the * timescale was set. This supports warnings about tangled timescales. @@ -89,6 +91,24 @@ static hname_t hier_name(const char*tail) return name; } +void pform_set_default_nettype(NetNet::Type type, + const char*file, unsigned lineno) +{ + pform_default_nettype = type; + + if (pform_cur_module) { + cerr << file<<":"<mod_name() + << " starts on line " + << pform_cur_module->get_line() << "." << endl; + error_count += 1; + } +} + /* * The lexor calls this function to set the active timescale when it * detects a `timescale directive. The function saves the directive @@ -192,6 +212,7 @@ void pform_startmodule(const char*name, const char*file, unsigned lineno, pform_cur_module = new Module(lex_name); pform_cur_module->time_unit = pform_time_unit; pform_cur_module->time_precision = pform_time_prec; + pform_cur_module->default_nettype = pform_default_nettype; pform_cur_module->set_file(file); pform_cur_module->set_lineno(lineno); @@ -1566,6 +1587,9 @@ int pform_parse(const char*path, FILE*file) /* * $Log: pform.cc,v $ + * Revision 1.127 2004/06/13 04:56:55 steve + * Add support for the default_nettype directive. + * * Revision 1.126 2004/05/31 23:34:39 steve * Rewire/generalize parsing an elaboration of * function return values to allow for better diff --git a/pform.h b/pform.h index 76d2ff19d6..bccd17ed83 100644 --- a/pform.h +++ b/pform.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: pform.h,v 1.79 2004/05/31 23:34:39 steve Exp $" +#ident "$Id: pform.h,v 1.80 2004/06/13 04:56:56 steve Exp $" #endif # include "netlist.h" @@ -110,6 +110,11 @@ struct lgate { unsigned lineno; }; + /* The lexor calls this function to change the default nettype. */ +extern void pform_set_default_nettype(NetNet::Type net, + const char*file, + unsigned lineno); + /* * The parser uses startmodule and endmodule together to build up a * module as it parses it. The startmodule tells the pform code that a @@ -290,6 +295,9 @@ extern void pform_dump(ostream&out, Module*mod); /* * $Log: pform.h,v $ + * Revision 1.80 2004/06/13 04:56:56 steve + * Add support for the default_nettype directive. + * * Revision 1.79 2004/05/31 23:34:39 steve * Rewire/generalize parsing an elaboration of * function return values to allow for better