From cb46c25cfb29e6dff7f337920ef3c2764ff7bd9f 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: Tue, 17 Jul 2018 19:52:08 +0900 Subject: [PATCH] [nest] Add 'Closure' class (#688) This commit adds 'Closure' class which temporarily records the domain and index expressions, which makes it easy for user to construct IR. Signed-off-by: Jonghyun Park --- contrib/nest/include/nest/Closure.h | 33 +++++++++++++++++++++++++++++++++ contrib/nest/src/Closure.cpp | 8 ++++++++ contrib/nest/src/Closure.test.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 contrib/nest/include/nest/Closure.h create mode 100644 contrib/nest/src/Closure.cpp create mode 100644 contrib/nest/src/Closure.test.cpp diff --git a/contrib/nest/include/nest/Closure.h b/contrib/nest/include/nest/Closure.h new file mode 100644 index 0000000..e9127e6 --- /dev/null +++ b/contrib/nest/include/nest/Closure.h @@ -0,0 +1,33 @@ +#ifndef __NEST_CLOSURE_H__ +#define __NEST_CLOSURE_H__ + +#include "nest/DomainID.h" +#include "nest/Expr.h" + +namespace nest +{ + +class Closure +{ +public: + template + Closure(const DomainID &id, Args &&... indices) : _id{id}, _sub{std::forward(indices)...} + { + // DO NOTHING + } + +public: + operator Expr() const; + +public: + const DomainID &id(void) const { return _id; } + const expr::Subscript &sub(void) const { return _sub; } + +private: + DomainID const _id; + expr::Subscript const _sub; +}; + +} // namespace nest + +#endif // __NEST_CLOSURE_H__ diff --git a/contrib/nest/src/Closure.cpp b/contrib/nest/src/Closure.cpp new file mode 100644 index 0000000..151e414 --- /dev/null +++ b/contrib/nest/src/Closure.cpp @@ -0,0 +1,8 @@ +#include "nest/Closure.h" + +namespace nest +{ + +Closure::operator Expr(void) const { return std::make_shared(_id, _sub); } + +} // namespace nest diff --git a/contrib/nest/src/Closure.test.cpp b/contrib/nest/src/Closure.test.cpp new file mode 100644 index 0000000..bab8d5a --- /dev/null +++ b/contrib/nest/src/Closure.test.cpp @@ -0,0 +1,29 @@ +#include "nest/Closure.h" + +#include + +namespace +{ +struct DummyNode final : public nest::expr::Node +{ +}; +} + +TEST(Closure, ctor) +{ + nest::DomainID dom_id{0}; + nest::Closure closure{dom_id, std::make_shared()}; + + ASSERT_EQ(closure.id().value(), 0); + ASSERT_EQ(closure.sub().rank(), 1); +} + +TEST(Closure, cast) +{ + nest::DomainID dom_id{0}; + nest::Closure closure{dom_id, std::make_shared()}; + + auto check = [](const nest::Expr &e) { ASSERT_NE(e.get(), nullptr); }; + + check(closure); +} -- 2.7.4