Skip to content

Commit dee89b0

Browse files
author
thk123
committed
Fixing the method to work with java_bytecode
The java bytecode entry point relied on things working a little differently. Firstly, the function name is transformed to allow simpler function names to be passed in. As such the rebuild_entry_point cannot be responsible for looking up the symbol. This in turn involved a new way of identifying the mode to use (using the existing entry points mode) Secondly, as the lanuages are destroyed after the parsing phase, we must re-provide the message handler as this is used by the entry point generation. Finally, the java_bytecode_entry_point adds a new symbol to the symbol table, so we remove all symbols that are in the scope of the original entry point.
1 parent 1ccd1a2 commit dee89b0

11 files changed

+65
-32
lines changed

src/ansi-c/ansi_c_language.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ void ansi_c_languaget::modules_provided(std::set<std::string> &modules)
4343
/// function symbol will be added to this table
4444
/// \return Returns false if the _start method was generated correctly
4545
bool ansi_c_languaget::generate_start_function(
46-
const symbolt &entry_function_symbol,
46+
const irep_idt &entry_function_symbol_id,
4747
symbol_tablet &symbol_table)
4848
{
4949
return generate_ansi_c_start_function(
50-
entry_function_symbol,
50+
symbol_table.symbols.at(entry_function_symbol_id),
5151
symbol_table,
5252
*message_handler);
5353
}

src/ansi-c/ansi_c_language.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ansi_c_languaget:public languaget
7474
void modules_provided(std::set<std::string> &modules) override;
7575

7676
virtual bool generate_start_function(
77-
const class symbolt &entry_function_symbol,
77+
const irep_idt &entry_function_symbol_id,
7878
class symbol_tablet &symbol_table) override;
7979

8080
protected:

src/cpp/cpp_language.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ void cpp_languaget::modules_provided(std::set<std::string> &modules)
6060
/// function symbol will be added to this table
6161
/// \return Returns false if the _start method was generated correctly
6262
bool cpp_languaget::generate_start_function(
63-
const symbolt &entry_function_symbol,
63+
const irep_idt &entry_function_symbol_id,
6464
symbol_tablet &symbol_table)
6565
{
6666
return generate_ansi_c_start_function(
67-
entry_function_symbol,
67+
symbol_table.lookup(entry_function_symbol_id),
6868
symbol_table,
6969
*message_handler);
7070
}

src/cpp/cpp_language.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class cpp_languaget:public languaget
8686
void modules_provided(std::set<std::string> &modules) override;
8787

8888
virtual bool generate_start_function(
89-
const class symbolt &entry_function_symbol,
89+
const irep_idt &entry_function_symbol_id,
9090
class symbol_tablet &symbol_table) override;
9191

9292
protected:

src/goto-programs/rebuild_goto_start_function.cpp

+45-20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <util/language.h>
1313
#include <util/symbol.h>
1414
#include <util/symbol_table.h>
15+
#include <util/prefix.h>
1516
#include <langapi/mode.h>
1617
#include <memory>
1718

