Go to the documentation of this file.
33 main_arguments.resize(parameters.size());
35 for(std::size_t param_number=0;
36 param_number<parameters.size();
49 object_factory_parameters,
53 return main_arguments;
61 bool has_return_value =
76 for(
const auto &p : parameters)
78 if(p.get_identifier().empty())
81 irep_idt identifier=p.get_identifier();
85 if(symbol.
type.
id()==ID_pointer)
87 codet output(ID_output);
98 init_code.
add(std::move(output));
121 std::list<irep_idt> matches;
123 for(
const auto &symbol_name_entry :
127 symbol_tablet::symbolst::const_iterator s_it =
128 symbol_table.
symbols.find(symbol_name_entry.second);
130 if(s_it==symbol_table.
symbols.end())
133 if(s_it->second.type.id() == ID_code && !s_it->second.is_property)
134 matches.push_back(symbol_name_entry.second);
140 message.
error() <<
"main symbol '" <<
config.
main.value() <<
"' not found"
145 if(matches.size()>=2)
153 main_symbol=matches.front();
159 symbol_tablet::symbolst::const_iterator s_it=
160 symbol_table.
symbols.find(main_symbol);
162 if(s_it==symbol_table.
symbols.end())
165 const symbolt &symbol=s_it->second;
179 symbol, symbol_table, message_handler, object_factory_parameters);
206 symbol_tablet::symbolst::const_iterator init_it=
209 if(init_it==symbol_table.
symbols.end())
220 init_code.
add(std::move(call_init));
232 return_symbol.
mode=ID_C;
234 return_symbol.
name=
"return'";
238 symbol_table.
add(return_symbol);
245 if(symbol.
name==ID_main)
247 if(parameters.empty())
258 parameters.size() >= 2 && parameters[1].type().id() == ID_pointer &&
259 (parameters.size() == 2 ||
260 (parameters.size() == 3 && parameters[2].type().id() == ID_pointer)))
268 argc_symbol.
name =
"argc'";
272 argc_symbol.
mode = ID_C;
274 auto r = symbol_table.
insert(argc_symbol);
275 if(!
r.second &&
r.first != argc_symbol)
278 message.
error() <<
"argc already exists but is not usable"
297 argv_symbol.
name =
"argv'";
298 argv_symbol.
type = argv_type;
301 argv_symbol.
mode = ID_C;
303 auto r = symbol_table.
insert(argv_symbol);
304 if(!
r.second &&
r.first != argv_symbol)
307 message.
error() <<
"argv already exists but is not usable"
325 argc_symbol.
symbol_expr(), ID_ge, std::move(zero));
336 argc_symbol.
symbol_expr(), ID_le, std::move(bound_expr));
344 if(parameters.size()==3)
348 envp_size_symbol.
base_name =
"envp_size'";
349 envp_size_symbol.
name =
"envp_size'";
352 envp_size_symbol.
mode = ID_C;
354 if(!symbol_table.
insert(std::move(envp_size_symbol)).second)
368 envp_symbol.
name =
"envp'";
372 envp_symbol.
mode = ID_C;
374 if(!symbol_table.
insert(std::move(envp_symbol)).second)
389 envp_size_symbol.
symbol_expr(), ID_le, std::move(max_minus_one));
427 init_code.
statements().back().add_source_location().add_pragma(
428 "disable:bounds-check");
431 if(parameters.size()==3)
450 init_code.
statements().back().add_source_location().add_pragma(
451 "disable:bounds-check");
457 if(parameters.size()==3)
462 exprt &op0=operands[0];
463 exprt &op1=operands[1];
483 if(parameters.size()==3)
503 const std::string main_signature =
type2c(symbol.
type, ns);
506 message.
error() <<
"'main' with signature '" << main_signature
508 <<
" but expecting one of:\n"
509 <<
" int main(void)\n"
510 <<
" int main(int argc, char *argv[])\n"
511 <<
" int main(int argc, char *argv[], char *envp[])\n"
512 <<
"If this is a non-standard main entry point please "
514 <<
"entry function and use --function instead"
523 parameters, init_code, symbol_table, object_factory_parameters);
526 init_code.
add(std::move(call_main));
534 for(
const auto &symbol_table_entry : symbol_table.
symbols)
536 const symbolt &symbol = symbol_table_entry.second;
538 if(symbol.
type.
id() != ID_code)
548 init_code.
add(std::move(destructor_call));
561 if(!symbol_table.
insert(std::move(new_symbol)).second)
Class that provides messages with a built-in verbosity 'level'.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
A codet representing sequential composition of program statements.
static exprt conditional_cast(const exprt &expr, const typet &type)
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
const symbol_base_mapt & symbol_base_map
Read-only field, used to look up symbol names given their base names.
@ AUTOMATIC_LOCAL
Allocate local objects with automatic lifetime.
std::vector< parametert > parameterst
typet type
Type of symbol.
const integer_bitvector_typet & to_integer_bitvector_type(const typet &type)
Cast a typet to an integer_bitvector_typet.
optionalt< std::string > main
void add_pragma(const irep_idt &pragma)
The plus expression Associativity is not specified.
symbol_exprt c_nondet_symbol_factory(code_blockt &init_code, symbol_tablet &symbol_table, const irep_idt base_name, const typet &type, const source_locationt &loc, const c_object_factory_parameterst &object_factory_parameters, const lifetimet lifetime)
Creates a symbol and generates code so that it can vary over all possible values for its type.
Base class for all expressions.
irep_idt base_name
Base (non-scoped) name.
exprt::operandst build_function_environment(const code_typet::parameterst ¶meters, code_blockt &init_code, symbol_tablet &symbol_table, const c_object_factory_parameterst &object_factory_parameters)
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Internally generated symbol table entry.
struct configt::ansi_ct ansi_c
bitvector_typet index_type()
void record_function_outputs(const symbolt &function, code_blockt &init_code, symbol_tablet &symbol_table)
code_operandst & statements()
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
A goto_instruction_codet representing the declaration that an output of a particular description has ...
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
goto_instruction_codet representation of a function call statement.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
irep_idt mode
Language mode.
const irep_idt & get_base_name() const
signedbv_typet signed_int_type()
The null pointer constant.
const std::string & id2string(const irep_idt &d)
source_locationt source_location
codet representation of a label for branch targets.
#define PRECONDITION(CONDITION)
An assumption, which must hold in subsequent code.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
#define INITIALIZE_FUNCTION
optionalt< mp_integer > max_argc
Maximum value of argc, which is operating-systems dependent: Windows limits the number of characters ...
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
pointer_typet pointer_type(const typet &subtype)
A codet representing an assignment in the program.
const irep_idt & id() const
std::vector< exprt > operandst
void add(const codet &code)
bool generate_ansi_c_start_function(const symbolt &symbol, symbol_tablet &symbol_table, message_handlert &message_handler, const c_object_factory_parameterst &object_factory_parameters)
Generate a _start function for a specific function.
const parameterst & parameters() const
bool ansi_c_entry_point(symbol_tablet &symbol_table, message_handlert &message_handler, const c_object_factory_parameterst &object_factory_parameters)
bitvector_typet char_type()
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
exprt value
Initial value of symbol.
A codet representing a skip statement.
source_locationt location
Source code location of definition of symbol.
static optionalt< codet > static_lifetime_init(const irep_idt &identifier, symbol_tablet &symbol_table)
const symbolst & symbols
Read-only field, used to look up symbols given their names.
A base class for relations, i.e., binary predicates whose two operands have the same type.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
mp_integer largest() const
Return the largest value that can be represented using this type.
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
const typet & return_type() const
std::string type2c(const typet &type, const namespacet &ns, const expr2c_configurationt &configuration)
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
Operator to return the address of an object.
source_locationt & add_source_location()
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
unsignedbv_typet size_type()
const source_locationt & source_location() const
typet index_type() const
The type of the index expressions into any instance of this type.
irep_idt name
The unique identifier.
const typet & element_type() const
The type of the elements of the array.
Data structure for representing an arbitrary statement in a program.
ranget< typename multimapt::const_iterator > equal_range(const multimapt &multimap, const typename multimapt::key_type &key)
Utility function to make equal_range method of multimap easier to use by returning a ranget object.