Skip to content

Commit 282de8f

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

File tree

7 files changed

+92
-3
lines changed

7 files changed

+92
-3
lines changed

regression/ebmc/CLI/json-modules.desc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
CORE
2+
json-modules.v
3+
--json-modules -
4+
activate-multi-line-match
5+
\[
6+
\{
7+
"identifier": "Verilog::foo",
8+
"location": \{
9+
"file": "json-modules\.v",
10+
"line": "1",
11+
"workingDirectory": ".*"
12+
\},
13+
"mode": "Verilog",
14+
"name": "foo"
15+
\},
16+
\{
17+
"identifier": "Verilog::bar",
18+
"location": \{
19+
"file": "json-modules.v",
20+
"line": "4",
21+
"workingDirectory": ".*"
22+
\},
23+
"mode": "Verilog",
24+
"name": "bar"
25+
\}
26+
\]
27+
^EXIT=0$
28+
^SIGNAL=0$
29+
--

regression/ebmc/CLI/json-modules.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module foo;
2+
endmodule
3+
4+
module bar;
5+
endmodule

src/ebmc/ebmc_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int ebmc_parse_optionst::doit()
103103
if(cmdline.isset("show-parse"))
104104
return show_parse(cmdline, ui_message_handler);
105105

106-
if(cmdline.isset("show-modules") || cmdline.isset("modules-xml"))
106+
if(cmdline.isset("show-modules") || cmdline.isset("modules-xml") || cmdline.isset("json-modules"))
107107
return show_modules(cmdline, ui_message_handler);
108108

109109
if(cmdline.isset("show-module-hierarchy"))

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-modules):"
3637
"(neural-liveness)(neural-engine):"
3738
"(reset):"
3839
"(version)(verilog-rtl)(verilog-netlist)"

src/ebmc/transition_system.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,23 @@ int get_transition_system(
280280
return 0;
281281
}
282282

283+
if(cmdline.isset("json-modules"))
284+
{
285+
auto file_name = cmdline.get_value("json-modules");
286+
if(file_name == "-")
287+
{
288+
json_modules(transition_system.symbol_table, std::cout);
289+
}
290+
else
291+
{
292+
std::ofstream out(widen_if_needed(file_name));
293+
if(!out)
294+
throw ebmc_errort() << "failed to open " << file_name;
295+
json_modules(transition_system.symbol_table, out);
296+
}
297+
return 0;
298+
}
299+
283300
if(cmdline.isset("show-symbol-table"))
284301
{
285302
std::cout << transition_system.symbol_table;

src/trans-word-level/show_modules.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
#include <util/xml.h>
9+
#include <util/json_irep.h>
1010
#include <util/xml_irep.h>
1111

1212
#include "show_modules.h"
@@ -91,3 +91,38 @@ void show_modules(const symbol_table_baset &symbol_table, std::ostream &out)
9191
}
9292
}
9393
}
94+
95+
/*******************************************************************\
96+
97+
Function: json_modules
98+
99+
Inputs:
100+
101+
Outputs:
102+
103+
Purpose:
104+
105+
\*******************************************************************/
106+
107+
void json_modules(const symbol_table_baset &symbol_table, std::ostream &out)
108+
{
109+
json_arrayt json_modules;
110+
111+
for(const auto &s : symbol_table.symbols)
112+
{
113+
const symbolt &symbol = s.second;
114+
115+
if(symbol.type.id() == ID_module)
116+
{
117+
json_objectt json_module;
118+
json_module["location"] = json(symbol.location);
119+
json_module["identifier"] = json_stringt{id2string(symbol.name)};
120+
json_module["mode"] = json_stringt{id2string(symbol.mode)};
121+
json_module["name"] = json_stringt{id2string(symbol.display_name())};
122+
123+
json_modules.push_back(std::move(json_module));
124+
}
125+
}
126+
127+
out << json_modules;
128+
}

src/trans-word-level/show_modules.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ void show_modules(const symbol_table_baset &, std::ostream &);
1515

1616
void show_modules_xml(const symbol_table_baset &, std::ostream &);
1717

18+
void json_modules(const symbol_table_baset &, std::ostream &);
19+
1820
#endif

0 commit comments

Comments
 (0)