2020-05-26 23:07:34 -05:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Alberto Gonzalez <boqwxp@airmail.cc>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel/yosys.h"
|
|
|
|
|
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
struct PrintAttrsPass : public Pass {
|
|
|
|
PrintAttrsPass() : Pass("printattrs", "print attributes of selected objects") { }
|
|
|
|
void help() YS_OVERRIDE
|
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" printattrs [selection]\n");
|
|
|
|
log("\n");
|
|
|
|
log("Print all attributes of the selected objects.\n");
|
|
|
|
log("\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
2020-05-27 02:40:40 -05:00
|
|
|
|
2020-05-27 18:15:07 -05:00
|
|
|
static std::string get_indent_str(const unsigned int indent) {
|
2020-05-28 00:30:00 -05:00
|
|
|
return stringf("%*s", indent, "");
|
2020-05-27 18:15:07 -05:00
|
|
|
}
|
|
|
|
|
2020-05-27 02:40:40 -05:00
|
|
|
static void log_const(const RTLIL::IdString &s, const RTLIL::Const &x, const unsigned int indent) {
|
|
|
|
if (x.flags == RTLIL::CONST_FLAG_STRING)
|
2020-05-27 18:15:07 -05:00
|
|
|
log("%s(* %s=\"%s\" *)\n", get_indent_str(indent).c_str(), log_id(s), x.decode_string().c_str());
|
2020-05-27 02:40:40 -05:00
|
|
|
else if (x.flags == RTLIL::CONST_FLAG_NONE)
|
2020-05-27 18:15:07 -05:00
|
|
|
log("%s(* %s=%s *)\n", get_indent_str(indent).c_str(), log_id(s), x.as_string().c_str());
|
2020-05-27 02:40:40 -05:00
|
|
|
else
|
|
|
|
log_assert(x.flags == RTLIL::CONST_FLAG_STRING || x.flags == RTLIL::CONST_FLAG_NONE); //intended to fail
|
|
|
|
}
|
|
|
|
|
2020-05-26 23:07:34 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
|
|
|
{
|
|
|
|
size_t argidx = 1;
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
|
|
|
unsigned int indent = 0;
|
|
|
|
for (auto mod : design->selected_modules())
|
|
|
|
{
|
|
|
|
if (design->selected_whole_module(mod)) {
|
2020-05-27 18:15:07 -05:00
|
|
|
log("%s%s\n", get_indent_str(indent).c_str(), log_id(mod->name));
|
2020-05-26 23:07:34 -05:00
|
|
|
indent += 2;
|
|
|
|
for (auto &it : mod->attributes)
|
2020-05-27 02:40:40 -05:00
|
|
|
log_const(it.first, it.second, indent);
|
2020-05-26 23:07:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto cell : mod->selected_cells()) {
|
2020-05-27 18:15:07 -05:00
|
|
|
log("%s%s\n", get_indent_str(indent).c_str(), log_id(cell->name));
|
2020-05-26 23:07:34 -05:00
|
|
|
indent += 2;
|
2020-05-27 02:40:40 -05:00
|
|
|
for (auto &it : cell->attributes)
|
|
|
|
log_const(it.first, it.second, indent);
|
2020-05-26 23:07:34 -05:00
|
|
|
indent -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto wire : mod->selected_wires()) {
|
2020-05-27 18:15:07 -05:00
|
|
|
log("%s%s\n", get_indent_str(indent).c_str(), log_id(wire->name));
|
2020-05-26 23:07:34 -05:00
|
|
|
indent += 2;
|
2020-05-27 02:40:40 -05:00
|
|
|
for (auto &it : wire->attributes)
|
|
|
|
log_const(it.first, it.second, indent);
|
2020-05-26 23:07:34 -05:00
|
|
|
indent -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (design->selected_whole_module(mod))
|
|
|
|
indent -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
} PrintAttrsPass;
|
|
|
|
|
|
|
|
PRIVATE_NAMESPACE_END
|