Skip to content

Commit e352e42

Browse files
committed
Extend the usage of method_offsett
1 parent b402401 commit e352e42

File tree

7 files changed

+75
-62
lines changed

7 files changed

+75
-62
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ symbol_exprt java_bytecode_convert_methodt::tmp_variable(
204204
exprt java_bytecode_convert_methodt::variable(
205205
const exprt &arg,
206206
char type_char,
207-
size_t address,
207+
method_offsett address,
208208
java_bytecode_convert_methodt::variable_cast_argumentt do_cast)
209209
{
210210
typet t=java_type_from_char(type_char);
@@ -555,7 +555,8 @@ void java_bytecode_convert_methodt::convert(
555555
variables[param_index][0].symbol_expr=parameter_symbol.symbol_expr();
556556
variables[param_index][0].is_parameter=true;
557557
variables[param_index][0].start_pc=0;
558-
variables[param_index][0].length=std::numeric_limits<size_t>::max();
558+
variables[param_index][0].length =
559+
std::numeric_limits<method_offsett>::max();
559560
param_index+=java_local_variable_slots(param.type());
560561
}
561562

@@ -937,7 +938,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
937938
}
938939

939940
static void gather_symbol_live_ranges(
940-
java_bytecode_convert_methodt::method_offsett pc,
941+
method_offsett pc,
941942
const exprt &e,
942943
std::map<irep_idt, java_bytecode_convert_methodt::variablet> &result)
943944
{
@@ -962,7 +963,8 @@ static void gather_symbol_live_ranges(
962963
}
963964
else
964965
{
965-
var.length=std::max(var.length, (pc-var.start_pc)+1);
966+
var.length = std::max(
967+
var.length, static_cast<method_offsett>((pc - var.start_pc) + 1));
966968
}
967969
}
968970
}
@@ -1078,7 +1080,8 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
10781080
{
10791081
PRECONDITION(!i_it->args.empty());
10801082

1081-
auto target = numeric_cast_v<unsigned>(to_constant_expr(i_it->args[0]));
1083+
auto target =
1084+
numeric_cast_v<method_offsett>(to_constant_expr(i_it->args[0]));
10821085
targets.insert(target);
10831086

10841087
a_entry.first->second.successors.push_back(target);
@@ -1101,7 +1104,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
11011104
{
11021105
if(is_label)
11031106
{
1104-
auto target = numeric_cast_v<unsigned>(to_constant_expr(arg));
1107+
auto target = numeric_cast_v<method_offsett>(to_constant_expr(arg));
11051108
targets.insert(target);
11061109
a_entry.first->second.successors.push_back(target);
11071110
}
@@ -1878,7 +1881,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
18781881
root,
18791882
root_block,
18801883
v.start_pc,
1881-
v.start_pc + v.length,
1884+
static_cast<method_offsett>(v.start_pc + v.length),
18821885
std::numeric_limits<method_offsett>::max(),
18831886
address_map);
18841887
}
@@ -1894,7 +1897,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
18941897
root,
18951898
root_block,
18961899
v.start_pc,
1897-
v.start_pc + v.length,
1900+
static_cast<method_offsett>(v.start_pc + v.length),
18981901
std::numeric_limits<method_offsett>::max());
18991902
code_declt d(v.symbol_expr);
19001903
block.statements().insert(block.statements().begin(), d);
@@ -2986,7 +2989,7 @@ void java_bytecode_convert_methodt::draw_edges_from_ret_to_jsr(
29862989
}
29872990
}
29882991

2989-
std::vector<java_bytecode_convert_methodt::method_offsett>
2992+
std::vector<method_offsett>
29902993
java_bytecode_convert_methodt::try_catch_handler(
29912994
const method_offsett address,
29922995
const java_bytecode_parse_treet::methodt::exception_tablet &exception_table)
@@ -3025,7 +3028,7 @@ void java_bytecode_initialize_parameter_names(
30253028
java_method_typet::parameterst &parameters = method_type.parameters();
30263029

30273030
// Find number of parameters
3028-
unsigned slots_for_parameters = java_method_parameter_slots(method_type);
3031+
auto slots_for_parameters = java_method_parameter_slots(method_type);
30293032

30303033
// Find parameter names in the local variable table:
30313034
typedef std::pair<irep_idt, irep_idt> base_name_and_identifiert;

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com
1515
#include "ci_lazy_methods_needed.h"
1616
#include "java_bytecode_parse_tree.h"
1717
#include "java_bytecode_convert_class.h"
18+
#include "java_utils.h"
1819

1920
#include <util/expanding_vector.h>
2021
#include <util/message.h>
@@ -66,8 +67,6 @@ class java_bytecode_convert_methodt:public messaget
6667
convert(class_symbol, method);
6768
}
6869

