Skip to content

Commit 3f2fa29

Browse files
committed
Factor compile-time scopes into PScope class
Modules, functions and tasks are named scopes so derive them all from the PScope base class. These items all take scoped items, so the eventual plan is to move these items into PScope.
1 parent 331faa2 commit 3f2fa29

File tree

11 files changed

+128
-145
lines changed

11 files changed

+128
-145
lines changed

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ parse.o parse_misc.o pform.o pform_dump.o pform_types.o \
111111
set_width.o symbol_search.o sync.o sys_funcs.o \
112112
verinum.o verireal.o target.o targets.o \
113113
Attrib.o HName.o LineInfo.o Module.o PDelays.o PEvent.o \
114-
PExpr.o PGate.o PGenerate.o PSpec.o \
114+
PExpr.o PGate.o PGenerate.o PScope.o PSpec.o \
115115
PTask.o PUdp.o PFunction.o PWire.o Statement.o StringHeap.o \
116116
$(FF) $(TT)
117117

Module.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/* n is a permallocated string. */
3131
Module::Module(perm_string n)
32-
: name_(n)
32+
: PScope(n)
3333
{
3434
library_flag = false;
3535
default_nettype = NetNet::NONE;

Module.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
# include "StringHeap.h"
2929
# include "HName.h"
3030
# include "named.h"
31+
# include "PScope.h"
3132
# include "LineInfo.h"
3233
# include "netlist.h"
3334
# include "pform_types.h"
34-
class PEvent;
3535
class PExpr;
3636
class PEIdent;
3737
class PGate;
@@ -50,7 +50,7 @@ class NetScope;
5050
* therefore the handle for grasping the described circuit.
5151
*/
5252

53-
class Module : public LineInfo {
53+
class Module : public PScope, public LineInfo {
5454

5555
/* The module ports are in general a vector of port_t
5656
objects. Each port has a name and an ordered list of
@@ -113,9 +113,6 @@ class Module : public LineInfo {
113113
named array of PEident pointers. */
114114
svector<port_t*> ports;
115115

116-
/* Keep a table of named events declared in the module. */
117-
map<perm_string,PEvent*>events;
118-
119116
map<perm_string,PExpr*> attributes;
120117

121118
/* These are the timescale for this module. The default is
@@ -132,7 +129,8 @@ class Module : public LineInfo {
132129

133130
list<PSpecPath*> specify_paths;
134131

135-
perm_string mod_name() const { return name_; }
132+
// The mod_name() is the name of the module type.
133+
perm_string mod_name() const { return pscope_name(); }
136134

137135
void add_gate(PGate*gate);
138136

@@ -166,8 +164,6 @@ class Module : public LineInfo {
166164
bool elaborate_sig(Design*, NetScope*scope) const;
167165

168166
private:
169-
perm_string name_;
170-
171167
map<pform_name_t,PWire*> wires_;
172168
list<PGate*> gates_;
173169
list<PProcess*> behaviors_;

PFunction.cc

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999 Stephen Williams ([email protected])
2+
* Copyright (c) 1999-2008 Stephen Williams ([email protected])
33
*
44
* This source code is free software; you can redistribute it
55
* and/or modify it in source code form under the terms of the GNU
@@ -16,16 +16,13 @@
1616
* along with this program; if not, write to the Free Software
1717
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
1818
*/
19-
#ifdef HAVE_CVS_IDENT
20-
#ident "$Id: PFunction.cc,v 1.7 2004/05/31 23:34:36 steve Exp $"
21-
#endif
2219

2320
# include "config.h"
2421

2522
#include "PTask.h"
2623

2724
PFunction::PFunction(perm_string name)
28-
: name_(name), ports_(0), statement_(0)
25+
: PScope(name), ports_(0), statement_(0)
2926
{
3027
return_type_.type = PTF_NONE;
3128
}
@@ -51,28 +48,3 @@ void PFunction::set_return(PTaskFuncArg t)
5148
{
5249
return_type_ = t;
5350
}
54-
55-
/*
56-
* $Log: PFunction.cc,v $
57-
* Revision 1.7 2004/05/31 23:34:36 steve
58-
* Rewire/generalize parsing an elaboration of
59-
* function return values to allow for better
60-
* speed and more type support.
61-
*
62-
* Revision 1.6 2002/08/12 01:34:58 steve
63-
* conditional ident string using autoconfig.
64-
*
65-
* Revision 1.5 2001/07/25 03:10:48 steve
66-
* Create a config.h.in file to hold all the config
67-
* junk, and support gcc 3.0. (Stephan Boettcher)
68-
*
69-
* Revision 1.4 2001/01/13 22:20:08 steve
70-
* Parse parameters within nested scopes.
71-
*
72-
* Revision 1.3 2000/02/23 02:56:53 steve
73-
* Macintosh compilers do not support ident.
74-
*
75-
* Revision 1.2 1999/08/25 22:22:41 steve
76-
* elaborate some aspects of functions.
77-
*
78-
*/

PScope.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2008 Stephen Williams ([email protected])
3+
*
4+
* This source code is free software; you can redistribute it
5+
* and/or modify it in source code form under the terms of the GNU
6+
* General Public License as published by the Free Software
7+
* Foundation; either version 2 of the License, or (at your option)
8+
* any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18+
*/
19+
20+
# include "PScope.h"
21+
22+
PScope::PScope(perm_string n)
23+
: name_(n)
24+
{
25+
}
26+
27+
PScope::~PScope()
28+
{
29+
}

PScope.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef __PScope_H
2+
#define __PScope_H
3+
/*
4+
* Copyright (c) 2008 Stephen Williams ([email protected])
5+
*
6+
* This source code is free software; you can redistribute it
7+
* and/or modify it in source code form under the terms of the GNU
8+
* General Public License as published by the Free Software
9+
* Foundation; either version 2 of the License, or (at your option)
10+
* any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20+
*/
21+
22+
# include "StringHeap.h"
23+
# include <map>
24+
25+
class PEvent;
26+
27+
/*
28+
* The PScope class is a base representation of an object that
29+
* represents some sort of compile-time scope. For example, a module,
30+
* a function/task, a named block is derived from a PScope.
31+
*
32+
* NOTE: This is note the same concept as the "scope" of an elaborated
33+
* hierarchy. That is represented by NetScope objects after elaboration.
34+
*/
35+
class PScope {
36+
37+
public:
38+
PScope(perm_string name);
39+
~PScope();
40+
41+
perm_string pscope_name() const { return name_; }
42+
43+
// Named events in the scope.
44+
map<perm_string,PEvent*>events;
45+
46+
private:
47+
perm_string name_;
48+
};
49+
50+
#endif

PTask.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999 Stephen Williams ([email protected])
2+
* Copyright (c) 1999-2008 Stephen Williams ([email protected])
33
*
44
* This source code is free software; you can redistribute it
55
* and/or modify it in source code form under the terms of the GNU
@@ -16,16 +16,13 @@
1616
* along with this program; if not, write to the Free Software
1717
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
1818
*/
19-
#ifdef HAVE_CVS_IDENT
20-
#ident "$Id: PTask.cc,v 1.7 2002/08/12 01:34:58 steve Exp $"
21-
#endif
2219

2320
# include "config.h"
2421

2522
# include "PTask.h"
2623

27-
PTask::PTask()
28-
: ports_(0), statement_(0)
24+
PTask::PTask(perm_string name)
25+
: PScope(name), ports_(0), statement_(0)
2926
{
3027
}
3128

PTask.h

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __PTask_H
22
#define __PTask_H
33
/*
4-
* Copyright (c) 1999-2000 Stephen Williams ([email protected])
4+
* Copyright (c) 1999-2008 Stephen Williams ([email protected])
55
*
66
* This source code is free software; you can redistribute it
77
* and/or modify it in source code form under the terms of the GNU
@@ -18,11 +18,9 @@
1818
* along with this program; if not, write to the Free Software
1919
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
2020
*/
21-
#ifdef HAVE_CVS_IDENT
22-
#ident "$Id: PTask.h,v 1.14 2007/03/06 05:22:49 steve Exp $"
23-
#endif
2421

2522
# include "LineInfo.h"
23+
# include "PScope.h"
2624
# include "svector.h"
2725
# include "StringHeap.h"
2826
# include <string>
@@ -50,10 +48,10 @@ struct PTaskFuncArg {
5048
/*
5149
* The PTask holds the parsed definitions of a task.
5250
*/
53-
class PTask : public LineInfo {
51+
class PTask : public PScope, public LineInfo {
5452

5553
public:
56-
explicit PTask();
54+
explicit PTask(perm_string name);
5755
~PTask();
5856

5957
void set_ports(svector<PWire *>*p);
@@ -89,7 +87,7 @@ class PTask : public LineInfo {
8987
*
9088
* The output value is not elaborated until elaborate_sig.
9189
*/
92-
class PFunction : public LineInfo {
90+
class PFunction : public PScope, public LineInfo {
9391

9492
public:
9593
explicit PFunction(perm_string name);
@@ -110,68 +108,9 @@ class PFunction : public LineInfo {
110108
void dump(ostream&, unsigned) const;
111109

112110
private:
113-
perm_string name_;
114111
PTaskFuncArg return_type_;
115112
svector<PWire *> *ports_;
116113
Statement *statement_;
117114
};
118115

119-
/*
120-
* $Log: PTask.h,v $
121-
* Revision 1.14 2007/03/06 05:22:49 steve
122-
* Support signed function return values.
123-
*
124-
* Revision 1.13 2004/05/31 23:34:36 steve
125-
* Rewire/generalize parsing an elaboration of
126-
* function return values to allow for better
127-
* speed and more type support.
128-
*
129-
* Revision 1.12 2002/08/12 01:34:58 steve
130-
* conditional ident string using autoconfig.
131-
*
132-
* Revision 1.11 2001/11/22 06:20:59 steve
133-
* Use NetScope instead of string for scope path.
134-
*
135-
* Revision 1.10 2001/01/13 22:20:08 steve
136-
* Parse parameters within nested scopes.
137-
*
138-
* Revision 1.9 2000/07/30 18:25:43 steve
139-
* Rearrange task and function elaboration so that the
140-
* NetTaskDef and NetFuncDef functions are created during
141-
* signal enaboration, and carry these objects in the
142-
* NetScope class instead of the extra, useless map in
143-
* the Design class.
144-
*
145-
* Revision 1.8 2000/03/08 04:36:53 steve
146-
* Redesign the implementation of scopes and parameters.
147-
* I now generate the scopes and notice the parameters
148-
* in a separate pass over the pform. Once the scopes
149-
* are generated, I can process overrides and evalutate
150-
* paremeters before elaboration begins.
151-
*
152-
* Revision 1.7 2000/02/23 02:56:53 steve
153-
* Macintosh compilers do not support ident.
154-
*
155-
* Revision 1.6 1999/09/30 21:28:34 steve
156-
* Handle mutual reference of tasks by elaborating
157-
* task definitions in two passes, like functions.
158-
*
159-
* Revision 1.5 1999/09/01 20:46:19 steve
160-
* Handle recursive functions and arbitrary function
161-
* references to other functions, properly pass
162-
* function parameters and save function results.
163-
*
164-
* Revision 1.4 1999/08/25 22:22:41 steve
165-
* elaborate some aspects of functions.
166-
*
167-
* Revision 1.3 1999/07/31 19:14:47 steve
168-
* Add functions up to elaboration (Ed Carter)
169-
*
170-
* Revision 1.2 1999/07/24 02:11:19 steve
171-
* Elaborate task input ports.
172-
*
173-
* Revision 1.1 1999/07/03 02:12:51 steve
174-
* Elaborate user defined tasks.
175-
*
176-
*/
177116
#endif

elab_sig.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ bool Module::elaborate_sig(Design*des, NetScope*scope) const
8989
if (wt == wires_.end()) {
9090
cerr << get_fileline() << ": error: "
9191
<< "Port " << pp->expr[cc]->path() << " ("
92-
<< (idx+1) << ") of module " << name_
92+
<< (idx+1) << ") of module " << mod_name()
9393
<< " is not declared within module." << endl;
9494
des->errors += 1;
9595
continue;
@@ -98,7 +98,7 @@ bool Module::elaborate_sig(Design*des, NetScope*scope) const
9898
if ((*wt).second->get_port_type() == NetNet::NOT_A_PORT) {
9999
cerr << get_fileline() << ": error: "
100100
<< "Port " << pp->expr[cc]->path() << " ("
101-
<< (idx+1) << ") of module " << name_
101+
<< (idx+1) << ") of module " << mod_name()
102102
<< " has no direction declaration."
103103
<< endl;
104104
des->errors += 1;

0 commit comments

Comments
 (0)