pass metadata: added the output of parameters,
authorAki Van Ness <aki@yosyshq.com>
Tue, 16 Nov 2021 20:25:14 +0000 (15:25 -0500)
committerN. Engelhardt <nakengelhardt@gmail.com>
Fri, 8 Apr 2022 06:05:15 +0000 (08:05 +0200)
it's kinda dumb at the moment and needs parsing based on type but it's a start

backends/metadata/metadata.cc

index eea8e8338611cf548406099d2efd35df0224ceb8..d5726d4d3006cd3e313a5be7b5691c7108cc6f15 100644 (file)
@@ -177,13 +177,41 @@ struct MetadataWriter
     {
         log_assert(cell != nullptr);
 
-        f << stringf("          {\n");
-        f << stringf("            \"name\": %s,\n", get_string(RTLIL::unescape_id(cell->name)).c_str());
-        f << stringf("            \"attributes\": {\n");
-        f << stringf("            },\n");
-        f << stringf("            \"parameters\": {\n");
-        f << stringf("            },\n");
-        f << stringf("          }");
+        f << stringf("            {\n");
+        f << stringf("              \"name\": %s,\n", get_string(RTLIL::unescape_id(cell->name)).c_str());
+        f << stringf("              \"attributes\": {\n");
+
+        bool first_attr{true};
+        for (auto& attr : cell->attributes) {
+            if (!first_attr)
+                f << stringf(",\n");
+            const auto attr_val = attr.second.decode_string();
+            if (attr_val.size() > 0)
+                f << stringf("                %s: \"%s\"\n", get_string(RTLIL::unescape_id(attr.first)).c_str(), attr_val.c_str());
+            else
+                f << stringf("                %s: true\n", get_string(RTLIL::unescape_id(attr.first)).c_str());
+
+            first_attr = false;
+        }
+
+        f << stringf("              },\n");
+        f << stringf("              \"parameters\": {\n");
+
+        bool first_param{true};
+        for (auto& param : cell->parameters) {
+            if (!first_param)
+                f << stringf(",\n");
+            const auto param_val = param.second.decode_string();
+            if (param_val.size() > 0)
+                f << stringf("                %s: \"%s\"\n", get_string(RTLIL::unescape_id(param.first)).c_str(), param_val.c_str());
+            else
+                f << stringf("                %s: true\n", get_string(RTLIL::unescape_id(param.first)).c_str());
+
+            first_param = false;
+        }
+
+        f << stringf("              },\n");
+        f << stringf("            }");
     }
 };