Skip to content
Browse files

Support localparam.

  • Loading branch information...
1 parent 79f7722 commit 6eef54595f0441257ba7eeee487065359eaf08ed steve committed Mar 12, 2000
Showing with 218 additions and 259 deletions.
  1. +1 −0 .cvsignore
  2. +7 −1 Makefile.in
  3. +19 −1 Module.cc
  4. +9 −5 Module.h
  5. +6 −0 README.txt
  6. +10 −1 design_dump.cc
  7. +23 −1 elab_scope.cc
  8. +6 −4 lexor.lex
  9. +0 −230 lexor_keyword.cc
  10. +14 −5 lexor_keyword.gperf
  11. +33 −0 lexor_keyword.h
  12. +22 −5 netlist.cc
  13. +6 −1 netlist.h
  14. +34 −2 parse.y
  15. +10 −1 pform.cc
  16. +5 −1 pform.h
  17. +13 −1 pform_dump.cc
View
1 .cvsignore
@@ -1,3 +1,4 @@
+lexor_keyword.cc
parse.h
parse.cc
parse.cc.output
View
8 Makefile.in
@@ -18,7 +18,7 @@
# 59 Temple Place - Suite 330
# Boston, MA 02111-1307, USA
#
-#ident "$Id: Makefile.in,v 1.37 2000/03/08 04:36:53 steve Exp $"
+#ident "$Id: Makefile.in,v 1.38 2000/03/12 17:09:40 steve Exp $"
#
#
SHELL = /bin/sh
@@ -119,6 +119,12 @@ parse.h parse.cc: $(srcdir)/parse.y
lexor.cc: $(srcdir)/lexor.lex
flex -PVL -s -olexor.cc $(srcdir)/lexor.lex
+lexor_keyword.o dep/lexor_keyword.d: lexor_keyword.cc
+
+lexor_keyword.cc: lexor_keyword.gperf
+ gperf -o -i 1 -C -k 1-3,$$ -L ANSI-C -H keyword_hash -N check_identifier -t lexor_keyword.gperf > lexor_keyword.cc
+
+
install: all installdirs $(bindir)/verilog $(bindir)/gverilog $(libdir)/ivl/ivl $(mandir)/man1/verilog.1
cd vpi ; $(MAKE) install
cd vvm ; $(MAKE) install
View
20 Module.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: Module.cc,v 1.10 2000/02/23 02:56:53 steve Exp $"
+#ident "$Id: Module.cc,v 1.11 2000/03/12 17:09:40 steve Exp $"
#endif
# include "Module.h"
@@ -126,9 +126,27 @@ PGate* Module::get_gate(const string&name)
return 0;
}
+const map<string,PWire*>& Module::get_wires() const
+{
+ return wires_;
+}
+
+const list<PGate*>& Module::get_gates() const
+{
+ return gates_;
+}
+
+const list<PProcess*>& Module::get_behaviors() const
+{
+ return behaviors_;
+}
+
/*
* $Log: Module.cc,v $
+ * Revision 1.11 2000/03/12 17:09:40 steve
+ * Support localparam.
+ *
* Revision 1.10 2000/02/23 02:56:53 steve
* Macintosh compilers do not support ident.
*
View
14 Module.h
@@ -1,7 +1,7 @@
#ifndef __Module_H
#define __Module_H
/*
- * Copyright (c) 1998 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 1998-2000 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
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: Module.h,v 1.15 2000/03/08 04:36:53 steve Exp $"
+#ident "$Id: Module.h,v 1.16 2000/03/12 17:09:40 steve Exp $"
#endif
# include <list>
@@ -65,6 +65,7 @@ class Module {
module is elaborated. During parsing, I put the parameters
into this map. */
map<string,PExpr*>parameters;
+ map<string,PExpr*>localparams;
/* The module also has defparam assignments which don't create
new parameters within the module, but may be used to set
@@ -102,9 +103,9 @@ class Module {
PWire* get_wire(const string&name) const;
PGate* get_gate(const string&name);
- const map<string,PWire*>& get_wires() const { return wires_; }
- const list<PGate*>& get_gates() const { return gates_; }
- const list<PProcess*>& get_behaviors() const { return behaviors_; }
+ const map<string,PWire*>& get_wires() const;
+ const list<PGate*>& get_gates() const;
+ const list<PProcess*>& get_behaviors() const;
void dump(ostream&out) const;
bool elaborate(Design*, NetScope*scope) const;
@@ -129,6 +130,9 @@ class Module {
/*
* $Log: Module.h,v $
+ * Revision 1.16 2000/03/12 17:09:40 steve
+ * Support localparam.
+ *
* Revision 1.15 2000/03/08 04:36:53 steve
* Redesign the implementation of scopes and parameters.
* I now generate the scopes and notice the parameters
View
6 README.txt
@@ -42,6 +42,12 @@ on a UNIX-like system:
- bison
+ - gperf 2.7
+ The lexical analyzer doesn't recognize keywords directly,
+ but instead matches symbols and looks them up in a hash
+ table in order to get the proper lexical code. The gperf
+ program generates the lookup table.
+
2.2 Compilation
Unpack the tar-ball and cd into the verilog-######### directory
View
11 design_dump.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: design_dump.cc,v 1.68 2000/03/08 04:36:53 steve Exp $"
+#ident "$Id: design_dump.cc,v 1.69 2000/03/12 17:09:40 steve Exp $"
#endif
/*
@@ -616,6 +616,12 @@ void NetScope::dump(ostream&o) const
o << " parameter " << (*pp).first << " = " <<
*(*pp).second << ";" << endl;
}
+
+ for (pp = localparams_.begin()
+ ; pp != localparams_.end() ; pp ++) {
+ o << " localparam " << (*pp).first << " = " <<
+ *(*pp).second << ";" << endl;
+ }
}
/* Dump the saved defparam assignments here. */
@@ -886,6 +892,9 @@ void Design::dump(ostream&o) const
/*
* $Log: design_dump.cc,v $
+ * Revision 1.69 2000/03/12 17:09:40 steve
+ * Support localparam.
+ *
* Revision 1.68 2000/03/08 04:36:53 steve
* Redesign the implementation of scopes and parameters.
* I now generate the scopes and notice the parameters
View
24 elab_scope.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: elab_scope.cc,v 1.2 2000/03/11 03:25:52 steve Exp $"
+#ident "$Id: elab_scope.cc,v 1.3 2000/03/12 17:09:41 steve Exp $"
#endif
/*
@@ -60,6 +60,13 @@ bool Module::elaborate_scope(Design*des, NetScope*scope) const
scope->set_parameter((*cur).first, new NetEParam);
}
+ for (mparm_it_t cur = localparams.begin()
+ ; cur != localparams.end() ; cur ++) {
+
+ scope->set_parameter((*cur).first, new NetEParam);
+ }
+
+
// Now scan the parameters again, this time elaborating them
// for use as parameter values. This is after the previous
// scan so that local parameter names can be used in the
@@ -77,6 +84,18 @@ bool Module::elaborate_scope(Design*des, NetScope*scope) const
delete val;
}
+ for (mparm_it_t cur = localparams.begin()
+ ; cur != localparams.end() ; cur ++) {
+
+ PExpr*ex = (*cur).second;
+ assert(ex);
+
+ NetExpr*val = ex->elaborate_pexpr(des, scope);
+ val = scope->set_parameter((*cur).first, val);
+ assert(val);
+ delete val;
+ }
+
// Run through the defparams for this module, elaborate the
// expressions in this context and save the result is a table
// for later final override.
@@ -372,6 +391,9 @@ void PWhile::elaborate_scope(Design*des, NetScope*scope) const
/*
* $Log: elab_scope.cc,v $
+ * Revision 1.3 2000/03/12 17:09:41 steve
+ * Support localparam.
+ *
* Revision 1.2 2000/03/11 03:25:52 steve
* Locate scopes in statements.
*
View
10 lexor.lex
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: lexor.lex,v 1.43 2000/03/05 06:14:10 steve Exp $"
+#ident "$Id: lexor.lex,v 1.44 2000/03/12 17:09:41 steve Exp $"
#endif
//# define YYSTYPE lexval
@@ -30,6 +30,7 @@
# include "parse.h"
# include <ctype.h>
# include <string.h>
+# include "lexor_keyword.h"
extern FILE*vl_input;
extern string vl_file;
@@ -42,7 +43,6 @@ static void reset_lexor();
static void line_directive();
static void line_directive2();
-extern int check_identifier(const char*str, int len);
static verinum*make_sized_binary(const char*txt);
static verinum*make_sized_dec(const char*txt);
static verinum*make_unsized_dec(const char*txt);
@@ -131,13 +131,15 @@ W [ \t\b\f\r]+
<UDPTABLE>[pPnN01\?\*\-] { return yytext[0]; }
[a-zA-Z_][a-zA-Z0-9$_]* {
- int rc = check_identifier(yytext, yyleng);
+ int rc = lexor_keyword_code(yytext, yyleng);
if (rc == IDENTIFIER)
yylval.text = strdup(yytext);
else
yylval.text = 0;
- return rc; }
+ return rc;
+ }
+
[a-zA-Z_][a-zA-Z0-9$_]*(\.[a-zA-Z_][a-zA-Z0-9$_]*)+ {
yylval.text = strdup(yytext);
View
230 lexor_keyword.cc
@@ -1,230 +0,0 @@
-/* C code produced by gperf version 2.7 */
-/* Command-line: gperf -o -i 1 -C -k 1-3,$ -L C -H keyword_hash -N check_identifier -tT lexor_keyword.gperf > lexor_keyword.cc */
-
-#include "parse_misc.h"
-#include "parse.h"
-#include <string.h>
-
-
-#define TOTAL_KEYWORDS 99
-#define MIN_WORD_LENGTH 2
-#define MAX_WORD_LENGTH 12
-#define MIN_HASH_VALUE 7
-#define MAX_HASH_VALUE 239
-/* maximum key range = 233, duplicates = 0 */
-
-#ifdef __GNUC__
-__inline
-#endif
-static unsigned int
-keyword_hash (const char *str, int len)
-{
- static const unsigned char asso_values[] =
- {
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 126, 66,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 31, 11, 81,
- 1, 1, 81, 26, 11, 51, 11, 21, 81, 81,
- 1, 46, 16, 240, 1, 1, 6, 11, 36, 46,
- 21, 16, 6, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
- 240, 240, 240, 240, 240, 240
- };
- int hval = len;
-
- hval += asso_values[(unsigned char)str[len - 1]];
- hval += asso_values[(unsigned char)str[0]];
- hval += asso_values[(unsigned char)str[1]];
-
- if (len > 2)
- hval += asso_values[(unsigned char)str[2]];
-
- return hval ;
-}
-
-int
-check_identifier (const char *str, int len)
-{
- static const struct { const char *name; int tokenType; } wordlist[] =
- {
- {""}, {""}, {""}, {""}, {""}, {""}, {""},
- {"end", K_end},
- {""}, {""}, {""},
- {"endcase", K_endcase},
- {"endtable", K_endtable},
- {"endmodule", K_endmodule},
- {"rtran", K_rtran},
- {"endfunction", K_endfunction},
- {"endprimitive", K_endprimitive},
- {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
- {""}, {""}, {""},
- {"endspecify", K_endspecify},
- {"repeat", K_repeat},
- {"endtask", K_endtask},
- {""},
- {"edge", K_edge},
- {""}, {""},
- {"negedge", K_negedge},
- {"and", K_and},
- {"nand", K_nand},
- {""},
- {"assign", K_assign},
- {"specify", K_specify},
- {"deassign", K_deassign},
- {"tran", K_tran},
- {"begin", K_begin},
- {""}, {""}, {""}, {""},
- {"event", K_event},
- {"or", K_or},
- {""},
- {"nor", K_nor},
- {""},
- {"table", K_table},
- {""}, {""},
- {"reg", K_reg},
- {"parameter", K_parameter},
- {""}, {""},
- {"disable", K_disable},
- {"not", K_not},
- {"task", K_task},
- {"trior", K_trior},
- {"triand", K_triand},
- {"integer", K_integer},
- {""}, {""}, {""}, {""},
- {"posedge", K_posedge},
- {"xor", K_xor},
- {"xnor", K_xnor},
- {""},
- {"output", K_output},
- {""}, {""},
- {"primitive", K_primitive},
- {"input", K_input},
- {""},
- {"strong1", K_strong1},
- {"rtranif1", K_rtranif1},
- {"wand", K_wand},
- {""}, {""}, {""}, {""},
- {"else", K_else},
- {"rnmos", K_rnmos},
- {"trireg", K_trireg},
- {"release", K_release},
- {""}, {""}, {""}, {""},
- {"default", K_default},
- {"wor", K_wor},
- {""}, {""}, {""},
- {"supply1", K_supply1},
- {"function", K_function},
- {"wire", K_wire},
- {"rpmos", K_rpmos},
- {""}, {""}, {""},
- {"specparam", K_specparam},
- {"inout", K_inout},
- {""},
- {"tranif1", K_tranif1},
- {"tri", K_tri},
- {"join", K_join},
- {"while", K_while},
- {""}, {""},
- {"pulldown", K_pulldown},
- {"case", K_case},
- {"large", K_large},
- {""}, {""},
- {"scalered", K_scalered},
- {""},
- {"casez", K_casez},
- {"notif1", K_notif1},
- {""},
- {"vectored", K_vectored},
- {"tri1", K_tri1},
- {""},
- {"pullup", K_pullup},
- {""},
- {"for", K_for},
- {"nmos", K_nmos},
- {"force", K_force},
- {"module", K_module},
- {"forever", K_forever},
- {""},
- {"wait", K_wait},
- {"casex", K_casex},
- {""},
- {"strong0", K_strong0},
- {"rtranif0", K_rtranif0},
- {"time", K_time},
- {""}, {""}, {""}, {""},
- {"pmos", K_pmos},
- {"weak1", K_weak1},
- {""}, {""}, {""},
- {"fork", K_fork},
- {""}, {""}, {""}, {""}, {""}, {""},
- {"highz1", K_highz1},
- {"supply0", K_supply0},
- {""}, {""}, {""},
- {"always", K_always},
- {""}, {""}, {""},
- {"rcmos", K_rcmos},
- {"medium", K_medium},
- {"tranif0", K_tranif0},
- {"defparam", K_defparam},
- {""}, {""},
- {"bufif1", K_bufif1},
- {""}, {""}, {""},
- {"pull1", K_pull1},
- {""}, {""}, {""}, {""}, {""},
- {"notif0", K_notif0},
- {""},
- {"buf", K_buf},
- {"tri0", K_tri0},
- {""}, {""},
- {"initial", K_initial},
- {""}, {""}, {""}, {""}, {""}, {""}, {""},
- {"small", K_small},
- {""}, {""}, {""}, {""}, {""},
- {"macromodule", K_macromodule},
- {""}, {""}, {""},
- {"weak0", K_weak0},
- {""}, {""}, {""},
- {"cmos", K_cmos},
- {""},
- {"if", K_if},
- {""}, {""}, {""}, {""},
- {"highz0", K_highz0},
- {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
- {""}, {""}, {""}, {""}, {""},
- {"bufif0", K_bufif0},
- {""}, {""}, {""},
- {"pull0", K_pull0}
- };
-
- if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
- {
- int key = keyword_hash (str, len);
-
- if (key <= MAX_HASH_VALUE && key >= 0)
- {
- const char *s = wordlist[key].name;
-
- if (*str == *s && !strcmp (str + 1, s + 1))
- return wordlist[key].tokenType;
- }
- }
- return IDENTIFIER;
-}
View
19 lexor_keyword.gperf
@@ -4,12 +4,10 @@
#include "parse_misc.h"
#include "parse.h"
#include <string.h>
+#include "lexor_keyword.h"
%}
-struct Keywords {
- char *name;
- int tokenType;
-} Keywords;
+struct lexor_keyword { const char*name; int tokenType; };
%%
always, K_always
and, K_and
@@ -51,6 +49,7 @@ input, K_input
integer, K_integer
join, K_join
large, K_large
+localparam, K_localparam
macromodule, K_macromodule
medium, K_medium
module, K_module
@@ -109,4 +108,14 @@ while, K_while
wire, K_wire
wor, K_wor
xnor, K_xnor
-xor, K_xor
+xor, K_xor
+%%
+
+int lexor_keyword_code(const char*str, unsigned nstr)
+{
+ const struct lexor_keyword*rc = check_identifier(str, nstr);
+ if (rc == 0)
+ return IDENTIFIER;
+ else
+ return rc->tokenType;
+}
View
33 lexor_keyword.h
@@ -0,0 +1,33 @@
+#ifndef __lexor_keyword_H
+#define __lexor_keyword_H
+/*
+ * Copyright (c) 2000 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) && !defined(macintosh)
+#ident "$Id: lexor_keyword.h,v 1.1 2000/03/12 17:09:41 steve Exp $"
+#endif
+
+extern int lexor_keyword_code (const char*str, unsigned len);
+
+/*
+ * $Log: lexor_keyword.h,v $
+ * Revision 1.1 2000/03/12 17:09:41 steve
+ * Support localparam.
+ *
+ */
+#endif
View
27 netlist.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: netlist.cc,v 1.107 2000/03/10 06:20:48 steve Exp $"
+#ident "$Id: netlist.cc,v 1.108 2000/03/12 17:09:41 steve Exp $"
#endif
# include <cassert>
@@ -2276,13 +2276,27 @@ NetExpr* NetScope::set_parameter(const string&key, NetExpr*expr)
return res;
}
+NetExpr* NetScope::set_localparam(const string&key, NetExpr*expr)
+{
+ NetExpr*&ref = localparams_[key];
+ NetExpr* res = ref;
+ ref = expr;
+ return res;
+}
+
const NetExpr* NetScope::get_parameter(const string&key) const
{
- map<string,NetExpr*>::const_iterator idx = parameters_.find(key);
- if (idx == parameters_.end())
- return 0;
- else
+ map<string,NetExpr*>::const_iterator idx;
+
+ idx = parameters_.find(key);
+ if (idx != parameters_.end())
+ return (*idx).second;
+
+ idx = localparams_.find(key);
+ if (idx != localparams_.end())
return (*idx).second;
+
+ return 0;
}
NetScope::TYPE NetScope::type() const
@@ -2632,6 +2646,9 @@ void NetUDP::set_initial(char val)
/*
* $Log: netlist.cc,v $
+ * Revision 1.108 2000/03/12 17:09:41 steve
+ * Support localparam.
+ *
* Revision 1.107 2000/03/10 06:20:48 steve
* Handle defparam to partial hierarchical names.
*
View
7 netlist.h
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: netlist.h,v 1.113 2000/03/11 03:25:52 steve Exp $"
+#ident "$Id: netlist.h,v 1.114 2000/03/12 17:09:41 steve Exp $"
#endif
/*
@@ -1993,6 +1993,7 @@ class NetScope {
previous expression, if there was one. */
NetExpr* set_parameter(const string&name, NetExpr*val);
+ NetExpr* set_localparam(const string&name, NetExpr*val);
const NetExpr*get_parameter(const string&name) const;
@@ -2024,6 +2025,7 @@ class NetScope {
string name_;
map<string,NetExpr*>parameters_;
+ map<string,NetExpr*>localparams_;
NetScope*up_;
NetScope*sib_;
@@ -2193,6 +2195,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
/*
* $Log: netlist.h,v $
+ * Revision 1.114 2000/03/12 17:09:41 steve
+ * Support localparam.
+ *
* Revision 1.113 2000/03/11 03:25:52 steve
* Locate scopes in statements.
*
View
36 parse.y
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: parse.y,v 1.85 2000/03/08 04:36:54 steve Exp $"
+#ident "$Id: parse.y,v 1.86 2000/03/12 17:09:41 steve Exp $"
#endif
# include "parse_misc.h"
@@ -81,7 +81,8 @@ extern void lex_end_table();
%token K_edge K_else K_end K_endcase K_endfunction K_endmodule
%token K_endprimitive K_endspecify K_endtable K_endtask K_event K_for
%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_initial K_inout K_input K_integer K_join K_large K_localparam
+%token 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_parameter K_pmos K_posedge K_primitive
%token K_pull0 K_pull1 K_pulldown K_pullup K_rcmos K_real K_realtime
@@ -1096,6 +1097,7 @@ module_item
delete $2;
}
| K_parameter parameter_assign_list ';'
+ | K_localparam localparam_assign_list ';'
| gatetype delay3_opt gate_instance_list ';'
{ pform_makegates($1, $2, $3);
}
@@ -1229,6 +1231,36 @@ parameter_assign_list
;
+ /* Localparam assignments and asignment lists are broken into
+ separate BNF so that I can call slightly different paramter
+ handling code. They parse the same as parameters, they just
+ behave differently when someone tries to override them. */
+
+localparam_assign
+ : IDENTIFIER '=' expression
+ { PExpr*tmp = $3;
+ if (!pform_expression_is_constant(tmp)) {
+ yyerror(@3, "error: parameter value "
+ "must be constant.");
+ delete tmp;
+ tmp = 0;
+ }
+ pform_set_localparam($1, tmp);
+ delete $1;
+ }
+ ;
+
+localparam_assign_list
+ : localparam_assign
+ | range localparam_assign
+ { yywarn(@1, "Ranges in localparam definition "
+ "are not supported.");
+ delete $1;
+ }
+ | localparam_assign_list ',' localparam_assign
+ ;
+
+
/* The parameters of a module instance can be overridden by writing
a list of expressions in a syntax much line a delay list. (The
difference being the list can have any length.) The pform that
View
11 pform.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: pform.cc,v 1.55 2000/03/08 04:36:54 steve Exp $"
+#ident "$Id: pform.cc,v 1.56 2000/03/12 17:09:41 steve Exp $"
#endif
# include "compiler.h"
@@ -732,6 +732,12 @@ void pform_set_parameter(const string&name, PExpr*expr)
pform_cur_module->param_names.push_back(name);
}
+void pform_set_localparam(const string&name, PExpr*expr)
+{
+ assert(expr);
+ pform_cur_module->localparams[name] = expr;
+}
+
void pform_set_defparam(const string&name, PExpr*expr)
{
assert(expr);
@@ -827,6 +833,9 @@ int pform_parse(const char*path, map<string,Module*>&modules,
/*
* $Log: pform.cc,v $
+ * Revision 1.56 2000/03/12 17:09:41 steve
+ * Support localparam.
+ *
* Revision 1.55 2000/03/08 04:36:54 steve
* Redesign the implementation of scopes and parameters.
* I now generate the scopes and notice the parameters
View
6 pform.h
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: pform.h,v 1.36 2000/03/08 04:36:54 steve Exp $"
+#ident "$Id: pform.h,v 1.37 2000/03/12 17:09:41 steve Exp $"
#endif
# include "netlist.h"
@@ -133,6 +133,7 @@ extern void pform_set_attrib(const string&name, const string&key,
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 void pform_set_localparam(const string&name, PExpr*expr);
extern void pform_set_defparam(const string&name, PExpr*expr);
extern PProcess* pform_make_behavior(PProcess::Type, Statement*);
@@ -181,6 +182,9 @@ extern void pform_dump(ostream&out, Module*mod);
/*
* $Log: pform.h,v $
+ * Revision 1.37 2000/03/12 17:09:41 steve
+ * Support localparam.
+ *
* Revision 1.36 2000/03/08 04:36:54 steve
* Redesign the implementation of scopes and parameters.
* I now generate the scopes and notice the parameters
View
14 pform_dump.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: pform_dump.cc,v 1.50 2000/03/08 04:36:54 steve Exp $"
+#ident "$Id: pform_dump.cc,v 1.51 2000/03/12 17:09:41 steve Exp $"
#endif
/*
@@ -609,6 +609,15 @@ void Module::dump(ostream&out) const
out << "/* ERROR */;" << endl;
}
+ for (parm_iter_t cur = localparams.begin()
+ ; cur != localparams.end() ; cur ++) {
+ out << " localparam " << (*cur).first << " = ";
+ if ((*cur).second)
+ out << *(*cur).second << ";" << endl;
+ else
+ out << "/* ERROR */;" << endl;
+ }
+
for (parm_iter_t cur = defparms.begin()
; cur != defparms.end() ; cur ++) {
out << " defparam " << (*cur).first << " = ";
@@ -711,6 +720,9 @@ void PUdp::dump(ostream&out) const
/*
* $Log: pform_dump.cc,v $
+ * Revision 1.51 2000/03/12 17:09:41 steve
+ * Support localparam.
+ *
* Revision 1.50 2000/03/08 04:36:54 steve
* Redesign the implementation of scopes and parameters.
* I now generate the scopes and notice the parameters

0 comments on commit 6eef545

Please sign in to comment.
Something went wrong with that request. Please try again.