From 90293d8e0a9f675cf9b80455bd7e082e1e13a4da Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 26 Jan 2015 11:15:57 +0100 Subject: [PATCH] vhdlpp: VTypeArray::is_variable_length() uses ScopeBase to determine if variable has constant length. --- vhdlpp/subprogram.cc | 2 +- vhdlpp/vtype.cc | 11 +++++++---- vhdlpp/vtype.h | 5 +++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/vhdlpp/subprogram.cc b/vhdlpp/subprogram.cc index a3990bc69..bfa1be9a7 100644 --- a/vhdlpp/subprogram.cc +++ b/vhdlpp/subprogram.cc @@ -107,7 +107,7 @@ void Subprogram::fix_variables() { // SystemVerilog does not handle variables that have length dependendent // on other variables. We have to convert it to a dynamic array and // construct it. - if(type->is_variable_length()) { + if(type->is_variable_length(this)) { const VTypeArray*arr = dynamic_cast(type); // Currently we handle only one dimensional variables diff --git a/vhdlpp/vtype.cc b/vhdlpp/vtype.cc index 795992649..cd4ea42e1 100644 --- a/vhdlpp/vtype.cc +++ b/vhdlpp/vtype.cc @@ -167,20 +167,23 @@ bool VTypeArray::is_unbounded() const { return etype_->is_unbounded(); } -bool VTypeArray::is_variable_length() const { +bool VTypeArray::is_variable_length(ScopeBase*scope) const { int64_t dummy; + if(is_unbounded()) + return true; + for(std::vector::const_iterator it = ranges_.begin(); it != ranges_.end(); ++it) { - if(!it->lsb()->evaluate(NULL, dummy)) + if(!it->lsb()->evaluate(scope, dummy)) return true; - if(!it->msb()->evaluate(NULL, dummy)) + if(!it->msb()->evaluate(scope, dummy)) return true; } - return etype_->is_variable_length(); + return etype_->is_variable_length(scope); } VTypeRange::VTypeRange(const VType*base, int64_t max_val, int64_t min_val) diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index e5b0fd378..eb6c10553 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -34,6 +34,7 @@ class Entity; class Expression; class prange_t; class VTypeDef; +class ScopeBase; typedef enum typedef_topo_e { NONE=0, PENDING, MARKED } typedef_topo_t; typedef std::map typedef_context_t; @@ -90,7 +91,7 @@ class VType { // Checks if the variable length is dependent on other expressions, that // cannot be evaluated (e.g. 'length, 'left, 'right). - virtual bool is_variable_length() const { return false; } + virtual bool is_variable_length(ScopeBase*) const { return false; } // Returns a perm_string that can be used in automatically created // typedefs (i.e. not ones defined by the user). @@ -231,7 +232,7 @@ class VTypeArray : public VType { bool is_unbounded() const; - bool is_variable_length() const; + bool is_variable_length(ScopeBase*scope) const; // To handle subtypes inline void set_parent_type(const VTypeArray*parent) { parent_ = parent; }