Skip to content

Commit f179ca8

Browse files
authored
Merge pull request #4079 from NlightNFotis/goto-programs-doc
Add example of translated goto function
2 parents 88ab7d5 + 1ee9696 commit f179ca8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/goto-programs/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,50 @@ In converting to a GOTO program this structure is changed in several ways:
298298
instruction. Each goto_programt should have precisely one such
299299
instruction.
300300

301+
\subsection subsection-goto-function-example Example goto-program
302+
303+
The following C program, in a file named `mult.c`:
304+
305+
```
306+
unsigned mult(unsigned a, unsigned b)
307+
{
308+
int acc = 0, i;
309+
for (i = 0; i < b; i++)
310+
acc += a;
311+
return acc;
312+
}
313+
```
314+
315+
is translated by `cbmc --show-goto-functions mult.c` into:
316+
317+
```
318+
mult /* mult */
319+
// 0 file third.c line 2 function mult
320+
signed int acc;
321+
// 1 file third.c line 2 function mult
322+
acc = 0;
323+
// 2 file third.c line 2 function mult
324+
signed int i;
325+
// 3 file third.c line 3 function mult
326+
i = 0;
327+
// 4 file third.c line 3 function mult
328+
1: IF !((unsigned int)i < b) THEN GOTO 2
329+
// 5 file third.c line 4 function mult
330+
acc = (signed int)((unsigned int)acc + a);
331+
// 6 file third.c line 3 function mult
332+
i = i + 1;
333+
// 7 file third.c line 3 function mult
334+
GOTO 1
335+
// 8 file third.c line 5 function mult
336+
2: mult#return_value = (unsigned int)acc;
337+
// 9 file third.c line 5 function mult
338+
dead i;
339+
// 10 file third.c line 5 function mult
340+
dead acc;
341+
// 11 file third.c line 6 function mult
342+
END_FUNCTION
343+
```
344+
301345
\section section-goto-transforms Subsequent Transformation
302346

303347
It is normal for a program that calls `goto_convert` to immediately pass the
@@ -524,6 +568,7 @@ then it performs 'linking' of the temporary into a passed destination
524568
Details about linking of `::goto_modelt` instances can be found
525569
[here](\ref section-linking-goto-models).
526570

571+
(The above result was produced using `cbmc version 5.11`)
527572

528573
\section section-linking-goto-models Linking Goto Models
529574

0 commit comments

Comments
 (0)