From 61a088fa78c9b87309c51b05e72bbf60d301f214 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 8 Jan 2022 22:42:20 +0100 Subject: [PATCH] Use elaborate_type() infrastructure to elaborate signal types Each data_type_t has a elaborate_type() method that returns the corresponding ivl_data_t for that type. Make use of that in PWire::elaborate_sig(). This removes duplicated code and ensures consistent behavior between the different places where types are elaborated. This will also make it easier to add new data type that are going to be elaborated this way. Signed-off-by: Lars-Peter Clausen --- elab_sig.cc | 86 +++++++---------------------------------------------- 1 file changed, 10 insertions(+), 76 deletions(-) diff --git a/elab_sig.cc b/elab_sig.cc index 47edb73d8..a84583a39 100644 --- a/elab_sig.cc +++ b/elab_sig.cc @@ -1213,52 +1213,7 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const NetNet*sig = 0; - if (class_type_t*class_type = dynamic_cast(set_data_type_)) { - // If this is a class variable, then the class type - // 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. - - 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); - - } else if (struct_type_t*struct_type = dynamic_cast(set_data_type_)) { - // If this is a struct type, then build the net with the - // struct type. - ivl_type_s*tmp_type = struct_type->elaborate_type(des, scope); - netstruct_t*use_type = dynamic_cast(tmp_type); - if (debug_elaborate) { - cerr << get_fileline() << ": debug: Create signal " << wtype; - if (use_type->packed()) - cerr << " " << use_type->packed_width() << " bit packed struct "; - else - cerr << " struct <> "; - cerr << name_; - cerr << " in scope " << scope_path(scope) << endl; - } - - sig = new NetNet(scope, name_, wtype, unpacked_dimensions, use_type); - - } else if (enum_type_t*enum_type = dynamic_cast(set_data_type_)) { - list::const_iterator sample_name = enum_type->names->begin(); - const netenum_t*use_enum = base_type_scope->find_enumeration_for_name(des, sample_name->name); - - if (debug_elaborate) { - cerr << get_fileline() << ": PWire::elaborate_sig: " - << "Create signal " << wtype - << " enumeration " - << name_ << " in scope " << scope_path(scope) - << " with packed_dimensions=" << packed_dimensions - << " and packed_width=" << use_enum->packed_width() << endl; - } - - ivl_assert(*this, packed_dimensions.empty()); - sig = new NetNet(scope, name_, wtype, unpacked_dimensions, use_enum); - - - } else if (netdarray) { + if (netdarray) { if (debug_elaborate) { cerr << get_fileline() << ": PWire::elaborate_sig: " @@ -1272,43 +1227,22 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const ivl_assert(*this, unpacked_dimensions.empty()); sig = new NetNet(scope, name_, wtype, netdarray); - } else if (dynamic_cast(set_data_type_)) { + } else if (dynamic_cast(set_data_type_) || + dynamic_cast(set_data_type_) || + dynamic_cast(set_data_type_) || + dynamic_cast(set_data_type_) || + dynamic_cast(set_data_type_)) { - // Signal declared as: string foo; + ivl_type_t use_type = set_data_type_->elaborate_type(des, scope); if (debug_elaborate) { - cerr << get_fileline() << ": " << __func__ << ": " - << "Create signal " << wtype - << " string " - << name_ << " in scope " << scope_path(scope) - << endl; - } - - sig = new NetNet(scope, name_, wtype, unpacked_dimensions, - &netstring_t::type_string); - - } else if (parray_type_t*parray_type = dynamic_cast(set_data_type_)) { - // The pform gives us a parray_type_t for packed arrays - // that show up in type definitions. This can be handled - // a lot like packed dimensions from other means. - - // The trick here is that the parray type has an - // arbitrary sub-type, and not just a scalar bit... - ivl_type_t tmp_type = parray_type->elaborate_type(des, scope); - const netparray_t*use_type = dynamic_cast(tmp_type); - // Should not be getting packed dimensions other than - // through the parray type declaration. - ivl_assert(*this, packed_dimensions.empty()); - - if (debug_elaborate) { - cerr << get_fileline() << ": debug: Create signal " << wtype - << " parray=" << use_type->static_dimensions() + cerr << get_fileline() << ": debug: Create signal " + << wtype << " " << *set_data_type_ << " " << name_ << unpacked_dimensions << " in scope " << scope_path(scope) << endl; } + ivl_assert(*this, packed_dimensions.empty()); sig = new NetNet(scope, name_, wtype, unpacked_dimensions, use_type); - - } else { if (debug_elaborate) { cerr << get_fileline() << ": PWire::elaborate_sig: "