Json backend improvements
authorClifford Wolf <clifford@clifford.at>
Tue, 3 Mar 2015 08:28:44 +0000 (09:28 +0100)
committerClifford Wolf <clifford@clifford.at>
Tue, 3 Mar 2015 08:28:44 +0000 (09:28 +0100)
backends/json/json.cc

index 33abccee294cd0f46331221d32e164ba5d516f9e..889e5b7ece3366df5d3cceb732c5a199b2f2be04 100644 (file)
@@ -43,8 +43,13 @@ struct JsonWriter
 
        string get_string(string str)
        {
-               // FIXME: proper string escaping
-               return stringf("\"%s\"", str.c_str());
+               string newstr = "\"";
+               for (char c : str) {
+                       if (c == '\\')
+                               newstr += c;
+                       newstr += c;
+               }
+               return newstr + "\"";
        }
 
        string get_name(IdString name)
@@ -157,7 +162,9 @@ struct JsonWriter
        void write_design(Design *design_)
        {
                design = design_;
-               f << stringf("{\n  \"modules\": {\n");
+               f << stringf("{\n");
+               f << stringf("  \"creator\": %s,\n", get_string(yosys_version_str).c_str());
+               f << stringf("  \"modules\": {\n");
                vector<Module*> modules = use_selection ? design->selected_modules() : design->modules();
                bool first_module = true;
                for (auto mod : modules) {
@@ -166,7 +173,8 @@ struct JsonWriter
                        write_module(mod);
                        first_module = false;
                }
-               f << stringf("\n  }\n}\n");
+               f << stringf("\n  }\n");
+               f << stringf("}\n");
        }
 };