vhdlpp: Added 'packed' property for VTypes.

It detetermines if a type can be used as the base type of a packed array.
This commit is contained in:
Maciej Suminski 2014-08-22 10:45:02 +02:00
parent feccae56bf
commit 8e9c25a23e
4 changed files with 28 additions and 8 deletions

View File

@ -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);

View File

@ -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 */

View File

@ -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;

View File

@ -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_;