Elaborate classes in lexical order so that mutual references work.

This commit is contained in:
Stephen Williams 2013-04-28 16:28:24 -07:00
parent ac78ba588f
commit de6c57d661
3 changed files with 20 additions and 9 deletions

View File

@ -24,6 +24,7 @@
# include "pform_types.h" # include "pform_types.h"
# include "ivl_target.h" # include "ivl_target.h"
# include <map> # include <map>
# include <vector>
class PEvent; class PEvent;
class PExpr; class PExpr;
@ -175,6 +176,9 @@ class PScopeExtra : public PScope {
std::map<perm_string,PFunction*> funcs; std::map<perm_string,PFunction*> funcs;
/* class definitions within this module. */ /* class definitions within this module. */
std::map<perm_string,PClass*> classes; std::map<perm_string,PClass*> classes;
/* This is the lexical order of the classes, and is used by
elaboration to choose an elaboration order. */
std::vector<PClass*> classes_lexical;
protected: protected:
void dump_classes_(ostream&out, unsigned indent) const; void dump_classes_(ostream&out, unsigned indent) const;

View File

@ -300,7 +300,7 @@ static void elaborate_scope_class(Design*des, NetScope*scope,
netclass_t*use_class = new netclass_t(use_type->name); netclass_t*use_class = new netclass_t(use_type->name);
if (debug_scopes) { if (debug_scopes) {
cerr << pclass->get_fileline() <<": debug: " cerr << pclass->get_fileline() <<": elaborate_scope_class: "
<< "Elaborate scope class " << pclass->pscope_name() << endl; << "Elaborate scope class " << pclass->pscope_name() << endl;
} }
@ -311,9 +311,16 @@ static void elaborate_scope_class(Design*des, NetScope*scope,
class_scope->set_class_def(use_class); class_scope->set_class_def(use_class);
use_class->set_class_scope(class_scope); use_class->set_class_scope(class_scope);
// Collect the properties, elaborate them, and add them to the
// elaborated class definition.
for (map<perm_string, data_type_t*>::iterator cur = use_type->properties.begin() for (map<perm_string, data_type_t*>::iterator cur = use_type->properties.begin()
; cur != use_type->properties.end() ; ++ cur) { ; cur != use_type->properties.end() ; ++ cur) {
if (debug_scopes) {
cerr << pclass->get_fileline() << ": elaborate_scope_class: "
<< " Property " << cur->first << endl;
}
ivl_type_s*tmp = cur->second->elaborate_type(des, scope); ivl_type_s*tmp = cur->second->elaborate_type(des, scope);
ivl_assert(*pclass, tmp);
use_class->set_property(cur->first, tmp); use_class->set_property(cur->first, tmp);
} }
@ -327,7 +334,7 @@ static void elaborate_scope_class(Design*des, NetScope*scope,
method_scope->set_line(cur->second); method_scope->set_line(cur->second);
if (debug_scopes) { if (debug_scopes) {
cerr << cur->second->get_fileline() << ": debug: " cerr << cur->second->get_fileline() << ": elaborate_scope_class: "
<< "Elaborate method (task) scope " << "Elaborate method (task) scope "
<< scope_path(method_scope) << endl; << scope_path(method_scope) << endl;
} }
@ -345,7 +352,7 @@ static void elaborate_scope_class(Design*des, NetScope*scope,
method_scope->set_line(cur->second); method_scope->set_line(cur->second);
if (debug_scopes) { if (debug_scopes) {
cerr << cur->second->get_fileline() << ": debug: " cerr << cur->second->get_fileline() << ": elaborate_scope_class: "
<< "Elaborate method (function) scope " << "Elaborate method (function) scope "
<< scope_path(method_scope) << endl; << scope_path(method_scope) << endl;
} }
@ -357,12 +364,10 @@ static void elaborate_scope_class(Design*des, NetScope*scope,
} }
static void elaborate_scope_classes(Design*des, NetScope*scope, static void elaborate_scope_classes(Design*des, NetScope*scope,
const map<perm_string,PClass*>&classes) const vector<PClass*>&classes)
{ {
for (map<perm_string,PClass*>::const_iterator cur = classes.begin() for (size_t idx = 0 ; idx < classes.size() ; idx += 1)
; cur != classes.end() ; ++ cur) { elaborate_scope_class(des, scope, classes[idx]);
elaborate_scope_class(des, scope, cur->second);
}
} }
static void replace_scope_parameters_(NetScope*scope, const LineInfo&loc, static void replace_scope_parameters_(NetScope*scope, const LineInfo&loc,
@ -593,7 +598,8 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,
elaborate_scope_enumerations(des, scope, enum_sets); elaborate_scope_enumerations(des, scope, enum_sets);
elaborate_scope_classes(des, scope, classes); assert(classes.size() == classes_lexical.size());
elaborate_scope_classes(des, scope, classes_lexical);
// Run through the defparams for this module and save the result // Run through the defparams for this module and save the result
// in a table for later final override. // in a table for later final override.

View File

@ -317,6 +317,7 @@ PClass* pform_push_class_scope(const struct vlltype&loc, perm_string name)
error_count += 1; error_count += 1;
} }
scopex->classes[name] = class_scope; scopex->classes[name] = class_scope;
scopex->classes_lexical .push_back(class_scope);
lexical_scope = class_scope; lexical_scope = class_scope;
return class_scope; return class_scope;