diff --git a/Makefile.in b/Makefile.in index 9326070cf7..28668c04d3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -111,7 +111,7 @@ parse.o parse_misc.o pform.o pform_dump.o pform_types.o \ set_width.o symbol_search.o sync.o sys_funcs.o \ verinum.o verireal.o target.o targets.o \ Attrib.o HName.o LineInfo.o Module.o PDelays.o PEvent.o \ -PExpr.o PGate.o PGenerate.o PSpec.o \ +PExpr.o PGate.o PGenerate.o PScope.o PSpec.o \ PTask.o PUdp.o PFunction.o PWire.o Statement.o StringHeap.o \ $(FF) $(TT) diff --git a/Module.cc b/Module.cc index ffe2c2e119..74f36f678c 100644 --- a/Module.cc +++ b/Module.cc @@ -29,7 +29,7 @@ /* n is a permallocated string. */ Module::Module(perm_string n) -: name_(n) +: PScope(n) { library_flag = false; default_nettype = NetNet::NONE; diff --git a/Module.h b/Module.h index 28be4fc11b..61757b4b73 100644 --- a/Module.h +++ b/Module.h @@ -28,10 +28,10 @@ # include "StringHeap.h" # include "HName.h" # include "named.h" +# include "PScope.h" # include "LineInfo.h" # include "netlist.h" # include "pform_types.h" -class PEvent; class PExpr; class PEIdent; class PGate; @@ -50,7 +50,7 @@ class NetScope; * therefore the handle for grasping the described circuit. */ -class Module : public LineInfo { +class Module : public PScope, public LineInfo { /* The module ports are in general a vector of port_t objects. Each port has a name and an ordered list of @@ -113,9 +113,6 @@ class Module : public LineInfo { named array of PEident pointers. */ svector ports; - /* Keep a table of named events declared in the module. */ - mapevents; - map attributes; /* These are the timescale for this module. The default is @@ -132,7 +129,8 @@ class Module : public LineInfo { list specify_paths; - perm_string mod_name() const { return name_; } + // The mod_name() is the name of the module type. + perm_string mod_name() const { return pscope_name(); } void add_gate(PGate*gate); @@ -166,8 +164,6 @@ class Module : public LineInfo { bool elaborate_sig(Design*, NetScope*scope) const; private: - perm_string name_; - map wires_; list gates_; list behaviors_; diff --git a/PFunction.cc b/PFunction.cc index ebf035b6e7..f8f5e6027e 100644 --- a/PFunction.cc +++ b/PFunction.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2008 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 @@ -16,16 +16,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#ifdef HAVE_CVS_IDENT -#ident "$Id: PFunction.cc,v 1.7 2004/05/31 23:34:36 steve Exp $" -#endif # include "config.h" #include "PTask.h" PFunction::PFunction(perm_string name) -: name_(name), ports_(0), statement_(0) +: PScope(name), ports_(0), statement_(0) { return_type_.type = PTF_NONE; } @@ -51,28 +48,3 @@ void PFunction::set_return(PTaskFuncArg t) { return_type_ = t; } - -/* - * $Log: PFunction.cc,v $ - * Revision 1.7 2004/05/31 23:34:36 steve - * Rewire/generalize parsing an elaboration of - * function return values to allow for better - * speed and more type support. - * - * Revision 1.6 2002/08/12 01:34:58 steve - * conditional ident string using autoconfig. - * - * Revision 1.5 2001/07/25 03:10:48 steve - * Create a config.h.in file to hold all the config - * junk, and support gcc 3.0. (Stephan Boettcher) - * - * Revision 1.4 2001/01/13 22:20:08 steve - * Parse parameters within nested scopes. - * - * Revision 1.3 2000/02/23 02:56:53 steve - * Macintosh compilers do not support ident. - * - * Revision 1.2 1999/08/25 22:22:41 steve - * elaborate some aspects of functions. - * - */ diff --git a/PScope.cc b/PScope.cc new file mode 100644 index 0000000000..3c1b1da4a4 --- /dev/null +++ b/PScope.cc @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2008 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 + */ + +# include "PScope.h" + +PScope::PScope(perm_string n) +: name_(n) +{ +} + +PScope::~PScope() +{ +} diff --git a/PScope.h b/PScope.h new file mode 100644 index 0000000000..5125f4bbae --- /dev/null +++ b/PScope.h @@ -0,0 +1,50 @@ +#ifndef __PScope_H +#define __PScope_H +/* + * Copyright (c) 2008 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 + */ + +# include "StringHeap.h" +# include + +class PEvent; + +/* + * The PScope class is a base representation of an object that + * represents some sort of compile-time scope. For example, a module, + * a function/task, a named block is derived from a PScope. + * + * NOTE: This is note the same concept as the "scope" of an elaborated + * hierarchy. That is represented by NetScope objects after elaboration. + */ +class PScope { + + public: + PScope(perm_string name); + ~PScope(); + + perm_string pscope_name() const { return name_; } + + // Named events in the scope. + mapevents; + + private: + perm_string name_; +}; + +#endif diff --git a/PTask.cc b/PTask.cc index bd725bbb71..9155cb0b2f 100644 --- a/PTask.cc +++ b/PTask.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2008 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 @@ -16,16 +16,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#ifdef HAVE_CVS_IDENT -#ident "$Id: PTask.cc,v 1.7 2002/08/12 01:34:58 steve Exp $" -#endif # include "config.h" # include "PTask.h" -PTask::PTask() -: ports_(0), statement_(0) +PTask::PTask(perm_string name) +: PScope(name), ports_(0), statement_(0) { } diff --git a/PTask.h b/PTask.h index 596cdc59da..9c296a78d2 100644 --- a/PTask.h +++ b/PTask.h @@ -1,7 +1,7 @@ #ifndef __PTask_H #define __PTask_H /* - * Copyright (c) 1999-2000 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2008 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 @@ -18,11 +18,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#ifdef HAVE_CVS_IDENT -#ident "$Id: PTask.h,v 1.14 2007/03/06 05:22:49 steve Exp $" -#endif # include "LineInfo.h" +# include "PScope.h" # include "svector.h" # include "StringHeap.h" # include @@ -50,10 +48,10 @@ struct PTaskFuncArg { /* * The PTask holds the parsed definitions of a task. */ -class PTask : public LineInfo { +class PTask : public PScope, public LineInfo { public: - explicit PTask(); + explicit PTask(perm_string name); ~PTask(); void set_ports(svector*p); @@ -89,7 +87,7 @@ class PTask : public LineInfo { * * The output value is not elaborated until elaborate_sig. */ -class PFunction : public LineInfo { +class PFunction : public PScope, public LineInfo { public: explicit PFunction(perm_string name); @@ -110,68 +108,9 @@ class PFunction : public LineInfo { void dump(ostream&, unsigned) const; private: - perm_string name_; PTaskFuncArg return_type_; svector *ports_; Statement *statement_; }; -/* - * $Log: PTask.h,v $ - * Revision 1.14 2007/03/06 05:22:49 steve - * Support signed function return values. - * - * Revision 1.13 2004/05/31 23:34:36 steve - * Rewire/generalize parsing an elaboration of - * function return values to allow for better - * speed and more type support. - * - * Revision 1.12 2002/08/12 01:34:58 steve - * conditional ident string using autoconfig. - * - * Revision 1.11 2001/11/22 06:20:59 steve - * Use NetScope instead of string for scope path. - * - * Revision 1.10 2001/01/13 22:20:08 steve - * Parse parameters within nested scopes. - * - * Revision 1.9 2000/07/30 18:25:43 steve - * Rearrange task and function elaboration so that the - * NetTaskDef and NetFuncDef functions are created during - * signal enaboration, and carry these objects in the - * NetScope class instead of the extra, useless map in - * the Design class. - * - * Revision 1.8 2000/03/08 04:36:53 steve - * Redesign the implementation of scopes and parameters. - * I now generate the scopes and notice the parameters - * in a separate pass over the pform. Once the scopes - * are generated, I can process overrides and evalutate - * paremeters before elaboration begins. - * - * Revision 1.7 2000/02/23 02:56:53 steve - * Macintosh compilers do not support ident. - * - * Revision 1.6 1999/09/30 21:28:34 steve - * Handle mutual reference of tasks by elaborating - * task definitions in two passes, like functions. - * - * Revision 1.5 1999/09/01 20:46:19 steve - * Handle recursive functions and arbitrary function - * references to other functions, properly pass - * function parameters and save function results. - * - * 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) - * - * Revision 1.2 1999/07/24 02:11:19 steve - * Elaborate task input ports. - * - * Revision 1.1 1999/07/03 02:12:51 steve - * Elaborate user defined tasks. - * - */ #endif diff --git a/elab_sig.cc b/elab_sig.cc index 7ea9be5dfb..ab484bfa05 100644 --- a/elab_sig.cc +++ b/elab_sig.cc @@ -89,7 +89,7 @@ bool Module::elaborate_sig(Design*des, NetScope*scope) const if (wt == wires_.end()) { cerr << get_fileline() << ": error: " << "Port " << pp->expr[cc]->path() << " (" - << (idx+1) << ") of module " << name_ + << (idx+1) << ") of module " << mod_name() << " is not declared within module." << endl; des->errors += 1; continue; @@ -98,7 +98,7 @@ bool Module::elaborate_sig(Design*des, NetScope*scope) const if ((*wt).second->get_port_type() == NetNet::NOT_A_PORT) { cerr << get_fileline() << ": error: " << "Port " << pp->expr[cc]->path() << " (" - << (idx+1) << ") of module " << name_ + << (idx+1) << ") of module " << mod_name() << " has no direction declaration." << endl; des->errors += 1; diff --git a/parse.y b/parse.y index 818372c7c2..96c9a8111d 100644 --- a/parse.y +++ b/parse.y @@ -1842,36 +1842,36 @@ module_item statements in the task body. But we continue to accept it as an extension. */ - | K_task IDENTIFIER ';' - { pform_push_scope($2); } - task_item_list_opt - statement_or_null - K_endtask - { PTask*tmp = new PTask; - perm_string tmp2 = lex_strings.make($2); - FILE_NAME(tmp, @1); - tmp->set_ports($5); - tmp->set_statement($6); - pform_set_task(tmp2, tmp); - pform_pop_scope(); - delete $2; - } + | K_task IDENTIFIER ';' + { pform_push_scope($2); } + task_item_list_opt + statement_or_null + K_endtask + { perm_string task_name = lex_strings.make($2); + PTask*tmp = new PTask(task_name); + FILE_NAME(tmp, @1); + tmp->set_ports($5); + tmp->set_statement($6); + pform_set_task(task_name, tmp); + pform_pop_scope(); + delete $2; + } - | K_task IDENTIFIER - { pform_push_scope($2); } - '(' task_port_decl_list ')' ';' - task_item_list_opt - statement_or_null - K_endtask - { PTask*tmp = new PTask; - perm_string tmp2 = lex_strings.make($2); - FILE_NAME(tmp, @1); - tmp->set_ports($5); - tmp->set_statement($9); - pform_set_task(tmp2, tmp); - pform_pop_scope(); - delete $2; - } + | K_task IDENTIFIER + { pform_push_scope($2); } + '(' task_port_decl_list ')' ';' + task_item_list_opt + statement_or_null + K_endtask + { perm_string task_name = lex_strings.make($2); + PTask*tmp = new PTask(task_name); + FILE_NAME(tmp, @1); + tmp->set_ports($5); + tmp->set_statement($9); + pform_set_task(task_name, tmp); + pform_pop_scope(); + delete $2; + } /* The function declaration rule matches the function declaration header, then pushes the function scope. This causes the diff --git a/pform_dump.cc b/pform_dump.cc index addc8932c0..cee72d81db 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -697,7 +697,7 @@ void PFunction::dump(ostream&out, unsigned ind) const out << "] "; } - out << name_ << ";" << endl; + out << pscope_name() << ";" << endl; if (ports_) for (unsigned idx = 0 ; idx < ports_->count() ; idx += 1) { @@ -911,7 +911,7 @@ void Module::dump(ostream&out) const out << " *) "; } - out << "module " << name_ << ";" << endl; + out << "module " << mod_name() << ";" << endl; for (unsigned idx = 0 ; idx < ports.count() ; idx += 1) { port_t*cur = ports[idx];