30 using namespace ILANG_BACKEND;
36 width = data.
bits.size() - offset;
38 if (width == 32 && autoint) {
40 for (
int i = 0; i < width; i++) {
42 switch (data.
bits[offset+i]) {
45 default: val = -1;
break;
54 for (
int i = offset+width-1; i >= offset; i--) {
56 switch (data.
bits[i]) {
68 for (
size_t i = 0; i < str.size(); i++) {
71 else if (str[i] ==
'\t')
75 else if (str[i] ==
'"')
77 else if (str[i] ==
'\\')
93 else if (chunk.
width == 1)
106 for (
auto it = sig.
chunks().rbegin(); it != sig.
chunks().rend(); it++) {
116 std::map<RTLIL::IdString, RTLIL::Const, RTLIL::sort_by_id_str> sorted_attributes(wire->attributes.begin(), wire->attributes.end());
118 for (
auto it = sorted_attributes.begin(); it != sorted_attributes.end(); it++) {
119 f <<
stringf(
"%s" "attribute %s ", indent.c_str(), it->first.c_str());
123 f <<
stringf(
"%s" "wire ", indent.c_str());
124 if (wire->
width != 1)
141 std::map<RTLIL::IdString, RTLIL::Const, RTLIL::sort_by_id_str> sorted_attributes(memory->attributes.begin(), memory->attributes.end());
143 for (
auto it = sorted_attributes.begin(); it != sorted_attributes.end(); it++) {
144 f <<
stringf(
"%s" "attribute %s ", indent.c_str(), it->first.c_str());
148 f <<
stringf(
"%s" "memory ", indent.c_str());
149 if (memory->
width != 1)
151 if (memory->
size != 0)
158 std::map<RTLIL::IdString, RTLIL::Const, RTLIL::sort_by_id_str> sorted_attributes(cell->attributes.begin(), cell->attributes.end());
159 std::map<RTLIL::IdString, RTLIL::Const, RTLIL::sort_by_id_str> sorted_parameters(cell->
parameters.begin(), cell->
parameters.end());
160 std::map<RTLIL::IdString, RTLIL::SigSpec, RTLIL::sort_by_id_str> sorted_connections(cell->
connections().begin(), cell->
connections().end());
162 for (
auto it = sorted_attributes.begin(); it != sorted_attributes.end(); it++) {
163 f <<
stringf(
"%s" "attribute %s ", indent.c_str(), it->first.c_str());
168 for (
auto it = sorted_parameters.begin(); it != sorted_parameters.end(); it++) {
173 for (
auto it = sorted_connections.begin(); it != sorted_connections.end(); it++) {
174 f <<
stringf(
"%s connect %s ", indent.c_str(), it->first.c_str());
178 f <<
stringf(
"%s" "end\n", indent.c_str());
183 for (
auto it = cs->
actions.begin(); it != cs->
actions.end(); it++)
185 f <<
stringf(
"%s" "assign ", indent.c_str());
198 for (
auto it = sw->attributes.begin(); it != sw->attributes.end(); it++) {
199 f <<
stringf(
"%s" "attribute %s ", indent.c_str(), it->first.c_str());
204 f <<
stringf(
"%s" "switch ", indent.c_str());
208 for (
auto it = sw->
cases.begin(); it != sw->
cases.end(); it++)
210 f <<
stringf(
"%s case ", indent.c_str());
211 for (
size_t i = 0; i < (*it)->compare.size(); i++) {
221 f <<
stringf(
"%s" "end\n", indent.c_str());
226 f <<
stringf(
"%s" "sync ", indent.c_str());
240 for (
auto it = sy->
actions.begin(); it != sy->
actions.end(); it++) {
241 f <<
stringf(
"%s update ", indent.c_str());
251 for (
auto it = proc->attributes.begin(); it != proc->attributes.end(); it++) {
252 f <<
stringf(
"%s" "attribute %s ", indent.c_str(), it->first.c_str());
258 for (
auto it = proc->
syncs.begin(); it != proc->
syncs.end(); it++)
260 f <<
stringf(
"%s" "end\n", indent.c_str());
265 f <<
stringf(
"%s" "connect ", indent.c_str());
279 for (
auto it = module->attributes.begin(); it != module->attributes.end(); it++) {
280 f <<
stringf(
"%s" "attribute %s ", indent.c_str(), it->first.c_str());
290 std::vector<RTLIL::Wire*> sorted_wires;
291 for (
auto it : module->
wires())
292 sorted_wires.push_back(it);
295 std::vector<RTLIL::Memory*> sorted_memories;
297 sorted_memories.push_back(it.second);
300 std::vector<RTLIL::Cell*> sorted_cells;
301 for (
auto it : module->
cells())
302 sorted_cells.push_back(it);
305 std::vector<RTLIL::Process*> sorted_processes;
307 sorted_processes.push_back(it.second);
310 for (
auto it : sorted_wires)
311 if (!only_selected || design->
selected(module, it)) {
317 for (
auto it : sorted_memories)
318 if (!only_selected || design->
selected(module, it)) {
324 for (
auto it : sorted_cells)
325 if (!only_selected || design->
selected(module, it)) {
331 for (
auto it : sorted_processes)
332 if (!only_selected || design->
selected(module, it)) {
338 bool first_conn_line =
true;
340 bool show_conn = !only_selected;
344 for (
auto &c : sigs.
chunks()) {
351 if (only_selected && first_conn_line)
353 dump_conn(f, indent +
" ", it->first, it->second);
354 first_conn_line =
false;
360 f <<
stringf(
"%s" "end\n", indent.c_str());
368 int count_selected_mods = 0;
369 for (
auto it = design->
modules_.begin(); it != design->
modules_.end(); it++) {
373 count_selected_mods++;
375 if (count_selected_mods > 1)
379 if (!only_selected || flag_m) {
385 for (
auto it = design->
modules_.begin(); it != design->
modules_.end(); it++) {
386 if (!only_selected || design->
selected(it->second)) {
389 dump_module(f,
"", it->second, design, only_selected, flag_m, flag_n);
405 log(
" write_ilang [filename]\n");
407 log(
"Write the current design to an 'ilang' file. (ilang is a text representation\n");
408 log(
"of a design in yosys's internal format.)\n");
411 log(
" only write selected parts of the design.\n");
416 bool selected =
false;
421 for (argidx = 1; argidx < args.size(); argidx++) {
422 std::string arg = args[argidx];
423 if (arg ==
"-selected") {
429 extra_args(f, filename, args, argidx);
431 log(
"Output filename: %s\n", filename.c_str());
438 DumpPass() :
Pass(
"dump",
"print parts of the design in ilang format") { }
443 log(
" dump [options] [selection]\n");
445 log(
"Write the selected parts of the design to the console or specified file in\n");
446 log(
"ilang format.\n");
449 log(
" also dump the module headers, even if only parts of a single\n");
450 log(
" module is selected\n");
453 log(
" only dump the module headers if the entire module is selected\n");
455 log(
" -outfile <filename>\n");
456 log(
" write to the specified file.\n");
458 log(
" -append <filename>\n");
459 log(
" like -outfile but append instead of overwrite\n");
464 std::string filename;
465 bool flag_m =
false, flag_n =
false,
append =
false;
468 for (argidx = 1; argidx < args.size(); argidx++)
470 std::string arg = args[argidx];
471 if (arg ==
"-outfile" && argidx+1 < args.size()) {
472 filename = args[++argidx];
476 if (arg ==
"-append" && argidx+1 < args.size()) {
477 filename = args[++argidx];
491 extra_args(args, argidx, design);
494 std::stringstream buf;
496 if (!filename.empty()) {
497 std::ofstream *ff =
new std::ofstream;
498 ff->open(filename.c_str(),
append ? std::ofstream::app : std::ofstream::trunc);
501 log_error(
"Can't open file `%s' for writing: %s\n", filename.c_str(), strerror(errno));
510 if (!filename.empty()) {
513 log(
"%s", buf.str().c_str());
const char * yosys_version_str
const char * c_str() const
bool selected(T1 *module) const
void dump_cell(std::ostream &f, std::string indent, const RTLIL::Cell *cell)
static void append(const vec< T > &from, vec< T > &to)
RTLIL::Wire * wire(RTLIL::IdString id)
std::string stringf(const char *fmt,...)
void sort(T *array, int size, LessThan lt)
void dump_proc_sync(std::ostream &f, std::string indent, const RTLIL::SyncRule *sy)
void log_header(const char *format,...)
const std::vector< RTLIL::SigSig > & connections() const
#define YOSYS_NAMESPACE_END
void dump_sigchunk(std::ostream &f, const RTLIL::SigChunk &chunk, bool autoint=true)
RTLIL_ATTRIBUTE_MEMBERS std::vector< RTLIL::CaseRule * > cases
void dump_proc_case_body(std::ostream &f, std::string indent, const RTLIL::CaseRule *cs)
RTLIL::ObjRange< RTLIL::Wire * > wires()
void dump_const(std::ostream &f, const RTLIL::Const &data, int width=-1, int offset=0, bool autoint=true)
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
std::map< RTLIL::IdString, RTLIL::Memory * > memories
void log_error(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Const > parameters
virtual void execute(std::ostream *&f, std::string filename, std::vector< std::string > args, RTLIL::Design *design)
#define PRIVATE_NAMESPACE_BEGIN
std::string decode_string() const
#define log_assert(_assert_expr_)
RTLIL::SigChunk as_chunk() const
bool selected_whole_module(RTLIL::IdString mod_name) const
void dump_proc_switch(std::ostream &f, std::string indent, const RTLIL::SwitchRule *sw)
#define PRIVATE_NAMESPACE_END
void dump_wire(std::ostream &f, std::string indent, const RTLIL::Wire *wire)
std::vector< RTLIL::SigSig > actions
void dump_memory(std::ostream &f, std::string indent, const RTLIL::Memory *memory)
std::map< RTLIL::IdString, RTLIL::Process * > processes
#define USING_YOSYS_NAMESPACE
RTLIL::ObjRange< RTLIL::Cell * > cells()
void dump_design(std::ostream &f, RTLIL::Design *design, bool only_selected, bool flag_m=true, bool flag_n=false)
std::map< RTLIL::IdString, RTLIL::Module * > modules_
#define YOSYS_NAMESPACE_BEGIN
void dump_sigspec(std::ostream &f, const RTLIL::SigSpec &sig, bool autoint=true)
void log(const char *format,...)
std::vector< RTLIL::SyncRule * > syncs
IlangBackend IlangBackend
void dump_conn(std::ostream &f, std::string indent, const RTLIL::SigSpec &left, const RTLIL::SigSpec &right)
void dump_module(std::ostream &f, std::string indent, RTLIL::Module *module, RTLIL::Design *design, bool only_selected, bool flag_m=true, bool flag_n=false)
std::vector< RTLIL::State > bits
void append(const RTLIL::SigSpec &signal)
std::vector< RTLIL::SigSig > actions
void dump_proc(std::ostream &f, std::string indent, const RTLIL::Process *proc)
std::vector< RTLIL::SwitchRule * > switches
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const
std::vector< RTLIL::State > data
YOSYS_NAMESPACE_BEGIN int autoidx
const std::vector< RTLIL::SigChunk > & chunks() const
RTLIL_ATTRIBUTE_MEMBERS RTLIL::CaseRule root_case