From 8e9c25a23e33cf7b5e1e8cfd8aa886b2aa90d581 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 22 Aug 2014 10:45:02 +0200 Subject: [PATCH] vhdlpp: Added 'packed' property for VTypes. It detetermines if a type can be used as the base type of a packed array. --- vhdlpp/library.cc | 15 ++++++++++++--- vhdlpp/parse_misc.h | 3 +++ vhdlpp/vtype.cc | 8 ++++---- vhdlpp/vtype.h | 10 +++++++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/vhdlpp/library.cc b/vhdlpp/library.cc index 7266fcba1..91c197267 100644 --- a/vhdlpp/library.cc +++ b/vhdlpp/library.cc @@ -343,11 +343,11 @@ static void import_ieee_use(ActiveScope*res, perm_string package, perm_string na } } -const VTypePrimitive primitive_BOOLEAN(VTypePrimitive::BOOLEAN); -const VTypePrimitive primitive_BIT(VTypePrimitive::BIT); +const VTypePrimitive primitive_BOOLEAN(VTypePrimitive::BOOLEAN, true); +const VTypePrimitive primitive_BIT(VTypePrimitive::BIT, true); const VTypePrimitive primitive_INTEGER(VTypePrimitive::INTEGER); const VTypePrimitive primitive_REAL(VTypePrimitive::REAL); -const VTypePrimitive primitive_STDLOGIC(VTypePrimitive::STDLOGIC); +const VTypePrimitive primitive_STDLOGIC(VTypePrimitive::STDLOGIC, true); const VTypePrimitive primitive_CHARACTER(VTypePrimitive::CHARACTER); const VTypeRange primitive_NATURAL(&primitive_INTEGER, INT64_MAX, 0); @@ -383,6 +383,15 @@ bool is_global_type(perm_string name) return false; } +bool can_be_packed(perm_string name) +{ + if (name == "boolean") return true; + if (name == "bit") return true; + if (name == "std_logic") return true; + if (name == "bit_vector") return true; + return true; +} + void library_set_work_path(const char*path) { assert(library_work_path == 0); diff --git a/vhdlpp/parse_misc.h b/vhdlpp/parse_misc.h index e4aa9e644..a2e6292c9 100644 --- a/vhdlpp/parse_misc.h +++ b/vhdlpp/parse_misc.h @@ -67,4 +67,7 @@ extern void generate_global_types(ActiveScope*res); extern bool is_global_type(perm_string type_name); +// Returns true if a type can be used as the base type in Verilog packed array. +extern bool can_be_packed(perm_string type_name); + #endif /* IVL_parse_misc_H */ diff --git a/vhdlpp/vtype.cc b/vhdlpp/vtype.cc index 9d35bd36b..7c0875f44 100644 --- a/vhdlpp/vtype.cc +++ b/vhdlpp/vtype.cc @@ -35,8 +35,8 @@ void VType::show(ostream&out) const write_to_stream(out); } -VTypePrimitive::VTypePrimitive(VTypePrimitive::type_t tt) -: type_(tt) +VTypePrimitive::VTypePrimitive(VTypePrimitive::type_t tt, bool packed) +: type_(tt), packed_(packed) { } @@ -60,8 +60,8 @@ void VTypePrimitive::show(ostream&out) const out << "INTEGER"; break; case REAL: - out << "REAL"; - break; + out << "REAL"; + break; case STDLOGIC: out << "std_logic"; break; diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index f9f66001e..003f8d937 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -82,6 +82,9 @@ class VType { // all the types that it emits. virtual int emit_typedef(std::ostream&out, typedef_context_t&ctx) const; + // Determines if a type can be used in Verilog packed array. + virtual bool can_be_packed() const { return false; } + private: friend class decl_t; // This virtual method is called to emit the declaration. This @@ -128,7 +131,7 @@ class VTypePrimitive : public VType { enum type_t { BOOLEAN, BIT, INTEGER, REAL, STDLOGIC, CHARACTER }; public: - VTypePrimitive(type_t); + VTypePrimitive(type_t tt, bool packed = false); ~VTypePrimitive(); void write_to_stream(std::ostream&fd) const; @@ -139,8 +142,11 @@ class VTypePrimitive : public VType { int emit_primitive_type(std::ostream&fd) const; int emit_def(std::ostream&out) const; + bool can_be_packed() const { return packed_; } + private: type_t type_; + bool packed_; }; extern const VTypePrimitive primitive_BOOLEAN; @@ -194,6 +200,8 @@ class VTypeArray : public VType { int emit_def(std::ostream&out) const; int emit_typedef(std::ostream&out, typedef_context_t&ctx) const; + bool can_be_packed() const { return etype_->can_be_packed(); } + private: const VType*etype_;