Some support for unpacked arrays in class properties.

This commit is contained in:
Stephen Williams
2014-09-02 09:23:54 -07:00
parent 1465fd1570
commit 3b0dfaadba
9 changed files with 245 additions and 69 deletions
+51 -1
View File
@@ -27,6 +27,7 @@
# include "netstruct.h"
# include "netclass.h"
# include "netdarray.h"
# include "netparray.h"
# include "netvector.h"
# include "compiler.h"
# include <cstdlib>
@@ -259,6 +260,12 @@ NetAssign_* PEIdent::elaborate_lval(Design*des,
}
ivl_assert(*this, reg);
if (debug_elaborate) {
cerr << get_fileline() << ": PEIdent::elaborate_lval: "
<< "Lval reg = " << reg->name() << endl;
}
// We are processing the tail of a string of names. For
// example, the verilog may be "a.b.c", so we are processing
// "c" at this point. (Note that if method_name is not nil,
@@ -389,7 +396,9 @@ NetAssign_* PEIdent::elaborate_lval_method_class_member_(Design*des,
if (class_type == 0)
return 0;
perm_string member_name = peek_tail_name(path_);
const name_component_t&name_comp = path_.back();
perm_string member_name = name_comp.name;
int pidx = class_type->property_idx_from_name(member_name);
if (pidx < 0)
return 0;
@@ -402,6 +411,46 @@ NetAssign_* PEIdent::elaborate_lval_method_class_member_(Design*des,
return 0;
}
if (debug_elaborate) {
cerr << get_fileline() << ": PEIdent::elaborate_lval_method_class_member_: "
<< "Ident " << member_name
<< " is a property of class " << class_type->get_name() << endl;
}
NetExpr*canon_index = 0;
if (name_comp.index.size() > 0) {
ivl_type_t property_type = class_type->get_prop_type(pidx);
if (const netsarray_t* stype = dynamic_cast<const netsarray_t*> (property_type)) {
list<long> indices_const;
list<NetExpr*> indices_expr;
indices_flags flags;
indices_to_expressions(des, scope, this,
name_comp.index, name_comp.index.size(),
false, flags,
indices_expr, indices_const);
if (flags.undefined) {
cerr << get_fileline() << ": warning: "
<< "ignoring undefined l-value array access "
<< member_name
<< " (" << path_ << ")"
<< "." << endl;
} else if (flags.variable) {
canon_index = normalize_variable_unpacked(*this, stype, indices_expr);
} else {
canon_index = normalize_variable_unpacked(stype, indices_const);
}
} else {
cerr << get_fileline() << ": error: "
<< "Index expressions don't apply to this type of property." << endl;
des->errors += 1;
}
}
// Detect assignment to constant properties. Note that the
// initializer constructor MAY assign to constant properties,
// as this is how the property gets its value.
@@ -438,6 +487,7 @@ NetAssign_* PEIdent::elaborate_lval_method_class_member_(Design*des,
NetAssign_*this_lval = new NetAssign_(this_net);
this_lval->set_property(member_name);
if (canon_index) this_lval->set_word(canon_index);
return this_lval;
}