From 79435924f24d2f62b8d34821611596d3dabfcde6 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sun, 18 Mar 2012 11:21:23 -0700 Subject: [PATCH] Move some VType::show methods to ::write_to_stream methods. --- vhdlpp/vtype.cc | 13 +--------- vhdlpp/vtype.h | 5 +++- vhdlpp/vtype_stream.cc | 55 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/vhdlpp/vtype.cc b/vhdlpp/vtype.cc index 25f669813..5c346ea5f 100644 --- a/vhdlpp/vtype.cc +++ b/vhdlpp/vtype.cc @@ -180,12 +180,7 @@ VTypeRecord::~VTypeRecord() void VTypeRecord::show(ostream&out) const { - out << "record "; - for (size_t idx = 0 ; idx < elements_.size() ; idx += 1) { - elements_[idx]->show(out); - out << "; "; - } - out << "endrecord"; + write_to_stream(out); } VTypeRecord::element_t::element_t(perm_string name, const VType*typ) @@ -193,12 +188,6 @@ VTypeRecord::element_t::element_t(perm_string name, const VType*typ) { } -void VTypeRecord::element_t::show(ostream&out) const -{ - out << name_ << ":"; - type_->show(out); -} - VTypeDef::VTypeDef(perm_string nam, const VType*typ) : name_(nam), type_(typ) { diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index bdda995ed..5d86f05c9 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -173,6 +173,8 @@ class VTypeRange : public VType { VTypeRange(const VType*base, int64_t max_val, int64_t min_val); ~VTypeRange(); + void write_to_stream(std::ostream&fd) const; + int emit_def(std::ostream&out, perm_string name) const; private: int emit_decl(std::ostream&out, perm_string name, bool reg_flag) const; @@ -205,7 +207,7 @@ class VTypeRecord : public VType { public: element_t(perm_string name, const VType*type); - void show(std::ostream&) const; + void write_to_stream(std::ostream&) const; private: perm_string name_; @@ -220,6 +222,7 @@ class VTypeRecord : public VType { explicit VTypeRecord(std::list*elements); ~VTypeRecord(); + void write_to_stream(std::ostream&fd) const; void show(std::ostream&) const; int emit_def(std::ostream&out, perm_string name) const; diff --git a/vhdlpp/vtype_stream.cc b/vhdlpp/vtype_stream.cc index c87b80ecc..179096211 100644 --- a/vhdlpp/vtype_stream.cc +++ b/vhdlpp/vtype_stream.cc @@ -37,9 +37,15 @@ void VTypeArray::write_to_stream(ostream&fd) const if (! ranges_.empty()) { assert(ranges_.size() < 2); fd << " ("; - ranges_[0].msb()->write_to_stream(fd); + if (ranges_[0].msb()) + ranges_[0].msb()->write_to_stream(fd); + else + fd << "<>"; fd << " downto "; - ranges_[0].lsb()->write_to_stream(fd); + if (ranges_[0].lsb()) + ranges_[0].lsb()->write_to_stream(fd); + else + fd << "<>"; fd << ") "; } return; @@ -48,11 +54,22 @@ void VTypeArray::write_to_stream(ostream&fd) const fd << "array "; if (! ranges_.empty()) { assert(ranges_.size() < 2); - fd << "("; - ranges_[0].msb()->write_to_stream(fd); - fd << " downto "; - ranges_[0].lsb()->write_to_stream(fd); - fd << ") "; + if (ranges_[0].is_box()) { + fd << "(INTEGER range <>) "; + } else { + assert(ranges_[0].msb() && ranges_[0].lsb()); + fd << "("; + if (ranges_[0].msb()) + ranges_[0].msb()->write_to_stream(fd); + else + fd << "<>"; + fd << " downto "; + if (ranges_[0].lsb()) + ranges_[0].lsb()->write_to_stream(fd); + else + fd << "<>"; + fd << ") "; + } } fd << "of "; @@ -71,9 +88,33 @@ void VTypePrimitive::write_to_stream(ostream&fd) const case STDLOGIC: fd << "std_logic"; break; + case BOOLEAN: + fd << "boolean"; + break; default: assert(0); fd << "/* PRIMITIVE: " << type_ << " */"; break; } } + +void VTypeRange::write_to_stream(ostream&fd) const +{ + fd << "range " << min_ << " to " << max_; +} + +void VTypeRecord::write_to_stream(ostream&fd) const +{ + fd << "record "; + for (size_t idx = 0 ; idx < elements_.size() ; idx += 1) { + elements_[idx]->write_to_stream(fd); + fd << "; "; + } + fd << "endrecord"; +} + +void VTypeRecord::element_t::write_to_stream(ostream&fd) const +{ + fd << name_ << ":"; + type_->write_to_stream(fd); +}