Skip to content

Commit

Permalink
Remove returns: support running per-function
Browse files Browse the repository at this point in the history
This converts functions from conventional to via-global-variable return style
on a function-by-function basis. It results in some complication, as the globals
are now seen by the language's final pass, meaning it must ignore them for initialisation
purposes, and we must cope with functions not having their "true" type while other functions
are still being loaded.

One test in cbmc-java failed because it was written in C, which we don't adapt to support
incremental loading yet, so it is moved to the cbmc test directory, where it can still achieve
its goal of checking whether uncaught_exceptions_analysist can tolerate CPROVER_assert and
similar builtins, since cbmc also runs the remove_exceptions pass.
  • Loading branch information
smowton committed Jan 23, 2018
1 parent fd6e195 commit a7595c1
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 93 deletions.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions src/goto-programs/lazy_goto_functions_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ class lazy_goto_functions_mapt final
return ensure_function_loaded_internal(name).second;
}

/// Determines if this lazy GOTO functions map can produce a body for the
/// given function
/// \param name: function ID to query
/// \return true if we can produce a function body, or false if we would leave
/// it a bodyless stub.
bool can_produce_function(const key_type &name) const
{
return language_files.can_convert_lazy_method(name);
}

void unload(const key_type &name) const { goto_functions.erase(name); }

void ensure_function_loaded(const key_type &name) const
Expand Down
9 changes: 7 additions & 2 deletions src/goto-programs/lazy_goto_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lazy_goto_modelt::lazy_goto_modelt(
[this] (goto_functionst::goto_functiont &function) -> void
{
goto_model_functiont model_function(*goto_model, function);
this->post_process_function(model_function);
this->post_process_function(model_function, *this);
},
message_handler),
post_process_function(std::move(post_process_function)),
Expand All @@ -51,7 +51,7 @@ lazy_goto_modelt::lazy_goto_modelt(lazy_goto_modelt &&other)
[this] (goto_functionst::goto_functiont &function) -> void
{
goto_model_functiont model_function(*goto_model, function);
this->post_process_function(model_function);
this->post_process_function(model_function, *this);
},
other.message_handler),
language_files(std::move(other.language_files)),
Expand Down Expand Up @@ -239,3 +239,8 @@ bool lazy_goto_modelt::finalize()

return post_process_functions(*goto_model);
}

bool lazy_goto_modelt::can_produce_function(const irep_idt &id) const
{
return goto_functions.can_produce_function(id);
}
27 changes: 20 additions & 7 deletions src/goto-programs/lazy_goto_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@
class cmdlinet;
class optionst;

/// Interface for a provider of function definitions to report whether or not it
/// can provide a definition (function body) for a given function ID.
struct can_produce_functiont
{
/// Determines if this function provider can produce a body for the given
/// function
/// \param id: function ID to query
/// \return true if we can produce a function body, or false if we would leave
/// it a bodyless stub.
virtual bool can_produce_function(const irep_idt &id) const = 0;
};

/// Model that holds partially loaded map of functions
class lazy_goto_modelt
class lazy_goto_modelt : public can_produce_functiont
{
public:
typedef std::function<void(goto_model_functiont &function)>
typedef std::function<
void(goto_model_functiont &function, const can_produce_functiont &)>
post_process_functiont;
typedef std::function<bool(goto_modelt &goto_model)> post_process_functionst;

Expand Down Expand Up @@ -51,12 +64,10 @@ class lazy_goto_modelt
message_handlert &message_handler)
{
return lazy_goto_modelt(
[&handler] (goto_model_functiont &function)
{
handler.process_goto_function(function);
[&handler] (goto_model_functiont &fun, const can_produce_functiont &cpf) { // NOLINT(*)
handler.process_goto_function(fun, cpf);
},
[&handler, &options] (goto_modelt &goto_model) -> bool
{
[&handler, &options] (goto_modelt &goto_model) -> bool { // NOLINT(*)
return handler.process_goto_functions(goto_model, options);
},
message_handler);
Expand Down Expand Up @@ -88,6 +99,8 @@ class lazy_goto_modelt
return std::move(model.goto_model);
}

virtual bool can_produce_function(const irep_idt &id) const;

private:
std::unique_ptr<goto_modelt> goto_model;

Expand Down
Loading

0 comments on commit a7595c1

Please sign in to comment.