29
29
30
30
#include < langapi/language_util.h>
31
31
32
- std::ostream &goto_programt::output (std::ostream &out) const
33
- {
34
- return output (namespacet (symbol_tablet ()), irep_idt (), out);
35
- }
36
-
37
32
goto_programt::instructiont goto_programt::make_incomplete_goto (
38
33
const code_gotot &_code,
39
34
const source_locationt &l)
@@ -48,67 +43,57 @@ goto_programt::instructiont goto_programt::make_incomplete_goto(
48
43
// / // Labels: {list-of-labels}
49
44
// / {representation of the instruction}
50
45
// / ```
51
- // / \param ns: the namespace to resolve the expressions in
52
- // / \param identifier: the identifier used to find a symbol to identify the
53
- // / source language
54
46
// / \param out: the stream to write the goto string to
55
- // / \param instruction: the instruction to convert
56
47
// / \return Appends to out a two line representation of the instruction
57
- std::ostream &goto_programt::output_instruction (
58
- const namespacet &ns,
59
- const irep_idt &identifier,
60
- std::ostream &out,
61
- const instructiont &instruction) const
48
+ std::ostream &goto_programt::instructiont::output (std::ostream &out) const
62
49
{
63
- out << " // " << instruction. location_number << " " ;
50
+ out << " // " << location_number << " " ;
64
51
65
- if (!instruction. source_location ().is_nil ())
66
- out << instruction. source_location ().as_string ();
52
+ if (!source_location ().is_nil ())
53
+ out << source_location ().as_string ();
67
54
else
68
55
out << " no location" ;
69
56
70
57
out << " \n " ;
71
58
72
- if (!instruction. labels .empty ())
59
+ if (!labels.empty ())
73
60
{
74
61
out << " // Labels:" ;
75
- for (const auto &label : instruction. labels )
62
+ for (const auto &label : labels)
76
63
out << " " << label;
77
64
78
65
out << ' \n ' ;
79
66
}
80
67
81
- if (instruction. is_target ())
82
- out << std::setw (6 ) << instruction. target_number << " : " ;
68
+ if (is_target ())
69
+ out << std::setw (6 ) << target_number << " : " ;
83
70
else
84
71
out << " " ;
85
72
86
- switch (instruction. type ())
73
+ switch (type ())
87
74
{
88
75
case NO_INSTRUCTION_TYPE:
89
76
out << " NO INSTRUCTION TYPE SET" << ' \n ' ;
90
77
break ;
91
78
92
79
case GOTO:
93
80
case INCOMPLETE_GOTO:
94
- if (!instruction. condition ().is_true ())
81
+ if (!condition ().is_true ())
95
82
{
96
- out << " IF " << format (instruction. condition ()) << " THEN " ;
83
+ out << " IF " << format (condition ()) << " THEN " ;
97
84
}
98
85
99
86
out << " GOTO " ;
100
87
101
- if (instruction. is_incomplete_goto ())
88
+ if (is_incomplete_goto ())
102
89
{
103
90
out << " (incomplete)" ;
104
91
}
105
92
else
106
93
{
107
- for (auto gt_it = instruction.targets .begin ();
108
- gt_it != instruction.targets .end ();
109
- gt_it++)
94
+ for (auto gt_it = targets.begin (); gt_it != targets.end (); gt_it++)
110
95
{
111
- if (gt_it != instruction. targets .begin ())
96
+ if (gt_it != targets.begin ())
112
97
out << " , " ;
113
98
out << (*gt_it)->target_number ;
114
99
}
@@ -118,9 +103,9 @@ std::ostream &goto_programt::output_instruction(
118
103
break ;
119
104
120
105
case OTHER:
121
- if (instruction. get_other ().id () == ID_code)
106
+ if (get_other ().id () == ID_code)
122
107
{
123
- const auto &code = instruction. get_other ();
108
+ const auto &code = get_other ();
124
109
if (code.get_statement () == ID_array_copy)
125
110
{
126
111
out << " ARRAY_COPY " << format (code.op0 ()) << ' ' << format (code.op1 ())
@@ -174,31 +159,31 @@ std::ostream &goto_programt::output_instruction(
174
159
// fallthrough
175
160
}
176
161
177
- out << " OTHER " << format (instruction. get_other ()) << ' \n ' ;
162
+ out << " OTHER " << format (get_other ()) << ' \n ' ;
178
163
break ;
179
164
180
165
case SET_RETURN_VALUE:
181
- out << " SET RETURN VALUE " << format (instruction. return_value ()) << ' \n ' ;
166
+ out << " SET RETURN VALUE " << format (return_value ()) << ' \n ' ;
182
167
break ;
183
168
184
169
case DECL:
185
- out << " DECL " << format (instruction. decl_symbol ()) << " : "
186
- << format (instruction. decl_symbol ().type ()) << ' \n ' ;
170
+ out << " DECL " << format (decl_symbol ()) << " : "
171
+ << format (decl_symbol ().type ()) << ' \n ' ;
187
172
break ;
188
173
189
174
case DEAD:
190
- out << " DEAD " << format (instruction. dead_symbol ()) << ' \n ' ;
175
+ out << " DEAD " << format (dead_symbol ()) << ' \n ' ;
191
176
break ;
192
177
193
178
case FUNCTION_CALL:
194
179
out << " CALL " ;
195
180
{
196
- if (instruction. call_lhs ().is_not_nil ())
197
- out << format (instruction. call_lhs ()) << " := " ;
198
- out << format (instruction. call_function ());
181
+ if (call_lhs ().is_not_nil ())
182
+ out << format (call_lhs ()) << " := " ;
183
+ out << format (call_function ());
199
184
out << ' (' ;
200
185
bool first = true ;
201
- for (const auto &argument : instruction. call_arguments ())
186
+ for (const auto &argument : call_arguments ())
202
187
{
203
188
if (first)
204
189
first = false ;
@@ -212,21 +197,21 @@ std::ostream &goto_programt::output_instruction(
212
197
break ;
213
198
214
199
case ASSIGN:
215
- out << " ASSIGN " << format (instruction. assign_lhs ())
216
- << " := " << format (instruction. assign_rhs ()) << ' \n ' ;
200
+ out << " ASSIGN " << format (assign_lhs ()) << " := " << format ( assign_rhs ())
201
+ << ' \n ' ;
217
202
break ;
218
203
219
204
case ASSUME:
220
205
case ASSERT:
221
- if (instruction. is_assume ())
206
+ if (is_assume ())
222
207
out << " ASSUME " ;
223
208
else
224
209
out << " ASSERT " ;
225
210
226
211
{
227
- out << format (instruction. condition ());
212
+ out << format (condition ());
228
213
229
- const irep_idt &comment = instruction. source_location ().get_comment ();
214
+ const irep_idt &comment = source_location ().get_comment ();
230
215
if (!comment.empty ())
231
216
out << " // " << comment;
232
217
}
@@ -251,49 +236,48 @@ std::ostream &goto_programt::output_instruction(
251
236
252
237
{
253
238
const irept::subt &exception_list =
254
- instruction. code ().find (ID_exception_list).get_sub ();
239
+ code ().find (ID_exception_list).get_sub ();
255
240
256
241
for (const auto &ex : exception_list)
257
242
out << " " << ex.id ();
258
243
}
259
244
260
- if (instruction. code ().operands ().size () == 1 )
261
- out << " : " << format (instruction. code ().op0 ());
245
+ if (code ().operands ().size () == 1 )
246
+ out << " : " << format (code ().op0 ());
262
247
263
248
out << ' \n ' ;
264
249
break ;
265
250
266
251
case CATCH:
267
252
{
268
- if (instruction. code ().get_statement () == ID_exception_landingpad)
253
+ if (code ().get_statement () == ID_exception_landingpad)
269
254
{
270
- const auto &landingpad = to_code_landingpad (instruction. code ());
255
+ const auto &landingpad = to_code_landingpad (code ());
271
256
out << " EXCEPTION LANDING PAD (" << format (landingpad.catch_expr ().type ())
272
257
<< ' ' << format (landingpad.catch_expr ()) << " )" ;
273
258
}
274
- else if (instruction. code ().get_statement () == ID_push_catch)
259
+ else if (code ().get_statement () == ID_push_catch)
275
260
{
276
261
out << " CATCH-PUSH " ;
277
262
278
263
unsigned i=0 ;
279
264
const irept::subt &exception_list =
280
- instruction. code ().find (ID_exception_list).get_sub ();
265
+ code ().find (ID_exception_list).get_sub ();
281
266
DATA_INVARIANT (
282
- instruction. targets .size () == exception_list.size (),
267
+ targets.size () == exception_list.size (),
283
268
" unexpected discrepancy between sizes of instruction"
284
269
" targets and exception list" );
285
- for (instructiont::targetst::const_iterator
286
- gt_it=instruction.targets .begin ();
287
- gt_it!=instruction.targets .end ();
270
+ for (instructiont::targetst::const_iterator gt_it = targets.begin ();
271
+ gt_it != targets.end ();
288
272
gt_it++, i++)
289
273
{
290
- if (gt_it!=instruction. targets .begin ())
274
+ if (gt_it != targets.begin ())
291
275
out << " , " ;
292
276
out << exception_list[i].id () << " ->"
293
277
<< (*gt_it)->target_number ;
294
278
}
295
279
}
296
- else if (instruction. code ().get_statement () == ID_pop_catch)
280
+ else if (code ().get_statement () == ID_pop_catch)
297
281
{
298
282
out << " CATCH-POP" ;
299
283
}
@@ -315,9 +299,7 @@ std::ostream &goto_programt::output_instruction(
315
299
break ;
316
300
317
301
case START_THREAD:
318
- out << " START THREAD "
319
- << instruction.get_target ()->target_number
320
- << ' \n ' ;
302
+ out << " START THREAD " << get_target ()->target_number << ' \n ' ;
321
303
break ;
322
304
323
305
case END_THREAD:
@@ -636,15 +618,12 @@ void goto_programt::update()
636
618
compute_loop_numbers ();
637
619
}
638
620
639
- std::ostream &goto_programt::output (
640
- const namespacet &ns,
641
- const irep_idt &identifier,
642
- std::ostream &out) const
621
+ std::ostream &goto_programt::output (std::ostream &out) const
643
622
{
644
- // output program
623
+ // output the program
645
624
646
625
for (const auto &instruction : instructions)
647
- output_instruction (ns, identifier, out, instruction );
626
+ instruction. output ( out);
648
627
649
628
return out;
650
629
}
0 commit comments