From d346fb098fbea40f46287da2010b9b2960aeafb3 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 15 Jun 2013 16:24:02 -0400 Subject: [PATCH] Collect initializer statements in the pform. --- elab_scope.cc | 6 ++++++ pform_dump.cc | 11 +++++++++++ pform_pclass.cc | 12 ++++++++---- pform_types.h | 10 ++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/elab_scope.cc b/elab_scope.cc index 91c1b9fb5..285122d3f 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -304,6 +304,12 @@ static void elaborate_scope_class(Design*des, NetScope*scope, << "Elaborate scope class " << pclass->pscope_name() << endl; } + if (! use_type->initialize.empty()) { + cerr << pclass->get_fileline() << ": sorry: " + << "Class property initializers not supported." << endl; + des->errors += 1; + } + // 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()), diff --git a/pform_dump.cc b/pform_dump.cc index feb274697..2a1bd1e09 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -181,9 +181,19 @@ void class_type_t::pform_dump(ostream&out, unsigned indent) const ; cur != properties.end() ; ++cur) { out << " " << cur->first; } + out << " }" << endl; } +void class_type_t::pform_dump_init(ostream&out, unsigned indent) const +{ + for (vector::const_iterator cur = initialize.begin() + ; cur != initialize.end() ; ++cur) { + Statement*curp = *cur; + curp->dump(out,indent+4); + } +} + void struct_member_t::pform_dump(ostream&out, unsigned indent) const { out << setw(indent) << "" << type; @@ -1315,6 +1325,7 @@ void PClass::dump(ostream&out, unsigned indent) const { out << setw(indent) << "" << "class " << type->name << ";" << endl; type->pform_dump(out, indent+2); + type->pform_dump_init(out, indent+2); dump_tasks_(out, indent+2); dump_funcs_(out, indent+2); out << setw(indent) << "" << "endclass" << endl; diff --git a/pform_pclass.cc b/pform_pclass.cc index f21479659..61698f7c1 100644 --- a/pform_pclass.cc +++ b/pform_pclass.cc @@ -64,11 +64,15 @@ void pform_class_property(const struct vlltype&loc, use_type = new uarray_type_t(use_type, pd); } - if (curp->expr.get()) { - VLerror(loc, "sorry: Initialization expressions for properties not implemented."); - } - pform_cur_class->type->properties[curp->name] = use_type; + + if (PExpr*rval = curp->expr.release()) { + PExpr*lval = new PEIdent(curp->name); + FILE_NAME(lval, loc); + PAssign*tmp = new PAssign(lval, rval); + FILE_NAME(tmp, loc); + pform_cur_class->type->initialize.push_back(tmp); + } } } diff --git a/pform_types.h b/pform_types.h index e99b966fc..b834884c3 100644 --- a/pform_types.h +++ b/pform_types.h @@ -27,6 +27,7 @@ # include "ivl_target.h" # include # include +# include # include # include @@ -37,6 +38,7 @@ class Design; class NetScope; class PExpr; +class Statement; class ivl_type_s; typedef named named_number_t; typedef named named_pexpr_t; @@ -212,10 +214,18 @@ struct class_type_t : public data_type_t { : name(n) { } void pform_dump(std::ostream&out, unsigned indent) const; + void pform_dump_init(std::ostream&out, unsigned indent) const; + // This is the name of the class type. perm_string name; + // This is a map of the properties. Map the name to the type. std::map properties; + // This is an ordered list of property initializers. The name + // is the name of the property to be assigned, and the val is + // the expression that is assigned. + std::vector initialize; + ivl_type_s* elaborate_type(Design*, NetScope*) const; };