11#ifndef MCRL2_DATA_DETAIL_REWR_JITTYC_PREAMBLE_H
12#define MCRL2_DATA_DETAIL_REWR_JITTYC_PREAMBLE_H
14#include "mcrl2/utilities/toolset_version_const.h"
15#include "mcrl2/utilities/export.h"
16#include "mcrl2/data/detail/rewrite/jitty_jittyc.h"
17#include "mcrl2/data/detail/rewrite/jittyc.h"
20using namespace mcrl2::
data;
28 MCRL2_EXPORT bool init(rewriter_interface* i, RewriterCompilingJitty* this_rewriter);
33template <
class REWRITE_TERM>
36 return t.normal_form();
39template <
class REWRITE_TERM>
42 t.normal_form(result);
60template <
bool ARGUMENTS_IN_NORMAL_FORM>
62template <
bool ARGUMENTS_IN_NORMAL_FORM>
68 RewriterCompilingJitty* this_rewriter)
70 rewrite_aux<
true>(result, t, this_rewriter);
76 rewrite_aux<
false>(result, t, this_rewriter);
83using rewriter_function =
void (*)(
data_expression&,
const application&, RewriterCompilingJitty*);
101 data_expression& local_store = this_rewriter->m_rewrite_stack.new_stack_position<data_expression>();
102 rewrite_aux<
false>(local_store, m_term, this_rewriter);
108 rewrite_aux<
false>(result, m_term, this_rewriter);
114template <
class TERM_TO_BE_REWRITTEN>
124 const variable_list& variables,
125 const TERM_TO_BE_REWRITTEN& body,
126 RewriterCompilingJitty* tr)
132 data_expression& t = this_rewriter->m_rewrite_stack.new_stack_position<data_expression>();
134 data_expression& result = this_rewriter->m_rewrite_stack.new_stack_position<data_expression>();
135 rewrite_abstraction_aux<
false>(result, atermpp::down_cast<abstraction>(t),t,this_rewriter);
141 local_rewrite(result,
m_body);
143 rewrite_abstraction_aux<
true>(result, atermpp::down_cast<abstraction>(result),result,this_rewriter);
159 rewrite_aux<
false>(result, arg, this_rewriter);
183 return atermpp::detail::index_traits<function_symbol, function_symbol_key_type, 2>::index(func);
189 return *(this_rewriter->global_sigma);
195 return reinterpret_cast<uintptr_t>(atermpp::detail::address(t));
202template <
bool ARGUMENTS_IN_NORMAL_FORM>
205 const std::size_t arity,
206 RewriterCompilingJitty* this_rewriter)
208 const std::size_t index = get_index(f);
209 if (index>=this_rewriter->index_bound || arity>=this_rewriter->arity_bound)
213 if (ARGUMENTS_IN_NORMAL_FORM)
215 assert(this_rewriter -> arity_bound * index + arity<this_rewriter->functions_when_arguments_are_in_normal_form.size());
216 return this_rewriter->functions_when_arguments_are_in_normal_form[this_rewriter->arity_bound * index + arity];
220 assert(this_rewriter->arity_bound * index + arity<this_rewriter->functions_when_arguments_are_not_in_normal_form.size());
221 return this_rewriter->functions_when_arguments_are_not_in_normal_form[this_rewriter->arity_bound * index + arity];
225template <
bool ARGUMENTS_IN_NORMAL_FORM>
232 this_rewriter->rewrite_lambda_application(result, a, sigma(this_rewriter), ARGUMENTS_IN_NORMAL_FORM);
238 this_rewriter->existential_quantifier_enumeration(result, head, sigma(this_rewriter));
243 this_rewriter->universal_quantifier_enumeration(result, head, sigma(this_rewriter));
250template <
bool ARGUMENTS_IN_NORMAL_FORM>
258 const std::size_t arity=recursive_number_of_args(t);
259 const rewriter_function f = get_precompiled_rewrite_function<ARGUMENTS_IN_NORMAL_FORM>(atermpp::down_cast<function_symbol>(thead),arity,this_rewriter);
262 f(result, t, this_rewriter);
266 make_application(result, t.head(), t.begin(), t.end(), rewrite_functor(this_rewriter));
274 head=sigma(this_rewriter)(down_cast<
const variable>(head0));
276 rewrite_all_arguments(result, t, rewrite_functor(this_rewriter),
true);
277 const application t1=atermpp::down_cast<application>(replace_nested_head(result, head));
278 rewrite_appl_aux<
true>(result, t1, this_rewriter);
283 this_rewriter->rewrite_where(head, atermpp::down_cast<where_clause>(head0), sigma(this_rewriter));
284 rewrite_all_arguments(result, t, rewrite_functor(this_rewriter),
true);
285 const application t1=atermpp::down_cast<application>(replace_nested_head(result, head));
286 rewrite_appl_aux<
true>(result, t1, this_rewriter);
295 if constexpr (ARGUMENTS_IN_NORMAL_FORM)
301 rewrite_all_arguments(result, t, rewrite_functor(this_rewriter),
true);
308 rewrite_abstraction_aux<ARGUMENTS_IN_NORMAL_FORM>(result, ha,t,this_rewriter);
312template <
bool ARGUMENTS_IN_NORMAL_FORM>
324 const std::size_t index = get_index(down_cast<function_symbol>(t));
325 if (index<this_rewriter->normal_forms_for_constants.size())
329 result.unprotected_assign<
false>(this_rewriter->normal_forms_for_constants[index]);
343 const application& appl = down_cast<application>(t);
347 const std::size_t appl_size=appl.size();
348 const rewriter_function f = get_precompiled_rewrite_function<ARGUMENTS_IN_NORMAL_FORM>(down_cast<function_symbol>(head), appl_size, this_rewriter);
351 f(result, appl,this_rewriter);
355 make_application(result, appl.head(), appl.begin(), appl.end(), rewrite_functor(this_rewriter));
361 rewrite_appl_aux<ARGUMENTS_IN_NORMAL_FORM>(result, appl, this_rewriter);
369 sigma(this_rewriter).apply(down_cast<variable>(t),result,
370 *this_rewriter->m_thread_aterm_pool);
380 this_rewriter->existential_quantifier_enumeration(result, abstr, sigma(this_rewriter));
386 this_rewriter->universal_quantifier_enumeration(result, abstr, sigma(this_rewriter));
391 this_rewriter->rewrite_single_lambda(result, abstr.variables(), abstr.body(), sigma(this_rewriter),
false);
397 this_rewriter->rewrite_where(result,down_cast<where_clause>(t), sigma(this_rewriter));
410 if (mcrl2::utilities::MCRL2_VERSION != i->caller_toolset_version)
412 i->status =
"rewriter version does not match the version of the calling application.";
416 i->rewrite_external = &rewrite;
417 i->rewrite_cleanup = &rewrite_cleanup;
418 set_the_precompiled_rewrite_functions_in_a_lookup_table(this_rewriter);
419 i->status =
"rewriter loaded successfully.";
A unordered_map class in which aterms can be stored.
const TERM_TO_BE_REWRITTEN & m_body
data_expression & normal_form() const
delayed_abstraction(const binder_type &binding_operator, const variable_list &variables, const TERM_TO_BE_REWRITTEN &body, RewriterCompilingJitty *tr)
RewriterCompilingJitty * this_rewriter
const binder_type & m_binding_operator
void normal_form(data_expression &result) const
const variable_list & m_variables
An abstraction expression.
const binder_type & binding_operator() const
\brief Assignment of a data expression to a variable
data_expression & operator=(const data_expression &) noexcept=default
sort_expression sort() const
Returns the sort of the data expression.
data_expression(const data_expression &) noexcept=default
Move semantics.
bool is_default_data_expression() const
A function to efficiently determine whether a data expression is made by the default constructor.
static void rewrite_abstraction_aux(data_expression &result, const abstraction &a, const data_expression &t, RewriterCompilingJitty *this_rewriter)
static void rewrite_with_arguments_in_normal_form(data_expression &result, const data_expression &t, RewriterCompilingJitty *this_rewriter)
static const data_expression & local_rewrite(const data_expression &t)
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
static void set_the_precompiled_rewrite_functions_in_a_lookup_table(RewriterCompilingJitty *this_rewriter)
static void rewrite_appl_aux(data_expression &result, const application &t, RewriterCompilingJitty *this_rewriter)
static void rewrite_cleanup()
static assignment_expression_list jittyc_local_push_front(assignment_expression_list l, const assignment &e)
static void pass_on(data_expression &result, const data_expression &t)
static void local_rewrite(data_expression &result, const REWRITE_TERM &t)
static uintptr_t uint_address(const atermpp::aterm &t)
static void rewrite(data_expression &result, const data_expression &t, RewriterCompilingJitty *this_rewriter)
static std::size_t get_index(const function_symbol &func)
static rewriter_function get_precompiled_rewrite_function(const function_symbol &f, const std::size_t arity, RewriterCompilingJitty *this_rewriter)
static void local_rewrite(data_expression &result, const data_expression &t)
static data_expression & local_rewrite(const REWRITE_TERM &t)
MCRL2_EXPORT bool init(rewriter_interface *i, RewriterCompilingJitty *this_rewriter)
static void rewrite_aux(data_expression &result, const data_expression &t, RewriterCompilingJitty *this_rewriter)
const data_expression & get_nested_head(const data_expression &t)
bool is_application_no_check(const atermpp::aterm &x)
Returns true if the term t is an application, but it does not check whether an application symbol of ...
bool is_where_clause(const atermpp::aterm &x)
Returns true if the term t is a where clause.
bool is_abstraction(const atermpp::aterm &x)
Returns true if the term t is an abstraction.
bool is_exists_binder(const atermpp::aterm &x)
bool is_lambda_binder(const atermpp::aterm &x)
bool is_function_symbol(const atermpp::aterm &x)
Returns true if the term t is a function symbol.
bool is_machine_number(const atermpp::aterm &x)
Returns true if the term t is a machine_number.
bool is_forall_binder(const atermpp::aterm &x)
bool is_variable(const atermpp::aterm &x)
Returns true if the term t is a variable.
data_expression operator()(const data_expression &arg) const
RewriterCompilingJitty * this_rewriter
rewrite_functor(RewriterCompilingJitty *tr)