Skip to content

Commit 024fc50

Browse files
author
Daniel Kroening
committed
compilet can now use a goto_modelt
1 parent 25f568d commit 024fc50

File tree

4 files changed

+69
-82
lines changed

4 files changed

+69
-82
lines changed

src/goto-cc/compile.cpp

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Date: June 2006
7676
/// \return true on error, false otherwise
7777
bool compilet::doit()
7878
{
79-
compiled_functions.clear();
79+
goto_model.goto_functions.clear();
8080

8181
add_compiler_specific_defines(config);
8282

@@ -346,13 +346,12 @@ bool compilet::link()
346346
{
347347
// "compile" hitherto uncompiled functions
348348
statistics() << "Compiling functions" << eom;
349-
convert_symbols(compiled_functions);
349+
convert_symbols(goto_model.goto_functions);
350350

351351
// parse object files
352352
for(const auto &file_name : object_files)
353353
{
354-
if(read_object_and_link(file_name, symbol_table,
355-
compiled_functions, get_message_handler()))
354+
if(read_object_and_link(file_name, goto_model, get_message_handler()))
356355
return true;
357356
}
358357

@@ -363,23 +362,23 @@ bool compilet::link()
363362
// new symbols may have been added to a previously linked file
364363
// make sure a new entry point is created that contains all
365364
// static initializers
366-
compiled_functions.function_map.erase(INITIALIZE_FUNCTION);
365+
goto_model.goto_functions.function_map.erase(INITIALIZE_FUNCTION);
367366

368-
symbol_table.remove(goto_functionst::entry_point());
369-
compiled_functions.function_map.erase(goto_functionst::entry_point());
367+
goto_model.symbol_table.remove(goto_functionst::entry_point());
368+
goto_model.goto_functions.function_map.erase(
369+
goto_functionst::entry_point());
370370

371-
if(ansi_c_entry_point(symbol_table, get_message_handler()))
371+
if(ansi_c_entry_point(goto_model.symbol_table, get_message_handler()))
372372
return true;
373373

374374
// entry_point may (should) add some more functions.
375-
convert_symbols(compiled_functions);
375+
convert_symbols(goto_model.goto_functions);
376376
}
377377

378-
if(write_object_file(
379-
output_file_executable, symbol_table, compiled_functions))
378+
if(write_object_file(output_file_executable, goto_model))
380379
return true;
381380

382-
return add_written_cprover_symbols(symbol_table);
381+
return add_written_cprover_symbols(goto_model.symbol_table);
383382
}
384383

385384
/// parses source files and writes object files, or keeps the symbols in the
@@ -419,7 +418,7 @@ bool compilet::compile()
419418
// output an object file for every source file
420419

421420
// "compile" functions
422-
convert_symbols(compiled_functions);
421+
convert_symbols(goto_model.goto_functions);
423422

424423
std::string cfn;
425424

@@ -436,14 +435,13 @@ bool compilet::compile()
436435
else
437436
cfn = output_file_object;
438437

439-
if(write_object_file(cfn, symbol_table, compiled_functions))
438+
if(write_object_file(cfn, goto_model))
440439
return true;
441440

442-
if(add_written_cprover_symbols(symbol_table))
441+
if(add_written_cprover_symbols(goto_model.symbol_table))
443442
return true;
444443

445-
symbol_table.clear(); // clean symbol table for next source file.
446-
compiled_functions.clear();
444+
goto_model.clear(); // clean symbol table for next source file.
447445
}
448446
}
449447

@@ -582,10 +580,9 @@ bool compilet::parse_stdin()
582580
/// \return true on error, false otherwise
583581
bool compilet::write_object_file(
584582
const std::string &file_name,
585-
const symbol_tablet &lsymbol_table,
586-
goto_functionst &functions)
583+
const goto_modelt &goto_model)
587584
{
588-
return write_bin_object_file(file_name, lsymbol_table, functions);
585+
return write_bin_object_file(file_name, goto_model);
589586
}
590587

