2011-01-03 08:38:08 +01:00
|
|
|
/*
|
2025-10-13 02:35:15 +02:00
|
|
|
* Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com)
|
2013-06-08 00:47:14 +02:00
|
|
|
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
|
2011-01-03 08:38:08 +01:00
|
|
|
*
|
|
|
|
|
* 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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-01-03 08:38:08 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# 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-02-14 04:01:21 +01:00
|
|
|
# include <cassert>
|
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-03-22 17:16:20 +01:00
|
|
|
cerr << "Elaborate entity " << get_name() << "..." << endl;
|
2011-01-03 08:38:08 +01:00
|
|
|
|
2011-07-29 02:07:49 +02:00
|
|
|
if (arch_.empty()) {
|
2011-01-31 20:16:14 +01:00
|
|
|
cerr << get_fileline() << ": error: "
|
2011-03-22 17:16:20 +01:00
|
|
|
<< "No architectures to choose from for entity " << get_name()
|
2011-01-31 20:16:14 +01:00
|
|
|
<< "." << endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2011-01-06 17:12:55 +01:00
|
|
|
|
2011-03-23 10:27:32 +01:00
|
|
|
/* FIXME: the architecture for the entity should be chosen in configuration
|
|
|
|
|
block (not yet implemented). Multiple architectures are allowed in general */
|
2011-01-31 20:16:14 +01:00
|
|
|
if (arch_.size() > 1) {
|
|
|
|
|
cerr << get_fileline() << ": sorry: "
|
2011-03-23 10:27:32 +01:00
|
|
|
<< "Multiple architectures for an entity are not yet supported"
|
|
|
|
|
<< ". Architectures for entity " << get_name() << " are:" << endl;
|
2011-01-31 20:16:14 +01:00
|
|
|
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-03-23 10:27:32 +01:00
|
|
|
//errors += 1;
|
2011-01-31 20:16:14 +01:00
|
|
|
}
|
2011-03-23 10:27:32 +01:00
|
|
|
/* FIXME: here we should look at configuration block */
|
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-10-30 02:07:03 +02:00
|
|
|
errors += elaborate_generic_exprs_();
|
2011-02-03 06:15:46 +01:00
|
|
|
errors += elaborate_ports_();
|
2011-03-27 21:01:58 +02:00
|
|
|
|
|
|
|
|
errors += bind_arch_->elaborate(this);
|
|
|
|
|
|
2011-02-03 06:15:46 +01:00
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-30 02:07:03 +02:00
|
|
|
int Entity::elaborate_generic_exprs_()
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
for (vector<InterfacePort*>::const_iterator cur = parms_.begin()
|
|
|
|
|
; cur != parms_.end() ; ++cur) {
|
|
|
|
|
InterfacePort*curp = *cur;
|
2015-03-06 19:30:02 +01:00
|
|
|
if(curp->expr)
|
|
|
|
|
curp->expr->elaborate_expr(this, 0, curp->type);
|
2011-10-30 02:07:03 +02:00
|
|
|
}
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-03 06:15:46 +01:00
|
|
|
int Entity::elaborate_ports_(void)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
2011-10-16 02:41:48 +02:00
|
|
|
for (std::vector<InterfacePort*>::const_iterator cur = ports_.begin()
|
|
|
|
|
; cur != ports_.end() ; ++cur) {
|
2011-02-03 06:15:46 +01:00
|
|
|
|
2025-10-13 02:35:15 +02:00
|
|
|
const InterfacePort*cur_port = *cur;
|
2011-02-03 06:15:46 +01:00
|
|
|
|
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
|
|
|
|
2013-06-08 00:47:14 +02:00
|
|
|
// Elaborate the type to elaborate any expressions that
|
|
|
|
|
// are used by the types.
|
|
|
|
|
errors += type->elaborate(this, bind_arch_);
|
|
|
|
|
|
2011-10-02 19:56:00 +02:00
|
|
|
VType::decl_t cur_decl;
|
|
|
|
|
cur_decl.type = type;
|
2011-02-03 06:15:46 +01:00
|
|
|
declarations_[cur_port->name] = cur_decl;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-03 08:38:08 +01:00
|
|
|
return errors;
|
|
|
|
|
}
|