|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <mutable/IR/PhysicalOptimizer.hpp> |
| 4 | + |
| 5 | + |
| 6 | +namespace m { |
| 7 | + |
| 8 | +/** This macro declares a simple 1:1 mapping between logical and physical operator for the `Interpreter`. */ |
| 9 | +#define DECLARE(CLASS) \ |
| 10 | +/* forward declarations */ \ |
| 11 | +namespace interpreter { struct CLASS; } \ |
| 12 | +template<> struct Match<interpreter::CLASS>; \ |
| 13 | +\ |
| 14 | +namespace interpreter { \ |
| 15 | +\ |
| 16 | +struct CLASS : PhysicalOperator<CLASS, m::CLASS> \ |
| 17 | +{ \ |
| 18 | + static void execute(const Match<CLASS>&, setup_t, pipeline_t, teardown_t) { M_unreachable("not implemented"); } \ |
| 19 | + static double cost(const Match<CLASS>&) { return 1.0; } \ |
| 20 | + static ConditionSet \ |
| 21 | + adapt_post_conditions(const Match<CLASS>&, std::vector<std::reference_wrapper<const ConditionSet>>&&) { \ |
| 22 | + return ConditionSet(); /* has to be overwritten for operators with multiple children, i.e. `JoinOperator` */ \ |
| 23 | + } \ |
| 24 | +}; \ |
| 25 | +\ |
| 26 | +} \ |
| 27 | +\ |
| 28 | +template<> \ |
| 29 | +struct Match<interpreter::CLASS> : MatchBase \ |
| 30 | +{ \ |
| 31 | + const CLASS &op; \ |
| 32 | + std::vector<std::reference_wrapper<const MatchBase>> children; \ |
| 33 | +\ |
| 34 | + Match(const CLASS *op, std::vector<std::reference_wrapper<const MatchBase>> &&children) \ |
| 35 | + : op(*op) \ |
| 36 | + , children(std::move(children)) \ |
| 37 | + { } \ |
| 38 | +\ |
| 39 | + void execute(setup_t, pipeline_t, teardown_t) const override { \ |
| 40 | + M_unreachable("must not be called since `Interpreter` uses former visitor pattern on logical operators for " \ |
| 41 | + "execution"); \ |
| 42 | + } \ |
| 43 | +\ |
| 44 | + const Operator & get_matched_singleton() const override { return op; } \ |
| 45 | +\ |
| 46 | + protected: \ |
| 47 | + void print(std::ostream &out, unsigned level) const override { \ |
| 48 | + indent(out, level) << "interpreter::" << #CLASS << " (cumulative cost " << cost() << ')'; \ |
| 49 | + for (auto &child : children) \ |
| 50 | + child.get().print(out, level + 1); \ |
| 51 | + } \ |
| 52 | +}; |
| 53 | +M_OPERATOR_LIST(DECLARE) |
| 54 | +#undef DECLARE |
| 55 | + |
| 56 | +void register_interpreter_operators(PhysicalOptimizer &phys_opt); |
| 57 | + |
| 58 | +} |
0 commit comments