-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathloop_ids.cpp
117 lines (98 loc) · 2.85 KB
/
loop_ids.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*******************************************************************\
Module: Loop IDs
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// Loop IDs
#include "loop_ids.h"
#include <iostream>
#include <util/json_irep.h>
#include <util/xml_irep.h>
#include "goto_model.h"
void show_loop_ids(
ui_message_handlert::uit ui,
const goto_modelt &goto_model)
{
show_loop_ids(ui, goto_model.goto_functions);
}
void show_loop_ids(
ui_message_handlert::uit ui,
const irep_idt &function_id,
const goto_programt &goto_program)
{
switch(ui)
{
case ui_message_handlert::uit::PLAIN:
{
for(const auto &instruction : goto_program.instructions)
{
if(instruction.is_backwards_goto())
{
std::cout << "Loop "
<< goto_programt::loop_id(function_id, instruction) << ":"
<< "\n";
std::cout << " " << instruction.source_location() << "\n";
std::cout << "\n";
}
}
break;
}
case ui_message_handlert::uit::XML_UI:
{
for(const auto &instruction : goto_program.instructions)
{
if(instruction.is_backwards_goto())
{
std::string id =
id2string(goto_programt::loop_id(function_id, instruction));
xmlt xml_loop("loop", {{"name", id}}, {});
xml_loop.new_element("loop-id").data=id;
xml_loop.new_element() = xml(instruction.source_location());
std::cout << xml_loop << "\n";
}
}
break;
}
case ui_message_handlert::uit::JSON_UI:
UNREACHABLE; // use function below
}
}
void show_loop_ids_json(
ui_message_handlert::uit ui,
const irep_idt &function_id,
const goto_programt &goto_program,
json_arrayt &loops)
{
PRECONDITION(ui == ui_message_handlert::uit::JSON_UI); // use function above
for(const auto &instruction : goto_program.instructions)
{
if(instruction.is_backwards_goto())
{
std::string id =
id2string(goto_programt::loop_id(function_id, instruction));
loops.push_back(json_objectt(
{{"name", json_stringt(id)},
{"sourceLocation", json(instruction.source_location())}}));
}
}
}
void show_loop_ids(
ui_message_handlert::uit ui,
const goto_functionst &goto_functions)
{
switch(ui)
{
case ui_message_handlert::uit::PLAIN:
case ui_message_handlert::uit::XML_UI:
for(const auto &f: goto_functions.function_map)
show_loop_ids(ui, f.first, f.second.body);
break;
case ui_message_handlert::uit::JSON_UI:
json_objectt json_result;
json_arrayt &loops=json_result["loops"].make_array();
for(const auto &f : goto_functions.function_map)
show_loop_ids_json(ui, f.first, f.second.body, loops);
std::cout << ",\n" << json_result;
break;
}
}