Skip to content

Commit 18aacc0

Browse files
committed
Add full JSON-structured output for value-set analysis
1 parent 0cdd9c6 commit 18aacc0

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

src/analyses/static_analysis.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,7 @@ jsont static_analysis_baset::output_json(
132132
pretty_type << i_it->type;
133133
instruction_object["instruction_type"]=json_stringt(pretty_type.str());
134134
}
135-
{
136-
std::ostringstream state_text;
137-
get_state(i_it).output(ns, state_text);
138-
instruction_object["state"]=json_stringt(state_text.str());
139-
}
135+
instruction_object["state"]=get_state(i_it).output_json(ns);
140136
retval.push_back(instruction_object);
141137
}
142138

src/analyses/static_analysis.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class domain_baset
6868
{
6969
}
7070

71+
virtual jsont output_json(const namespacet &ns) const
72+
{
73+
return json_stringt("");
74+
}
75+
7176
typedef std::unordered_set<exprt, irep_hash> expr_sett;
7277

7378
// will go away

src/pointer-analysis/value_set.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <util/arith_tools.h>
2121
#include <util/pointer_offset_size.h>
2222
#include <util/cprover_prefix.h>
23+
#include <util/json_irep.h>
2324

2425
#include <util/c_types.h>
2526

@@ -192,6 +193,33 @@ void value_sett::output(
192193
}
193194
}
194195

196+
jsont value_sett::output_json(const namespacet &) const
197+
{
198+
json_arrayt retval;
199+
json_irept irep_converter(true);
200+
201+
for(const auto &name_values : values)
202+
{
203+
json_objectt json_entry;
204+
205+
json_entry["id"]=json_stringt(id2string(name_values.second.identifier));
206+
json_entry["suffix"]=json_stringt(id2string(name_values.second.suffix));
207+
208+
json_arrayt vals;
209+
for(const auto &obj_entry : name_values.second.object_map.read())
210+
{
211+
vals.push_back(
212+
irep_converter.convert_from_irep(object_numbering[obj_entry.first]));
213+
}
214+
215+
json_entry["values"]=vals;
216+
217+
retval.push_back(json_entry);
218+
}
219+
220+
return retval;
221+
}
222+
195223
exprt value_sett::to_expr(const object_map_dt::value_type &it) const
196224
{
197225
const exprt &object=object_numbering[it.first];

src/pointer-analysis/value_set.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <set>
1616

17+
#include <util/json.h>
1718
#include <util/mp_arith.h>
1819
#include <util/reference_counting.h>
1920

@@ -206,6 +207,8 @@ class value_sett
206207
const namespacet &ns,
207208
std::ostream &out) const;
208209

210+
jsont output_json(const namespacet &) const;
211+
209212
valuest values;
210213

211214
// true = added something new

src/pointer-analysis/value_set_domain.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,39 @@ class value_set_domaint:public domain_baset
3030
return value_set.make_union(other.value_set);
3131
}
3232

33-
virtual void output(
33+
void output(
3434
const namespacet &ns,
35-
std::ostream &out) const
35+
std::ostream &out) const override
3636
{
3737
value_set.output(ns, out);
3838
}
3939

40-
virtual void initialize(
40+
jsont output_json(const namespacet &ns) const override
41+
{
42+
return value_set.output_json(ns);
43+
}
44+
45+
void initialize(
4146
const namespacet &ns,
42-
locationt l)
47+
locationt l) override
4348
{
4449
value_set.clear();
4550
value_set.location_number=l->location_number;
4651
value_set.function=l->function;
4752
}
4853

49-
virtual void get_reference_set(
54+
void get_reference_set(
5055
const namespacet &ns,
5156
const exprt &expr,
52-
value_setst::valuest &dest)
57+
value_setst::valuest &dest) override
5358
{
5459
value_set.get_reference_set(expr, dest, ns);
5560
}
5661

57-
virtual void transform(
62+
void transform(
5863
const namespacet &ns,
5964
locationt from_l,
60-
locationt to_l)
65+
locationt to_l) override
6166
{
6267
switch(from_l->type)
6368
{

0 commit comments

Comments
 (0)