From f915b7ca8b1812b15c188ef8acc7bf7257d3255f 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, 26 Jul 2018 08:17:10 +0900 Subject: [PATCH] [nest] Introduce 'Level' class (#800) This commit introduces 'Level' class in nest IR which represents the (iteration) level of each iteration variables. Signed-off-by: Jonghyun Park --- contrib/nest/include/nest/Level.h | 29 +++++++++++++++++++++++++++++ contrib/nest/src/Level.cpp | 32 ++++++++++++++++++++++++++++++++ contrib/nest/src/Level.test.cpp | 23 +++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 contrib/nest/include/nest/Level.h create mode 100644 contrib/nest/src/Level.cpp create mode 100644 contrib/nest/src/Level.test.cpp diff --git a/contrib/nest/include/nest/Level.h b/contrib/nest/include/nest/Level.h new file mode 100644 index 0000000..7d92d80 --- /dev/null +++ b/contrib/nest/include/nest/Level.h @@ -0,0 +1,29 @@ +#ifndef __NEST_LEVEL_H__ +#define __NEST_LEVEL_H__ + +#include + +namespace nest +{ +class Level final +{ +public: + Level(); + explicit Level(uint32_t value); + +public: + bool valid(void) const; + +public: + uint32_t value(void) const { return _value; } + +private: + uint32_t _value; +}; + +bool operator==(const Level &lhs, const Level &rhs); +bool operator<(const Level &lhs, const Level &rhs); + +} // namespace nest + +#endif // __NEST_LEVEL_H__ diff --git a/contrib/nest/src/Level.cpp b/contrib/nest/src/Level.cpp new file mode 100644 index 0000000..e7b6ef7 --- /dev/null +++ b/contrib/nest/src/Level.cpp @@ -0,0 +1,32 @@ +#include "nest/Level.h" + +#include + +namespace +{ +const uint32_t invalid_tag = 0xffffffff; +} // namespace + +namespace nest +{ +Level::Level() : _value{invalid_tag} +{ + // DO NOTHING +} + +Level::Level(uint32_t value) : _value{value} { assert(value != invalid_tag); } + +bool Level::valid(void) const { return _value != invalid_tag; } + +bool operator==(const Level &lhs, const Level &rhs) +{ + assert(lhs.valid() && rhs.valid()); + return lhs.value() == rhs.value(); +} + +bool operator<(const Level &lhs, const Level &rhs) +{ + assert(lhs.valid() && rhs.valid()); + return lhs.value() < rhs.value(); +} +} // namespace nest diff --git a/contrib/nest/src/Level.test.cpp b/contrib/nest/src/Level.test.cpp new file mode 100644 index 0000000..f99a2f5 --- /dev/null +++ b/contrib/nest/src/Level.test.cpp @@ -0,0 +1,23 @@ +#include "nest/Level.h" + +#include + +TEST(LEVEL, constructor) +{ + nest::Level lv{3}; + + ASSERT_EQ(lv.value(), 3); +} + +TEST(LEVEL, operator_eq) +{ + ASSERT_TRUE(nest::Level(3) == nest::Level(3)); + ASSERT_FALSE(nest::Level(3) == nest::Level(4)); +} + +TEST(LEVEL, operator_lt) +{ + ASSERT_FALSE(nest::Level(3) < nest::Level(3)); + ASSERT_TRUE(nest::Level(3) < nest::Level(4)); + ASSERT_FALSE(nest::Level(4) < nest::Level(3)); +} -- 2.7.4