69-
typedef uint16_t method_offsett;
70-
7170
protected:
7271
symbol_table_baset &symbol_table;
7372
namespacet ns;
@@ -116,8 +115,8 @@ class java_bytecode_convert_methodt:public messaget
116115
{
117116
public:
118117
symbol_exprt symbol_expr;
119-
size_t start_pc;
120-
size_t length;
118+
method_offsett start_pc;
119+
method_offsett length;
121120
bool is_parameter;
122121
std::vector<holet> holes;
123122

@@ -143,7 +142,7 @@ class java_bytecode_convert_methodt:public messaget
143142

144143
// return corresponding reference of variable
145144
const variablet &find_variable_for_slot(
146-
size_t address,
145+
method_offsett address,
147146
variablest &var_list);
148147

149148
// JVM local variables
@@ -156,7 +155,7 @@ class java_bytecode_convert_methodt:public messaget
156155
exprt variable(
157156
const exprt &arg,
158157
char type_char,
159-
size_t address,
158+
method_offsett address,
160159
variable_cast_argumentt do_cast);
161160

162161
// temporary variables

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Author: Daniel Kroening, kroening@kroening.com
1919

2020
#include "bytecode_info.h"
2121

22+
typedef uint16_t method_offsett;
23+
2224
struct java_bytecode_parse_treet
2325
{
2426
// Disallow copy construction and copy assignment, but allow move construction
@@ -57,7 +59,7 @@ struct java_bytecode_parse_treet
5759
struct instructiont
5860
{
5961
source_locationt source_location;
60-
unsigned address;
62+
method_offsett address;
6163
irep_idt statement;
6264
typedef std::vector<exprt> argst;
6365
argst args;
@@ -114,9 +116,9 @@ struct java_bytecode_parse_treet
114116
{
115117
}
116118

117-
std::size_t start_pc;
118-
std::size_t end_pc;
119-
std::size_t handler_pc;
119+
method_offsett start_pc;
120+
method_offsett end_pc;
121+
method_offsett handler_pc;
120122
struct_tag_typet catch_type;
121123
};
122124

@@ -130,9 +132,9 @@ struct java_bytecode_parse_treet
130132
irep_idt name;
131133
std::string descriptor;
132134
optionalt<std::string> signature;
133-
std::size_t index;
134-
std::size_t start_pc;
135-
std::size_t length;
135+
method_offsett index;
136+
method_offsett start_pc;
137+
method_offsett length;
136138
};
137139

138140
typedef std::vector<local_variablet> local_variable_tablet;

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ void java_bytecode_parsert::rbytecode(
986986
instructions.push_back(instructiont());
987987
instructiont &instruction=instructions.back();
988988
instruction.statement=bytecodes[bytecode].mnemonic;
989-
instruction.address=start_of_instruction;
989+
instruction.address=static_cast<method_offsett>(start_of_instruction);
990990
instruction.source_location
991991
.set_java_bytecode_index(std::to_string(bytecode_index));
992992

@@ -1655,7 +1655,7 @@ void java_bytecode_parsert::rinner_classes_attribute(
16551655
{
16561656
std::string name = parsed_class.name.c_str();
16571657
u2 number_of_classes = read_u2();
1658-
u4 number_of_bytes_to_be_read = number_of_classes * 8 + 2;
1658+
u4 number_of_bytes_to_be_read = static_cast<u4>(number_of_classes * 8 + 2);
16591659
INVARIANT(
16601660
number_of_bytes_to_be_read == attribute_length,
16611661
"The number of bytes to be read for the InnerClasses attribute does not "

jbmc/src/java_bytecode/java_local_variable_table.cpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ template <class T>
2828
struct procedure_local_cfg_baset<
2929
T,
3030
java_bytecode_convert_methodt::method_with_amapt,
31-
java_bytecode_convert_methodt::method_offsett>
31+
method_offsett>
3232
: public grapht<
33-
cfg_base_nodet<T, java_bytecode_convert_methodt::method_offsett>>
33+
cfg_base_nodet<T, method_offsett>>
3434
{
3535
typedef java_bytecode_convert_methodt::method_with_amapt method_with_amapt;
36-
typedef std::map<java_bytecode_convert_methodt::method_offsett,
37-
java_bytecode_convert_methodt::method_offsett>
38-
entry_mapt;
36+
typedef std::map<method_offsett, method_offsett> entry_mapt;
3937
entry_mapt entry_map;
4038

4139
procedure_local_cfg_baset() {}
@@ -47,7 +45,7 @@ struct procedure_local_cfg_baset<
4745
for(const auto &inst : amap)
4846
{
4947
// Map instruction PCs onto node indices:
50-
entry_map[inst.first]=this->add_node();
48+
entry_map[inst.first] = static_cast<method_offsett>(this->add_node());
5149
// Map back:
5250
(*this)[entry_map[inst.first]].PC=inst.first;
5351
}
@@ -85,14 +83,12 @@ struct procedure_local_cfg_baset<
8583
}
8684
}
8785

88-
java_bytecode_convert_methodt::method_offsett
89-
get_first_node(const method_with_amapt &args) const
86+
method_offsett get_first_node(const method_with_amapt &args) const
9087
{
9188
return args.second.begin()->first;
9289
}
9390

94-
java_bytecode_convert_methodt::method_offsett
95-
get_last_node(const method_with_amapt &args) const
91+
method_offsett get_last_node(const method_with_amapt &args) const
9692
{
9793
return (--args.second.end())->first;
9894
}
@@ -216,14 +212,13 @@ static bool is_store_to_slot(
216212
/// \param [out] var: A hole is added to `var`, unless it would be of zero size
217213
static void maybe_add_hole(
218214
local_variable_with_holest &var,
219-
java_bytecode_convert_methodt::method_offsett from,
220-
java_bytecode_convert_methodt::method_offsett to)
215+
method_offsett from,
216+
method_offsett to)
221217
{
222218
PRECONDITION(to>=from);
223219
if(to!=from)
224220
var.holes.push_back(
225-
{from,
226-
static_cast<java_bytecode_convert_methodt::method_offsett>(to - from)});
221+
{from, static_cast<method_offsett>(to - from)});
227222
}
228223

229224
/// See above
@@ -240,10 +235,17 @@ static void populate_variable_address_map(
240235
{
241236
for(auto it=firstvar, itend=varlimit; it!=itend; ++it)
242237
{
243-
if(it->var.start_pc+it->var.length>live_variable_at_address.size())
244-
live_variable_at_address.resize(it->var.start_pc+it->var.length);
238+
if(
239+
static_cast<std::size_t>(it->var.start_pc + it->var.length) >
240+
live_variable_at_address.size())
241+
{
242+
live_variable_at_address.resize(
243+
static_cast<std::size_t>(it->var.start_pc + it->var.length));
244+
}
245245

246-
for(auto idx = it->var.start_pc, idxlim = it->var.start_pc + it->var.length;
246+
for(method_offsett idx = it->var.start_pc,
247+
idxlim = static_cast<method_offsett>(
248+
it->var.start_pc + it->var.length);
247249
idx != idxlim;
248250
++idx)
249251
{
@@ -310,7 +312,8 @@ static void populate_predecessor_map(
310312
#endif
311313

312314
// Find the last instruction within the live range:
313-
const auto end_pc = it->var.start_pc + it->var.length;
315+
const auto end_pc =
316+
static_cast<method_offsett>(it->var.start_pc + it->var.length);
314317
auto amapit=amap.find(end_pc);
315318
INVARIANT(
316319
amapit!=amap.begin(),
@@ -423,22 +426,20 @@ static void populate_predecessor_map(
423426
/// \return Returns the bytecode address of the closest common dominator of all
424427
/// given variable table entries. In the worst case the function entry point
425428
/// should always satisfy this criterion.
426-
static java_bytecode_convert_methodt::method_offsett get_common_dominator(
429+
static method_offsett get_common_dominator(
427430
const std::set<local_variable_with_holest *> &merge_vars,
428431
const java_cfg_dominatorst &dominator_analysis)
429432
{
430433
PRECONDITION(!merge_vars.empty());
431434

432-
auto first_pc =
433-
std::numeric_limits<java_bytecode_convert_methodt::method_offsett>::max();
435+
auto first_pc = std::numeric_limits<method_offsett>::max();
434436
for(auto v : merge_vars)
435437
{
436438
if(v->var.start_pc<first_pc)
437439
first_pc=v->var.start_pc;
438440
}
439441

440-
std::vector<java_bytecode_convert_methodt::method_offsett>
441-
candidate_dominators;
442+
std::vector<method_offsett> candidate_dominators;
442443
for(auto v : merge_vars)
443444
{
444445
const auto &dominator_nodeidx=
@@ -485,7 +486,7 @@ static java_bytecode_convert_methodt::method_offsett get_common_dominator(
485486
static void populate_live_range_holes(
486487
local_variable_with_holest &merge_into,
487488
const std::set<local_variable_with_holest *> &merge_vars,
488-
java_bytecode_convert_methodt::method_offsett expanded_live_range_start)
489+
method_offsett expanded_live_range_start)
489490
{
490491
std::vector<local_variable_with_holest *> sorted_by_startpc(
491492
merge_vars.begin(), merge_vars.end());
@@ -495,14 +496,16 @@ static void populate_live_range_holes(
495496
merge_into,
496497
expanded_live_range_start,
497498
sorted_by_startpc[0]->var.start_pc);
498-
for(java_bytecode_convert_methodt::method_offsett idx = 0;
499+
for(method_offsett idx = 0;
499500
idx < sorted_by_startpc.size() - 1;
500501
++idx)
501502
{
502503
maybe_add_hole(
503504
merge_into,
504-
sorted_by_startpc[idx]->var.start_pc+sorted_by_startpc[idx]->var.length,
505-
sorted_by_startpc[idx+1]->var.start_pc);
505+
static_cast<method_offsett>(
506+
sorted_by_startpc[idx]->var.start_pc +
507+
sorted_by_startpc[idx]->var.length),
508+
sorted_by_startpc[static_cast<method_offsett>(idx + 1)]->var.start_pc);
506509
}
507510
}
508511

@@ -533,16 +536,17 @@ static void merge_variable_table_entries(
533536
// as it was not visible in the original local variable table)
534537
populate_live_range_holes(merge_into, merge_vars, found_dominator);
535538

536-
java_bytecode_convert_methodt::method_offsett last_pc = 0;
539+
method_offsett last_pc = 0;
537540
for(auto v : merge_vars)
538541
{
539-
if(v->var.start_pc+v->var.length>last_pc)
540-
last_pc=v->var.start_pc+v->var.length;
542+
if(static_cast<method_offsett>(v->var.start_pc + v->var.length) > last_pc)
543+
last_pc = static_cast<method_offsett>(v->var.start_pc + v->var.length);
541544
}
542545

543546
// Apply the changes:
544547
merge_into.var.start_pc=found_dominator;
545-
merge_into.var.length=last_pc-found_dominator;
548+
merge_into.var.length =
549+
static_cast<method_offsett>(last_pc - found_dominator);
546550

547551
#ifdef DEBUG
548552
debug_out << "Merged " << merge_vars.size() << " variables named "
@@ -837,7 +841,7 @@ void java_bytecode_convert_methodt::setup_local_variables(
837841
/// nothing covers `address`.
838842
const java_bytecode_convert_methodt::variablet &
839843
java_bytecode_convert_methodt::find_variable_for_slot(
840-
size_t address,
844+
method_offsett address,
841845
variablest &var_list)
842846
{
843847
for(const variablet &var : var_list)
@@ -865,6 +869,6 @@ java_bytecode_convert_methodt::find_variable_for_slot(
865869
size_t list_length=var_list.size();
866870
var_list.resize(list_length+1);
867871
var_list[list_length].start_pc=0;
868-
var_list[list_length].length=std::numeric_limits<size_t>::max();
872+
var_list[list_length].length = std::numeric_limits<method_offsett>::max();
869873
return var_list[list_length];
870874
}

0 commit comments

Comments
 (0)