2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* ---
|
|
|
|
*
|
|
|
|
* A very simple and straightforward backend for the RTLIL text
|
|
|
|
* representation (as understood by the 'ilang' frontend).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ilang_backend.h"
|
2014-08-23 06:54:21 -05:00
|
|
|
#include "kernel/yosys.h"
|
2013-06-02 10:53:30 -05:00
|
|
|
#include <errno.h>
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
2013-01-05 04:13:26 -06:00
|
|
|
using namespace ILANG_BACKEND;
|
2014-09-27 09:17:53 -05:00
|
|
|
YOSYS_NAMESPACE_BEGIN
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_const(std::ostream &f, const RTLIL::Const &data, int width, int offset, bool autoint)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
if (width < 0)
|
|
|
|
width = data.bits.size() - offset;
|
2013-12-04 07:14:05 -06:00
|
|
|
if ((data.flags & RTLIL::CONST_FLAG_STRING) == 0 || width != (int)data.bits.size()) {
|
2013-01-05 04:13:26 -06:00
|
|
|
if (width == 32 && autoint) {
|
|
|
|
int32_t val = 0;
|
|
|
|
for (int i = 0; i < width; i++) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(offset+i < (int)data.bits.size());
|
2013-01-05 04:13:26 -06:00
|
|
|
switch (data.bits[offset+i]) {
|
|
|
|
case RTLIL::S0: break;
|
|
|
|
case RTLIL::S1: val |= 1 << i; break;
|
|
|
|
default: val = -1; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (val >= 0) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%d", val);
|
2013-01-05 04:13:26 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%d'", width);
|
2013-01-05 04:13:26 -06:00
|
|
|
for (int i = offset+width-1; i >= offset; i--) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(i < (int)data.bits.size());
|
2013-01-05 04:13:26 -06:00
|
|
|
switch (data.bits[i]) {
|
2014-08-23 06:54:21 -05:00
|
|
|
case RTLIL::S0: f << stringf("0"); break;
|
|
|
|
case RTLIL::S1: f << stringf("1"); break;
|
|
|
|
case RTLIL::Sx: f << stringf("x"); break;
|
|
|
|
case RTLIL::Sz: f << stringf("z"); break;
|
|
|
|
case RTLIL::Sa: f << stringf("-"); break;
|
|
|
|
case RTLIL::Sm: f << stringf("m"); break;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\"");
|
2013-12-04 07:14:05 -06:00
|
|
|
std::string str = data.decode_string();
|
|
|
|
for (size_t i = 0; i < str.size(); i++) {
|
|
|
|
if (str[i] == '\n')
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\\n");
|
2013-12-04 07:14:05 -06:00
|
|
|
else if (str[i] == '\t')
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\\t");
|
2013-12-04 07:14:05 -06:00
|
|
|
else if (str[i] < 32)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\\%03o", str[i]);
|
2013-12-04 07:14:05 -06:00
|
|
|
else if (str[i] == '"')
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\\\"");
|
2013-12-04 07:14:05 -06:00
|
|
|
else if (str[i] == '\\')
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\\\\");
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << str[i];
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\"");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_sigchunk(std::ostream &f, const RTLIL::SigChunk &chunk, bool autoint)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
if (chunk.wire == NULL) {
|
|
|
|
dump_const(f, chunk.data, chunk.width, chunk.offset, autoint);
|
|
|
|
} else {
|
|
|
|
if (chunk.width == chunk.wire->width && chunk.offset == 0)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s", chunk.wire->name.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
else if (chunk.width == 1)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s [%d]", chunk.wire->name.c_str(), chunk.offset);
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s [%d:%d]", chunk.wire->name.c_str(), chunk.offset+chunk.width-1, chunk.offset);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_sigspec(std::ostream &f, const RTLIL::SigSpec &sig, bool autoint)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-07-25 07:23:31 -05:00
|
|
|
if (sig.is_chunk()) {
|
|
|
|
dump_sigchunk(f, sig.as_chunk(), autoint);
|
2013-01-05 04:13:26 -06:00
|
|
|
} else {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("{ ");
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = sig.chunks().rbegin(); it != sig.chunks().rend(); ++it) {
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigchunk(f, *it, false);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" ");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("}");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_wire(std::ostream &f, std::string indent, const RTLIL::Wire *wire)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2015-01-23 17:13:27 -06:00
|
|
|
for (auto &it : wire->attributes) {
|
|
|
|
f << stringf("%s" "attribute %s ", indent.c_str(), it.first.c_str());
|
|
|
|
dump_const(f, it.second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "wire ", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
if (wire->width != 1)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("width %d ", wire->width);
|
2014-07-28 05:12:13 -05:00
|
|
|
if (wire->upto)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("upto ");
|
2013-01-05 04:13:26 -06:00
|
|
|
if (wire->start_offset != 0)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("offset %d ", wire->start_offset);
|
2013-01-05 04:13:26 -06:00
|
|
|
if (wire->port_input && !wire->port_output)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("input %d ", wire->port_id);
|
2013-01-05 04:13:26 -06:00
|
|
|
if (!wire->port_input && wire->port_output)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("output %d ", wire->port_id);
|
2013-01-05 04:13:26 -06:00
|
|
|
if (wire->port_input && wire->port_output)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("inout %d ", wire->port_id);
|
|
|
|
f << stringf("%s\n", wire->name.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_memory(std::ostream &f, std::string indent, const RTLIL::Memory *memory)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2015-01-23 17:13:27 -06:00
|
|
|
for (auto &it : memory->attributes) {
|
|
|
|
f << stringf("%s" "attribute %s ", indent.c_str(), it.first.c_str());
|
|
|
|
dump_const(f, it.second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "memory ", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
if (memory->width != 1)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("width %d ", memory->width);
|
2013-01-05 04:13:26 -06:00
|
|
|
if (memory->size != 0)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("size %d ", memory->size);
|
2015-01-01 05:56:01 -06:00
|
|
|
if (memory->start_offset != 0)
|
|
|
|
f << stringf("offset %d ", memory->start_offset);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s\n", memory->name.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_cell(std::ostream &f, std::string indent, const RTLIL::Cell *cell)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2015-01-23 17:13:27 -06:00
|
|
|
for (auto &it : cell->attributes) {
|
|
|
|
f << stringf("%s" "attribute %s ", indent.c_str(), it.first.c_str());
|
|
|
|
dump_const(f, it.second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "cell %s %s\n", indent.c_str(), cell->type.c_str(), cell->name.c_str());
|
2015-01-23 17:13:27 -06:00
|
|
|
for (auto &it : cell->parameters) {
|
|
|
|
f << stringf("%s parameter%s %s ", indent.c_str(), (it.second.flags & RTLIL::CONST_FLAG_SIGNED) != 0 ? " signed" : "", it.first.c_str());
|
|
|
|
dump_const(f, it.second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2015-01-23 17:13:27 -06:00
|
|
|
for (auto &it : cell->connections()) {
|
|
|
|
f << stringf("%s connect %s ", indent.c_str(), it.first.c_str());
|
|
|
|
dump_sigspec(f, it.second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "end\n", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_proc_case_body(std::ostream &f, std::string indent, const RTLIL::CaseRule *cs)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = cs->actions.begin(); it != cs->actions.end(); ++it)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "assign ", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigspec(f, it->first);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" ");
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigspec(f, it->second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = cs->switches.begin(); it != cs->switches.end(); ++it)
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_proc_switch(f, indent, *it);
|
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_proc_switch(std::ostream &f, std::string indent, const RTLIL::SwitchRule *sw)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = sw->attributes.begin(); it != sw->attributes.end(); ++it) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "attribute %s ", indent.c_str(), it->first.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_const(f, it->second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "switch ", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigspec(f, sw->signal);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = sw->cases.begin(); it != sw->cases.end(); ++it)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s case ", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
for (size_t i = 0; i < (*it)->compare.size(); i++) {
|
|
|
|
if (i > 0)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(", ");
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigspec(f, (*it)->compare[i]);
|
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
dump_proc_case_body(f, indent + " ", *it);
|
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "end\n", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_proc_sync(std::ostream &f, std::string indent, const RTLIL::SyncRule *sy)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "sync ", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
switch (sy->type) {
|
2014-08-23 06:54:21 -05:00
|
|
|
if (0) case RTLIL::ST0: f << stringf("low ");
|
|
|
|
if (0) case RTLIL::ST1: f << stringf("high ");
|
|
|
|
if (0) case RTLIL::STp: f << stringf("posedge ");
|
|
|
|
if (0) case RTLIL::STn: f << stringf("negedge ");
|
|
|
|
if (0) case RTLIL::STe: f << stringf("edge ");
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigspec(f, sy->signal);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
break;
|
2014-08-23 06:54:21 -05:00
|
|
|
case RTLIL::STa: f << stringf("always\n"); break;
|
|
|
|
case RTLIL::STi: f << stringf("init\n"); break;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = sy->actions.begin(); it != sy->actions.end(); ++it) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s update ", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigspec(f, it->first);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" ");
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigspec(f, it->second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_proc(std::ostream &f, std::string indent, const RTLIL::Process *proc)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = proc->attributes.begin(); it != proc->attributes.end(); ++it) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "attribute %s ", indent.c_str(), it->first.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_const(f, it->second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "process %s\n", indent.c_str(), proc->name.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_proc_case_body(f, indent + " ", &proc->root_case);
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = proc->syncs.begin(); it != proc->syncs.end(); ++it)
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_proc_sync(f, indent + " ", *it);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "end\n", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
void ILANG_BACKEND::dump_conn(std::ostream &f, std::string indent, const RTLIL::SigSpec &left, const RTLIL::SigSpec &right)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "connect ", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigspec(f, left);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" ");
|
2013-01-05 04:13:26 -06:00
|
|
|
dump_sigspec(f, right);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-09-19 08:50:34 -05:00
|
|
|
void ILANG_BACKEND::dump_module(std::ostream &f, std::string indent, RTLIL::Module *module, RTLIL::Design *design, bool only_selected, bool flag_m, bool flag_n)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2013-11-29 03:33:36 -06:00
|
|
|
bool print_header = flag_m || design->selected_whole_module(module->name);
|
|
|
|
bool print_body = !flag_n || !design->selected_whole_module(module->name);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2013-11-29 03:33:36 -06:00
|
|
|
if (print_header)
|
|
|
|
{
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = module->attributes.begin(); it != module->attributes.end(); ++it) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "attribute %s ", indent.c_str(), it->first.c_str());
|
2013-11-29 03:33:36 -06:00
|
|
|
dump_const(f, it->second);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-06-02 10:53:30 -05:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "module %s\n", indent.c_str(), module->name.c_str());
|
2013-11-29 03:33:36 -06:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2013-11-29 03:33:36 -06:00
|
|
|
if (print_body)
|
|
|
|
{
|
2014-09-19 08:50:34 -05:00
|
|
|
for (auto it : module->wires())
|
|
|
|
if (!only_selected || design->selected(module, it)) {
|
2013-11-29 03:33:36 -06:00
|
|
|
if (only_selected)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2014-09-19 08:50:34 -05:00
|
|
|
dump_wire(f, indent + " ", it);
|
2013-11-29 03:33:36 -06:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2015-01-23 17:13:27 -06:00
|
|
|
for (auto it : module->memories)
|
|
|
|
if (!only_selected || design->selected(module, it.second)) {
|
2013-11-29 03:33:36 -06:00
|
|
|
if (only_selected)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2015-01-23 17:13:27 -06:00
|
|
|
dump_memory(f, indent + " ", it.second);
|
2013-11-29 03:33:36 -06:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2015-01-23 17:13:27 -06:00
|
|
|
for (auto it : module->cells())
|
2014-09-19 08:50:34 -05:00
|
|
|
if (!only_selected || design->selected(module, it)) {
|
2013-11-29 03:33:36 -06:00
|
|
|
if (only_selected)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2014-09-19 08:50:34 -05:00
|
|
|
dump_cell(f, indent + " ", it);
|
2013-11-29 03:33:36 -06:00
|
|
|
}
|
|
|
|
|
2015-01-23 17:13:27 -06:00
|
|
|
for (auto it : module->processes)
|
|
|
|
if (!only_selected || design->selected(module, it.second)) {
|
2013-11-29 03:33:36 -06:00
|
|
|
if (only_selected)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2015-01-23 17:13:27 -06:00
|
|
|
dump_proc(f, indent + " ", it.second);
|
2013-11-29 03:33:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool first_conn_line = true;
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = module->connections().begin(); it != module->connections().end(); ++it) {
|
2013-11-29 03:33:36 -06:00
|
|
|
bool show_conn = !only_selected;
|
|
|
|
if (only_selected) {
|
|
|
|
RTLIL::SigSpec sigs = it->first;
|
|
|
|
sigs.append(it->second);
|
2014-07-22 13:15:14 -05:00
|
|
|
for (auto &c : sigs.chunks()) {
|
2013-11-29 03:33:36 -06:00
|
|
|
if (c.wire == NULL || !design->selected(module, c.wire))
|
|
|
|
continue;
|
|
|
|
show_conn = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (show_conn) {
|
|
|
|
if (only_selected && first_conn_line)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-11-29 03:33:36 -06:00
|
|
|
dump_conn(f, indent + " ", it->first, it->second);
|
|
|
|
first_conn_line = false;
|
2013-06-02 10:53:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2013-11-29 03:33:36 -06:00
|
|
|
if (print_header)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s" "end\n", indent.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-09-19 08:50:34 -05:00
|
|
|
void ILANG_BACKEND::dump_design(std::ostream &f, RTLIL::Design *design, bool only_selected, bool flag_m, bool flag_n)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2015-01-24 05:16:46 -06:00
|
|
|
#ifndef NDEBUG
|
2014-07-31 06:19:47 -05:00
|
|
|
int init_autoidx = autoidx;
|
2015-01-24 05:16:46 -06:00
|
|
|
#endif
|
2014-07-21 08:15:18 -05:00
|
|
|
|
2013-11-29 03:33:36 -06:00
|
|
|
if (!flag_m) {
|
|
|
|
int count_selected_mods = 0;
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = design->modules_.begin(); it != design->modules_.end(); ++it) {
|
2014-07-21 08:15:18 -05:00
|
|
|
if (design->selected_whole_module(it->first))
|
|
|
|
flag_m = true;
|
2013-11-29 03:33:36 -06:00
|
|
|
if (design->selected(it->second))
|
|
|
|
count_selected_mods++;
|
2014-07-21 08:15:18 -05:00
|
|
|
}
|
2013-11-29 03:33:36 -06:00
|
|
|
if (count_selected_mods > 1)
|
|
|
|
flag_m = true;
|
|
|
|
}
|
|
|
|
|
2014-07-21 08:15:18 -05:00
|
|
|
if (!only_selected || flag_m) {
|
|
|
|
if (only_selected)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
|
|
|
f << stringf("autoidx %d\n", autoidx);
|
2014-07-21 08:15:18 -05:00
|
|
|
}
|
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = design->modules_.begin(); it != design->modules_.end(); ++it) {
|
2013-06-10 05:38:02 -05:00
|
|
|
if (!only_selected || design->selected(it->second)) {
|
|
|
|
if (only_selected)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-11-29 03:33:36 -06:00
|
|
|
dump_module(f, "", it->second, design, only_selected, flag_m, flag_n);
|
2013-06-10 05:38:02 -05:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-07-21 08:15:18 -05:00
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
log_assert(init_autoidx == autoidx);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
YOSYS_NAMESPACE_END
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
struct IlangBackend : public Backend {
|
2013-02-28 17:36:19 -06:00
|
|
|
IlangBackend() : Backend("ilang", "write design to ilang file") { }
|
|
|
|
virtual void help()
|
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" write_ilang [filename]\n");
|
|
|
|
log("\n");
|
|
|
|
log("Write the current design to an 'ilang' file. (ilang is a text representation\n");
|
|
|
|
log("of a design in yosys's internal format.)\n");
|
|
|
|
log("\n");
|
2013-09-03 12:10:11 -05:00
|
|
|
log(" -selected\n");
|
|
|
|
log(" only write selected parts of the design.\n");
|
|
|
|
log("\n");
|
2013-02-28 17:36:19 -06:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design)
|
2013-09-03 12:10:11 -05:00
|
|
|
{
|
|
|
|
bool selected = false;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
log_header("Executing ILANG backend.\n");
|
2013-09-03 12:10:11 -05:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
|
|
|
std::string arg = args[argidx];
|
|
|
|
if (arg == "-selected") {
|
|
|
|
selected = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(f, filename, args, argidx);
|
|
|
|
|
2015-01-23 17:13:27 -06:00
|
|
|
design->sort();
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
log("Output filename: %s\n", filename.c_str());
|
2014-08-23 06:54:21 -05:00
|
|
|
*f << stringf("# Generated by %s\n", yosys_version_str);
|
|
|
|
ILANG_BACKEND::dump_design(*f, design, selected, true, false);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
} IlangBackend;
|
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
struct DumpPass : public Pass {
|
|
|
|
DumpPass() : Pass("dump", "print parts of the design in ilang format") { }
|
|
|
|
virtual void help()
|
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" dump [options] [selection]\n");
|
|
|
|
log("\n");
|
|
|
|
log("Write the selected parts of the design to the console or specified file in\n");
|
|
|
|
log("ilang format.\n");
|
|
|
|
log("\n");
|
2013-11-29 03:33:36 -06:00
|
|
|
log(" -m\n");
|
2013-12-28 05:14:47 -06:00
|
|
|
log(" also dump the module headers, even if only parts of a single\n");
|
2013-11-29 03:33:36 -06:00
|
|
|
log(" module is selected\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -n\n");
|
|
|
|
log(" only dump the module headers if the entire module is selected\n");
|
|
|
|
log("\n");
|
2015-01-31 16:52:36 -06:00
|
|
|
log(" -o <filename>\n");
|
2014-02-04 16:45:30 -06:00
|
|
|
log(" write to the specified file.\n");
|
|
|
|
log("\n");
|
2015-01-31 16:52:36 -06:00
|
|
|
log(" -a <filename>\n");
|
2014-02-04 16:45:30 -06:00
|
|
|
log(" like -outfile but append instead of overwrite\n");
|
2013-06-02 10:53:30 -05:00
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
|
|
|
|
{
|
|
|
|
std::string filename;
|
2014-02-04 16:45:30 -06:00
|
|
|
bool flag_m = false, flag_n = false, append = false;
|
2013-06-02 10:53:30 -05:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
std::string arg = args[argidx];
|
2015-01-31 16:52:36 -06:00
|
|
|
if ((arg == "-o" || arg == "-outfile") && argidx+1 < args.size()) {
|
2013-06-02 10:53:30 -05:00
|
|
|
filename = args[++argidx];
|
2014-02-04 16:45:30 -06:00
|
|
|
append = false;
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-31 16:52:36 -06:00
|
|
|
if ((arg == "-a" || arg == "-append") && argidx+1 < args.size()) {
|
2014-02-04 16:45:30 -06:00
|
|
|
filename = args[++argidx];
|
|
|
|
append = true;
|
2013-06-02 10:53:30 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-11-29 03:33:36 -06:00
|
|
|
if (arg == "-m") {
|
|
|
|
flag_m = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-n") {
|
|
|
|
flag_n = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-02 10:53:30 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
std::ostream *f;
|
|
|
|
std::stringstream buf;
|
2013-06-02 10:53:30 -05:00
|
|
|
|
|
|
|
if (!filename.empty()) {
|
2014-08-23 06:54:21 -05:00
|
|
|
std::ofstream *ff = new std::ofstream;
|
|
|
|
ff->open(filename.c_str(), append ? std::ofstream::app : std::ofstream::trunc);
|
|
|
|
if (ff->fail()) {
|
|
|
|
delete ff;
|
2013-06-02 10:53:30 -05:00
|
|
|
log_error("Can't open file `%s' for writing: %s\n", filename.c_str(), strerror(errno));
|
2014-08-23 06:54:21 -05:00
|
|
|
}
|
|
|
|
f = ff;
|
2013-06-02 10:53:30 -05:00
|
|
|
} else {
|
2014-08-23 06:54:21 -05:00
|
|
|
f = &buf;
|
2013-06-02 10:53:30 -05:00
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
ILANG_BACKEND::dump_design(*f, design, true, flag_m, flag_n);
|
2013-06-02 10:53:30 -05:00
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
if (!filename.empty()) {
|
|
|
|
delete f;
|
|
|
|
} else {
|
|
|
|
log("%s", buf.str().c_str());
|
2013-06-02 10:53:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} DumpPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|