Skip to content

added splice-call feature in goto instrument #1360

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
Sep 18, 2017
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions regression/goto-instrument/splice_call_01/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void moo()
{
return;
}

int main()
{
return 0;
}
7 changes: 7 additions & 0 deletions regression/goto-instrument/splice_call_01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
main.c
--splice-call main,moo
activate-multi-line-match
moo\(\);\n.*function main.*
EXIT=0
SIGNAL=0
1 change: 1 addition & 0 deletions src/goto-instrument/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ SRC = accelerate/accelerate.cpp \
rw_set.cpp \
show_locations.cpp \
skip_loops.cpp \
splice_call.cpp \
stack_depth.cpp \
thread_instrumentation.cpp \
undefined_functions.cpp \
Expand Down
15 changes: 15 additions & 0 deletions src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Author: Daniel Kroening, [email protected]
#include "model_argc_argv.h"
#include "undefined_functions.h"
#include "remove_function.h"
#include "splice_call.h"

void goto_instrument_parse_optionst::eval_verbosity()
{
Expand Down Expand Up @@ -1408,6 +1409,19 @@ void goto_instrument_parse_optionst::instrument_goto_program()
full_slicer(goto_model);
}

// splice option
if(cmdline.isset("splice-call"))
{
status() << "Performing call splicing" << eom;
std::string callercallee=cmdline.get_value("splice-call");
if(splice_call(
goto_model.goto_functions,
callercallee,
goto_model.symbol_table,
get_message_handler()))
throw 0;
}

// recalculate numbers, etc.
goto_model.goto_functions.update();
}
Expand Down Expand Up @@ -1474,6 +1488,7 @@ void goto_instrument_parse_optionst::help()
" --nondet-static add nondeterministic initialization of variables with static lifetime\n" // NOLINT(*)
" --check-invariant function instruments invariant checking function\n"
" --remove-pointers converts pointer arithmetic to base+offset expressions\n" // NOLINT(*)
" --splice-call caller,callee prepends a call to callee in the body of caller\n" // NOLINT(*)
// NOLINTNEXTLINE(whitespace/line_length)
" --undefined-function-is-assume-false\n" // NOLINTNEXTLINE(whitespace/line_length)
" convert each call to an undefined function to assume(false)\n"
Expand Down
4 changes: 3 additions & 1 deletion src/goto-instrument/goto_instrument_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ Author: Daniel Kroening, [email protected]
"(horn)(skip-loops):(apply-code-contracts)(model-argc-argv):" \
"(show-threaded)(list-calls-args)(print-path-lengths)" \
"(undefined-function-is-assume-false)" \
"(remove-function-body):"
"(remove-function-body):"\
"(splice-call):" \


class goto_instrument_parse_optionst:
public parse_options_baset,
Expand Down
79 changes: 79 additions & 0 deletions src/goto-instrument/splice_call.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************\

Module: Prepend/ splice a 0-ary function call in the beginning of a function
e.g. for setting/ modelling the global environment

Author: Konstantinos Pouliasis

Date: July 2017

\*******************************************************************/

/// \file
/// Prepend a nullary call to another function
// useful for context/ environment setting in arbitrary nodes

#include "splice_call.h"
#include <util/message.h>
#include <util/string2int.h>
#include <util/string_utils.h>
#include <util/language.h>
#include <goto-programs/goto_functions.h>
#include <algorithm>

// split the argument in caller/ callee two-position vector
// expect input as a string of two names glued with comma: "caller,callee"
static bool parse_caller_callee(
const std::string &callercallee,
std::vector<std::string> &result)
{
split_string(callercallee, ',', result);
return (result.size()!= 2);
}

bool splice_call(
goto_functionst &goto_functions,
const std::string &callercallee,
const symbol_tablet &symbol_table,
message_handlert &message_handler)
{
messaget message(message_handler);
const namespacet ns(symbol_table);
std::vector<std::string> caller_callee;
if(parse_caller_callee(callercallee, caller_callee))
{
message.error() << "Expecting two function names seperated by a comma"
<< messaget::eom;
return true;
}
goto_functionst::function_mapt::iterator caller_fun=
goto_functions.function_map.find(caller_callee[0]);
goto_functionst::function_mapt::const_iterator callee_fun=
goto_functions.function_map.find(caller_callee[1]);
if(caller_fun==goto_functions.function_map.end())
{
message.error() << "Caller function does not exist" << messaget::eom;
return true;
}
if(!caller_fun->second.body_available())
{
message.error() << "Caller function has no available body" << messaget::eom;
return true;
}
if(callee_fun==goto_functions.function_map.end())
{
message.error() << "Callee function does not exist" << messaget::eom;
return true;
}
goto_programt::const_targett start=
caller_fun->second.body.instructions.begin();
goto_programt::targett g=
caller_fun->second.body.insert_before(start);
code_function_callt splice_call;
splice_call.function()=ns.lookup(callee_fun->first).symbol_expr();
g->make_function_call(to_code_function_call(splice_call));

// update counters etc.
goto_functions.update();
return false;
}
27 changes: 27 additions & 0 deletions src/goto-instrument/splice_call.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************\

Module: Prepend/ splice a 0-ary function call in the beginning of a function
e.g. for setting/ modelling the global environment

Author: Konstantinos Pouliasis

Date: July 2017

\*******************************************************************/

/// \file
/// Harnessing for goto functions

#ifndef CPROVER_GOTO_INSTRUMENT_SPLICE_CALL_H
#define CPROVER_GOTO_INSTRUMENT_SPLICE_CALL_H

#include <goto-programs/goto_functions.h>
class message_handlert;

bool splice_call(
goto_functionst &goto_functions,
const std::string &callercallee,
const symbol_tablet &symbol_table,
message_handlert &message_handler);

#endif // CPROVER_GOTO_INSTRUMENT_SPLICE_CALL_H