31 main_arguments.resize(parameters.size());
33 for(std::size_t param_number=0;
34 param_number<parameters.size();
47 object_factory_parameters,
51 return main_arguments;
59 bool has_return_value =
74 for(
const auto &p : parameters)
76 if(p.get_identifier().empty())
79 irep_idt identifier=p.get_identifier();
83 if(symbol.
type.
id()==ID_pointer)
85 codet output(ID_output);
96 init_code.
add(std::move(output));
119 std::list<irep_idt> matches;
125 symbol_tablet::symbolst::const_iterator s_it=
126 symbol_table.
symbols.find(it->second);
128 if(s_it==symbol_table.
symbols.end())
131 if(s_it->second.type.id()==ID_code)
132 matches.push_back(it->second);
143 if(matches.size()>=2)
151 main_symbol=matches.front();
157 symbol_tablet::symbolst::const_iterator s_it=
158 symbol_table.
symbols.find(main_symbol);
160 if(s_it==symbol_table.
symbols.end())
163 const symbolt &symbol=s_it->second;
177 symbol, symbol_table, message_handler, object_factory_parameters);
204 symbol_tablet::symbolst::const_iterator init_it=
207 if(init_it==symbol_table.
symbols.end())
218 init_code.
add(std::move(call_init));
230 return_symbol.
mode=ID_C;
232 return_symbol.
name=
"return'";
236 symbol_table.
add(return_symbol);
243 if(symbol.
name==ID_main)
245 if(parameters.empty())
249 else if(parameters.size()==2 || parameters.size()==3)
257 argc_symbol.
name =
"argc'";
261 argc_symbol.
mode = ID_C;
263 auto r = symbol_table.
insert(argc_symbol);
264 if(!
r.second &&
r.first != argc_symbol)
267 message.error() <<
"argc already exists but is not usable"
286 argv_symbol.
name =
"argv'";
287 argv_symbol.
type = argv_type;
290 argv_symbol.
mode = ID_C;
292 auto r = symbol_table.
insert(argv_symbol);
293 if(!
r.second &&
r.first != argv_symbol)
296 message.error() <<
"argv already exists but is not usable"
322 argc_symbol.
symbol_expr(), ID_le, std::move(bound_expr));
330 if(parameters.size()==3)
334 envp_size_symbol.
base_name =
"envp_size'";
335 envp_size_symbol.
name =
"envp_size'";
338 envp_size_symbol.
mode = ID_C;
340 if(!symbol_table.
insert(std::move(envp_size_symbol)).second)
354 envp_symbol.
name =
"envp'";
358 envp_symbol.
mode = ID_C;
360 if(!symbol_table.
insert(std::move(envp_symbol)).second)
375 envp_size_symbol.
symbol_expr(), ID_le, std::move(max_minus_one));
410 index_expr.set(
"bounds_check",
false);
415 if(parameters.size()==3)
426 index_expr.set(
"bounds_check",
false);
436 if(parameters.size()==3)
441 exprt &op0=operands[0];
442 exprt &op1=operands[1];
452 index_expr.
set(
"bounds_check",
false);
462 if(parameters.size()==3)
480 const std::string main_signature =
type2c(symbol.
type, ns);
482 "'main' with signature '" + main_signature +
484 " but expecting one of:\n"
486 " int main(int argc, char *argv[])\n"
487 " int main(int argc, char *argv[], char *envp[])\n"
488 "If this is a non-standard main entry point please provide a custom\n"
489 "entry function and point to it via cbmc --function instead"};
496 parameters, init_code, symbol_table, object_factory_parameters);
499 init_code.
add(std::move(call_main));
513 if(!symbol_table.
insert(std::move(new_symbol)).second)
@ AUTOMATIC_LOCAL
Allocate local objects with automatic lifetime.
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)
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.
void record_function_outputs(const symbolt &function, code_blockt &init_code, symbol_tablet &symbol_table)
bool ansi_c_entry_point(symbol_tablet &symbol_table, message_handlert &message_handler, const c_object_factory_parameterst &object_factory_parameters)
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.
bitvector_typet index_type()
unsignedbv_typet size_type()
signedbv_typet signed_int_type()
pointer_typet pointer_type(const typet &subtype)
bitvector_typet char_type()
Operator to return the address of an object.
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
A base class for relations, i.e., binary predicates whose two operands have the same type.
A codet representing an assignment in the program.
An assumption, which must hold in subsequent code.
A codet representing sequential composition of program statements.
void add(const codet &code)
codet representation of a function call statement.
codet representation of a label for branch targets.
A codet representing the declaration that an output of a particular description has a value which cor...
A codet representing a skip statement.
const irep_idt & get_base_name() const
std::vector< parametert > parameterst
const typet & return_type() const
const parameterst & parameters() const
Data structure for representing an arbitrary statement in a program.
optionalt< std::string > main
struct configt::ansi_ct ansi_c
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
std::vector< exprt > operandst
source_locationt & add_source_location()
const source_locationt & source_location() const
typet & type()
Return the type of the expression.
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
mp_integer largest() const
Return the largest value that can be represented using this type.
Thrown when we can't handle something in an input source file.
void set(const irep_namet &name, const irep_idt &value)
const irep_idt & id() const
Class that provides messages with a built-in verbosity 'level'.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
The null pointer constant.
The plus expression Associativity is not specified.
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
const symbol_base_mapt & symbol_base_map
Read-only field, used to look up symbol names given their base names.
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
irep_idt base_name
Base (non-scoped) name.
source_locationt location
Source code location of definition of symbol.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
exprt value
Initial value of symbol.
irep_idt mode
Language mode.
static exprt conditional_cast(const exprt &expr, const typet &type)
const typet & subtype() const
std::string type2c(const typet &type, const namespacet &ns, const expr2c_configurationt &configuration)
Goto Programs with Functions.
const std::string & id2string(const irep_idt &d)
API to expression classes for Pointers.
#define PRECONDITION(CONDITION)
static optionalt< codet > static_lifetime_init(const irep_idt &identifier, symbol_tablet &symbol_table)
#define INITIALIZE_FUNCTION
static const char * message(const statust &status)
Makes a status message string from a status.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const integer_bitvector_typet & to_integer_bitvector_type(const typet &type)
Cast a typet to an integer_bitvector_typet.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
#define forall_symbol_base_map(it, expr, base_name)