@@ -19,10 +19,15 @@ Author: Daniel Kroening, kroening@kroening.com
1919Function: goto_programt::output_instruction
2020
2121 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
2227
23- Outputs:
28+ Outputs: See below.
2429
25- Purpose:
30+ Purpose: See below.
2631
2732\*******************************************************************/
2833
@@ -32,51 +37,81 @@ std::ostream& goto_programt::output_instruction(
3237 std::ostream& out,
3338 instructionst::const_iterator it) const
3439{
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
3653
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 ();
3973 else
4074 out << " no location" ;
4175
4276 out << " \n " ;
4377
44- if (!it-> labels .empty ())
78+ if (!instruction. labels .empty ())
4579 {
4680 out << " // Labels:" ;
47- for (const auto &label : it-> labels )
81+ for (const auto &label : instruction. labels )
4882 out << " " << label;
4983
5084 out << ' \n ' ;
5185 }
5286
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 << " : " ;
5589 else
5690 out << " " ;
5791
58- switch (it-> type )
92+ switch (instruction. type )
5993 {
6094 case NO_INSTRUCTION_TYPE:
6195 out << " NO INSTRUCTION TYPE SET" << ' \n ' ;
6296 break ;
6397
6498 case GOTO:
65- if (!it-> guard .is_true ())
99+ if (!instruction. guard .is_true ())
66100 {
67101 out << " IF "
68- << from_expr (ns, identifier, it-> guard )
102+ << from_expr (ns, identifier, instruction. guard )
69103 << " THEN " ;
70104 }
71105
72106 out << " GOTO " ;
73107
74108 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 ();
77111 gt_it++)
78112 {
79- if (gt_it!=it->targets .begin ()) out << " , " ;
113+ if (gt_it!=instruction.targets .begin ())
114+ out << " , " ;
80115 out << (*gt_it)->target_number ;
81116 }
82117
@@ -89,20 +124,20 @@ std::ostream& goto_programt::output_instruction(
89124 case DEAD:
90125 case FUNCTION_CALL:
91126 case ASSIGN:
92- out << from_expr (ns, identifier, it-> code ) << ' \n ' ;
127+ out << from_expr (ns, identifier, instruction. code ) << ' \n ' ;
93128 break ;
94129
95130 case ASSUME:
96131 case ASSERT:
97- if (it-> is_assume ())
132+ if (instruction. is_assume ())
98133 out << " ASSUME " ;
99134 else
100135 out << " ASSERT " ;
101136
102137 {
103- out << from_expr (ns, identifier, it-> guard );
138+ out << from_expr (ns, identifier, instruction. guard );
104139
105- const irep_idt &comment=it-> source_location .get_comment ();
140+ const irep_idt &comment=instruction. source_location .get_comment ();
106141 if (comment!=" " ) out << " // " << comment;
107142 }
108143
@@ -126,34 +161,35 @@ std::ostream& goto_programt::output_instruction(
126161
127162 {
128163 const irept::subt &exception_list=
129- it-> code .find (ID_exception_list).get_sub ();
164+ instruction. code .find (ID_exception_list).get_sub ();
130165
131166 for (const auto &ex : exception_list)
132167 out << " " << ex.id ();
133168 }
134169
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 ());
137172
138173 out << ' \n ' ;
139174 break ;
140175
141176 case CATCH:
142- if (!it-> targets .empty ())
177+ if (!instruction. targets .empty ())
143178 {
144179 out << " CATCH-PUSH " ;
145180
146181 unsigned i=0 ;
147182 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 ());
150185 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 ();
153188 gt_it++,
154189 i++)
155190 {
156- if (gt_it!=it->targets .begin ()) out << " , " ;
191+ if (gt_it!=instruction.targets .begin ())
192+ out << " , " ;
157193 out << exception_list[i].id () << " ->"
158194 << (*gt_it)->target_number ;
159195 }
@@ -175,8 +211,8 @@ std::ostream& goto_programt::output_instruction(
175211 case START_THREAD:
176212 out << " START THREAD " ;
177213
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 ;
180216
181217 out << ' \n ' ;
182218 break ;
0 commit comments