Skip to content

Add example of translated goto function #4079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/goto-programs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,50 @@ In converting to a GOTO program this structure is changed in several ways:
instruction. Each goto_programt should have precisely one such
instruction.

\subsection subsection-goto-function-example Example goto-program

The following C program, in a file named `mult.c`:

```
unsigned mult(unsigned a, unsigned b)
{
int acc = 0, i;
for (i = 0; i < b; i++)
acc += a;
return acc;
}
```

is translated by `cbmc --show-goto-functions mult.c` into:

```
mult /* mult */
// 0 file third.c line 2 function mult
signed int acc;
// 1 file third.c line 2 function mult
acc = 0;
// 2 file third.c line 2 function mult
signed int i;
// 3 file third.c line 3 function mult
i = 0;
// 4 file third.c line 3 function mult
1: IF !((unsigned int)i < b) THEN GOTO 2
// 5 file third.c line 4 function mult
acc = (signed int)((unsigned int)acc + a);
// 6 file third.c line 3 function mult
i = i + 1;
// 7 file third.c line 3 function mult
GOTO 1
// 8 file third.c line 5 function mult
2: mult#return_value = (unsigned int)acc;
// 9 file third.c line 5 function mult
dead i;
// 10 file third.c line 5 function mult
dead acc;
// 11 file third.c line 6 function mult
END_FUNCTION
```

\section section-goto-transforms Subsequent Transformation

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

(The above result was produced using `cbmc version 5.11`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course our documentation will always be up-to-date so that isn't needed :-)


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

Expand Down