From c92dea77fcecf5a3c3bb4035c1af2f299d5e9268 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 8 Aug 2014 17:17:47 +0200 Subject: [PATCH] vhdlpp: Basic support for unbounded array types. Once a signal/variable of unbounded array type becomes limited in its size, it is emitted as a packed array. Therefore currently it works only for bit/logic/reg/wire types. --- vhdlpp/parse.y | 4 ++-- vhdlpp/parse_misc.cc | 6 ++++++ vhdlpp/vtype_emit.cc | 12 +++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/vhdlpp/parse.y b/vhdlpp/parse.y index e9ac90604..0372d4925 100644 --- a/vhdlpp/parse.y +++ b/vhdlpp/parse.y @@ -684,8 +684,8 @@ composite_type_definition /* unbounded_array_definition IEEE 1076-2008 P5.3.2.1 */ | K_array '(' index_subtype_definition_list ')' K_of subtype_indication - { sorrymsg(@1, "unbounded_array_definition not supported.\n"); - std::list r; + { std::list r; + r.push_back(new prange_t(NULL, NULL, true)); // NULL boundaries indicate unbounded array type VTypeArray*tmp = new VTypeArray($6, &r); $$ = tmp; } diff --git a/vhdlpp/parse_misc.cc b/vhdlpp/parse_misc.cc index 0049388bf..3956b4a1a 100644 --- a/vhdlpp/parse_misc.cc +++ b/vhdlpp/parse_misc.cc @@ -82,6 +82,12 @@ static const VType* calculate_subtype_array(const YYLTYPE&loc, const char*base_n assert(array_left==0 || array_right!=0); + // unfold typedef, if it is the case + const VTypeDef*type_def = dynamic_cast (base_type); + if (type_def) { + base_type = type_def->peek_definition(); + } + const VTypeArray*base_array = dynamic_cast (base_type); if (base_array) { assert(array_left && array_right); diff --git a/vhdlpp/vtype_emit.cc b/vhdlpp/vtype_emit.cc index d5f8b32da..baea99a3d 100644 --- a/vhdlpp/vtype_emit.cc +++ b/vhdlpp/vtype_emit.cc @@ -88,16 +88,14 @@ int VTypeArray::emit_def(ostream&out) const while (! dims.empty()) { cur = dims.front(); dims.pop_front(); + out << "["; - if (cur->dimension(0).msb()) + if (cur->dimension(0).msb() && cur->dimension(0).lsb()) { + // bounded array, unbounded arrays have msb() & lsb() nullified errors += cur->dimension(0).msb()->emit(out, 0, 0); - else - out << "?error?"; - out << ":"; - if (cur->dimension(0).lsb()) + out << ":"; errors += cur->dimension(0).lsb()->emit(out, 0, 0); - else - out << "?error?"; + } out << "]"; }