[nest] Add 'VarID' class (#655)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 16 Jul 2018 02:21:43 +0000 (11:21 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 16 Jul 2018 02:21:43 +0000 (11:21 +0900)
This commit adds 'VarID' class which is an internal representation of
nest variables (in IR).

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/nest/.FORMATCHECKED [new file with mode: 0644]
contrib/nest/CMakeLists.txt [new file with mode: 0644]
contrib/nest/include/nest/VarID.h [new file with mode: 0644]
contrib/nest/src/VarID.cpp [new file with mode: 0644]
contrib/nest/src/VarID.test.cpp [new file with mode: 0644]

diff --git a/contrib/nest/.FORMATCHECKED b/contrib/nest/.FORMATCHECKED
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/contrib/nest/CMakeLists.txt b/contrib/nest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0731f22
--- /dev/null
@@ -0,0 +1,18 @@
+file(GLOB_RECURSE SOURCES "src/*.cpp")
+file(GLOB_RECURSE TESTS "src/*.test.cpp")
+list(REMOVE_ITEM SOURCES ${TESTS})
+
+add_library(nest STATIC ${SOURCES})
+set_target_properties(nest PROPERTIES POSITION_INDEPENDENT_CODE ON)
+target_include_directories(nest PUBLIC include)
+
+nncc_find_package(GTest QUIET)
+
+if(NOT GTest_FOUND)
+  return()
+endif(NOT GTest_FOUND)
+
+add_executable(nest_test ${TESTS})
+target_link_libraries(nest_test gtest_main)
+target_link_libraries(nest_test nest)
+add_test(nest_test nest_test)
diff --git a/contrib/nest/include/nest/VarID.h b/contrib/nest/include/nest/VarID.h
new file mode 100644 (file)
index 0000000..6907dd7
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef __NEST_VAR_ID_H__
+#define __NEST_VAR_ID_H__
+
+#include <cstdint>
+
+namespace nest
+{
+
+class VarID
+{
+public:
+  VarID();
+
+public:
+  explicit VarID(uint32_t value) : _value{value}
+  {
+    // DO NOTHING
+  }
+
+public:
+  VarID(const VarID &vid) : _value{vid._value}
+  {
+    // DO NOTHING
+  }
+
+public:
+  uint32_t value(void) const { return _value; }
+
+private:
+  uint32_t _value;
+};
+
+bool operator==(const VarID &lhs, const VarID &rhs);
+bool operator<(const VarID &lhs, const VarID &rhs);
+
+} // namespace nest
+
+#endif // __NEST_VAR_ID_H__
diff --git a/contrib/nest/src/VarID.cpp b/contrib/nest/src/VarID.cpp
new file mode 100644 (file)
index 0000000..dc7edad
--- /dev/null
@@ -0,0 +1,14 @@
+#include "nest/VarID.h"
+
+namespace nest
+{
+
+VarID::VarID() : _value{0xffffffff}
+{
+  // DO NOTHING
+}
+
+bool operator==(const VarID &lhs, const VarID &rhs) { return lhs.value() == rhs.value(); }
+bool operator<(const VarID &lhs, const VarID &rhs) { return lhs.value() < rhs.value(); }
+
+} // namespace nest
diff --git a/contrib/nest/src/VarID.test.cpp b/contrib/nest/src/VarID.test.cpp
new file mode 100644 (file)
index 0000000..c0ab460
--- /dev/null
@@ -0,0 +1,22 @@
+#include "nest/VarID.h"
+
+#include <gtest/gtest.h>
+
+TEST(VAR_ID, ctor)
+{
+  nest::VarID id{0};
+
+  ASSERT_EQ(id.value(), 0);
+}
+
+TEST(VAR_ID, operator_eq)
+{
+  ASSERT_TRUE(nest::VarID(0) == nest::VarID(0));
+  ASSERT_FALSE(nest::VarID(0) == nest::VarID(1));
+}
+
+TEST(VAR_ID, operator_lt)
+{
+  ASSERT_TRUE(nest::VarID(0) < nest::VarID(1));
+  ASSERT_FALSE(nest::VarID(1) < nest::VarID(0));
+}