Merge pull request #2479 from zachjs/const-arg-hint
[yosys.git] / backends / cxxrtl / cxxrtl_backend.cc
index 9875aba60a34255f48db71ac8c29696d6cba4c29..916303bfe49d37f0bd491e490fb27ad70e460060 100644 (file)
@@ -832,11 +832,26 @@ struct CxxrtlWorker {
                } else if (sig.is_chunk()) {
                        return dump_sigchunk(sig.as_chunk(), is_lhs, for_debug);
                } else {
-                       dump_sigchunk(*sig.chunks().rbegin(), is_lhs, for_debug);
-                       for (auto it = sig.chunks().rbegin() + 1; it != sig.chunks().rend(); ++it) {
-                               f << ".concat(";
-                               dump_sigchunk(*it, is_lhs, for_debug);
-                               f << ")";
+                       bool first = true;
+                       auto chunks = sig.chunks();
+                       for (auto it = chunks.rbegin(); it != chunks.rend(); it++) {
+                               if (!first)
+                                       f << ".concat(";
+                               bool is_complex = dump_sigchunk(*it, is_lhs, for_debug);
+                               if (!is_lhs && it->width == 1) {
+                                       size_t repeat = 1;
+                                       while ((it + repeat) != chunks.rend() && *(it + repeat) == *it)
+                                               repeat++;
+                                       if (repeat > 1) {
+                                               if (is_complex)
+                                                       f << ".val()";
+                                               f << ".repeat<" << repeat << ">()";
+                                       }
+                                       it += repeat - 1;
+                               }
+                               if (!first)
+                                       f << ")";
+                               first = false;
                        }
                        return true;
                }
@@ -1702,19 +1717,19 @@ struct CxxrtlWorker {
                                        continue;
                                }
                                if (!module->get_bool_attribute(ID(cxxrtl_blackbox)) || wire->port_id != 0)
-                                       f << indent << "changed |= " << mangle(wire) << ".commit();\n";
+                                       f << indent << "if (" << mangle(wire) << ".commit()) changed = true;\n";
                        }
                        if (!module->get_bool_attribute(ID(cxxrtl_blackbox))) {
                                for (auto memory : module->memories) {
                                        if (!writable_memories[memory.second])
                                                continue;
-                                       f << indent << "changed |= " << mangle(memory.second) << ".commit();\n";
+                                       f << indent << "if (" << mangle(memory.second) << ".commit()) changed = true;\n";
                                }
                                for (auto cell : module->cells()) {
                                        if (is_internal_cell(cell->type))
                                                continue;
                                        const char *access = is_cxxrtl_blackbox_cell(cell) ? "->" : ".";
-                                       f << indent << "changed |= " << mangle(cell) << access << "commit();\n";
+                                       f << indent << "if (" << mangle(cell) << access << "commit()) changed = true;\n";
                                }
                        }
                        f << indent << "return changed;\n";