@@ -19,10 +19,15 @@ Author: Daniel Kroening, kroening@kroening.com
19
19
Function: goto_programt::output_instruction
20
20
21
21
Inputs:
22
+ ns - the namespace to resolve the expressions in
23
+ identifier - the identifier used to find a symbol to identify the
24
+ source language
25
+ out - the stream to write the goto string to
26
+ it - an iterator pointing to the instruction to convert
22
27
23
- Outputs:
28
+ Outputs: See below.
24
29
25
- Purpose:
30
+ Purpose: See below.
26
31
27
32
\*******************************************************************/
28
33
@@ -32,51 +37,81 @@ std::ostream& goto_programt::output_instruction(
32
37
std::ostream& out,
33
38
instructionst::const_iterator it) const
34
39
{
35
- out << " // " << it->location_number << " " ;
40
+ return output_instruction (ns, identifier, out, *it);
41
+ }
42
+
43
+ /* ******************************************************************\
44
+
45
+ Function: goto_programt::output_instruction
46
+
47
+ Inputs:
48
+ ns - the namespace to resolve the expressions in
49
+ identifier - the identifier used to find a symbol to identify the
50
+ source language
51
+ out - the stream to write the goto string to
52
+ instruction - the instruction to convert
36
53
37
- if (!it->source_location .is_nil ())
38
- out << it->source_location .as_string ();
54
+ Outputs: Appends to out a two line representation of the instruction
55
+
56
+ Purpose: Writes to out a two line string representation of the specific
57
+ instruction. It is of the format:
58
+ // {location} file {source file} line {line in source file}
59
+ {representation of the instruction}
60
+
61
+ \*******************************************************************/
62
+
63
+ std::ostream &goto_programt::output_instruction (
64
+ const namespacet &ns,
65
+ const irep_idt &identifier,
66
+ std::ostream &out,
67
+ const goto_program_templatet::instructiont &instruction) const
68
+ {
69
+ out << " // " << instruction.location_number << " " ;
70
+
71
+ if (!instruction.source_location .is_nil ())
72
+ out << instruction.source_location .as_string ();
39
73
else
40
74
out << " no location" ;
41
75
42
76
out << " \n " ;
43
77
44
- if (!it-> labels .empty ())
78
+ if (!instruction. labels .empty ())
45
79
{
46
80
out << " // Labels:" ;
47
- for (const auto &label : it-> labels )
81
+ for (const auto &label : instruction. labels )
48
82
out << " " << label;
49
83
50
84
out << ' \n ' ;
51
85
}
52
86
53
- if (it-> is_target ())
54
- out << std::setw (6 ) << it-> target_number << " : " ;
87
+ if (instruction. is_target ())
88
+ out << std::setw (6 ) << instruction. target_number << " : " ;
55
89
else
56
90
out << " " ;
57
91
58
- switch (it-> type )
92
+ switch (instruction. type )
59
93
{
60
94
case NO_INSTRUCTION_TYPE:
61
95
out << " NO INSTRUCTION TYPE SET" << ' \n ' ;
62
96
break ;
63
97
64
98
case GOTO:
65
- if (!it-> guard .is_true ())
99
+ if (!instruction. guard .is_true ())
66
100
{
67
101
out << " IF "
68
- << from_expr (ns, identifier, it-> guard )
102
+ << from_expr (ns, identifier, instruction. guard )
69
103
<< " THEN " ;
70
104
}
71
105
72
106
out << " GOTO " ;
73
107
74
108
for (instructiont::targetst::const_iterator
75
- gt_it=it-> targets .begin ();
76
- gt_it!=it-> targets .end ();
109
+ gt_it=instruction. targets .begin ();
110
+ gt_it!=instruction. targets .end ();
77
111
gt_it++)
78
112
{
79
- if (gt_it!=it->targets .begin ()) out << " , " ;
113
+ if (gt_it!=instruction.targets .begin ())
114
+ out << " , " ;
80
115
out << (*gt_it)->target_number ;
81
116
}
82
117
@@ -89,20 +124,20 @@ std::ostream& goto_programt::output_instruction(
89
124
case DEAD:
90
125
case FUNCTION_CALL:
91
126
case ASSIGN:
92
- out << from_expr (ns, identifier, it-> code ) << ' \n ' ;
127
+ out << from_expr (ns, identifier, instruction. code ) << ' \n ' ;
93
128
break ;
94
129
95
130
case ASSUME:
96
131
case ASSERT:
97
- if (it-> is_assume ())
132
+ if (instruction. is_assume ())
98
133
out << " ASSUME " ;
99
134
else
100
135
out << " ASSERT " ;
101
136
102
137
{
103
- out << from_expr (ns, identifier, it-> guard );
138
+ out << from_expr (ns, identifier, instruction. guard );
104
139
105
- const irep_idt &comment=it-> source_location .get_comment ();
140
+ const irep_idt &comment=instruction. source_location .get_comment ();
106
141
if (comment!=" " ) out << " // " << comment;
107
142
}
108
143
@@ -126,34 +161,35 @@ std::ostream& goto_programt::output_instruction(
126
161
127
162
{
128
163
const irept::subt &exception_list=
129
- it-> code .find (ID_exception_list).get_sub ();
164
+ instruction. code .find (ID_exception_list).get_sub ();
130
165
131
166
for (const auto &ex : exception_list)
132
167
out << " " << ex.id ();
133
168
}
134
169
135
- if (it-> code .operands ().size ()==1 )
136
- out << " : " << from_expr (ns, identifier, it-> code .op0 ());
170
+ if (instruction. code .operands ().size ()==1 )
171
+ out << " : " << from_expr (ns, identifier, instruction. code .op0 ());
137
172
138
173
out << ' \n ' ;
139
174
break ;
140
175
141
176
case CATCH:
142
- if (!it-> targets .empty ())
177
+ if (!instruction. targets .empty ())
143
178
{
144
179
out << " CATCH-PUSH " ;
145
180
146
181
unsigned i=0 ;
147
182
const irept::subt &exception_list=
148
- it-> code .find (ID_exception_list).get_sub ();
149
- assert (it-> targets .size ()==exception_list.size ());
183
+ instruction. code .find (ID_exception_list).get_sub ();
184
+ assert (instruction. targets .size ()==exception_list.size ());
150
185
for (instructiont::targetst::const_iterator
151
- gt_it=it-> targets .begin ();
152
- gt_it!=it-> targets .end ();
186
+ gt_it=instruction. targets .begin ();
187
+ gt_it!=instruction. targets .end ();
153
188
gt_it++,
154
189
i++)
155
190
{
156
- if (gt_it!=it->targets .begin ()) out << " , " ;
191
+ if (gt_it!=instruction.targets .begin ())
192
+ out << " , " ;
157
193
out << exception_list[i].id () << " ->"
158
194
<< (*gt_it)->target_number ;
159
195
}
@@ -175,8 +211,8 @@ std::ostream& goto_programt::output_instruction(
175
211
case START_THREAD:
176
212
out << " START THREAD " ;
177
213
178
- if (it-> targets .size ()==1 )
179
- out << it-> targets .front ()->target_number ;
214
+ if (instruction. targets .size ()==1 )
215
+ out << instruction. targets .front ()->target_number ;
180
216
181
217
out << ' \n ' ;
182
218
break ;
0 commit comments