Skip to content

Commit

Permalink
Add packages and their own scope.
Browse files Browse the repository at this point in the history
This makes <pkg>::<name> work properly, and also makes the
package descriptions available through VPI.
  • Loading branch information
steveicarus committed Feb 18, 2013
1 parent 97f3a01 commit 60cb78e
Show file tree
Hide file tree
Showing 23 changed files with 255 additions and 60 deletions.
11 changes: 9 additions & 2 deletions PExpr.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1998-2012 Stephen Williams <steve@icarus.com>
* Copyright CERN 2013 / 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
Expand Down Expand Up @@ -305,12 +306,18 @@ const verireal& PEFNumber::value() const
}

PEIdent::PEIdent(const pform_name_t&that)
: path_(that), no_implicit_sig_(false)
: package_(0), path_(that), no_implicit_sig_(false)
{
}

PEIdent::PEIdent(perm_string s, bool no_implicit_sig)
: no_implicit_sig_(no_implicit_sig)
: package_(0), no_implicit_sig_(no_implicit_sig)
{
path_.push_back(name_component_t(s));
}

PEIdent::PEIdent(PPackage*pkg, perm_string s)
: package_(pkg), no_implicit_sig_(true)
{
path_.push_back(name_component_t(s));
}
Expand Down
4 changes: 4 additions & 0 deletions PExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __PExpr_H
/*
* Copyright (c) 1998-2011 Stephen Williams <steve@icarus.com>
* Copyright CERN 2013 / 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
Expand Down Expand Up @@ -33,6 +34,7 @@ class LexicalScope;
class NetNet;
class NetExpr;
class NetScope;
class PPackage;

/*
* The PExpr class hierarchy supports the description of
Expand Down Expand Up @@ -286,6 +288,7 @@ class PEIdent : public PExpr {

public:
explicit PEIdent(perm_string, bool no_implicit_sig=false);
explicit PEIdent(PPackage*pkg, perm_string name);
explicit PEIdent(const pform_name_t&);
~PEIdent();

Expand Down Expand Up @@ -329,6 +332,7 @@ class PEIdent : public PExpr {
const pform_name_t& path() const { return path_; }

private:
PPackage*package_;
pform_name_t path_;
bool no_implicit_sig_;

Expand Down
4 changes: 2 additions & 2 deletions PPackage.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2012 Picture Elements, Inc.
* Stephen Williams (steve@icarus.com)
* Copyright (c) 2012 Stephen Williams (steve@icarus.com)
* Copyright CERN 2013 / 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
Expand Down
3 changes: 3 additions & 0 deletions PPackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __PPackage_H
/*
* Copyright (c) 2012 Stephen Williams (steve@icarus.com)
* Copyright CERN 2013 / 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
Expand Down Expand Up @@ -36,6 +37,8 @@ class PPackage : public PScopeExtra, public LineInfo {
explicit PPackage (perm_string name, LexicalScope*parent);
~PPackage();

bool elaborate_scope(Design*des, NetScope*scope);

void pform_dump(std::ostream&out) const;
};

Expand Down
10 changes: 9 additions & 1 deletion design_dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1643,10 +1643,18 @@ void NetEUnary::dump(ostream&o) const
void Design::dump(ostream&o) const
{
o << "DESIGN TIME PRECISION: 10e" << get_precision() << endl;

o << "PACKAGES:" << endl;
for (map<perm_string,NetScope*>::const_iterator cur = packages_.begin()
; cur != packages_.end() ; ++cur) {
cur->second->dump(o);
}

o << "SCOPES:" << endl;
for (list<NetScope*>::const_iterator scope = root_scopes_.begin();
scope != root_scopes_.end(); ++ scope )
scope != root_scopes_.end(); ++ scope ) {
(*scope)->dump(o);
}

o << "ELABORATED NODES:" << endl;

Expand Down
26 changes: 23 additions & 3 deletions elab_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# include <climits>
# include "compiler.h"

# include "PPackage.h"
# include "pform.h"
# include "netlist.h"
# include "netclass.h"
Expand Down Expand Up @@ -2410,7 +2411,14 @@ unsigned PEIdent::test_width(Design*des, NetScope*scope, width_mode_t&mode)

const NetExpr*ex1, *ex2;

NetScope*found_in = symbol_search(this, des, scope, path_, net, par, eve,
NetScope*use_scope = scope;
if (package_) {
use_scope = des->find_package(package_->pscope_name());
ivl_assert(*this, use_scope);
}

NetScope*found_in = symbol_search(this, des, use_scope, path_,
net, par, eve,
ex1, ex2);

// If there is a part/bit select expression, then process it
Expand Down Expand Up @@ -2610,7 +2618,13 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope,
NetEvent* eve = 0;
const NetExpr*ex1, *ex2;

/* NetScope*found_in = */ symbol_search(this, des, scope, path_,
NetScope*use_scope = scope;
if (package_) {
use_scope = des->find_package(package_->pscope_name());
ivl_assert(*this, use_scope);
}

/* NetScope*found_in = */ symbol_search(this, des, use_scope, path_,
net, par, eve,
ex1, ex2);

Expand Down Expand Up @@ -2718,7 +2732,13 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope,
if (debug_elaborate)
cerr << get_fileline() << ": PEIdent::elaborate_expr: path_=" << path_ << endl;

NetScope*found_in = symbol_search(this, des, scope, path_,
NetScope*use_scope = scope;
if (package_) {
use_scope = des->find_package(package_->pscope_name());
ivl_assert(*this, use_scope);
}

NetScope*found_in = symbol_search(this, des, use_scope, path_,
net, par, eve,
ex1, ex2);

Expand Down
13 changes: 13 additions & 0 deletions elab_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# include "PClass.h"
# include "PGate.h"
# include "PGenerate.h"
# include "PPackage.h"
# include "PTask.h"
# include "PWire.h"
# include "Statement.h"
Expand Down Expand Up @@ -495,6 +496,18 @@ class generate_schemes_work_item_t : public elaborator_work_item_t {
Module*mod_;
};

bool PPackage::elaborate_scope(Design*des, NetScope*scope)
{
if (debug_scopes) {
cerr << get_fileline() << ": debug: Elaborate package scope "
<< scope_path(scope) << "." << endl;
}

collect_scope_parameters_(des, scope, parameters);

return true;
}

bool Module::elaborate_scope(Design*des, NetScope*scope,
const replace_t&replacements)
{
Expand Down
32 changes: 32 additions & 0 deletions elaborate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# include "pform.h"
# include "PEvent.h"
# include "PGenerate.h"
# include "PPackage.h"
# include "PSpec.h"
# include "netlist.h"
# include "netvector.h"
Expand Down Expand Up @@ -4860,6 +4861,25 @@ struct root_elem {
NetScope *scope;
};

class elaborate_package_t : public elaborator_work_item_t {
public:
elaborate_package_t(Design*d, NetScope*scope, PPackage*p)
: elaborator_work_item_t(d), scope_(scope), package_(p)
{ }

~elaborate_package_t() { }

virtual void elaborate_runrun()
{
if (! package_->elaborate_scope(des, scope_))
des->errors += 1;
}

private:
NetScope*scope_;
PPackage*package_;
};

class elaborate_root_scope_t : public elaborator_work_item_t {
public:
elaborate_root_scope_t(Design*des__, NetScope*scope, Module*rmod)
Expand Down Expand Up @@ -5022,6 +5042,18 @@ Design* elaborate(list<perm_string>roots)
// module and elaborate what I find.
Design*des = new Design;

// Elaborate the packages. Package elaboration is simpler
// because there are fewer sub-scopes involved.
for (map<perm_string,PPackage*>::iterator pac = pform_packages.begin()
; pac != pform_packages.end() ; ++ pac) {

NetScope*scope = des->make_package_scope(pac->first);
scope->set_line(pac->second);

elaborator_work_item_t*es = new elaborate_package_t(des, scope, pac->second);
des->elaboration_work_list.push_back(es);
}

// Scan the root modules by name, and elaborate their scopes.
for (list<perm_string>::const_iterator root = roots.begin()
; root != roots.end() ; ++ root ) {
Expand Down
3 changes: 2 additions & 1 deletion ivl_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ typedef enum ivl_scope_type_e {
IVL_SCT_TASK = 2,
IVL_SCT_BEGIN = 3,
IVL_SCT_FORK = 4,
IVL_SCT_GENERATE= 5
IVL_SCT_GENERATE= 5,
IVL_SCT_PACKAGE = 6
} ivl_scope_type_t;

/* Signals (ivl_signal_t) that are ports into the scope that contains
Expand Down
8 changes: 6 additions & 2 deletions ivl_target_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ struct ivl_design_s {

ivl_process_t threads_;

ivl_scope_t *roots_;
unsigned nroots_;
// Keep arrays of root scopes.
std::vector<ivl_scope_t> packages;
std::vector<ivl_scope_t> roots;

// This is used to implement the ivl_design_roots function.
std::vector<ivl_scope_t> root_scope_list;

// Keep an array of constants objects.
std::valarray<ivl_net_const_t> consts;
Expand Down
31 changes: 28 additions & 3 deletions net_design.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,39 @@ NetScope* Design::find_root_scope()
return root_scopes_.front();
}

list<NetScope*> Design::find_root_scopes()
list<NetScope*> Design::find_root_scopes() const
{
return root_scopes_;
}

const list<NetScope*> Design::find_root_scopes() const
NetScope* Design::make_package_scope(perm_string name)
{
return root_scopes_;
NetScope*scope;

scope = new NetScope(0, hname_t(name), NetScope::PACKAGE, false, false);
scope->set_module_name(scope->basename());
packages_[name] = scope;
return scope;
}

NetScope* Design::find_package(perm_string name) const
{
map<perm_string,NetScope*>::const_iterator cur = packages_.find(name);
if (cur == packages_.end())
return 0;

return cur->second;
}

list<NetScope*> Design::find_package_scopes() const
{
list<NetScope*>res;
for (map<perm_string,NetScope*>::const_iterator cur = packages_.begin()
; cur != packages_.end() ; ++cur) {
res.push_back (cur->second);
}

return res;
}

/*
Expand Down
15 changes: 9 additions & 6 deletions net_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ NetScope::NetScope(NetScope*up, const hname_t&n, NetScope::TYPE t, bool nest, bo
time_unit_ = 0;
time_prec_ = 0;
time_from_timescale_ = false;
assert(t == MODULE);
assert(t==MODULE || t==PACKAGE);
}

switch (t) {
Expand All @@ -71,6 +71,7 @@ NetScope::NetScope(NetScope*up, const hname_t&n, NetScope::TYPE t, bool nest, bo
func_ = 0;
break;
case NetScope::MODULE:
case NetScope::PACKAGE:
module_name_ = perm_string();
break;
default: /* BEGIN_END and FORK_JOIN, do nothing */
Expand Down Expand Up @@ -301,15 +302,17 @@ void NetScope::print_type(ostream&stream) const
stream << "function";
break;
case MODULE:
stream << "module <" << (module_name_ ? module_name_.str() : "")
<< "> instance";
stream << "module <" << module_name_ << "> instance";
break;
case TASK:
stream << "task";
break;
case GENBLOCK:
stream << "generate block";
break;
case PACKAGE:
stream << "package " << module_name_;
break;
}
}

Expand Down Expand Up @@ -358,13 +361,13 @@ const NetFuncDef* NetScope::func_def() const

void NetScope::set_module_name(perm_string n)
{
assert(type_ == MODULE);
module_name_ = n; /* NOTE: n must have been permallocated. */
assert(type_==MODULE || type_==PACKAGE);
module_name_ = n;
}

perm_string NetScope::module_name() const
{
assert(type_ == MODULE);
assert(type_==MODULE || type_==PACKAGE);
return module_name_;
}

Expand Down
Loading

0 comments on commit 60cb78e

Please sign in to comment.