Skip to content

Commit 54fab5b

Browse files
committed
Add Java locals to the symbol table and give them declarations
This is required for SSA renaming to work on Java local symbols.
1 parent 7069c17 commit 54fab5b

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ class java_bytecode_convert_methodt:public messaget
8282
symbol_exprt symbol_expr;
8383
size_t start_pc;
8484
size_t length;
85+
bool is_parameter;
8586
};
8687

8788
typedef std::vector<variablet> variablest;
8889
expanding_vector<variablest> variables;
89-
90+
std::set<symbol_exprt> used_local_names;
9091
bool method_has_this;
9192

9293
typedef enum instruction_sizet
@@ -150,13 +151,16 @@ class java_bytecode_convert_methodt:public messaget
150151

151152
symbol_exprt result(identifier, t);
152153
result.set(ID_C_base_name, base_name);
154+
used_local_names.insert(result);
153155

154156
return result;
155157
}
156158
else
157159
{
158160
exprt result=var.symbol_expr;
159-
if(do_cast==CAST_AS_NEEDED && t!=result.type()) result=typecast_exprt(result, t);
161+
if(!var.is_parameter)
162+
used_local_names.insert(to_symbol_expr(result));
163+
if(do_cast==CAST_AS_NEEDED && t!=result.type()) result=typecast_exprt(result, t);
160164
return result;
161165
}
162166
}
@@ -379,6 +383,7 @@ void java_bytecode_convert_methodt::convert(
379383
variables[param_index][0].symbol_expr=parameter_symbol.symbol_expr();
380384
variables[param_index][0].start_pc=0;
381385
variables[param_index][0].length = std::numeric_limits<size_t>::max();
386+
variables[param_index][0].is_parameter=true;
382387
param_index+=slots;
383388
}
384389

@@ -1529,6 +1534,22 @@ codet java_bytecode_convert_methodt::convert_instructions(
15291534
// review successor computation of athrow!
15301535
code_blockt code;
15311536

1537+
// locals
1538+
for(const auto & var : used_local_names)
1539+
{
1540+
code.add(code_declt(var));
1541+
symbolt new_symbol;
1542+
new_symbol.name=var.get_identifier();
1543+
new_symbol.type=var.type();
1544+
new_symbol.base_name=var.get(ID_C_base_name);
1545+
new_symbol.pretty_name=id2string(var.get_identifier()).substr(6, std::string::npos);
1546+
new_symbol.mode=ID_java;
1547+
new_symbol.is_type=false;
1548+
new_symbol.is_file_local=true;
1549+
new_symbol.is_thread_local=true;
1550+
new_symbol.is_lvalue=true;
1551+
symbol_table.add(new_symbol);
1552+
}
15321553
// temporaries
15331554
for(const auto & var : tmp_vars)
15341555
{

0 commit comments

Comments
 (0)