2011-01-24 05:26:27 +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
|
|
|
|
|
* Picture Elements, Inc., 777 Panoramic Way, Berkeley, CA 94704.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "entity.h"
|
|
|
|
|
# include "architec.h"
|
2011-01-30 02:27:30 +01:00
|
|
|
# include "expression.h"
|
2011-03-22 17:16:20 +01:00
|
|
|
# include "vsignal.h"
|
2011-02-14 01:37:10 +01:00
|
|
|
# include "vtype.h"
|
2011-01-24 05:26:27 +01:00
|
|
|
# include <fstream>
|
|
|
|
|
# include <iomanip>
|
2011-01-30 02:27:30 +01:00
|
|
|
# include <typeinfo>
|
2011-01-24 05:26:27 +01:00
|
|
|
|
|
|
|
|
static ostream& operator << (ostream&out, port_mode_t that)
|
|
|
|
|
{
|
|
|
|
|
switch (that) {
|
|
|
|
|
case PORT_NONE:
|
|
|
|
|
out << "NO-PORT";
|
|
|
|
|
break;
|
|
|
|
|
case PORT_IN:
|
|
|
|
|
out << "IN";
|
|
|
|
|
break;
|
|
|
|
|
case PORT_OUT:
|
|
|
|
|
out << "OUT";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
out << "PORT-????";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-18 02:19:09 +02:00
|
|
|
void dump_design_entities(ostream&file)
|
2011-01-24 05:26:27 +01:00
|
|
|
{
|
|
|
|
|
for (map<perm_string,Entity*>::iterator cur = design_entities.begin()
|
|
|
|
|
; cur != design_entities.end() ; ++cur) {
|
|
|
|
|
cur->second->dump(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 17:27:58 +02:00
|
|
|
void ComponentBase::dump_ports(ostream&out, int indent) const
|
2011-01-24 05:26:27 +01:00
|
|
|
{
|
2011-02-03 04:59:20 +01:00
|
|
|
if (ports_.size() == 0) {
|
2011-04-06 17:27:58 +02:00
|
|
|
out << setw(indent) << "" << "No ports" << endl;
|
2011-01-24 05:26:27 +01:00
|
|
|
} else {
|
2011-04-06 17:27:58 +02:00
|
|
|
out << setw(indent) << "" << "PORTS:" << endl;
|
2011-02-03 04:59:20 +01:00
|
|
|
for (vector<InterfacePort*>::const_iterator cur = ports_.begin()
|
|
|
|
|
; cur != ports_.end() ; ++cur) {
|
2011-01-24 05:26:27 +01:00
|
|
|
InterfacePort*item = *cur;
|
2011-04-06 17:27:58 +02:00
|
|
|
out << setw(indent+2) << "" << item->name
|
2011-01-24 05:26:27 +01:00
|
|
|
<< " : " << item->mode
|
2011-02-14 04:01:21 +01:00
|
|
|
<< ", type=";
|
|
|
|
|
if (item->type)
|
|
|
|
|
item->type->show(out);
|
|
|
|
|
else
|
|
|
|
|
out << "<nil>";
|
|
|
|
|
out << ", file=" << item->get_fileline() << endl;
|
2011-01-24 05:26:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-03-22 17:16:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 03:30:00 +02:00
|
|
|
void Scope::dump_scope(ostream&out) const
|
|
|
|
|
{
|
2011-04-18 02:19:09 +02:00
|
|
|
// Dump types
|
|
|
|
|
for (map<perm_string,const VType*>::const_iterator cur = types_.begin()
|
|
|
|
|
; cur != types_.end() ; ++cur) {
|
|
|
|
|
out << " " << cur->first << ": ";
|
|
|
|
|
cur->second->show(out);
|
|
|
|
|
out << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dump constants
|
|
|
|
|
for (map<perm_string,const_t>::const_iterator cur = constants_.begin()
|
|
|
|
|
; cur != constants_.end() ; ++cur) {
|
|
|
|
|
out << " constant " << cur->first << " = ";
|
|
|
|
|
out << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dump signal declarations
|
|
|
|
|
for (map<perm_string,Signal*>::const_iterator cur = signals_.begin()
|
|
|
|
|
; cur != signals_.end() ; ++cur) {
|
|
|
|
|
if (cur->second)
|
|
|
|
|
cur->second->dump(out, 3);
|
|
|
|
|
else
|
|
|
|
|
out << " signal " << cur->first.str() << ": ???" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 03:30:00 +02:00
|
|
|
// Dump component declarations
|
|
|
|
|
for (map<perm_string,ComponentBase*>::const_iterator cur = components_.begin()
|
|
|
|
|
; cur != components_.end() ; ++cur) {
|
|
|
|
|
out << " component " << cur->first << " is" << endl;
|
|
|
|
|
cur->second->dump_ports(out);
|
|
|
|
|
out << " end component " << cur->first << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 17:27:58 +02:00
|
|
|
void Entity::dump(ostream&out, int indent) const
|
2011-03-22 17:16:20 +01:00
|
|
|
{
|
2011-04-06 17:27:58 +02:00
|
|
|
out << setw(indent) << "" << "entity " << get_name()
|
2011-03-22 17:16:20 +01:00
|
|
|
<< " file=" << get_fileline() << endl;
|
2011-04-06 17:27:58 +02:00
|
|
|
dump_ports(out, indent+2);
|
2011-01-24 05:26:27 +01:00
|
|
|
|
|
|
|
|
for (map<perm_string,Architecture*>::const_iterator cur = arch_.begin()
|
|
|
|
|
; cur != arch_.end() ; ++cur) {
|
2011-04-06 17:27:58 +02:00
|
|
|
cur->second->dump(out, get_name(), indent);
|
2011-01-24 05:26:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 17:27:58 +02:00
|
|
|
void Architecture::dump(ostream&out, perm_string of_entity, int indent) const
|
2011-01-24 05:26:27 +01:00
|
|
|
{
|
2011-04-06 17:27:58 +02:00
|
|
|
out << setw(indent) << "" << "architecture " << name_
|
2011-01-24 05:26:27 +01:00
|
|
|
<< " of entity " << of_entity
|
|
|
|
|
<< " file=" << get_fileline() << endl;
|
2011-01-27 05:38:20 +01:00
|
|
|
|
2011-04-14 03:30:00 +02:00
|
|
|
dump_scope(out);
|
2011-03-22 17:16:20 +01:00
|
|
|
|
2011-01-27 05:38:20 +01:00
|
|
|
for (list<Architecture::Statement*>::const_iterator cur = statements_.begin()
|
|
|
|
|
; cur != statements_.end() ; ++cur) {
|
2011-04-06 17:27:58 +02:00
|
|
|
(*cur)->dump(out, indent+3);
|
2011-01-27 05:38:20 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 17:27:58 +02:00
|
|
|
void Architecture::Statement::dump(ostream&out, int indent) const
|
2011-01-27 05:38:20 +01:00
|
|
|
{
|
2011-04-06 17:27:58 +02:00
|
|
|
out << setw(indent) << "" << "Architecture::Statement at file=" << get_fileline() << endl;
|
2011-01-27 05:38:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-06 17:27:58 +02:00
|
|
|
void Signal::dump(ostream&out, int indent) const
|
2011-03-22 17:16:20 +01:00
|
|
|
{
|
2011-04-18 02:19:09 +02:00
|
|
|
out << setw(indent) << "" << "signal " << name_ << " is ";
|
|
|
|
|
if (type_)
|
|
|
|
|
out << *type_;
|
|
|
|
|
else
|
|
|
|
|
out << "?NO TYPE?";
|
|
|
|
|
out << endl;
|
2011-03-22 17:16:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-06 17:27:58 +02:00
|
|
|
void SignalAssignment::dump(ostream&out, int indent) const
|
2011-01-27 05:38:20 +01:00
|
|
|
{
|
2011-04-06 17:27:58 +02:00
|
|
|
out << setw(indent) << "" << "SignalAssignment file=" << get_fileline() << endl;
|
|
|
|
|
lval_->dump(out, indent+1);
|
|
|
|
|
out << setw(indent+2) << "" << "<= <expr>..." << endl;
|
2011-01-30 02:27:30 +01:00
|
|
|
|
|
|
|
|
for (list<Expression*>::const_iterator cur = rval_.begin()
|
|
|
|
|
; cur != rval_.end() ; ++cur) {
|
2011-04-06 17:27:58 +02:00
|
|
|
(*cur)->dump(out, indent+2);
|
2011-01-30 02:27:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 17:27:58 +02:00
|
|
|
void ComponentInstantiation::dump(ostream&out, int indent) const
|
2011-04-01 03:50:48 +02:00
|
|
|
{
|
2011-04-06 17:27:58 +02:00
|
|
|
out << setw(indent) << "" << "Component Instantiation file=" << get_fileline() << endl;
|
2011-04-01 03:50:48 +02:00
|
|
|
|
|
|
|
|
for (map<perm_string,Expression*>::const_iterator cur = port_map_.begin()
|
|
|
|
|
; cur != port_map_.end() ; ++cur) {
|
2011-04-06 17:27:58 +02:00
|
|
|
out << setw(indent+2) <<""<< cur->first << " => ..." << endl;
|
|
|
|
|
cur->second->dump(out, indent+6);
|
2011-04-01 03:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-30 02:27:30 +01:00
|
|
|
void Expression::dump(ostream&out, int indent) const
|
|
|
|
|
{
|
|
|
|
|
out << setw(indent) << "" << "Expression [" << typeid(*this).name() << "]"
|
|
|
|
|
<< " at " << get_fileline()<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-20 02:47:30 +01:00
|
|
|
void ExpArithmetic::dump(ostream&out, int indent) const
|
|
|
|
|
{
|
|
|
|
|
const char*fun_name = "?";
|
|
|
|
|
switch (fun_) {
|
|
|
|
|
case PLUS:
|
|
|
|
|
fun_name = "+";
|
|
|
|
|
break;
|
|
|
|
|
case MINUS:
|
|
|
|
|
fun_name = "-";
|
|
|
|
|
break;
|
|
|
|
|
case MULT:
|
|
|
|
|
fun_name = "*";
|
|
|
|
|
break;
|
|
|
|
|
case DIV:
|
|
|
|
|
fun_name = "/";
|
|
|
|
|
break;
|
|
|
|
|
case MOD:
|
|
|
|
|
fun_name = "mod";
|
|
|
|
|
break;
|
|
|
|
|
case REM:
|
|
|
|
|
fun_name = "rem";
|
|
|
|
|
break;
|
|
|
|
|
case POW:
|
|
|
|
|
fun_name = "**";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out << setw(indent) << "" << "Arithmetic " << fun_name
|
|
|
|
|
<< " at " << get_fileline() << endl;
|
2011-02-21 02:03:46 +01:00
|
|
|
dump_operands(out, indent+4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExpBinary::dump_operands(ostream&out, int indent) const
|
|
|
|
|
{
|
|
|
|
|
operand1_->dump(out, indent);
|
|
|
|
|
operand2_->dump(out, indent);
|
2011-02-20 02:47:30 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-14 04:01:21 +01:00
|
|
|
void ExpInteger::dump(ostream&out, int indent) const
|
|
|
|
|
{
|
2011-02-21 02:03:46 +01:00
|
|
|
out << setw(indent) << "" << "Integer " << value_
|
|
|
|
|
<< " at " << get_fileline() << endl;
|
2011-02-14 04:01:21 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-30 02:27:30 +01:00
|
|
|
void ExpLogical::dump(ostream&out, int indent) const
|
|
|
|
|
{
|
|
|
|
|
const char*fun_name = "?";
|
|
|
|
|
switch (fun_) {
|
|
|
|
|
case AND:
|
|
|
|
|
fun_name = "AND";
|
|
|
|
|
break;
|
|
|
|
|
case OR:
|
|
|
|
|
fun_name = "OR";
|
|
|
|
|
break;
|
|
|
|
|
case NAND:
|
|
|
|
|
fun_name = "NAND";
|
|
|
|
|
break;
|
|
|
|
|
case NOR:
|
|
|
|
|
fun_name = "NOR";
|
|
|
|
|
break;
|
|
|
|
|
case XOR:
|
|
|
|
|
fun_name = "XOR";
|
|
|
|
|
break;
|
|
|
|
|
case XNOR:
|
|
|
|
|
fun_name = "XNOR";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out << setw(indent) << "" << "Logical " << fun_name
|
|
|
|
|
<< " at " << get_fileline() << endl;
|
2011-02-21 02:03:46 +01:00
|
|
|
dump_operands(out, indent+4);
|
2011-01-30 02:27:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExpName::dump(ostream&out, int indent) const
|
|
|
|
|
{
|
|
|
|
|
out << setw(indent) << "" << "ExpName(\"" << name_ << "\")"
|
|
|
|
|
<< " at " << get_fileline() << endl;
|
2011-03-27 21:01:58 +02:00
|
|
|
if (index_)
|
|
|
|
|
index_->dump(out, indent+6);
|
2011-01-24 05:26:27 +01:00
|
|
|
}
|
2011-02-21 02:03:46 +01:00
|
|
|
|
|
|
|
|
void ExpUAbs::dump(ostream&out, int indent) const
|
|
|
|
|
{
|
|
|
|
|
out << setw(indent) << "" << "abs() at " << get_fileline() << endl;
|
|
|
|
|
dump_operand1(out, indent+4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExpUnary::dump_operand1(ostream&out, int indent) const
|
|
|
|
|
{
|
|
|
|
|
operand1_->dump(out, indent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExpUNot::dump(ostream&out, int indent) const
|
|
|
|
|
{
|
|
|
|
|
out << setw(indent) << "" << "not() at " << get_fileline() << endl;
|
|
|
|
|
dump_operand1(out, indent+4);
|
|
|
|
|
}
|