diff --git a/tgt-vhdl/vhdl_type.cc b/tgt-vhdl/vhdl_type.cc index b431b02f1..38183b36e 100644 --- a/tgt-vhdl/vhdl_type.cc +++ b/tgt-vhdl/vhdl_type.cc @@ -20,6 +20,7 @@ #include "vhdl_type.hh" +#include #include @@ -63,6 +64,12 @@ vhdl_type *vhdl_type::time() return new vhdl_type(VHDL_TYPE_TIME); } +vhdl_type *vhdl_type::get_base() const +{ + assert(name_ == VHDL_TYPE_ARRAY); + return base_; +} + /* * This is just the name of the type, without any parameters. */ @@ -87,6 +94,9 @@ std::string vhdl_type::get_string() const return std::string("signed"); case VHDL_TYPE_UNSIGNED: return std::string("unsigned"); + case VHDL_TYPE_ARRAY: + // Each array has its own type declaration + return array_name_; default: return std::string("BadType"); } @@ -107,6 +117,14 @@ std::string vhdl_type::get_decl_string() const ss << " downto " << lsb_ << ")"; return ss.str(); } + case VHDL_TYPE_ARRAY: + { + std::ostringstream ss; + ss << "array (" << msb_ << " downto " + << lsb_ << ") of " + << base_->get_decl_string(); + return ss.str(); + } default: return get_string(); } @@ -131,3 +149,8 @@ vhdl_type *vhdl_type::type_for(int width, bool issigned, int lsb) else return vhdl_type::nunsigned(width, lsb); } + +vhdl_type *vhdl_type::array_of(vhdl_type *b, std::string &n, int m, int l) +{ + return new vhdl_type(b, n, m, l); +} diff --git a/tgt-vhdl/vhdl_type.hh b/tgt-vhdl/vhdl_type.hh index 7b5878478..af9e1515b 100644 --- a/tgt-vhdl/vhdl_type.hh +++ b/tgt-vhdl/vhdl_type.hh @@ -34,6 +34,7 @@ enum vhdl_type_name_t { VHDL_TYPE_SIGNED, VHDL_TYPE_UNSIGNED, VHDL_TYPE_TIME, + VHDL_TYPE_ARRAY, }; /* @@ -43,14 +44,23 @@ enum vhdl_type_name_t { */ class vhdl_type : public vhdl_element { public: + // Scalar constructor vhdl_type(vhdl_type_name_t name, int msb = 0, int lsb = 0) - : name_(name), msb_(msb), lsb_(lsb) {} + : name_(name), msb_(msb), lsb_(lsb), base_(NULL) {} + + // Array constructor + vhdl_type(vhdl_type *base, const std::string &array_name, + int msb, int lsb) + : name_(VHDL_TYPE_ARRAY), msb_(msb), lsb_(lsb), base_(base), + array_name_(array_name) {} + virtual ~vhdl_type() {} void emit(std::ostream &of, int level) const; vhdl_type_name_t get_name() const { return name_; } std::string get_string() const; std::string get_decl_string() const; + vhdl_type *get_base() const; int get_width() const { return msb_ - lsb_ + 1; } int get_msb() const { return msb_; } int get_lsb() const { return lsb_; } @@ -67,9 +77,12 @@ public: static vhdl_type *time(); static vhdl_type *type_for(int width, bool issigned, int lsb=0); + static vhdl_type *array_of(vhdl_type *b, std::string &n, int m, int l); protected: vhdl_type_name_t name_; int msb_, lsb_; + vhdl_type *base_; // Array base type for VHDL_TYPE_ARRAY + std::string array_name_; // Type name for the array `type array_name_ is ...' }; #endif