@@ -43,30 +44,18 @@ rebuild_goto_start_functiont::rebuild_goto_start_functiont(
4344
bool rebuild_goto_start_functiont::operator()(
4445
const irep_idt &entry_function)
4546
{
46-
const auto &desired_entry_function=
47-
symbol_table.symbols.find(entry_function);
47+
const irep_idt &mode=get_entry_point_mode();
4848

49-
// Check the specified entry function is a function in the symbol table
50-
if(desired_entry_function==symbol_table.symbols.end())
51-
{
52-
error() << "main symbol `" << entry_function
53-
<< "' not found" << eom;
54-
return true;
55-
}
49+
// Get the relevant languaget to generate the new entry point with
50+
std::unique_ptr<languaget> language=get_language_from_mode(mode);
51+
INVARIANT(language, "No language found for mode: "+id2string(mode));
52+
language->set_message_handler(get_message_handler());
5653

57-
// Remove the existing _start function so we can create a new one
58-
symbol_table.remove(goto_functionst::entry_point());
59-
60-
auto language=
61-
std::unique_ptr<languaget>(
62-
get_language_from_mode(
63-
desired_entry_function->second.mode));
64-
assert(language);
54+
// To create a new entry point we must first remove the old one
55+
remove_existing_entry_point();
6556

6657
bool return_code=
67-
language->generate_start_function(
68-
desired_entry_function->second,
69-
symbol_table);
58+
language->generate_start_function(entry_function, symbol_table);
7059

7160
// Remove the function from the goto_functions so it is copied back in
7261
// from the symbol table during goto_convert
@@ -82,3 +71,39 @@ bool rebuild_goto_start_functiont::operator()(
8271

8372
return return_code;
8473
}
74+
75+
/// Find out the mode of the current entry point to determine the mode of the
76+
/// replacement entry point
77+
/// \return A mode string saying which language to use
78+
irep_idt rebuild_goto_start_functiont::get_entry_point_mode() const
79+
{
80+
const symbolt &current_entry_point=
81+
symbol_table.lookup(goto_functionst::entry_point());
82+
return current_entry_point.mode;
83+
}
84+
85+
/// Eliminate the existing entry point function symbol and any symbols created
86+
/// in that scope from the symbol table.
87+
void rebuild_goto_start_functiont::remove_existing_entry_point()
88+
{
89+
// Remove the function itself
90+
symbol_table.remove(goto_functionst::entry_point());
91+
92+
// And any symbols created in the scope of the entry point
93+
std::vector<irep_idt> entry_point_symbols;
94+
for(const auto &symbol_entry : symbol_table.symbols)
95+
{
96+
const bool is_entry_point_symbol=
97+
has_prefix(
98+
id2string(symbol_entry.first),
99+
id2string(goto_functionst::entry_point()));
100+
101+
if(is_entry_point_symbol)
102+
entry_point_symbols.push_back(symbol_entry.first);
103+
}
104+
105+
for(const irep_idt &entry_point_symbol : entry_point_symbols)
106+
{
107+
symbol_table.remove(entry_point_symbol);
108+
}
109+
}

src/goto-programs/rebuild_goto_start_function.h

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class rebuild_goto_start_functiont: public messaget
3131
bool operator()(const irep_idt &entry_function);
3232

3333
private:
34+
irep_idt get_entry_point_mode() const;
35+
36+
void remove_existing_entry_point();
37+
3438
symbol_tablet &symbol_table;
3539
goto_functionst &goto_functions;
3640
};

src/java_bytecode/java_bytecode_language.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,15 @@ void java_bytecode_languaget::modules_provided(std::set<std::string> &modules)
113113
/// function symbol will be added to this table
114114
/// \return Returns false if the _start method was generated correctly
115115
bool java_bytecode_languaget::generate_start_function(
116-
const symbolt &entry_function_symbol,
116+
const irep_idt &entry_function_symbol_id,
117117
symbol_tablet &symbol_table)
118118
{
119+
const auto res=
120+
get_main_symbol(
121+
symbol_table, entry_function_symbol_id, get_message_handler());
122+
119123
return generate_java_start_function(
120-
entry_function_symbol,
124+
res.main_function,
121125
symbol_table,
122126
get_message_handler(),
123127
assume_inputs_non_null,

src/java_bytecode/java_bytecode_language.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class java_bytecode_languaget:public languaget
138138
const irep_idt &id, symbol_tablet &) override;
139139

140140
virtual bool generate_start_function(
141-
const class symbolt &entry_function_symbol,
141+
const irep_idt &entry_function_symbol_id,
142142
class symbol_tablet &symbol_table) override;
143143

144144
protected:

src/jsil/jsil_language.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bool jsil_languaget::interfaces(symbol_tablet &symbol_table)
4848
/// function symbol will be added to this table
4949
/// \return Returns false if the _start method was generated correctly
5050
bool jsil_languaget::generate_start_function(
51-
const symbolt &entry_function_symbol,
51+
const irep_idt &entry_function_symbol_id,
5252
symbol_tablet &symbol_table)
5353
{
5454
// TODO(tkiley): This should be implemented if this language

src/jsil/jsil_language.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class jsil_languaget:public languaget
7070
virtual bool interfaces(symbol_tablet &symbol_table) override;
7171

7272
virtual bool generate_start_function(
73-
const class symbolt &entry_function_symbol,
73+
const irep_idt &entry_function_symbol_id,
7474
class symbol_tablet &symbol_table) override;
7575

7676
protected:

src/util/language.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class languaget:public messaget
120120
void set_should_generate_opaque_method_stubs(bool should_generate_stubs);
121121

122122
virtual bool generate_start_function(
123-
const class symbolt &entry_function_symbol,
123+
const irep_idt &entry_function_symbol_id,
124124
class symbol_tablet &symbol_table)=0;
125125

126126
// constructor / destructor

0 commit comments

Comments
 (0)