backends/verilog: Support meminit with mask.
authorMarcelina Kościelnicka <mwk@0x04.net>
Mon, 12 Jul 2021 18:43:09 +0000 (20:43 +0200)
committerMarcelina Kościelnicka <mwk@0x04.net>
Wed, 28 Jul 2021 21:18:38 +0000 (23:18 +0200)
backends/verilog/verilog_backend.cc

index 800865414dd9186299ea9ad1c04053feef5e3423..b363bc2fe439780288edc6cc1975c93e95e82575 100644 (file)
@@ -504,9 +504,24 @@ void dump_memory(std::ostream &f, std::string indent, Mem &mem)
                                int start = init.addr.as_int();
                                for (int i=0; i<words; i++)
                                {
-                                       f << stringf("%s" "  %s[%d] = ", indent.c_str(), mem_id.c_str(), i + start);
-                                       dump_const(f, init.data.extract(i*mem.width, mem.width));
-                                       f << stringf(";\n");
+                                       for (int j = 0; j < mem.width; j++)
+                                       {
+                                               if (init.en[j] != State::S1)
+                                                       continue;
+
+                                               int start_j = j, width = 1;
+
+                                               while (j+1 < mem.width && init.en[j+1] == State::S1)
+                                                       j++, width++;
+
+                                               if (width == mem.width) {
+                                                       f << stringf("%s" "  %s[%d] = ", indent.c_str(), mem_id.c_str(), i + start);
+                                               } else {
+                                                       f << stringf("%s" "  %s[%d][%d:%d] = ", indent.c_str(), mem_id.c_str(), i + start, j, start_j);
+                                               }
+                                               dump_const(f, init.data.extract(i*mem.width+start_j, width));
+                                               f << stringf(";\n");
+                                       }
                                }
                        }
                        f << stringf("%s" "end\n", indent.c_str());