write_cxxrtl: add support for $slice and $concat cells.
authorwhitequark <whitequark@whitequark.org>
Sun, 5 Apr 2020 07:46:42 +0000 (07:46 +0000)
committerwhitequark <whitequark@whitequark.org>
Thu, 9 Apr 2020 04:08:36 +0000 (04:08 +0000)
backends/cxxrtl/cxxrtl.cc

index 6fd63548f7e4164d1e7ae27ad62874222cd75f32..e2c33c3d787fda45d53ba8a21275134c1ac873fe 100644 (file)
@@ -189,7 +189,8 @@ static bool is_binary_cell(RTLIL::IdString type)
 
 static bool is_elidable_cell(RTLIL::IdString type)
 {
-       return is_unary_cell(type) || is_binary_cell(type) || type == ID($mux);
+       return is_unary_cell(type) || is_binary_cell(type) || type.in(
+               ID($mux), ID($concat), ID($slice));
 }
 
 static bool is_ff_cell(RTLIL::IdString type)
@@ -672,6 +673,20 @@ struct CxxrtlWorker {
                        f << " : ";
                        dump_sigspec_rhs(cell->getPort(ID(A)));
                        f << ")";
+               // Concats
+               } else if (cell->type == ID($concat)) {
+                       dump_sigspec_rhs(cell->getPort(ID(B)));
+                       f << ".concat(";
+                       dump_sigspec_rhs(cell->getPort(ID(A)));
+                       f << ").val()";
+               // Slices
+               } else if (cell->type == ID($slice)) {
+                       dump_sigspec_rhs(cell->getPort(ID(A)));
+                       f << ".slice<";
+                       f << cell->getParam(ID(OFFSET)).as_int() + cell->getParam(ID(Y_WIDTH)).as_int() - 1;
+                       f << ",";
+                       f << cell->getParam(ID(OFFSET)).as_int();
+                       f << ">().val()";
                } else {
                        log_assert(false);
                }