Skip to content

Commit

Permalink
Elaborate classes in packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveicarus committed Oct 11, 2014
1 parent d6685f4 commit 712f394
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 34 deletions.
12 changes: 8 additions & 4 deletions elab_scope.cc
Expand Up @@ -428,6 +428,9 @@ static void elaborate_scope_class(Design*des, NetScope*scope, PClass*pclass)

netclass_t*use_class = new netclass_t(use_type->name, use_base_class);

ivl_assert(*pclass, use_type->save_elaborated_type == 0);
use_type->save_elaborated_type = use_class;

// Class scopes have no parent scope, because references are
// not allowed to escape a class method.
NetScope*class_scope = new NetScope(0, hname_t(pclass->pscope_name()),
Expand Down Expand Up @@ -747,13 +750,14 @@ class generate_schemes_work_item_t : public elaborator_work_item_t {
bool PPackage::elaborate_scope(Design*des, NetScope*scope)
{
if (debug_scopes) {
cerr << get_fileline() << ": debug: Elaborate package scope "
<< scope_path(scope) << "." << endl;
cerr << get_fileline() << ": PPackage::elaborate_scope: "
<< "Elaborate package " << scope_path(scope) << "." << endl;
}

collect_scope_parameters_(des, scope, parameters);
collect_scope_localparams_(des, scope, localparams);
elaborate_scope_enumerations(des, scope, enum_sets);
elaborate_scope_classes(des, scope, classes_lexical);
elaborate_scope_funcs(des, scope, funcs);
elaborate_scope_tasks(des, scope, tasks);
return true;
Expand All @@ -763,8 +767,8 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,
const replace_t&replacements)
{
if (debug_scopes) {
cerr << get_fileline() << ": debug: Elaborate scope "
<< scope_path(scope) << "." << endl;
cerr << get_fileline() << ": Module::elaborate_scope: "
<< "Elaborate " << scope_path(scope) << "." << endl;
}

// Add the genvars to the scope.
Expand Down
38 changes: 15 additions & 23 deletions elab_sig.cc
Expand Up @@ -207,6 +207,11 @@ bool PPackage::elaborate_sig(Design*des, NetScope*scope) const
{
bool flag = true;

if (debug_elaborate) {
cerr << get_fileline() << ": PPackage::elaborate_sig: "
<< "Start package scope=" << scope_path(scope) << endl;
}

flag = elaborate_sig_wires_(des, scope) && flag;

// After all the wires are elaborated, we are free to
Expand All @@ -215,6 +220,13 @@ bool PPackage::elaborate_sig(Design*des, NetScope*scope) const

elaborate_sig_funcs(des, scope, funcs);
elaborate_sig_tasks(des, scope, tasks);
elaborate_sig_classes(des, scope, classes);

if (debug_elaborate) {
cerr << get_fileline() << ": PPackage::elaborate_sig: "
<< "Done package scope=" << scope_path(scope)
<< ", flag=" << flag << endl;
}

return flag;
}
Expand Down Expand Up @@ -836,16 +848,6 @@ void PWhile::elaborate_sig(Design*des, NetScope*scope) const
statement_->elaborate_sig(des, scope);
}

static netclass_t* locate_class_type(Design*des, NetScope*scope,
class_type_t*class_type)
{
netclass_t*use_class = scope->find_class(class_type->name);
if (use_class) return use_class;

use_class = des->find_class(class_type->name);
return use_class;
}

static ivl_type_s*elaborate_type(Design*des, NetScope*scope,
data_type_t*pform_type)
{
Expand Down Expand Up @@ -1174,19 +1176,9 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
// should already have been elaborated. All we need to
// do right now is locate the netclass_t object for the
// class, and use that to build the net.
netclass_t*use_type = locate_class_type(des, scope, class_type);
if (use_type == 0) {
cerr << get_fileline() << ": internal error: "
<< "Class " << class_type->name
<< " isn't elaborated in scope=" << scope_path(scope) << endl;
des->errors += 1;
}
ivl_assert(*this, use_type);
if (debug_elaborate) {
cerr << get_fileline() << ": PWire::elaborate_sig: "
<< "Create class instance signal " << wtype
<< " " << packed_dimensions << name_ << unpacked_dimensions << endl;
}

ivl_assert(*this, class_type->save_elaborated_type);
netclass_t*use_type = class_type->save_elaborated_type;

sig = new NetNet(scope, name_, wtype, unpacked_dimensions, use_type);

Expand Down
9 changes: 3 additions & 6 deletions elab_type.cc
Expand Up @@ -95,13 +95,10 @@ ivl_type_s* atom2_type_t::elaborate_type_raw(Design*des, NetScope*) const
}
}

ivl_type_s* class_type_t::elaborate_type_raw(Design*des, NetScope*scope) const
ivl_type_s* class_type_t::elaborate_type_raw(Design*, NetScope*) const
{
ivl_type_s* found_class = scope->find_class(name);
if (found_class == 0)
found_class = des->find_class(name);

return found_class;
ivl_assert(*this, save_elaborated_type);
return save_elaborated_type;
}

/*
Expand Down
4 changes: 4 additions & 0 deletions elaborate.cc
Expand Up @@ -5554,6 +5554,9 @@ bool PPackage::elaborate(Design*des, NetScope*scope) const
// Elaborate task methods.
elaborate_tasks(des, scope, tasks);

// Elaborate class definitions.
elaborate_classes(des, scope, classes);

return result_flag;
}

Expand Down Expand Up @@ -6046,6 +6049,7 @@ Design* elaborate(list<perm_string>roots)
for (map<perm_string,PPackage*>::iterator pac = pform_packages.begin()
; pac != pform_packages.end() ; ++ pac) {

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

Expand Down
1 change: 1 addition & 0 deletions netlist.h
Expand Up @@ -901,6 +901,7 @@ class Definitions {
std::map<const enum_type_t*,netenum_t*> enum_sets_;
std::map<perm_string,NetEConstEnum*> enum_names_;

// This is a map of all the classes (by name) in this scope.
std::map<perm_string,netclass_t*> classes_;

};
Expand Down
8 changes: 7 additions & 1 deletion pform_types.h
Expand Up @@ -44,6 +44,7 @@ class PExpr;
class PWire;
class Statement;
class ivl_type_s;
class netclass_t;
class netenum_t;
typedef named<verinum> named_number_t;
typedef named<PExpr*> named_pexpr_t;
Expand Down Expand Up @@ -273,7 +274,7 @@ struct string_type_t : public data_type_t {
struct class_type_t : public data_type_t {

inline explicit class_type_t(perm_string n)
: name(n), base_type(0) { }
: name(n), base_type(0), save_elaborated_type(0) { }

void pform_dump(std::ostream&out, unsigned indent) const;
void pform_dump_init(std::ostream&out, unsigned indent) const;
Expand Down Expand Up @@ -308,6 +309,11 @@ struct class_type_t : public data_type_t {
std::vector<Statement*> initialize_static;

ivl_type_s* elaborate_type_raw(Design*, NetScope*) const;
// The save_elaborated_type member must be set to the pointer
// to the netclass_t object that is created to represent this
// type. The elaborate_type_raw() method uses this pointer,
// and it is used in some other situations as well.
netclass_t* save_elaborated_type;
};

/*
Expand Down
2 changes: 2 additions & 0 deletions t-dll-proc.cc
Expand Up @@ -80,6 +80,8 @@ void dll_target::task_def(const NetScope*net)
ivl_scope_t scop = lookup_scope_(net);
const NetTaskDef*def = net->task_def();

assert(def);
assert(def->proc());
assert(stmt_cur_ == 0);
stmt_cur_ = (struct ivl_statement_s*)calloc(1, sizeof*stmt_cur_);
def->proc()->emit_proc(this);
Expand Down

0 comments on commit 712f394

Please sign in to comment.