diff options
author | Clifford Wolf <clifford@clifford.at> | 2015-03-03 09:28:44 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2015-03-03 09:28:44 +0100 |
commit | 4fc63f27a1a879e4b724b7e478dbd3047961ae71 (patch) | |
tree | 2ba1a0bef1f6c10b5c37923cd22c4a4e9132039b | |
parent | 795a6e1d04c666dbdef9a91ea55595fb168087d6 (diff) | |
download | yosys-4fc63f27a1a879e4b724b7e478dbd3047961ae71.tar.gz yosys-4fc63f27a1a879e4b724b7e478dbd3047961ae71.tar.bz2 yosys-4fc63f27a1a879e4b724b7e478dbd3047961ae71.zip |
Json backend improvements
-rw-r--r-- | backends/json/json.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/backends/json/json.cc b/backends/json/json.cc index 33abccee2..889e5b7ec 100644 --- a/backends/json/json.cc +++ b/backends/json/json.cc @@ -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"); } }; |