394 if(cell->
type ==
"$assert")
396 log(
"writing assert cell - %s\n",
cstr(cell->
type));
411 expr_line, one_line);
423 else if(cell->
type ==
"$not" || cell->
type ==
"$neg" || cell->
type ==
"$pos" || cell->
type ==
"$reduce_and" ||
424 cell->
type ==
"$reduce_or" || cell->
type ==
"$reduce_xor" || cell->
type ==
"$reduce_bool")
426 log(
"writing unary cell - %s\n",
cstr(cell->
type));
429 w = w>output_width ? w:output_width;
432 if(cell->
type !=
"$pos")
435 bool reduced = (cell->
type ==
"$not" || cell->
type ==
"$neg") ?
false :
true;
439 if(output_width < w && (cell->
type ==
"$not" || cell->
type ==
"$neg" || cell->
type ==
"$pos"))
442 str =
stringf (
"%d slice %d %d %d %d;4", line_num, output_width, cell_line, output_width-1, 0);
448 else if(cell->
type ==
"$reduce_xnor" || cell->
type ==
"$logic_not")
450 log(
"writing unary cell - %s\n",
cstr(cell->
type));
455 if(cell->
type ==
"$logic_not" && w > 1)
461 else if(cell->
type ==
"$reduce_xnor")
473 else if(cell->
type ==
"$and" || cell->
type ==
"$or" || cell->
type ==
"$xor" || cell->
type ==
"$xnor" ||
474 cell->
type ==
"$lt" || cell->
type ==
"$le" || cell->
type ==
"$eq" || cell->
type ==
"$ne" ||
475 cell->
type ==
"$eqx" || cell->
type ==
"$nex" || cell->
type ==
"$ge" || cell->
type ==
"$gt" )
477 log(
"writing binary cell - %s\n",
cstr(cell->
type));
480 cell->
type ==
"$ge" || cell->
type ==
"$gt") || output_width == 1);
487 l1_width = l1_width > output_width ? l1_width : output_width;
488 l1_width = l1_width > l2_width ? l1_width : l2_width;
489 l2_width = l2_width > l1_width ? l2_width : l1_width;
496 if(cell->
type ==
"$lt" || cell->
type ==
"$le" ||
497 cell->
type ==
"$eq" || cell->
type ==
"$ne" || cell->
type ==
"$eqx" || cell->
type ==
"$nex" ||
498 cell->
type ==
"$ge" || cell->
type ==
"$gt")
504 str =
stringf (
"%d %s %d %d %d", line_num, op.c_str(), output_width, l1, l2);
509 else if(cell->
type ==
"$add" || cell->
type ==
"$sub" || cell->
type ==
"$mul" || cell->
type ==
"$div" ||
510 cell->
type ==
"$mod" )
513 log(
"writing binary cell - %s\n",
cstr(cell->
type));
521 l1_width = l1_width > output_width ? l1_width : output_width;
522 l1_width = l1_width > l2_width ? l1_width : l2_width;
523 l2_width = l2_width > l1_width ? l2_width : l1_width;
530 if(cell->
type ==
"$div" && l1_signed)
532 else if(cell->
type ==
"$mod")
539 str =
stringf (
"%d %s %d %d %d", line_num, op.c_str(), l1_width, l1, l2);
542 if(output_width < l1_width)
545 str =
stringf (
"%d slice %d %d %d %d;5", line_num, output_width, line_num-1, output_width-1, 0);
550 else if(cell->
type ==
"$shr" || cell->
type ==
"$shl" || cell->
type ==
"$sshr" || cell->
type ==
"$sshl" || cell->
type ==
"$shift" || cell->
type ==
"$shiftx")
552 log(
"writing binary cell - %s\n",
cstr(cell->
type));
557 l1_width = pow(2, ceil(
log(l1_width)/
log(2)));
566 if(l2_width > ceil(
log(l1_width)/
log(2)))
568 int extra_width = l2_width - ceil(
log(l1_width)/
log(2));
571 str =
stringf (
"%d slice %d %d %d %d;6", line_num, extra_width, l2, l2_width-1, l2_width-extra_width);
574 str =
stringf (
"%d one %d", line_num, extra_width);
580 str =
stringf(
"%d %s %d", line_num, l1_signed && cell->
type ==
"$sshr" ?
"ones":
"zero", l1_width);
588 if(output_width < l1_width)
591 str =
stringf (
"%d slice %d %d %d %d;5", line_num, output_width, cell_output, output_width-1, 0);
597 else if(cell->
type ==
"$logic_and" || cell->
type ==
"$logic_or")
599 log(
"writing binary cell - %s\n",
cstr(cell->
type));
620 if(cell->
type ==
"$logic_and")
625 else if(cell->
type ==
"$logic_or")
634 else if(cell->
type ==
"$mux")
636 log(
"writing mux cell\n");
648 else if(cell->
type ==
"$pmux")
650 log(
"writing pmux cell\n");
656 int *c =
new int[select_width];
658 for (
int i=0; i<select_width; ++i)
661 str =
stringf (
"%d slice 1 %d %d %d", line_num, select, i, i);
665 str =
stringf (
"%d slice %d %d %d %d", line_num, output_width, cases, i*output_width+output_width-1,
671 str =
stringf (
"%d cond %d %d %d %d", line_num, output_width, c[select_width-1], c[select_width-1]+1, default_case);
674 for (
int i=select_width-2; i>=0; --i)
677 str =
stringf (
"%d cond %d %d %d %d", line_num, output_width, c[i], c[i]+1, line_num-1);
684 else if(cell->
type ==
"$dff" || cell->
type ==
"$adff" || cell->
type ==
"$dffsr")
689 log(
" - width is %d\n", output_width);
694 unsigned start_bit = 0;
695 for(
unsigned i=0; i<cell_output->
chunks().size(); ++i)
697 output_width = cell_output->
chunks().at(i).width;
701 if(cell_output->
chunks().size()>1)
703 start_bit+=output_width;
705 str =
stringf (
"%d slice %d %d %d %d;", line_num, output_width, value, start_bit-1,
706 start_bit-output_width);
709 if(cell->
type ==
"$dffsr")
718 output_width, sync_reset_pol ?
"":
"-", sync_reset, sync_reset_value_pol?
"":
"-",
719 sync_reset_value, slice);
725 output_width, polarity?
"":
"-", cond, slice, reg);
729 if(cell->
type ==
"$adff")
737 output_width, async_reset_pol ?
"":
"-", async_reset, async_reset_value, next);
742 output_width, reg, next);
748 else if(cell->
type ==
"$memrd")
750 log(
"writing memrd cell\n");
751 if (cell->
parameters.at(
"\\CLK_ENABLE").as_bool() ==
true)
752 log_error(
"The btor backen does not support $memrd cells with built-in registers. Run memory_dff with -wr_only.\n");
759 str =
stringf(
"%d read %d %d %d", line_num, data_width, mem, address);
763 else if(cell->
type ==
"$memwr")
765 log(
"writing memwr cell\n");
766 if (cell->
parameters.at(
"\\CLK_ENABLE").as_bool() ==
false)
767 log_error(
"The btor backen does not support $memwr cells without built-in registers. Run memory_dff (but with -wr_only).\n");
784 int address_bits = ceil(
log(memory->
size)/
log(2));
785 str =
stringf(
"%d array %d %d", line_num, memory->
width, address_bits);
788 str =
stringf(
"%d eq 1 %d %d", line_num, mem, line_num - 1);
794 str =
stringf(
"%d one 1", line_num);
796 str =
stringf(
"%d zero 1", line_num);
799 str =
stringf(
"%d eq 1 %d %d", line_num, clk, line_num-1);
802 str =
stringf(
"%d and 1 %d %d", line_num, line_num-1, enable);
805 str =
stringf(
"%d write %d %d %d %d %d", line_num, data_width, address_width, mem, address, data);
808 str =
stringf(
"%d acond %d %d %d %d %d", line_num, data_width, address_width, line_num-2, line_num-1, mem);
811 str =
stringf(
"%d anext %d %d %d %d", line_num, data_width, address_width, mem, line_num-1);
816 else if(cell->
type ==
"$slice")
818 log(
"writing slice cell\n");
832 else if(cell->
type ==
"$concat")
834 log(
"writing concat cell\n");
838 int input_a_line =
dump_sigspec(input_a, input_a_width);
842 int input_b_line =
dump_sigspec(input_b, input_b_width);
845 input_a_line, input_b_line);
std::string stringf(const char *fmt,...)
std::map< RTLIL::IdString, int > line_ref
std::map< RTLIL::IdString, RTLIL::Memory * > memories
int dump_wire(RTLIL::Wire *wire)
void log_error(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Const > parameters
std::map< std::string, std::string > cell_type_translation
const char * cstr(const RTLIL::IdString id)
RTLIL::IdString curr_cell
int dump_const(const RTLIL::Const *data, int width, int offset)
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
int dump_memory(const RTLIL::Memory *memory)
#define log_assert(_assert_expr_)
int dump_sigspec(const RTLIL::SigSpec *sig, int expected_width)
void log(const char *format,...)
std::map< std::string, std::string > s_cell_type_translation
const std::vector< RTLIL::SigChunk > & chunks() const