591588
/// writes the goto functions in the function table to a binary format object
@@ -594,15 +591,14 @@ bool compilet::write_object_file(
594591
/// \return true on error, false otherwise
595592
bool compilet::write_bin_object_file(
596593
const std::string &file_name,
597-
const symbol_tablet &lsymbol_table,
598-
goto_functionst &functions)
594+
const goto_modelt &goto_model)
599595
{
600596
statistics() << "Writing binary format object `"
601597
<< file_name << "'" << eom;
602598

603599
// symbols
604-
statistics() << "Symbols in table: "
605-
<< lsymbol_table.symbols.size() << eom;
600+
statistics() << "Symbols in table: " << goto_model.symbol_table.symbols.size()
601+
<< eom;
606602

607603
std::ofstream outfile(file_name, std::ios::binary);
608604

@@ -612,12 +608,12 @@ bool compilet::write_bin_object_file(
612608
return true;
613609
}
614610

615-
if(write_goto_binary(outfile, lsymbol_table, functions))
611+
if(write_goto_binary(outfile, goto_model))
616612
return true;
617613

618-
const auto cnt = function_body_count(functions);
614+
const auto cnt = function_body_count(goto_model.goto_functions);
619615

620-
statistics() << "Functions: " << functions.function_map.size()
616+
statistics() << "Functions: " << goto_model.goto_functions.function_map.size()
621617
<< "; " << cnt << " have a body." << eom;
622618

623619
outfile.close();
@@ -637,13 +633,13 @@ bool compilet::parse_source(const std::string &file_name)
637633
return true;
638634

639635
// we just typecheck one file here
640-
if(language_files.typecheck(symbol_table))
636+
if(language_files.typecheck(goto_model.symbol_table))
641637
{
642638
error() << "CONVERSION ERROR" << eom;
643639
return true;
644640
}
645641

646-
if(language_files.final(symbol_table))
642+
if(language_files.final(goto_model.symbol_table))
647643
{
648644
error() << "CONVERSION ERROR" << eom;
649645
return true;
@@ -655,7 +651,10 @@ bool compilet::parse_source(const std::string &file_name)
655651
/// constructor
656652
/// \return nothing
657653
compilet::compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
658-
: messaget(mh), ns(symbol_table), cmdline(_cmdline), warning_is_fatal(Werror)
654+
: messaget(mh),
655+
ns(goto_model.symbol_table),
656+
cmdline(_cmdline),
657+
warning_is_fatal(Werror)
659658
{
660659
mode=COMPILE_LINK_EXECUTABLE;
661660
echo_file_name=false;
@@ -693,28 +692,29 @@ void compilet::add_compiler_specific_defines(configt &config) const
693692

694693
void compilet::convert_symbols(goto_functionst &dest)
695694
{
696-
goto_convert_functionst converter(symbol_table, get_message_handler());
695+
goto_convert_functionst converter(
696+
goto_model.symbol_table, get_message_handler());
697697

698698
// the compilation may add symbols!
699699

700700
symbol_tablet::symbolst::size_type before=0;
701701

702-
while(before!=symbol_table.symbols.size())
702+
while(before != goto_model.symbol_table.symbols.size())
703703
{
704-
before=symbol_table.symbols.size();
704+
before = goto_model.symbol_table.symbols.size();
705705

706706
typedef std::set<irep_idt> symbols_sett;
707707
symbols_sett symbols;
708708

709-
for(const auto &named_symbol : symbol_table.symbols)
709+
for(const auto &named_symbol : goto_model.symbol_table.symbols)
710710
symbols.insert(named_symbol.first);
711711

712712
// the symbol table iterators aren't stable
713713
for(const auto &symbol : symbols)
714714
{
715715
symbol_tablet::symbolst::const_iterator s_it =
716-
symbol_table.symbols.find(symbol);
717-
CHECK_RETURN(s_it != symbol_table.symbols.end());
716+
goto_model.symbol_table.symbols.find(symbol);
717+
CHECK_RETURN(s_it != goto_model.symbol_table.symbols.end());
718718

719719
if(s_it->second.type.id()==ID_code &&
720720
!s_it->second.is_macro &&
@@ -724,7 +724,8 @@ void compilet::convert_symbols(goto_functionst &dest)
724724
{
725725
debug() << "Compiling " << s_it->first << eom;
726726
converter.convert_function(s_it->first, dest.function_map[s_it->first]);
727-
symbol_table.get_writeable_ref(symbol).value = exprt("compiled");
727+
goto_model.symbol_table.get_writeable_ref(symbol).value =
728+
exprt("compiled");
728729
}
729730
}
730731
}

src/goto-cc/compile.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Date: June 2006
1717
#include <util/cmdline.h>
1818
#include <util/message.h>
1919
#include <util/rename_symbol.h>
20-
#include <util/symbol_table.h>
2120

2221
#include <goto-programs/goto_model.h>
2322

@@ -28,8 +27,7 @@ class compilet : public messaget
2827
public:
2928
// compilation results
3029
namespacet ns;
31-
symbol_tablet symbol_table;
32-
goto_functionst compiled_functions;
30+
goto_modelt goto_model;
3331

3432
// configuration
3533
bool echo_file_name;
@@ -73,15 +71,9 @@ class compilet : public messaget
7371

7472
bool parse_source(const std::string &);
7573

76-
bool write_object_file(
77-
const std::string &,
78-
const symbol_tablet &,
79-
goto_functionst &);
74+
bool write_object_file(const std::string &, const goto_modelt &);
8075

81-
bool write_bin_object_file(
82-
const std::string &,
83-
const symbol_tablet &,
84-
goto_functionst &);
76+
bool write_bin_object_file(const std::string &, const goto_modelt &);
8577

8678
/// \brief Has this compiler written any object files?
8779
bool wrote_object_files() const { return wrote_object; }

src/goto-cc/linker_script_merge.cpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ int linker_script_merget::add_linker_script_definitions()
3232

3333
temporary_filet linker_def_outfile("goto-cc-linker-info", ".json");
3434
std::list<irep_idt> linker_defined_symbols;
35-
int fail=
36-
get_linker_script_data(
37-
linker_defined_symbols,
38-
compiler.symbol_table,
39-
elf_binary,
40-
linker_def_outfile());
35+
int fail = get_linker_script_data(
36+
linker_defined_symbols,
37+
compiler.goto_model.symbol_table,
38+
elf_binary,
39+
linker_def_outfile());
4140
// ignore linker script parsing failures until the code is tested more widely
4241
if(fail!=0)
4342
return 0;
@@ -58,11 +57,10 @@ int linker_script_merget::add_linker_script_definitions()
5857
return fail;
5958
}
6059

61-
symbol_tablet original_st;
62-
goto_functionst original_gf;
60+
goto_modelt original_goto_model;
6361

64-
fail=read_goto_binary(goto_binary, original_st, original_gf,
65-
get_message_handler());
62+
fail =
63+
read_goto_binary(goto_binary, original_goto_model, get_message_handler());
6664

6765
if(fail!=0)
6866
{
@@ -72,19 +70,20 @@ int linker_script_merget::add_linker_script_definitions()
7270

7371
fail=1;
7472
linker_valuest linker_values;
75-
const auto &pair=original_gf.function_map.find(INITIALIZE_FUNCTION);
76-
if(pair==original_gf.function_map.end())
73+
const auto &pair =
74+
original_goto_model.goto_functions.function_map.find(INITIALIZE_FUNCTION);
75+
if(pair == original_goto_model.goto_functions.function_map.end())
7776
{
7877
error() << "No " << INITIALIZE_FUNCTION << " found in goto_functions"
7978
<< eom;
8079
return fail;
8180
}
82-
fail=ls_data2instructions(
83-
data,
84-
cmdline.get_value('T'),
85-
pair->second.body,
86-
original_st,
87-
linker_values);
81+
fail = ls_data2instructions(
82+
data,
83+
cmdline.get_value('T'),
84+
pair->second.body,
85+
original_goto_model.symbol_table,
86+
linker_values);
8887
if(fail!=0)
8988
{
9089
error() << "Could not add linkerscript defs to " INITIALIZE_FUNCTION << eom;
@@ -98,16 +97,15 @@ int linker_script_merget::add_linker_script_definitions()
9897
// The keys of linker_values are exactly the elements of
9998
// linker_defined_symbols, so iterate over linker_values from now on.
10099

101-
fail=pointerize_linker_defined_symbols(original_gf, original_st,
102-
linker_values);
100+
fail = pointerize_linker_defined_symbols(original_goto_model, linker_values);
103101

104102
if(fail!=0)
105103
{
106104
error() << "Could not pointerize all linker-defined expressions" << eom;
107105
return fail;
108106
}
109107

110-
fail=compiler.write_object_file(goto_binary, original_st, original_gf);
108+
fail = compiler.write_object_file(goto_binary, original_goto_model);
111109

112110
if(fail!=0)
113111
error() << "Could not write linkerscript-augmented binary" << eom;
@@ -185,17 +183,16 @@ linker_script_merget::linker_script_merget(
185183
{}
186184

187185
int linker_script_merget::pointerize_linker_defined_symbols(
188-
goto_functionst &goto_functions,
189-
symbol_tablet &symbol_table,
190-
const linker_valuest &linker_values)
186+
goto_modelt &goto_model,
187+
const linker_valuest &linker_values)
191188
{
192-
const namespacet ns(symbol_table);
189+
const namespacet ns(goto_model.symbol_table);
193190

194191
int ret=0;
195192
// First, pointerize the actual linker-defined symbols
196193
for(const auto &pair : linker_values)
197194
{
198-
const auto maybe_symbol=symbol_table.get_writeable(pair.first);
195+
const auto maybe_symbol = goto_model.symbol_table.get_writeable(pair.first);
199196
if(!maybe_symbol)
200197
continue;
201198
symbolt &entry=*maybe_symbol;
@@ -206,7 +203,7 @@ int linker_script_merget::pointerize_linker_defined_symbols(
206203

207204
// Next, find all occurrences of linker-defined symbols that are _values_
208205
// of some symbol in the symbol table, and pointerize them too
209-
for(const auto &pair : symbol_table.symbols)
206+
for(const auto &pair : goto_model.symbol_table.symbols)
210207
{
211208
std::list<symbol_exprt> to_pointerize;
212209
symbols_to_pointerize(linker_values, pair.second.value, to_pointerize);
@@ -215,8 +212,8 @@ int linker_script_merget::pointerize_linker_defined_symbols(
215212
continue;
216213
debug() << "Pointerizing the symbol-table value of symbol " << pair.first
217214
<< eom;
218-
int fail=pointerize_subexprs_of(
219-
symbol_table.get_writeable_ref(pair.first).value,
215+
int fail = pointerize_subexprs_of(
216+
goto_model.symbol_table.get_writeable_ref(pair.first).value,
220217
to_pointerize,
221218
linker_values,
222219
ns);
@@ -232,7 +229,7 @@ int linker_script_merget::pointerize_linker_defined_symbols(
232229

233230
// Finally, pointerize all occurrences of linker-defined symbols in the
234231
// goto program
235-
for(auto &gf : goto_functions.function_map)
232+
for(auto &gf : goto_model.goto_functions.function_map)
236233
{
237234
goto_programt &program=gf.second.body;
238235
Forall_goto_program_instructions(iit, program)

src/goto-cc/linker_script_merge.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,7 @@ class linker_script_merget:public messaget
156156
/// \post Expressions of the shape `&foo[0]`, `&foo`, and `foo`, where `foo`
157157
/// is a linker-script defined symbol with type array, have been
158158
/// converted to `foo` whose type is `char*`.
159-
int pointerize_linker_defined_symbols(
160-
goto_functionst &goto_functions,
161-
symbol_tablet &symbol_table,
162-
const linker_valuest &linker_values);
159+
int pointerize_linker_defined_symbols(goto_modelt &, const linker_valuest &);
163160

164161
/// \param expr an expr whose subexpressions may need to be pointerized
165162
/// \param to_pointerize The symbols that are contained in the subexpressions

0 commit comments

Comments
 (0)