Skip to content

Conversation

areejatawi
Copy link

Trying to add a new loop transformation option to eliminate loops in C programs by converting them into recursive function calls.

Copy link
Owner

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

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

Good start!
Please add regression tests to test your implementation. Have a look in https://github.com/peterschrammel/cbmc/tree/master/regression/goto-instrument how to do that.
You can just push new commits to your branch. They'll automatically appear in this Pull Request.

Forall_goto_program_instructions(it, goto_function_body)

{
if(!it->is_backwards_goto() &&
Copy link
Owner

Choose a reason for hiding this comment

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

Lines 41-43 seem unnecessary.


//search for loop
Forall_goto_program_instructions(it, goto_function_body)

Copy link
Owner

Choose a reason for hiding this comment

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

style: remove blank line (several occurrences)

bool has_loop (
goto_programt &goto_function_body)
{

Copy link
Owner

Choose a reason for hiding this comment

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

style: remove blank line

#include <goto-programs/remove_skip.h>


#include "loop_to_recursion.h"
Copy link
Owner

Choose a reason for hiding this comment

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

put this include first


if(it->is_backwards_goto())
found = true;
break;
Copy link
Owner

Choose a reason for hiding this comment

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

Returning directly from here seems easier. Lines 49-54 (except 51) can go away...

goto_functionst &goto_functions,
symbol_tablet &symbol_table,
messaget message)
{
Copy link
Owner

Choose a reason for hiding this comment

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

Style: don't indent braces, but only block inside braces (multiple occurrences)


//add REC_function symbol
symbolt recursive_function;
const irep_idt rec_f_name = "REC_function";
Copy link
Owner

Choose a reason for hiding this comment

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

When you have multiple loops, you'll need call them differently.

goto_functions.function_map.find("REC_function");

//not added?
if(rec_func_id==goto_functions.function_map.end())
Copy link
Owner

Choose a reason for hiding this comment

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

You'll need a different function for each loop.

if(!goto_function.body_available())
continue;

if(has_loop(goto_function.body))
Copy link
Owner

Choose a reason for hiding this comment

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

In the end you should replace all the loops in all the functions by its own corresponding recursive function.


symbolt &rec_f = symbol_table.lookup("REC_function");

/*before adding replacing loop by REC_function call,
Copy link
Owner

Choose a reason for hiding this comment

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

Style: Use
// comments
// even if they are over
// multiple lines

…le. 3. Considering more than one loop in a function. 4. Adding a regression test.
@areejatawi areejatawi closed this Feb 28, 2018
peterschrammel added a commit that referenced this pull request Nov 14, 2018
Allows to detect errors related to synchronization on null references,
for example.
peterschrammel added a commit that referenced this pull request Nov 14, 2018
Allows to detect errors related to synchronization on null references,
for example.

Fixes diffblue#1236.
peterschrammel added a commit that referenced this pull request Nov 16, 2018
Allows to detect errors related to synchronization on null references,
for example.

Fixes diffblue#1236.
peterschrammel added a commit that referenced this pull request Nov 17, 2018
Allows to detect errors related to synchronization on null references,
for example.

Fixes diffblue#1236.
peterschrammel added a commit that referenced this pull request Nov 17, 2018
Allows to detect errors related to synchronization on null references
on Monitor enter.

Partially fixes issue 1236.
peterschrammel added a commit that referenced this pull request Nov 17, 2018
Allows to detect errors related to synchronization on null references
on Monitor enter.

Partially fixes issue 1236.
peterschrammel added a commit that referenced this pull request Nov 17, 2018
Allows to detect errors related to synchronization on null references
on Monitor enter.

Partially fixes issue 1236.
peterschrammel added a commit that referenced this pull request Nov 18, 2018
…xceptions

Update jbmc/lib/java-models-library to #11 (enable-monitor-exceptions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants