Skip to content

Commit 0cec13d

Browse files
author
Daniel Kroening
authored
Merge pull request #1360 from KPouliasis/konst_splice_call
added splice-call feature in goto instrument
2 parents 9f9f30d + 22fb7c1 commit 0cec13d

File tree

7 files changed

+141
-1
lines changed

7 files changed

+141
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
void moo()
2+
{
3+
return;
4+
}
5+
6+
int main()
7+
{
8+
return 0;
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
--splice-call main,moo
4+
activate-multi-line-match
5+
moo\(\);\n.*function main.*
6+
EXIT=0
7+
SIGNAL=0

src/goto-instrument/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SRC = accelerate/accelerate.cpp \
4646
rw_set.cpp \
4747
show_locations.cpp \
4848
skip_loops.cpp \
49+
splice_call.cpp \
4950
stack_depth.cpp \
5051
thread_instrumentation.cpp \
5152
undefined_functions.cpp \

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Author: Daniel Kroening, [email protected]
9696
#include "model_argc_argv.h"
9797
#include "undefined_functions.h"
9898
#include "remove_function.h"
99+
#include "splice_call.h"
99100

100101
void goto_instrument_parse_optionst::eval_verbosity()
101102
{
@@ -1392,6 +1393,19 @@ void goto_instrument_parse_optionst::instrument_goto_program()
13921393
full_slicer(goto_model);
13931394
}
13941395

1396+
// splice option
1397+
if(cmdline.isset("splice-call"))
1398+
{
1399+
status() << "Performing call splicing" << eom;
1400+
std::string callercallee=cmdline.get_value("splice-call");
1401+
if(splice_call(
1402+
goto_model.goto_functions,
1403+
callercallee,
1404+
goto_model.symbol_table,
1405+
get_message_handler()))
1406+
throw 0;
1407+
}
1408+
13951409
// recalculate numbers, etc.
13961410
goto_model.goto_functions.update();
13971411
}
@@ -1458,6 +1472,7 @@ void goto_instrument_parse_optionst::help()
14581472
" --nondet-static add nondeterministic initialization of variables with static lifetime\n" // NOLINT(*)
14591473
" --check-invariant function instruments invariant checking function\n"
14601474
" --remove-pointers converts pointer arithmetic to base+offset expressions\n" // NOLINT(*)
1475+
" --splice-call caller,callee prepends a call to callee in the body of caller\n" // NOLINT(*)
14611476
// NOLINTNEXTLINE(whitespace/line_length)
14621477
" --undefined-function-is-assume-false\n" // NOLINTNEXTLINE(whitespace/line_length)
14631478
" convert each call to an undefined function to assume(false)\n"

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ Author: Daniel Kroening, [email protected]
7777
"(horn)(skip-loops):(apply-code-contracts)(model-argc-argv):" \
7878
"(show-threaded)(list-calls-args)(print-path-lengths)" \
7979
"(undefined-function-is-assume-false)" \
80-
"(remove-function-body):"
80+
"(remove-function-body):"\
81+
"(splice-call):" \
82+
8183

8284
class goto_instrument_parse_optionst:
8385
public parse_options_baset,

src/goto-instrument/splice_call.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*******************************************************************\
2+
3+
Module: Prepend/ splice a 0-ary function call in the beginning of a function
4+
e.g. for setting/ modelling the global environment
5+
6+
Author: Konstantinos Pouliasis
7+
8+
Date: July 2017
9+
10+
\*******************************************************************/
11+
12+
/// \file
13+
/// Prepend a nullary call to another function
14+
// useful for context/ environment setting in arbitrary nodes
15+
16+
#include "splice_call.h"
17+
#include <util/message.h>
18+
#include <util/string2int.h>
19+
#include <util/string_utils.h>
20+
#include <util/language.h>
21+
#include <goto-programs/goto_functions.h>
22+
#include <algorithm>
23+
24+
// split the argument in caller/ callee two-position vector
25+
// expect input as a string of two names glued with comma: "caller,callee"
26+
static bool parse_caller_callee(
27+
const std::string &callercallee,
28+
std::vector<std::string> &result)
29+
{
30+
split_string(callercallee, ',', result);
31+
return (result.size()!= 2);
32+
}
33+
34+
bool splice_call(
35+
goto_functionst &goto_functions,
36+
const std::string &callercallee,
37+
const symbol_tablet &symbol_table,
38+
message_handlert &message_handler)
39+
{
40+
messaget message(message_handler);
41+
const namespacet ns(symbol_table);
42+
std::vector<std::string> caller_callee;
43+
if(parse_caller_callee(callercallee, caller_callee))
44+
{
45+
message.error() << "Expecting two function names seperated by a comma"
46+
<< messaget::eom;
47+
return true;
48+
}
49+
goto_functionst::function_mapt::iterator caller_fun=
50+
goto_functions.function_map.find(caller_callee[0]);
51+
goto_functionst::function_mapt::const_iterator callee_fun=
52+
goto_functions.function_map.find(caller_callee[1]);
53+
if(caller_fun==goto_functions.function_map.end())
54+
{
55+
message.error() << "Caller function does not exist" << messaget::eom;
56+
return true;
57+
}
58+
if(!caller_fun->second.body_available())
59+
{
60+
message.error() << "Caller function has no available body" << messaget::eom;
61+
return true;
62+
}
63+
if(callee_fun==goto_functions.function_map.end())
64+
{
65+
message.error() << "Callee function does not exist" << messaget::eom;
66+
return true;
67+
}
68+
goto_programt::const_targett start=
69+
caller_fun->second.body.instructions.begin();
70+
goto_programt::targett g=
71+
caller_fun->second.body.insert_before(start);
72+
code_function_callt splice_call;
73+
splice_call.function()=ns.lookup(callee_fun->first).symbol_expr();
74+
g->make_function_call(to_code_function_call(splice_call));
75+
76+
// update counters etc.
77+
goto_functions.update();
78+
return false;
79+
}

src/goto-instrument/splice_call.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************\
2+
3+
Module: Prepend/ splice a 0-ary function call in the beginning of a function
4+
e.g. for setting/ modelling the global environment
5+
6+
Author: Konstantinos Pouliasis
7+
8+
Date: July 2017
9+
10+
\*******************************************************************/
11+
12+
/// \file
13+
/// Harnessing for goto functions
14+
15+
#ifndef CPROVER_GOTO_INSTRUMENT_SPLICE_CALL_H
16+
#define CPROVER_GOTO_INSTRUMENT_SPLICE_CALL_H
17+
18+
#include <goto-programs/goto_functions.h>
19+
class message_handlert;
20+
21+
bool splice_call(
22+
goto_functionst &goto_functions,
23+
const std::string &callercallee,
24+
const symbol_tablet &symbol_table,
25+
message_handlert &message_handler);
26+
27+
#endif // CPROVER_GOTO_INSTRUMENT_SPLICE_CALL_H

0 commit comments

Comments
 (0)