2011-01-03 08:38:08 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "entity.h"
|
|
|
|
|
# include "compiler.h"
|
2011-01-31 20:16:14 +01:00
|
|
|
# include "architec.h"
|
2011-02-07 05:55:31 +01:00
|
|
|
# include "vtype.h"
|
2011-01-03 08:38:08 +01:00
|
|
|
# include <iostream>
|
2011-02-14 01:37:10 +01:00
|
|
|
# include <typeinfo>
|
2011-01-03 08:38:08 +01:00
|
|
|
# include <fstream>
|
|
|
|
|
# include <iomanip>
|
2011-02-03 06:15:46 +01:00
|
|
|
# include <cstring>
|
2011-01-03 08:38:08 +01:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int elaborate_entities(void)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
|
|
for (map<perm_string,Entity*>::iterator cur = design_entities.begin()
|
|
|
|
|
; cur != design_entities.end() ; ++cur) {
|
|
|
|
|
errors += cur->second->elaborate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Entity::elaborate()
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
|
|
if (verbose_flag)
|
2011-01-24 05:26:27 +01:00
|
|
|
cerr << "Elaborate entity " << name_ << "..." << endl;
|
2011-01-03 08:38:08 +01:00
|
|
|
|
2011-01-31 20:16:14 +01:00
|
|
|
if (arch_.size() == 0) {
|
|
|
|
|
cerr << get_fileline() << ": error: "
|
|
|
|
|
<< "No architectures to choose from for entity " << name_
|
|
|
|
|
<< "." << endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2011-01-06 17:12:55 +01:00
|
|
|
|
2011-01-03 08:38:08 +01:00
|
|
|
|
2011-01-31 20:16:14 +01:00
|
|
|
if (arch_.size() > 1) {
|
|
|
|
|
cerr << get_fileline() << ": sorry: "
|
|
|
|
|
<< "Too many architectures for entity " << name_
|
|
|
|
|
<< ". Architectures are:" << endl;
|
|
|
|
|
for (map<perm_string,Architecture*>::const_iterator cur = arch_.begin()
|
|
|
|
|
; cur != arch_.end() ; ++cur) {
|
|
|
|
|
cerr << get_fileline() << ": : " << cur->first
|
|
|
|
|
<< " at " << cur->second->get_fileline() << endl;
|
2011-01-03 08:38:08 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:16:14 +01:00
|
|
|
errors += 1;
|
|
|
|
|
}
|
2011-01-03 08:38:08 +01:00
|
|
|
|
2011-01-31 20:16:14 +01:00
|
|
|
bind_arch_ = arch_.begin()->second;
|
|
|
|
|
if (verbose_flag)
|
|
|
|
|
cerr << "For entity " << get_name()
|
|
|
|
|
<< ", choosing architecture " << bind_arch_->get_name()
|
|
|
|
|
<< "." << endl;
|
2011-01-03 08:38:08 +01:00
|
|
|
|
2011-02-03 06:15:46 +01:00
|
|
|
errors += elaborate_ports_();
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Entity::elaborate_ports_(void)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
|
|
for (std::vector<InterfacePort*>::const_iterator cur = ports_.begin()
|
|
|
|
|
; cur != ports_.end() ; ++cur) {
|
|
|
|
|
|
|
|
|
|
InterfacePort*cur_port = *cur;
|
|
|
|
|
decl_t cur_decl;
|
|
|
|
|
cur_decl.type = VNONE;
|
2011-02-05 04:30:40 +01:00
|
|
|
cur_decl.signed_flag = false;
|
2011-02-03 06:15:46 +01:00
|
|
|
cur_decl.msb = 0;
|
|
|
|
|
cur_decl.lsb = 0;
|
|
|
|
|
|
2011-02-14 01:37:10 +01:00
|
|
|
const VType*type = cur_port->type;
|
2011-02-07 05:55:31 +01:00
|
|
|
if (type == 0) {
|
|
|
|
|
cerr << get_fileline() << ": error: "
|
2011-02-14 01:37:10 +01:00
|
|
|
<< "Giving up on unknown type for port " << cur_port->name
|
2011-02-07 05:55:31 +01:00
|
|
|
<< "." << endl;
|
2011-02-14 01:37:10 +01:00
|
|
|
errors += 1;
|
2011-02-07 05:55:31 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2011-02-05 04:30:40 +01:00
|
|
|
|
2011-02-07 05:55:31 +01:00
|
|
|
if (const VTypePrimitive*use_type = dynamic_cast<const VTypePrimitive*>(type)) {
|
|
|
|
|
switch (use_type->type()) {
|
|
|
|
|
case VTypePrimitive::BOOLEAN:
|
|
|
|
|
case VTypePrimitive::BIT:
|
|
|
|
|
cur_decl.type = VBOOL;
|
|
|
|
|
break;
|
|
|
|
|
case VTypePrimitive::STDLOGIC:
|
|
|
|
|
cur_decl.type = VLOGIC;
|
|
|
|
|
break;
|
|
|
|
|
case VTypePrimitive::INTEGER:
|
|
|
|
|
cur_decl.type = VBOOL;
|
|
|
|
|
cur_decl.msb = 31;
|
|
|
|
|
cur_decl.lsb = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-02-03 06:15:46 +01:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
cerr << get_fileline() << ": error: "
|
|
|
|
|
<< "I don't know how to map port " << cur_port->name
|
2011-02-14 01:37:10 +01:00
|
|
|
<< " type " << typeid(*cur_port->type).name() << "." << endl;
|
2011-02-03 06:15:46 +01:00
|
|
|
errors += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declarations_[cur_port->name] = cur_decl;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-03 08:38:08 +01:00
|
|
|
return errors;
|
|
|
|
|
}
|