2011-01-31 20:16:14 +01:00
|
|
|
/*
|
2025-10-13 02:35:15 +02:00
|
|
|
* Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com)
|
2011-01-31 20:16:14 +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-31 20:16:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "entity.h"
|
|
|
|
|
# include "architec.h"
|
|
|
|
|
# include <iostream>
|
|
|
|
|
# include <fstream>
|
|
|
|
|
# include <iomanip>
|
2011-10-16 02:41:48 +02:00
|
|
|
# include <ivl_assert.h>
|
2011-01-31 20:16:14 +01:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
2011-01-31 20:16:14 +01:00
|
|
|
int emit_entities(void)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
|
|
for (map<perm_string,Entity*>::iterator cur = design_entities.begin()
|
|
|
|
|
; cur != design_entities.end() ; ++cur) {
|
|
|
|
|
errors += cur->second->emit(cout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Entity::emit(ostream&out)
|
|
|
|
|
{
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
2011-10-16 20:01:32 +02:00
|
|
|
out << "module \\" << get_name() << " ";
|
|
|
|
|
|
2011-10-16 02:41:48 +02:00
|
|
|
// If there are generics, emit them
|
|
|
|
|
if (parms_.size() > 0) {
|
|
|
|
|
out << "#(";
|
|
|
|
|
for (vector<InterfacePort*>::const_iterator cur = parms_.begin()
|
|
|
|
|
; cur != parms_.end() ; ++cur) {
|
|
|
|
|
const InterfacePort*curp = *cur;
|
|
|
|
|
if (cur != parms_.begin())
|
|
|
|
|
out << ", ";
|
2015-05-16 00:40:26 +02:00
|
|
|
out << "parameter \\" << curp->name << " = ";
|
2015-03-06 19:30:02 +01:00
|
|
|
if(curp->expr) {
|
|
|
|
|
errors += curp->expr->emit(out, this, 0);
|
2015-05-16 00:40:26 +02:00
|
|
|
} else {
|
|
|
|
|
// Unlike VHDL, Verilog module parameter port list
|
|
|
|
|
// elements are always assignments. Fill in the blank.
|
|
|
|
|
out << "1'bx";
|
|
|
|
|
}
|
2011-10-16 02:41:48 +02:00
|
|
|
}
|
|
|
|
|
out << ") ";
|
|
|
|
|
}
|
2011-03-22 17:16:20 +01:00
|
|
|
|
2011-01-31 20:16:14 +01:00
|
|
|
// If there are ports, emit them.
|
2011-10-16 02:41:48 +02:00
|
|
|
if (ports_.size() > 0) {
|
2011-01-31 20:16:14 +01:00
|
|
|
out << "(";
|
|
|
|
|
const char*sep = 0;
|
2011-10-16 02:41:48 +02:00
|
|
|
for (vector<InterfacePort*>::const_iterator cur = ports_.begin()
|
|
|
|
|
; cur != ports_.end() ; ++cur) {
|
2011-01-31 20:16:14 +01:00
|
|
|
InterfacePort*port = *cur;
|
|
|
|
|
|
2025-10-13 02:35:15 +02:00
|
|
|
const VType::decl_t&decl = declarations_[port->name];
|
2011-02-05 04:30:40 +01:00
|
|
|
|
2012-04-15 18:57:42 +02:00
|
|
|
if (sep) out << sep << endl;
|
2011-01-31 20:16:14 +01:00
|
|
|
else sep = ", ";
|
|
|
|
|
|
|
|
|
|
switch (port->mode) {
|
|
|
|
|
case PORT_NONE: // Should not happen
|
2015-05-08 15:55:26 +02:00
|
|
|
cerr << get_fileline() << ": error: Undefined port direction." << endl;
|
2011-01-31 20:16:14 +01:00
|
|
|
out << "NO_PORT " << port->name;
|
|
|
|
|
break;
|
|
|
|
|
case PORT_IN:
|
2011-02-05 04:30:40 +01:00
|
|
|
out << "input ";
|
2011-01-31 20:16:14 +01:00
|
|
|
break;
|
|
|
|
|
case PORT_OUT:
|
2011-02-05 04:30:40 +01:00
|
|
|
out << "output ";
|
2015-05-08 15:55:26 +02:00
|
|
|
break;
|
|
|
|
|
case PORT_INOUT:
|
|
|
|
|
out << "inout ";
|
2011-01-31 20:16:14 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2015-05-08 15:55:26 +02:00
|
|
|
|
|
|
|
|
errors += decl.emit(out, port->name);
|
2011-01-31 20:16:14 +01:00
|
|
|
}
|
|
|
|
|
cout << ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out << ";" << endl;
|
|
|
|
|
|
|
|
|
|
errors += bind_arch_->emit(out, this);
|
|
|
|
|
|
|
|
|
|
out << "endmodule" << endl;
|
|
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
|
}
|