Skip to content

Commit 51eed48

Browse files
authored
Merge pull request #2872 from mgudemann/feature/generalize_nondet_switch
Make `generate_nondet_switch` available in CBMC
2 parents 4af07fc + 71340ee commit 51eed48

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

jbmc/src/java_bytecode/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ SRC = bytecode_info.cpp \
3636
java_utils.cpp \
3737
load_method_by_regex.cpp \
3838
mz_zip_archive.cpp \
39-
nondet.cpp \
4039
remove_exceptions.cpp \
4140
remove_instanceof.cpp \
4241
remove_java_new.cpp \

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Author: Daniel Kroening, [email protected]
2222
#include "java_object_factory.h"
2323
#include "java_string_literals.h"
2424
#include "java_utils.h"
25-
#include "nondet.h"
2625
#include <util/fresh_symbol.h>
26+
#include <util/nondet.h>
2727

2828
#define JAVA_MAIN_METHOD "main:([Ljava/lang/String;)V"
2929

@@ -402,6 +402,7 @@ exprt::operandst java_build_arguments(
402402
id2string(function.name) + "_" + std::to_string(param_number),
403403
cases,
404404
java_int_type(),
405+
ID_java,
405406
function.location,
406407
symbol_table));
407408
}

src/util/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ SRC = arith_tools.cpp \
4545
message.cpp \
4646
mp_arith.cpp \
4747
namespace.cpp \
48+
nondet.cpp \
4849
options.cpp \
4950
parse_options.cpp \
5051
parser.cpp \

jbmc/src/java_bytecode/nondet.cpp renamed to src/util/nondet.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/*******************************************************************\
22
3-
Module: Non-deterministic object init and choice for JBMC
3+
Module: Non-deterministic object init and choice for CBMC
44
55
Author: Diffblue Ltd.
66
77
\*******************************************************************/
88

99
#include "nondet.h"
1010

11-
#include <java_bytecode/java_types.h>
1211
#include <util/arith_tools.h>
1312
#include <util/c_types.h>
1413
#include <util/fresh_symbol.h>
@@ -23,7 +22,8 @@ Module: Non-deterministic object init and choice for JBMC
2322
/// ```
2423
/// \param min_value: Minimum value (inclusive) of returned int.
2524
/// \param max_value: Maximum value (inclusive) of returned int.
26-
/// \param name_prefix: Prefix for the fresh symbol name generated.
25+
/// \param name_prefix: Prefix for the fresh symbol name generated (should be
26+
/// function id)
2727
/// \param int_type: The type of the int used to non-deterministically choose
2828
/// one of the switch cases.
2929
/// \param source_location: The location to mark the generated int with.
@@ -37,21 +37,18 @@ symbol_exprt generate_nondet_int(
3737
const int64_t max_value,
3838
const std::string &name_prefix,
3939
const typet &int_type,
40+
const irep_idt &mode,
4041
const source_locationt &source_location,
4142
symbol_table_baset &symbol_table,
4243
code_blockt &instructions)
4344
{
4445
PRECONDITION(min_value < max_value);
4546

4647
// Declare a symbol for the non deterministic integer.
47-
const symbol_exprt &nondet_symbol = get_fresh_aux_symbol(
48-
int_type,
49-
name_prefix,
50-
"nondet_int",
51-
source_location,
52-
ID_java,
53-
symbol_table)
54-
.symbol_expr();
48+
const symbol_exprt &nondet_symbol =
49+
get_fresh_aux_symbol(
50+
int_type, name_prefix, "nondet_int", source_location, mode, symbol_table)
51+
.symbol_expr();
5552
instructions.add(code_declt(nondet_symbol));
5653

5754
// Assign the symbol any non deterministic integer value.
@@ -77,7 +74,7 @@ symbol_exprt generate_nondet_int(
7774
}
7875

7976
/// Pick nondeterministically between imperative actions 'switch_cases'.
80-
/// \param name_prefix: Name prefix for fresh symbols
77+
/// \param name_prefix: Name prefix for fresh symbols (should be function id)
8178
/// \param switch_cases: List of codet objects to execute in each switch case.
8279
/// \param int_type: The type of the int used to non-deterministically choose
8380
/// one of the switch cases.
@@ -89,6 +86,7 @@ code_blockt generate_nondet_switch(
8986
const irep_idt &name_prefix,
9087
const alternate_casest &switch_cases,
9188
const typet &int_type,
89+
const irep_idt &mode,
9290
const source_locationt &source_location,
9391
symbol_table_baset &symbol_table)
9492
{
@@ -105,14 +103,15 @@ code_blockt generate_nondet_switch(
105103
switch_cases.size() - 1,
106104
id2string(name_prefix),
107105
int_type,
106+
mode,
108107
source_location,
109108
symbol_table,
110109
result_block);
111110

112111
result_switch.value() = switch_value;
113112

114113
code_blockt switch_block;
115-
int64_t case_number = 0;
114+
size_t case_number = 0;
116115
for(const auto &switch_case : switch_cases)
117116
{
118117
code_blockt this_block;

jbmc/src/java_bytecode/nondet.h renamed to src/util/nondet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ symbol_exprt generate_nondet_int(
1818
int64_t max_value,
1919
const std::string &name_prefix,
2020
const typet &int_type,
21+
const irep_idt &mode,
2122
const source_locationt &source_location,
2223
symbol_table_baset &symbol_table,
2324
code_blockt &instructions);
@@ -28,6 +29,7 @@ code_blockt generate_nondet_switch(
2829
const irep_idt &name_prefix,
2930
const alternate_casest &switch_cases,
3031
const typet &int_type,
32+
const irep_idt &mode,
3133
const source_locationt &source_location,
3234
symbol_table_baset &symbol_table);
3335

0 commit comments

Comments
 (0)