2011-03-27 21:01:58 +02:00
|
|
|
/*
|
2021-01-02 22:35:38 +01:00
|
|
|
* Copyright (c) 2011-2021 Stephen Williams (steve@icarus.com)
|
2011-03-27 21:01:58 +02: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-03-27 21:01:58 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "architec.h"
|
|
|
|
|
# include "entity.h"
|
|
|
|
|
# include "expression.h"
|
2011-05-16 01:17:51 +02:00
|
|
|
# include "sequential.h"
|
2015-12-10 10:42:46 +01:00
|
|
|
# include "subprogram.h"
|
2011-03-27 21:01:58 +02:00
|
|
|
# include <typeinfo>
|
|
|
|
|
# include <cassert>
|
|
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
2011-03-27 21:01:58 +02:00
|
|
|
int Architecture::elaborate(Entity*entity)
|
2011-04-10 18:42:22 +02:00
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
2012-04-09 04:06:58 +02:00
|
|
|
// Constant assignments in the architecture get their types
|
|
|
|
|
// from the constant declaration itself. Elaborate the value
|
|
|
|
|
// expression with the declared type.
|
|
|
|
|
|
2013-05-13 04:17:12 +02:00
|
|
|
for (map<perm_string,struct const_t*>::iterator cur = use_constants_.begin()
|
|
|
|
|
; cur != use_constants_.end() ; ++cur) {
|
2012-04-09 04:06:58 +02:00
|
|
|
cur->second->val->elaborate_expr(entity, this, cur->second->typ);
|
|
|
|
|
}
|
2013-05-13 04:17:12 +02:00
|
|
|
for (map<perm_string,struct const_t*>::iterator cur = cur_constants_.begin()
|
|
|
|
|
; cur != cur_constants_.end() ; ++cur) {
|
2012-04-09 04:06:58 +02:00
|
|
|
cur->second->val->elaborate_expr(entity, this, cur->second->typ);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 14:18:16 +02:00
|
|
|
// Elaborate initializer expressions for signals & variables
|
|
|
|
|
for (map<perm_string,Signal*>::iterator cur = old_signals_.begin()
|
|
|
|
|
; cur != old_signals_.end() ; ++cur) {
|
2016-01-28 10:22:24 +01:00
|
|
|
cur->second->elaborate(entity, this);
|
2014-08-20 14:18:16 +02:00
|
|
|
}
|
|
|
|
|
for (map<perm_string,Signal*>::iterator cur = new_signals_.begin()
|
|
|
|
|
; cur != new_signals_.end() ; ++cur) {
|
2016-01-28 10:22:24 +01:00
|
|
|
cur->second->elaborate(entity, this);
|
2014-08-20 14:18:16 +02:00
|
|
|
}
|
|
|
|
|
for (map<perm_string,Variable*>::iterator cur = old_variables_.begin()
|
|
|
|
|
; cur != old_variables_.end() ; ++cur) {
|
2016-01-28 10:22:24 +01:00
|
|
|
cur->second->elaborate(entity, this);
|
2014-08-20 14:18:16 +02:00
|
|
|
}
|
|
|
|
|
for (map<perm_string,Variable*>::iterator cur = new_variables_.begin()
|
|
|
|
|
; cur != new_variables_.end() ; ++cur) {
|
2016-01-28 10:22:24 +01:00
|
|
|
cur->second->elaborate(entity, this);
|
2014-08-20 14:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-10 10:42:46 +01:00
|
|
|
// Elaborate subprograms
|
2016-01-29 16:34:10 +01:00
|
|
|
for (map<perm_string,SubHeaderList>::const_iterator cur = cur_subprograms_.begin()
|
2015-12-10 10:42:46 +01:00
|
|
|
; cur != cur_subprograms_.end() ; ++cur) {
|
2016-01-29 16:34:10 +01:00
|
|
|
const SubHeaderList& subp_list = cur->second;
|
|
|
|
|
|
|
|
|
|
for(SubHeaderList::const_iterator it = subp_list.begin();
|
|
|
|
|
it != subp_list.end(); ++it) {
|
2016-03-13 18:58:08 +01:00
|
|
|
errors += (*it)->elaborate();
|
2016-01-29 16:34:10 +01:00
|
|
|
}
|
2015-12-10 10:42:46 +01:00
|
|
|
}
|
2015-11-30 17:08:02 +01:00
|
|
|
// Create 'initial' and 'final' blocks for implicit
|
2016-03-13 18:58:08 +01:00
|
|
|
// initialization and clean-up actions
|
2015-11-30 17:08:02 +01:00
|
|
|
if(!initializers_.empty())
|
|
|
|
|
statements_.push_front(new InitialStatement(&initializers_));
|
|
|
|
|
|
|
|
|
|
if(!finalizers_.empty())
|
|
|
|
|
statements_.push_front(new FinalStatement(&finalizers_));
|
|
|
|
|
|
2011-04-10 18:42:22 +02:00
|
|
|
for (list<Architecture::Statement*>::iterator cur = statements_.begin()
|
|
|
|
|
; cur != statements_.end() ; ++cur) {
|
|
|
|
|
|
2012-04-09 00:45:17 +02:00
|
|
|
int cur_errors = (*cur)->elaborate(entity, this);
|
|
|
|
|
errors += cur_errors;
|
2011-04-10 18:42:22 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-09 04:06:58 +02:00
|
|
|
if (errors > 0) {
|
|
|
|
|
cerr << errors << " errors in "
|
|
|
|
|
<< name_ << " architecture of "
|
|
|
|
|
<< entity->get_name() << "." << endl;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-09 00:45:17 +02:00
|
|
|
return errors;
|
2011-04-10 18:42:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Architecture::Statement::elaborate(Entity*, Architecture*)
|
2011-03-27 21:01:58 +02:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-04-10 18:42:22 +02:00
|
|
|
|
2011-06-13 01:59:07 +02:00
|
|
|
int ComponentInstantiation::elaborate(Entity*ent, Architecture*arc)
|
2011-04-10 18:42:22 +02:00
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
2011-05-16 01:17:51 +02:00
|
|
|
ComponentBase*base = arc->find_component(cname_);
|
2011-04-10 18:42:22 +02:00
|
|
|
if (base == 0) {
|
|
|
|
|
cerr << get_fileline() << ": error: No component declaration"
|
|
|
|
|
<< " for instance " << iname_
|
|
|
|
|
<< " of " << cname_ << "." << endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-06 16:59:30 +01:00
|
|
|
arc->set_cur_component(this);
|
|
|
|
|
|
2011-10-24 02:08:48 +02:00
|
|
|
for (map<perm_string,Expression*>::const_iterator cur = generic_map_.begin()
|
|
|
|
|
; cur != generic_map_.end() ; ++cur) {
|
|
|
|
|
// check if generic from component instantiation
|
|
|
|
|
// exists in the component declaration
|
|
|
|
|
const InterfacePort*iparm = base->find_generic(cur->first);
|
|
|
|
|
if (iparm == 0) {
|
2015-02-11 11:44:08 +01:00
|
|
|
cerr << get_fileline() << ": warning: No generic " << cur->first
|
2011-10-24 02:08:48 +02:00
|
|
|
<< " in component " << cname_ << "." << endl;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExpName* tmp;
|
|
|
|
|
if (cur->second && (tmp = dynamic_cast<ExpName*>(cur->second)))
|
|
|
|
|
errors += tmp->elaborate_rval(ent, arc, iparm);
|
2011-04-10 18:42:22 +02:00
|
|
|
|
2011-10-24 02:08:48 +02:00
|
|
|
if (cur->second)
|
|
|
|
|
errors += cur->second->elaborate_expr(ent, arc, iparm->type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (map<perm_string,Expression*>::const_iterator cur = port_map_.begin()
|
2011-04-10 18:42:22 +02:00
|
|
|
; cur != port_map_.end() ; ++cur) {
|
2011-10-24 02:08:48 +02:00
|
|
|
// check if a port from component instantiation
|
|
|
|
|
// exists in the component declaration
|
2011-04-10 18:42:22 +02:00
|
|
|
const InterfacePort*iport = base->find_port(cur->first);
|
|
|
|
|
if (iport == 0) {
|
|
|
|
|
cerr << get_fileline() << ": error: No port " << cur->first
|
|
|
|
|
<< " in component " << cname_ << "." << endl;
|
|
|
|
|
errors += 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-06-13 01:59:07 +02:00
|
|
|
|
2011-10-24 02:08:48 +02:00
|
|
|
ExpName* tmp;
|
|
|
|
|
if (cur->second && (tmp = dynamic_cast<ExpName*>(cur->second)))
|
|
|
|
|
errors += tmp->elaborate_rval(ent, arc, iport);
|
2011-06-13 01:59:07 +02:00
|
|
|
/* It is possible for the port to be explicitly
|
|
|
|
|
unconnected. In that case, the Expression will be nil */
|
2011-07-12 18:09:50 +02:00
|
|
|
|
2011-06-13 01:59:07 +02:00
|
|
|
if (cur->second)
|
|
|
|
|
cur->second->elaborate_expr(ent, arc, iport->type);
|
2011-04-10 18:42:22 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-06 16:59:30 +01:00
|
|
|
arc->set_cur_component(NULL);
|
|
|
|
|
|
2011-04-10 18:42:22 +02:00
|
|
|
return errors;
|
|
|
|
|
}
|
2011-05-15 17:57:19 +02:00
|
|
|
|
2011-10-31 01:10:19 +01:00
|
|
|
int GenerateStatement::elaborate_statements(Entity*ent, Architecture*arc)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
for (list<Architecture::Statement*>::iterator cur = statements_.begin()
|
|
|
|
|
; cur != statements_.end() ; ++cur) {
|
|
|
|
|
Architecture::Statement*curp = *cur;
|
|
|
|
|
errors += curp->elaborate(ent, arc);
|
|
|
|
|
}
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ForGenerate::elaborate(Entity*ent, Architecture*arc)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
2012-09-08 00:14:48 +02:00
|
|
|
arc->push_genvar_type(genvar_, lsb_->probe_type(ent, arc));
|
2011-10-31 01:10:19 +01:00
|
|
|
errors += elaborate_statements(ent, arc);
|
2012-09-08 00:14:48 +02:00
|
|
|
arc->pop_genvar_type();
|
2011-10-31 01:10:19 +01:00
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 01:37:19 +01:00
|
|
|
int IfGenerate::elaborate(Entity*ent, Architecture*arc)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
errors += elaborate_statements(ent, arc);
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 10:14:50 +01:00
|
|
|
int StatementList::elaborate(Entity*ent, ScopeBase*scope)
|
2015-11-25 18:15:09 +01:00
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
|
|
for (std::list<SequentialStmt*>::iterator it = statements_.begin();
|
|
|
|
|
it != statements_.end(); ++it) {
|
2016-02-24 10:14:50 +01:00
|
|
|
errors += (*it)->elaborate(ent, scope);
|
2015-11-25 18:15:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-15 17:57:19 +02:00
|
|
|
int ProcessStatement::elaborate(Entity*ent, Architecture*arc)
|
|
|
|
|
{
|
2011-05-16 01:17:51 +02:00
|
|
|
int errors = 0;
|
|
|
|
|
|
2016-02-24 10:14:50 +01:00
|
|
|
arc->set_cur_process(this);
|
|
|
|
|
|
|
|
|
|
for (map<perm_string,Variable*>::iterator cur = new_variables_.begin()
|
|
|
|
|
; cur != new_variables_.end() ; ++cur) {
|
|
|
|
|
cur->second->elaborate(ent, arc);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-25 18:15:09 +01:00
|
|
|
StatementList::elaborate(ent, arc);
|
2011-05-16 01:17:51 +02:00
|
|
|
|
2016-02-24 10:14:50 +01:00
|
|
|
arc->set_cur_process(NULL);
|
|
|
|
|
|
2011-05-16 01:17:51 +02:00
|
|
|
return errors;
|
2011-05-15 17:57:19 +02:00
|
|
|
}
|
2011-06-12 19:51:31 +02:00
|
|
|
|
|
|
|
|
int SignalAssignment::elaborate(Entity*ent, Architecture*arc)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
|
|
// Elaborate the l-value expression.
|
2011-06-13 00:38:03 +02:00
|
|
|
errors += lval_->elaborate_lval(ent, arc, false);
|
2011-06-12 19:51:31 +02:00
|
|
|
|
|
|
|
|
// The elaborate_lval should have resolved the type of the
|
|
|
|
|
// l-value expression. We'll use that type to elaborate the
|
|
|
|
|
// r-value.
|
|
|
|
|
const VType*lval_type = lval_->peek_type();
|
|
|
|
|
if (lval_type == 0) {
|
2012-04-09 00:45:17 +02:00
|
|
|
if (errors == 0) {
|
|
|
|
|
errors += 1;
|
|
|
|
|
cerr << get_fileline() << ": error: Unable to calculate type for l-value expression." << endl;
|
|
|
|
|
}
|
2011-06-12 19:51:31 +02:00
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-22 17:17:02 +01:00
|
|
|
for (list<Expression*>::iterator cur = rval_.begin()
|
2011-06-12 19:51:31 +02:00
|
|
|
; cur != rval_.end() ; ++cur) {
|
2015-02-19 17:01:32 +01:00
|
|
|
errors += (*cur)->elaborate_expr(ent, arc, lval_type);
|
2011-06-12 19:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
2016-01-22 10:20:03 +01:00
|
|
|
|
|
|
|
|
int CondSignalAssignment::elaborate(Entity*ent, Architecture*arc)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
2016-03-16 06:27:03 +01:00
|
|
|
// Visitor to extract signal names occurring in the conditional
|
2016-01-22 10:20:03 +01:00
|
|
|
// statements to create the sensitivity list
|
|
|
|
|
struct name_extractor_t : public ExprVisitor {
|
2021-01-02 22:35:38 +01:00
|
|
|
explicit name_extractor_t(list<const ExpName*>& name_list)
|
2016-01-22 10:20:03 +01:00
|
|
|
: name_list_(name_list) {}
|
|
|
|
|
void operator() (Expression*s) {
|
|
|
|
|
if(const ExpName*name = dynamic_cast<const ExpName*>(s))
|
|
|
|
|
name_list_.push_back(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
list<const ExpName*>& name_list_;
|
|
|
|
|
} name_extractor(sens_list_);
|
|
|
|
|
|
|
|
|
|
// Elaborate the l-value expression.
|
|
|
|
|
errors += lval_->elaborate_lval(ent, arc, true);
|
|
|
|
|
|
|
|
|
|
// The elaborate_lval should have resolved the type of the
|
|
|
|
|
// l-value expression. We'll use that type to elaborate the
|
|
|
|
|
// r-value.
|
|
|
|
|
const VType*lval_type = lval_->peek_type();
|
|
|
|
|
if (lval_type == 0) {
|
|
|
|
|
if (errors == 0) {
|
|
|
|
|
errors += 1;
|
|
|
|
|
cerr << get_fileline()
|
|
|
|
|
<< ": error: Unable to calculate type for l-value expression."
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(list<ExpConditional::case_t*>::iterator it = options_.begin();
|
|
|
|
|
it != options_.end(); ++it) {
|
|
|
|
|
ExpConditional::case_t*cas = (*it);
|
|
|
|
|
cas->elaborate_expr(ent, arc, lval_type);
|
|
|
|
|
cas->visit(name_extractor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
|
}
|