Skip to content

Commit

Permalink
Objects of lexical scope use PScope base class.
Browse files Browse the repository at this point in the history
All the pform objects that represent lexical scope now are derived
from the PScope class, and are kept in a lexical_scope table so that
the scope can be managed.
  • Loading branch information
steveicarus committed Feb 16, 2008
1 parent 3f2fa29 commit b0e4a68
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 129 deletions.
2 changes: 1 addition & 1 deletion Module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/* n is a permallocated string. */
Module::Module(perm_string n)
: PScope(n)
: PScope(n, 0)
{
library_flag = false;
default_nettype = NetNet::NONE;
Expand Down
4 changes: 2 additions & 2 deletions PFunction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#include "PTask.h"

PFunction::PFunction(perm_string name)
: PScope(name), ports_(0), statement_(0)
PFunction::PFunction(perm_string name, PScope*parent)
: PScope(name, parent), ports_(0), statement_(0)
{
return_type_.type = PTF_NONE;
}
Expand Down
4 changes: 2 additions & 2 deletions PScope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

# include "PScope.h"

PScope::PScope(perm_string n)
: name_(n)
PScope::PScope(perm_string n, PScope*p)
: name_(n), parent_(p)
{
}

Expand Down
19 changes: 15 additions & 4 deletions PScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,42 @@
*/

# include "StringHeap.h"
# include "pform_types.h"
# include <map>

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.
* represents lexical 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();
// When created, a scope has a name and a parent. The name is
// the name of the definition. For example, if this is a
// module declaration, the name is the name after the "module"
// keyword, and if this is a task scope, the name is the task
// name. The parent is the lexical parent of this scope. Since
// modules do not nest in Verilog, the parent must be nil for
// modules. Scopes for tasks and functions point to their
// containing module.
PScope(perm_string name, PScope*parent);
virtual ~PScope();

perm_string pscope_name() const { return name_; }
PScope* pscope_parent() { return parent_; }

// Named events in the scope.
map<perm_string,PEvent*>events;

private:
perm_string name_;
PScope*parent_;
};

#endif
4 changes: 2 additions & 2 deletions PTask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

# include "PTask.h"

PTask::PTask(perm_string name)
: PScope(name), ports_(0), statement_(0)
PTask::PTask(perm_string name, PScope*parent)
: PScope(name, parent), ports_(0), statement_(0)
{
}

Expand Down
4 changes: 2 additions & 2 deletions PTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct PTaskFuncArg {
class PTask : public PScope, public LineInfo {

public:
explicit PTask(perm_string name);
explicit PTask(perm_string name, PScope*parent);
~PTask();

void set_ports(svector<PWire *>*p);
Expand Down Expand Up @@ -90,7 +90,7 @@ class PTask : public PScope, public LineInfo {
class PFunction : public PScope, public LineInfo {

public:
explicit PFunction(perm_string name);
explicit PFunction(perm_string name, PScope*parent);
~PFunction();

void set_ports(svector<PWire *>*p);
Expand Down
16 changes: 8 additions & 8 deletions Statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,13 @@ PAssignNB::~PAssignNB()
{
}

PBlock::PBlock(perm_string n, BL_TYPE t, const svector<Statement*>&st)
: name_(n), bl_type_(t), list_(st)
{
}

PBlock::PBlock(BL_TYPE t, const svector<Statement*>&st)
: bl_type_(t), list_(st)
PBlock::PBlock(perm_string n, PScope*parent, BL_TYPE t)
: PScope(n, parent), bl_type_(t)
{
}

PBlock::PBlock(BL_TYPE t)
: bl_type_(t)
: PScope(perm_string(),0), bl_type_(t)
{
}

Expand All @@ -107,6 +102,11 @@ PBlock::~PBlock()
delete list_[idx];
}

void PBlock::set_statement(const svector<Statement*>&st)
{
list_ = st;
}

PCallTask::PCallTask(const pform_name_t&n, const svector<PExpr*>&p)
: path_(n), parms_(p)
{
Expand Down
10 changes: 6 additions & 4 deletions Statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# include "StringHeap.h"
# include "PDelays.h"
# include "PExpr.h"
# include "PScope.h"
# include "HName.h"
# include "LineInfo.h"
class PExpr;
Expand Down Expand Up @@ -147,25 +148,26 @@ class PAssignNB : public PAssign_ {
* statements before constructing this object, so it knows a priori
* what is contained.
*/
class PBlock : public Statement {
class PBlock : public PScope, public Statement {

public:
enum BL_TYPE { BL_SEQ, BL_PAR };

explicit PBlock(perm_string n, BL_TYPE t, const svector<Statement*>&st);
explicit PBlock(BL_TYPE t, const svector<Statement*>&st);
// If the block has a name, it is a scope and also has a parent.
explicit PBlock(perm_string n, PScope*parent, BL_TYPE t);
// If it doesn't have a name, it's not a scope
explicit PBlock(BL_TYPE t);
~PBlock();

BL_TYPE bl_type() const { return bl_type_; }

void set_statement(const svector<Statement*>&st);

virtual void dump(ostream&out, unsigned ind) const;
virtual NetProc* elaborate(Design*des, NetScope*scope) const;
virtual void elaborate_scope(Design*des, NetScope*scope) const;

private:
perm_string name_;
const BL_TYPE bl_type_;
svector<Statement*>list_;
};
Expand Down
4 changes: 2 additions & 2 deletions elab_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@ void PBlock::elaborate_scope(Design*des, NetScope*scope) const
{
NetScope*my_scope = scope;

if (name_ != 0) {
hname_t use_name(name_);
if (pscope_name() != 0) {
hname_t use_name(pscope_name());
if (scope->child(use_name)) {
cerr << get_fileline() << ": error: block/scope name "
<< use_name << " already used in this context."
Expand Down
8 changes: 4 additions & 4 deletions elaborate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1846,12 +1846,12 @@ NetProc* PBlock::elaborate(Design*des, NetScope*scope) const
: NetBlock::SEQU;

NetScope*nscope = 0;
if (name_.str() != 0) {
nscope = scope->child(hname_t(name_));
if (pscope_name() != 0) {
nscope = scope->child(hname_t(pscope_name()));
if (nscope == 0) {
cerr << get_fileline() << ": internal error: "
"unable to find block scope " << scope_path(scope)
<< "<" << name_ << ">" << endl;
<< "<" << pscope_name() << ">" << endl;
des->errors += 1;
return 0;
}
Expand All @@ -1869,7 +1869,7 @@ NetProc* PBlock::elaborate(Design*des, NetScope*scope) const
// statement. There is no need to keep the block node. Also,
// don't elide named blocks, because they might be referenced
// elsewhere.
if ((list_.count() == 1) && (name_.str() == 0)) {
if ((list_.count() == 1) && (pscope_name() == 0)) {
assert(list_[0]);
NetProc*tmp = list_[0]->elaborate(des, nscope);
return tmp;
Expand Down
Loading

0 comments on commit b0e4a68

Please sign in to comment.