Skip to content

Commit 81ec9d7

Browse files
authored
Merge pull request #573 from diffblue/json-modules
JSON output for the modules
2 parents a4f2f15 + 8465313 commit 81ec9d7

File tree

7 files changed

+95
-5
lines changed

7 files changed

+95
-5
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ 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(
107+
cmdline.isset("show-modules") || cmdline.isset("modules-xml") ||
108+
cmdline.isset("json-modules"))
107109
return show_modules(cmdline, ui_message_handler);
108110

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

src/ebmc/ebmc_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ebmc_parse_optionst:public parse_options_baset
3333
"(dimacs)(module):(top):"
3434
"(po)(cegar)(k-induction)(2pi)(bound2):"
3535
"(outfile):(xml-ui)(verbosity):(gui)"
36-
"(json-result):(json-properties):"
36+
"(json-modules):(json-properties):(json-result):"
3737
"(neural-liveness)(neural-engine):"
3838
"(reset):"
3939
"(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: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
#include <util/xml.h>
10-
#include <util/xml_irep.h>
11-
129
#include "show_modules.h"
1310

11+
#include <util/json_irep.h>
12+
#include <util/xml_irep.h>
13+
1414
/*******************************************************************\
1515
1616
Function: show_modules_xml
@@ -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)