From eccebd0e7d74a214b9019180f2e63baa3936e558 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 19 Jul 2018 14:41:32 +0900 Subject: [PATCH] [nest] Introduce 'Mul' expression node (#713) This commit adds 'MulNode' class under nest::expr namespace to support arithmetic multiplication in nest IR. Signed-off-by: Jonghyun Park --- contrib/nest/include/nest/expr/MulNode.h | 37 ++++++++++++++++++++++++++++++++ contrib/nest/include/nest/expr/Node.def | 1 + contrib/nest/src/expr/MulNode.test.cpp | 27 +++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 contrib/nest/include/nest/expr/MulNode.h create mode 100644 contrib/nest/src/expr/MulNode.test.cpp diff --git a/contrib/nest/include/nest/expr/MulNode.h b/contrib/nest/include/nest/expr/MulNode.h new file mode 100644 index 0000000..cf40c00 --- /dev/null +++ b/contrib/nest/include/nest/expr/MulNode.h @@ -0,0 +1,37 @@ +#ifndef __NEST_EXPR_MUL_NODE_H__ +#define __NEST_EXPR_MUL_NODE_H__ + +#include "nest/expr/Node.h" + +#include + +namespace nest +{ +namespace expr +{ + +class MulNode final : public Node +{ +public: + MulNode(const std::shared_ptr &lhs, const std::shared_ptr &rhs) + : _lhs{lhs}, _rhs{rhs} + { + // DO NOTHING + } + +public: + const MulNode *asMul(void) const override { return this; } + +public: + const std::shared_ptr &lhs(void) const { return _lhs; } + const std::shared_ptr &rhs(void) const { return _rhs; } + +private: + std::shared_ptr const _lhs; + std::shared_ptr const _rhs; +}; + +} // namespace expr +} // namespace nest + +#endif // __NEST_EXPR_MUL_NODE_H__ diff --git a/contrib/nest/include/nest/expr/Node.def b/contrib/nest/include/nest/expr/Node.def index baf9aaa..0429517 100644 --- a/contrib/nest/include/nest/expr/Node.def +++ b/contrib/nest/include/nest/expr/Node.def @@ -6,3 +6,4 @@ EXPR(Var) EXPR(Deref) EXPR(Add) +EXPR(Mul) diff --git a/contrib/nest/src/expr/MulNode.test.cpp b/contrib/nest/src/expr/MulNode.test.cpp new file mode 100644 index 0000000..4c4f974 --- /dev/null +++ b/contrib/nest/src/expr/MulNode.test.cpp @@ -0,0 +1,27 @@ +#include "nest/expr/MulNode.h" + +#include + +#include + +namespace +{ +struct DummyNode final : public nest::expr::Node +{ +}; +} + +TEST(MUL_NODE, cast) +{ + auto left = std::make_shared(); + auto right = std::make_shared(); + + auto derived = std::make_shared(left, right); + std::shared_ptr base = derived; + + ASSERT_NE(derived.get(), nullptr); + ASSERT_EQ(base->asMul(), derived.get()); + + ASSERT_EQ(derived->lhs().get(), left.get()); + ASSERT_EQ(derived->rhs().get(), right.get()); +} -- 2.7.4