Skip to content

Set function member in instructions #1843

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 2 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Set function member of each goto instruction in goto program passes
  • Loading branch information
peterschrammel committed Feb 15, 2018
commit 552b10080b63e7c77407da7ecb9238c8e23bb84d
5 changes: 2 additions & 3 deletions src/goto-programs/goto_convert_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ void goto_convert_functionst::convert_function(
// add "end of function"
f.body.destructive_append(tmp_end_function);

// do function tags
Forall_goto_program_instructions(i_it, f.body)
i_it->function=identifier;
// do function tags (they are empty at this point)
f.update_instructions_function(identifier);

f.body.update();

Expand Down
19 changes: 19 additions & 0 deletions src/goto-programs/goto_functions_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class goto_function_templatet
parameter_identifiers.clear();
}

/// update the function member in each instruction
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate this comment to explain how the instructions_function are being updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

added param description

/// \param function_id: the `function_id` used for assigning empty function
/// members
void update_instructions_function(const irep_idt &function_id)
{
body.update_instructions_function(function_id);
}

void swap(goto_function_templatet &other)
{
body.swap(other.body);
Expand Down Expand Up @@ -149,12 +157,23 @@ class goto_functions_templatet
void compute_target_numbers();
void compute_incoming_edges();

/// update the function member in each instruction by setting it to
/// the goto function's identifier
void update_instructions_function()
{
for(auto &func : function_map)
{
func.second.update_instructions_function(func.first);
}
}

void update()
{
compute_incoming_edges();
compute_target_numbers();
compute_location_numbers();
compute_loop_numbers();
update_instructions_function();
}

static inline irep_idt entry_point()
Expand Down
7 changes: 7 additions & 0 deletions src/goto-programs/goto_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ class goto_model_functiont
goto_functions.compute_location_numbers(goto_function.body);
}

/// Updates the empty function member of each instruction by setting them
/// to `function_id`
void update_instructions_function()
{
goto_function.update_instructions_function(function_id);
}

/// Get symbol table
/// \return journalling symbol table that (a) wraps the global symbol table,
/// and (b) has recorded all symbol mutations (insertions, updates and
Expand Down
16 changes: 16 additions & 0 deletions src/goto-programs/goto_program_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,22 @@ class goto_program_templatet
}
}

/// Sets the `function` member of each instruction if not yet set
/// Note that a goto program need not be a goto function and therefore,
/// we cannot do this in update(), but only at the level of
/// of goto_functionst where goto programs are guaranteed to be
/// named functions.
void update_instructions_function(const irep_idt &function_id)
{
for(auto &instruction : instructions)
{
if(instruction.function.empty())
{
instruction.function = function_id;
}
}
}

/// Compute location numbers
void compute_location_numbers()
{
Expand Down
3 changes: 3 additions & 0 deletions src/jbmc/jbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ void jbmc_parse_optionst::process_goto_function(
symbol_table.lookup_ref(new_symbol_name),
symbol_table);
}

// update the function member in each instruction
function.update_instructions_function();
}

catch(const char *e)
Expand Down