Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
chlict committed Oct 3, 2020
1 parent 687d30a commit a4837e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/includes/xforms/CodeGen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "XformUtils.hpp"

struct CodeGenXform {
// Gen code for dest = src1 op src2
template <yap::expr_kind BinaryOP, typename Dest, typename Src1, typename Src2>
auto operator()(yap::expr_tag<yap::expr_kind::assign>,
Dest const &dest_expr,
Expand All @@ -24,26 +25,25 @@ struct CodeGenXform {
static_assert(is_tensor_type<std::remove_reference_t<decltype(src1)> >);
static_assert(is_tensor_type<std::remove_reference_t<decltype(src2)> >);

// printf("CodeGenXform: tensor = expr1 op expr2 matched\n");
// printf("CodeGenXform: tensor = expr1 op expr2 matched\n");

if constexpr (BinaryOP == yap::expr_kind::plus) {

auto tadd = TAdd(dest, src1, src2);
auto code = tadd.gen_code();
return code;
//auto code = TAdd(dest, src1, src2).gen_code();
//return code;
// std::cout << "Executing TensorAdd`" << std::endl;
return tadd.gen_code();
}
else if constexpr (BinaryOP == yap::expr_kind::multiplies) {
return []() { printf("Code generation for multiplication is not implemented\n"); };
}
// else if constexpr (BinaryOP == yap::expr_kind::multiplies) {
// std::cout << "Executing TensorMul" << std::endl;
// }
else {
return []() {
printf("Not implemented\n");
};
return []() { printf("Code generation for this operation is not implemented\n"); };
}
}

// Not work?
template <yap::expr_kind AnyOP, typename ... Children>
auto operator()(yap::expression<AnyOP, hana::tuple<Children...> > expr) {
return []() { printf("Code generation not implemented for this expression\n"); };
}
};

struct CodeGen : StaticTransform {
Expand Down
1 change: 1 addition & 0 deletions test/TestExprBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TEST(TestExprList, Test1) {
};
std::cout << list1 << std::endl;

// Actuall only assign expressions can be code generated for.
list1.gen_code(1, 2, 3);
}

Expand Down

0 comments on commit a4837e9

Please sign in to comment.