Fix handling of some formal cells in btor back-end
[yosys.git] / backends / json / json.cc
index 4aa8046d602e45371fd642481cc75052914a3fc9..42eedc606273c15ea477b7c6269b6dff00af0515 100644 (file)
@@ -52,8 +52,23 @@ struct JsonWriter
                string newstr = "\"";
                for (char c : str) {
                        if (c == '\\')
+                               newstr += "\\\\";
+                       else if (c == '"')
+                               newstr += "\\\"";
+                       else if (c == '\b')
+                               newstr += "\\b";
+                       else if (c == '\f')
+                               newstr += "\\f";
+                       else if (c == '\n')
+                               newstr += "\\n";
+                       else if (c == '\r')
+                               newstr += "\\r";
+                       else if (c == '\t')
+                               newstr += "\\t";
+                       else if (c < 0x20)
+                               newstr += stringf("\\u%04X", c);
+                       else
                                newstr += c;
-                       newstr += c;
                }
                return newstr + "\"";
        }