Clean up entity interface.

This commit is contained in:
Stephen Williams 2011-02-02 19:59:20 -08:00
parent 798ead9345
commit 5914617727
5 changed files with 25 additions and 17 deletions

View File

@ -57,12 +57,12 @@ void Entity::dump(ostream&out) const
{ {
out << "entity " << name_ out << "entity " << name_
<< " file=" << get_fileline() << endl; << " file=" << get_fileline() << endl;
if (ports.size() == 0) { if (ports_.size() == 0) {
out << " No ports" << endl; out << " No ports" << endl;
} else { } else {
out << " PORTS:" << endl; out << " PORTS:" << endl;
for (vector<InterfacePort*>::const_iterator cur = ports.begin() for (vector<InterfacePort*>::const_iterator cur = ports_.begin()
; cur != ports.end() ; ++cur) { ; cur != ports_.end() ; ++cur) {
InterfacePort*item = *cur; InterfacePort*item = *cur;
out << setw(6) << "" << item->name out << setw(6) << "" << item->name
<< " : " << item->mode << " : " << item->mode

View File

@ -34,6 +34,14 @@ Entity::~Entity()
{ {
} }
void Entity::set_interface(std::list<InterfacePort*>*ports)
{
while (ports->size() > 0) {
ports_.push_back(ports->front());
ports->pop_front();
}
}
Architecture* Entity::add_architecture(Architecture*that) Architecture* Entity::add_architecture(Architecture*that)
{ {
if (Architecture*tmp = arch_ [that->get_name()]) { if (Architecture*tmp = arch_ [that->get_name()]) {

View File

@ -20,6 +20,7 @@
*/ */
# include <map> # include <map>
# include <list>
# include <vector> # include <vector>
# include "StringHeap.h" # include "StringHeap.h"
# include "LineInfo.h" # include "LineInfo.h"
@ -47,6 +48,12 @@ class Entity : public LineInfo {
// Entities have names. // Entities have names.
perm_string get_name() const { return name_; } perm_string get_name() const { return name_; }
// Declare the ports for the entity. The parser calls this
// method with a list of interface elements that were parsed
// for the entity. This method collects those entities, and
// empties the list in the process.
void set_interface(std::list<InterfacePort*>*ports);
// bind an architecture to the entity, and return the // bind an architecture to the entity, and return the
// Architecture that was bound. If there was a previous // Architecture that was bound. If there was a previous
// architecture with the same name bound, then do not replace // architecture with the same name bound, then do not replace
@ -60,12 +67,11 @@ class Entity : public LineInfo {
void dump(ostream&out) const; void dump(ostream&out) const;
public:
std::vector<InterfacePort*> ports;
private: private:
perm_string name_; perm_string name_;
std::vector<InterfacePort*> ports_;
std::map<perm_string,Architecture*>arch_; std::map<perm_string,Architecture*>arch_;
Architecture*bind_arch_; Architecture*bind_arch_;

View File

@ -42,11 +42,11 @@ int Entity::emit(ostream&out)
out << "module " << name_; out << "module " << name_;
// If there are ports, emit them. // If there are ports, emit them.
if (ports.size() > 0) { if (ports_.size() > 0) {
out << "("; out << "(";
const char*sep = 0; const char*sep = 0;
for (vector<InterfacePort*>::iterator cur = ports.begin() for (vector<InterfacePort*>::iterator cur = ports_.begin()
; cur != ports.end() ; ++cur) { ; cur != ports_.end() ; ++cur) {
InterfacePort*port = *cur; InterfacePort*port = *cur;
// FIXME: this is a stub. This port handling code // FIXME: this is a stub. This port handling code

View File

@ -194,10 +194,7 @@ entity_declaration
FILE_NAME(tmp, @1); FILE_NAME(tmp, @1);
// Transfer the ports // Transfer the ports
std::list<InterfacePort*>*ports = $4; std::list<InterfacePort*>*ports = $4;
while (ports->size() > 0) { tmp->set_interface(ports);
tmp->ports.push_back(ports->front());
ports->pop_front();
}
delete ports; delete ports;
// Save the entity in the entity map. // Save the entity in the entity map.
design_entities[tmp->get_name()] = tmp; design_entities[tmp->get_name()] = tmp;
@ -214,10 +211,7 @@ entity_declaration
delete[]$7; delete[]$7;
// Transfer the ports // Transfer the ports
std::list<InterfacePort*>*ports = $4; std::list<InterfacePort*>*ports = $4;
while (ports->size() > 0) { tmp->set_interface(ports);
tmp->ports.push_back(ports->front());
ports->pop_front();
}
delete ports; delete ports;
// Save the entity in the entity map. // Save the entity in the entity map.
design_entities[tmp->get_name()] = tmp; design_entities[tmp->get_name()] = tmp;