Skip to content

Commit 1161a44

Browse files
committed
JSON output for the properties
This adds --json-properties, to get a JSON array with all the properties.
1 parent 459b5f8 commit 1161a44

File tree

6 files changed

+81
-3
lines changed

6 files changed

+81
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CORE
2+
json-properties.v
3+
--json-properties -
4+
activate-multi-line-match
5+
\[
6+
\{
7+
"description": "",
8+
"location": \{
9+
"file": "json-properties\.v",
10+
"line": "3",
11+
"workingDirectory": ".*"
12+
\},
13+
"name": "main\.property\.p0"
14+
\}
15+
\]
16+
^EXIT=0$
17+
^SIGNAL=0$
18+
--
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module main;
2+
3+
always assert p0: 1 == 2;
4+
5+
endmodule

src/ebmc/ebmc_base.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ int ebmc_baset::get_properties()
338338
return 0;
339339
}
340340

341+
if(cmdline.isset("json-properties"))
342+
{
343+
json_properties(cmdline.get_value("json-properties"));
344+
return 0;
345+
}
346+
341347
return -1; // done
342348
}
343349

src/ebmc/ebmc_base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ebmc_baset
5252
bool parse_property(const std::string &property);
5353
bool get_model_properties();
5454
void show_properties();
55+
void json_properties(const std::string &file_name);
5556

5657
bool parse();
5758
bool parse(const std::string &filename);

src/ebmc/ebmc_parse_options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class ebmc_parse_optionst:public parse_options_baset
3232
"(show-properties)(property):p:(trace)(waveform)(numbered-trace)"
3333
"(dimacs)(module):(top):"
3434
"(po)(cegar)(k-induction)(2pi)(bound2):"
35-
"(outfile):(xml-ui)(verbosity):(gui)(json-result):"
35+
"(outfile):(xml-ui)(verbosity):(gui)"
36+
"(json-result):(json-properties):"
3637
"(neural-liveness)(neural-engine):"
3738
"(reset):"
3839
"(version)(verilog-rtl)(verilog-netlist)"

src/ebmc/show_properties.cpp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ Author: Daniel Kroening, kroening@kroening.com
66
77
\*******************************************************************/
88

9-
#include <iostream>
10-
9+
#include <util/json.h>
10+
#include <util/json_irep.h>
11+
#include <util/unicode.h>
1112
#include <util/xml.h>
1213
#include <util/xml_irep.h>
1314

1415
#include "ebmc_base.h"
16+
#include "ebmc_error.h"
17+
18+
#include <iostream>
1519

1620
/*******************************************************************\
1721
@@ -62,3 +66,46 @@ void ebmc_baset::show_properties()
6266
p_nr++;
6367
}
6468
}
69+
70+
/*******************************************************************\
71+
72+
Function: ebmc_baset::json_properties
73+
74+
Inputs:
75+
76+
Outputs:
77+
78+
Purpose:
79+
80+
\*******************************************************************/
81+
82+
void ebmc_baset::json_properties(const std::string &file_name)
83+
{
84+
json_arrayt json;
85+
86+
for(const auto &p : properties.properties)
87+
{
88+
json_objectt json_property;
89+
json_property["identifier"] = json_stringt{id2string(p.identifier)};
90+
json_property["name"] = json_stringt{id2string(p.name)};
91+
json_property["description"] = json_stringt{p.description};
92+
93+
if(p.location.is_not_nil())
94+
json_property["location"] = ::json(p.location);
95+
96+
json.push_back(std::move(json_property));
97+
}
98+
99+
if(file_name == "-")
100+
{
101+
std::cout << json;
102+
}
103+
else
104+
{
105+
std::ofstream out(widen_if_needed(file_name));
106+
if(!out)
107+
throw ebmc_errort() << "failed to open " << file_name;
108+
109+
out << json;
110+
}
111+
}

0 commit comments

Comments
 (0)