summaryrefslogtreecommitdiff
path: root/compiler/nest
diff options
context:
space:
mode:
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>2019-07-18 14:58:51 +0900
committerGitHub Enterprise <noreply-CODE@samsung.com>2019-07-18 14:58:51 +0900
commitdcfc6d1b6089b497608c3c63a564f240a7d247ee (patch)
tree8f30b3a52a898703019d276b7b14d7c023dd597a /compiler/nest
parent9df0e14167706f46dce5eab712f8961161af9e12 (diff)
downloadnnfw-dcfc6d1b6089b497608c3c63a564f240a7d247ee.tar.gz
nnfw-dcfc6d1b6089b497608c3c63a564f240a7d247ee.tar.bz2
nnfw-dcfc6d1b6089b497608c3c63a564f240a7d247ee.zip
Rename contrib as compiler (#4342)
* Rename contrib as compiler This commit renames the top-level contrib directory as "compiler". Signed-off-by: Jonghyun Park <jh1302.park@samsung.com> * Fix CMakeLists.txt
Diffstat (limited to 'compiler/nest')
-rw-r--r--compiler/nest/.FORMATCHECKED0
-rw-r--r--compiler/nest/CMakeLists.txt1
-rw-r--r--compiler/nest/README.md8
-rw-r--r--compiler/nest/core/CMakeLists.txt27
-rw-r--r--compiler/nest/core/examples/conv2d.cpp152
-rw-r--r--compiler/nest/core/include/nest/Block.h46
-rw-r--r--compiler/nest/core/include/nest/Bound.h47
-rw-r--r--compiler/nest/core/include/nest/Closure.h49
-rw-r--r--compiler/nest/core/include/nest/Domain.h54
-rw-r--r--compiler/nest/core/include/nest/DomainContext.h45
-rw-r--r--compiler/nest/core/include/nest/DomainID.h54
-rw-r--r--compiler/nest/core/include/nest/DomainInfo.h48
-rw-r--r--compiler/nest/core/include/nest/Expr.h44
-rw-r--r--compiler/nest/core/include/nest/FV.h39
-rw-r--r--compiler/nest/core/include/nest/Level.h45
-rw-r--r--compiler/nest/core/include/nest/Module.h70
-rw-r--r--compiler/nest/core/include/nest/Ret.h49
-rw-r--r--compiler/nest/core/include/nest/Schedule.h52
-rw-r--r--compiler/nest/core/include/nest/Stmt.h34
-rw-r--r--compiler/nest/core/include/nest/Var.h49
-rw-r--r--compiler/nest/core/include/nest/VarContext.h46
-rw-r--r--compiler/nest/core/include/nest/VarID.h54
-rw-r--r--compiler/nest/core/include/nest/expr/AddNode.h53
-rw-r--r--compiler/nest/core/include/nest/expr/DerefNode.h54
-rw-r--r--compiler/nest/core/include/nest/expr/Forward.h34
-rw-r--r--compiler/nest/core/include/nest/expr/Macro.h28
-rw-r--r--compiler/nest/core/include/nest/expr/MulNode.h53
-rw-r--r--compiler/nest/core/include/nest/expr/Node.def9
-rw-r--r--compiler/nest/core/include/nest/expr/Node.h62
-rw-r--r--compiler/nest/core/include/nest/expr/Subscript.h53
-rw-r--r--compiler/nest/core/include/nest/expr/VarNode.h52
-rw-r--r--compiler/nest/core/include/nest/expr/Visitor.h40
-rw-r--r--compiler/nest/core/include/nest/stmt/Forward.h34
-rw-r--r--compiler/nest/core/include/nest/stmt/Macro.h28
-rw-r--r--compiler/nest/core/include/nest/stmt/Node.def6
-rw-r--r--compiler/nest/core/include/nest/stmt/Node.h62
-rw-r--r--compiler/nest/core/include/nest/stmt/PushNode.h49
-rw-r--r--compiler/nest/core/include/nest/stmt/Visitor.h40
-rw-r--r--compiler/nest/core/src/Block.test.cpp41
-rw-r--r--compiler/nest/core/src/Bound.test.cpp27
-rw-r--r--compiler/nest/core/src/Closure.cpp24
-rw-r--r--compiler/nest/core/src/Closure.test.cpp45
-rw-r--r--compiler/nest/core/src/Domain.test.cpp41
-rw-r--r--compiler/nest/core/src/DomainContext.cpp38
-rw-r--r--compiler/nest/core/src/DomainContext.test.cpp56
-rw-r--r--compiler/nest/core/src/DomainID.cpp30
-rw-r--r--compiler/nest/core/src/DomainID.test.cpp38
-rw-r--r--compiler/nest/core/src/DomainInfo.test.cpp30
-rw-r--r--compiler/nest/core/src/Expr.cpp27
-rw-r--r--compiler/nest/core/src/Expr.test.cpp58
-rw-r--r--compiler/nest/core/src/FV.cpp75
-rw-r--r--compiler/nest/core/src/FV.test.cpp75
-rw-r--r--compiler/nest/core/src/Level.cpp48
-rw-r--r--compiler/nest/core/src/Level.test.cpp39
-rw-r--r--compiler/nest/core/src/Module.cpp44
-rw-r--r--compiler/nest/core/src/Module.test.cpp99
-rw-r--r--compiler/nest/core/src/Ret.test.cpp58
-rw-r--r--compiler/nest/core/src/Schedule.cpp51
-rw-r--r--compiler/nest/core/src/Schedule.test.cpp44
-rw-r--r--compiler/nest/core/src/Var.cpp24
-rw-r--r--compiler/nest/core/src/Var.test.cpp38
-rw-r--r--compiler/nest/core/src/VarContext.cpp36
-rw-r--r--compiler/nest/core/src/VarContext.test.cpp82
-rw-r--r--compiler/nest/core/src/VarID.cpp30
-rw-r--r--compiler/nest/core/src/VarID.test.cpp38
-rw-r--r--compiler/nest/core/src/expr/AddNode.test.cpp43
-rw-r--r--compiler/nest/core/src/expr/DerefNode.test.cpp39
-rw-r--r--compiler/nest/core/src/expr/Macro.cpp21
-rw-r--r--compiler/nest/core/src/expr/MulNode.test.cpp43
-rw-r--r--compiler/nest/core/src/expr/Node.cpp21
-rw-r--r--compiler/nest/core/src/expr/Subscript.test.cpp37
-rw-r--r--compiler/nest/core/src/expr/VarNode.test.cpp47
-rw-r--r--compiler/nest/core/src/expr/Visitor.cpp21
-rw-r--r--compiler/nest/core/src/stmt/Macro.cpp21
-rw-r--r--compiler/nest/core/src/stmt/Node.cpp21
-rw-r--r--compiler/nest/core/src/stmt/PushNode.test.cpp37
-rw-r--r--compiler/nest/core/src/stmt/Visitor.cpp21
77 files changed, 3278 insertions, 0 deletions
diff --git a/compiler/nest/.FORMATCHECKED b/compiler/nest/.FORMATCHECKED
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/compiler/nest/.FORMATCHECKED
diff --git a/compiler/nest/CMakeLists.txt b/compiler/nest/CMakeLists.txt
new file mode 100644
index 000000000..ad6d4787c
--- /dev/null
+++ b/compiler/nest/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(core)
diff --git a/compiler/nest/README.md b/compiler/nest/README.md
new file mode 100644
index 000000000..64cfb75ed
--- /dev/null
+++ b/compiler/nest/README.md
@@ -0,0 +1,8 @@
+# nest
+
+_nest_ is a lightweight nested loop generation library, which makes it easy to generate complex,
+optimized nested loops (such as loops in conv2d).
+
+## References
+- [Halide](https://github.com/halide/Halide)
+- [Tensor Comprehension](https://github.com/facebookresearch/TensorComprehensions)
diff --git a/compiler/nest/core/CMakeLists.txt b/compiler/nest/core/CMakeLists.txt
new file mode 100644
index 000000000..b6754b081
--- /dev/null
+++ b/compiler/nest/core/CMakeLists.txt
@@ -0,0 +1,27 @@
+file(GLOB_RECURSE SOURCES "src/*.cpp")
+file(GLOB_RECURSE TESTS "src/*.test.cpp")
+list(REMOVE_ITEM SOURCES ${TESTS})
+
+add_library(nest_core STATIC ${SOURCES})
+set_target_properties(nest_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
+target_include_directories(nest_core PUBLIC include)
+
+file(GLOB EXAMPLE_FILES "examples/*.cpp")
+
+foreach(EXAMPLE_FILE IN ITEMS ${EXAMPLE_FILES})
+ get_filename_component(EXAMPLE_NAME ${EXAMPLE_FILE} NAME_WE)
+ set(TARGET_NAME nest_IR_example_${EXAMPLE_NAME})
+ add_executable(${TARGET_NAME} ${EXAMPLE_FILE})
+ target_link_libraries(${TARGET_NAME} nest_core)
+endforeach(EXAMPLE_FILE)
+
+nncc_find_package(GTest QUIET)
+
+if(NOT GTest_FOUND)
+ return()
+endif(NOT GTest_FOUND)
+
+add_executable(nest_core_test ${TESTS})
+target_link_libraries(nest_core_test gtest_main)
+target_link_libraries(nest_core_test nest_core)
+add_test(nest_core_test nest_core_test)
diff --git a/compiler/nest/core/examples/conv2d.cpp b/compiler/nest/core/examples/conv2d.cpp
new file mode 100644
index 000000000..e405af9c0
--- /dev/null
+++ b/compiler/nest/core/examples/conv2d.cpp
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <nest/Module.h>
+
+int main(int, char **)
+{
+ // This example shows how to specify convolution with IFM(1x3x3) and Kernel(1x1x3x3) with nest
+ // - STRIDE is 1, and there is no padding
+ //
+ // The below code corresponds to the following nest DSL code:
+ // ----------------------------------------------------------------------------------------------
+ // Domain ofm(1, 1, 1)
+ // Domain ifm(1, 3, 3)
+ // Domain ker(1, 1, 3, 3)
+ //
+ // Var ofm_ch : { min = 0, max = 1 }
+ // Var ofm_row : { min = 0, max = 1 }
+ // Var ofm_col : { min = 0, max = 1 }
+ // Var ker_ch : { min = 0, max = 1 }
+ // Var ker_row : { min = 0, max = 3 }
+ // Var ker_col : { min = 0, max = 3 }
+ //
+ // PUSH ifm(ker_ch, ker_row, ker_col) * ker(ofm_ch, ker_ch, ofm_row + ker_row, ofm_col + ker_col)
+ // RET ofm(ofm_ch, ofm_row, ofm_col)
+ // ----------------------------------------------------------------------------------------------
+ //
+ // The first part declares Domain(s) which corresponds to a multi-dimensional array in C-style
+ // (without type). For example, 'Domain ofm(1, 3, 3)' corresponds to the
+ // following C array declaration.
+ // float ofm[1][3][3];
+ // (Here we assume that domain type is 'float')
+ //
+ // The second part declares Var(s) which serves as a loop iteration variable. Basically, each
+ // variable emits one for loop and these loops are nested. As there are 6 variables in the above
+ // example, there will be 6 nested-loops.
+ //
+ // Each variable has a corresponding bound, and the bound of each variable states the starting /
+ // termination condition. For example, 'Var ofm_ch : { min = 0, max = 1 }' will introduce the
+ // following for loop:
+ // ----------------------------------------------------------------------------------------------
+ // for (int ofm_ch = 0; ofm_ch < 1; ++ofm_ch) { ... }
+ // ----------------------------------------------------------------------------------------------
+ //
+ // The last part declares statement(s) which state the computation performed inside these nested
+ // loops. Nest is stack-based. There is a virtual stack inside nested loop, and the evaluation of
+ // each statement will update this stack.
+ //
+ // Each nest code has one return statement (RET). This return statement specifies where to write
+ // the computed result.
+ //
+ // PUSH 'expr' statement evaluates an arithmetic expression (specified by 'expr') and pushes the
+ // numeric result to the stack. When PUSH statement evaluates an arithmetic expression, variables
+ // that do not appear in RET statement are treated as reduction variables. For example,
+ // ker_ch, ker_row, and ker_col do not appear in RET statement. So, PUSH '...' statement in the
+ // above example corresponds to the following nested loops:
+ // ----------------------------------------------------------------------------------------------
+ // float value = 0.0f;
+ //
+ // for (int ker_ch = 0; ker_ch < 1; ++ker_ch) {
+ // for (int ker_row = 0; ker_row < 3; ++ker_row) {
+ // for (int ker_col = 0; ker_col < 3; ++ker_col) {
+ // float ifm_value = ifm[ker_ch][ofm_row + ker_row][ofm_col + ker_col];
+ // float ker_value = ker[ofm_ch][ker_ch][ker_row][ker_col];
+ // value += ifm_value * ker_value;
+ // }
+ // }
+ // }
+ // ----------------------------------------------------------------------------------------------
+ //
+ // In summary, the above nest example corresponds to the following 2D convolution:
+ // ----------------------------------------------------------------------------------------------
+ // float ofm[1][1][1];
+ // float ifm[1][3][3];
+ // float ker[1][1][3][3];
+ //
+ // for (int ofm_ch = 0; ofm_ch < 1; ++ofm_ch) {
+ // for (int ofm_row = 0; ofm_row < 1; ++ofm_row) {
+ // for (int ofm_col = 0; ofm_col < 1; ++ofm_col) {
+ // float value = 0.0f;
+ //
+ // for (int ker_ch = 0; ker_ch < 1; ++ker_ch) {
+ // for (int ker_row = 0; ker_row < 3; ++ker_row) {
+ // for (int ker_col = 0; ker_col < 3; ++ker_col) {
+ // float ifm_value = ifm[ker_ch][ofm_row + ker_row][ofm_col + ker_col];
+ // float ker_value = ker[ofm_ch][ker_ch][ker_row][ker_col];
+ // value += ifm_value * ker_value;
+ // }
+ // }
+ // }
+ //
+ // ofm[ofm_ch][ofm_col][ofm_row] = value;
+ // }
+ // }
+ // }
+ // ----------------------------------------------------------------------------------------------
+ //
+ nest::Module m;
+
+ //
+ // Domains
+ //
+ auto ofm = m.domain().make({1 /*C*/, 1 /*H*/, 1 /*W*/});
+ auto ifm = m.domain().make({1 /*C*/, 3 /*H*/, 3 /*W*/});
+ auto ker = m.domain().make({1 /*N*/, 1 /*C*/, 3 /*H*/, 3 /*W*/});
+
+ //
+ // Variables
+ //
+ auto ofm_ch = m.var().make();
+ auto ofm_row = m.var().make();
+ auto ofm_col = m.var().make();
+
+ auto ker_ch = m.var().make();
+ auto ker_row = m.var().make();
+ auto ker_col = m.var().make();
+
+ // Declare the bound of each variables
+ using nest::Bound;
+
+ m.var().bound(ofm_ch) = Bound{0, 1};
+ m.var().bound(ofm_row) = Bound{0, 1};
+ m.var().bound(ofm_col) = Bound{0, 1};
+
+ m.var().bound(ker_ch) = Bound{0, 1};
+ m.var().bound(ker_row) = Bound{0, 3};
+ m.var().bound(ker_col) = Bound{0, 3};
+
+ //
+ // Statement
+ //
+ auto ifm_value = ifm(ker_ch, ofm_row + ker_row, ofm_col + ker_col);
+ auto ker_value = ker(ofm_ch, ker_ch, ker_row, ker_col);
+
+ m.push(ifm_value * ker_value);
+ m.ret(ofm(ofm_ch, ofm_row, ofm_col));
+
+ return 0;
+}
diff --git a/compiler/nest/core/include/nest/Block.h b/compiler/nest/core/include/nest/Block.h
new file mode 100644
index 000000000..e9b646f4e
--- /dev/null
+++ b/compiler/nest/core/include/nest/Block.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_BLOCK_H__
+#define __NEST_BLOCK_H__
+
+#include "nest/Stmt.h"
+
+#include <vector>
+
+#include <cstdint>
+
+namespace nest
+{
+
+struct Block
+{
+public:
+ uint32_t size(void) const { return _stmts.size(); }
+
+public:
+ const Stmt &at(uint32_t n) const { return _stmts.at(n); }
+
+public:
+ void append(const Stmt &stmt) { _stmts.emplace_back(stmt); }
+
+private:
+ std::vector<Stmt> _stmts;
+};
+
+} // namespace nest
+
+#endif // __NEST_BLOCK_H__
diff --git a/compiler/nest/core/include/nest/Bound.h b/compiler/nest/core/include/nest/Bound.h
new file mode 100644
index 000000000..252a69e85
--- /dev/null
+++ b/compiler/nest/core/include/nest/Bound.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_BOUND_H__
+#define __NEST_BOUND_H__
+
+#include <cstdint>
+
+namespace nest
+{
+
+class Bound
+{
+public:
+ Bound() = default;
+
+public:
+ Bound(int64_t min, int64_t max) : _min{min}, _max{max}
+ {
+ // DO NOTHING
+ }
+
+public:
+ int64_t min(void) const { return _min; }
+ int64_t max(void) const { return _max; }
+
+private:
+ int64_t _min;
+ int64_t _max;
+};
+
+} // namespace nest
+
+#endif // __NEST_BOUND_H__
diff --git a/compiler/nest/core/include/nest/Closure.h b/compiler/nest/core/include/nest/Closure.h
new file mode 100644
index 000000000..7e09afa1a
--- /dev/null
+++ b/compiler/nest/core/include/nest/Closure.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_CLOSURE_H__
+#define __NEST_CLOSURE_H__
+
+#include "nest/DomainID.h"
+#include "nest/Expr.h"
+
+namespace nest
+{
+
+class Closure
+{
+public:
+ template <typename... Args>
+ Closure(const DomainID &id, Args &&... indices) : _id{id}, _sub{std::forward<Args>(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/compiler/nest/core/include/nest/Domain.h b/compiler/nest/core/include/nest/Domain.h
new file mode 100644
index 000000000..8d809e2ad
--- /dev/null
+++ b/compiler/nest/core/include/nest/Domain.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_DOMAIN_H__
+#define __NEST_DOMAIN_H__
+
+#include "nest/Closure.h"
+
+namespace nest
+{
+
+class Domain
+{
+public:
+ Domain() = default;
+
+public:
+ Domain(const DomainID &id) : _id{id}
+ {
+ // DO NOTHING
+ }
+
+public:
+ Domain(const Domain &) = default;
+
+public:
+ template <typename... Args> Closure operator()(Args &&... indices)
+ {
+ return Closure{_id, std::forward<Args>(indices)...};
+ }
+
+public:
+ const DomainID &id(void) const { return _id; }
+
+private:
+ DomainID const _id;
+};
+
+} // namespace nest
+
+#endif // __NEST_DOMAIN_H__
diff --git a/compiler/nest/core/include/nest/DomainContext.h b/compiler/nest/core/include/nest/DomainContext.h
new file mode 100644
index 000000000..425accb93
--- /dev/null
+++ b/compiler/nest/core/include/nest/DomainContext.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_DOMAIN_CONTEXT_H__
+#define __NEST_DOMAIN_CONTEXT_H__
+
+#include "nest/DomainInfo.h"
+#include "nest/Domain.h"
+
+#include <vector>
+
+namespace nest
+{
+
+class DomainContext
+{
+public:
+ uint32_t count(void) const;
+
+public:
+ Domain make(std::initializer_list<uint32_t> dims);
+
+public:
+ const DomainInfo &info(const Domain &) const;
+
+private:
+ std::vector<DomainInfo> _info;
+};
+
+} // namespace nest
+
+#endif // __NEST_DOMAIN_CONTEXT_H__
diff --git a/compiler/nest/core/include/nest/DomainID.h b/compiler/nest/core/include/nest/DomainID.h
new file mode 100644
index 000000000..935680f58
--- /dev/null
+++ b/compiler/nest/core/include/nest/DomainID.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_DOMAIN_ID_H__
+#define __NEST_DOMAIN_ID_H__
+
+#include <cstdint>
+
+namespace nest
+{
+
+class DomainID
+{
+public:
+ DomainID();
+
+public:
+ explicit DomainID(uint32_t value) : _value{value}
+ {
+ // DO NOTHING
+ }
+
+public:
+ DomainID(const DomainID &vid) : _value{vid._value}
+ {
+ // DO NOTHING
+ }
+
+public:
+ uint32_t value(void) const { return _value; }
+
+private:
+ uint32_t _value;
+};
+
+bool operator==(const DomainID &lhs, const DomainID &rhs);
+bool operator<(const DomainID &lhs, const DomainID &rhs);
+
+} // namespace nest
+
+#endif // __NEST_DOMAIN_ID_H__
diff --git a/compiler/nest/core/include/nest/DomainInfo.h b/compiler/nest/core/include/nest/DomainInfo.h
new file mode 100644
index 000000000..ac8f04e8f
--- /dev/null
+++ b/compiler/nest/core/include/nest/DomainInfo.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_DOMAIN_INFO_H__
+#define __NEST_DOMAIN_INFO_H__
+
+#include <initializer_list>
+#include <vector>
+
+#include <cstdint>
+
+namespace nest
+{
+
+class DomainInfo
+{
+public:
+ DomainInfo(std::initializer_list<uint32_t> dims) : _dims{dims}
+ {
+ // DO NOTHING
+ }
+
+public:
+ uint32_t rank(void) const { return _dims.size(); }
+
+public:
+ uint32_t dim(uint32_t axis) const { return _dims.at(axis); }
+
+private:
+ std::vector<uint32_t> _dims;
+};
+
+} // namespace nest
+
+#endif // __NEST_DOMAIN_INFO_H__
diff --git a/compiler/nest/core/include/nest/Expr.h b/compiler/nest/core/include/nest/Expr.h
new file mode 100644
index 000000000..520edcd30
--- /dev/null
+++ b/compiler/nest/core/include/nest/Expr.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_EXPR_H__
+#define __NEST_EXPR_H__
+
+#include "nest/expr/Node.h"
+#include "nest/expr/Visitor.h"
+
+#include "nest/expr/VarNode.h"
+#include "nest/expr/DerefNode.h"
+#include "nest/expr/AddNode.h"
+#include "nest/expr/MulNode.h"
+
+#include <memory>
+
+namespace nest
+{
+
+// WARNING All of the descendant of expr::Node SHOULD BE immutable
+//
+// The copy/move constructor of Block and Module class simply copies their shared pointer under
+// the assumption that these classes are immutable.
+using Expr = std::shared_ptr<nest::expr::Node>;
+
+} // namespace nest
+
+nest::Expr operator+(const nest::Expr &, const nest::Expr &);
+nest::Expr operator*(const nest::Expr &, const nest::Expr &);
+
+#endif // __NEST_EXPR_H__
diff --git a/compiler/nest/core/include/nest/FV.h b/compiler/nest/core/include/nest/FV.h
new file mode 100644
index 000000000..089f1596b
--- /dev/null
+++ b/compiler/nest/core/include/nest/FV.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_FV_H__
+#define __NEST_FV_H__
+
+#include "nest/VarID.h"
+
+#include "nest/Expr.h"
+
+#include <set>
+
+namespace nest
+{
+
+/**
+ * @brief Collect free variables from nest expr/stmt/block/...
+ */
+struct FV
+{
+ static std::set<VarID> in(const Expr &);
+};
+
+} // namespace nest
+
+#endif // __NEST_FV_H__
diff --git a/compiler/nest/core/include/nest/Level.h b/compiler/nest/core/include/nest/Level.h
new file mode 100644
index 000000000..ac1788636
--- /dev/null
+++ b/compiler/nest/core/include/nest/Level.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_LEVEL_H__
+#define __NEST_LEVEL_H__
+
+#include <cstdint>
+
+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/compiler/nest/core/include/nest/Module.h b/compiler/nest/core/include/nest/Module.h
new file mode 100644
index 000000000..1294e3089
--- /dev/null
+++ b/compiler/nest/core/include/nest/Module.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_MODULE_H__
+#define __NEST_MODULE_H__
+
+#include "nest/VarContext.h"
+#include "nest/DomainContext.h"
+#include "nest/Ret.h"
+#include "nest/Block.h"
+
+namespace nest
+{
+
+class Module
+{
+public:
+ Module() = default;
+
+private:
+ VarContext _var_ctx;
+
+public:
+ VarContext &var(void) { return _var_ctx; }
+ const VarContext &var(void) const { return _var_ctx; }
+
+private:
+ DomainContext _domain_ctx;
+
+public:
+ DomainContext &domain(void) { return _domain_ctx; }
+ const DomainContext &domain(void) const { return _domain_ctx; }
+
+private:
+ Block _block;
+
+public:
+ const Block &block(void) const { return _block; }
+
+public:
+ void push(const Expr &expr);
+
+private:
+ std::shared_ptr<Ret> _ret;
+
+public:
+ // NOTE Do NOT invoke ret() before ret(expr) call
+ const Ret &ret(void) const;
+
+public:
+ // NOTE Only one ret(expr) call is allowed for each module
+ void ret(const Closure &closure);
+};
+
+} // namespace nest
+
+#endif // __NEST_MODULE_H__
diff --git a/compiler/nest/core/include/nest/Ret.h b/compiler/nest/core/include/nest/Ret.h
new file mode 100644
index 000000000..8f8af15e2
--- /dev/null
+++ b/compiler/nest/core/include/nest/Ret.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_RET_H__
+#define __NEST_RET_H__
+
+#include "nest/DomainID.h"
+#include "nest/Expr.h"
+
+namespace nest
+{
+
+// WARNING Ret SHOULD BE immutable
+//
+// The copy/move constructor of Module class simply copies the shared pointer under the assumption
+// that Ret is immutable.
+class Ret
+{
+public:
+ Ret(const DomainID &id, const expr::Subscript &sub) : _id{id}, _sub{sub}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const DomainID &id(void) const { return _id; }
+ const expr::Subscript &sub(void) const { return _sub; }
+
+private:
+ DomainID _id;
+ expr::Subscript _sub;
+};
+
+} // namespace nest
+
+#endif // __NEST_RET_H__
diff --git a/compiler/nest/core/include/nest/Schedule.h b/compiler/nest/core/include/nest/Schedule.h
new file mode 100644
index 000000000..a92c245c3
--- /dev/null
+++ b/compiler/nest/core/include/nest/Schedule.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_SCHEDULE_H__
+#define __NEST_SCHEDULE_H__
+
+#include "nest/Module.h"
+#include "nest/Level.h"
+
+#include <vector>
+
+namespace nest
+{
+
+class Schedule final
+{
+public:
+ explicit Schedule(const Module &);
+
+public:
+ const VarContext &var(void) const { return _module.var(); }
+ const DomainContext &domain(void) const { return _module.domain(); }
+ const Block &block(void) const { return _module.block(); }
+ const Ret &ret(void) const { return _module.ret(); }
+
+public:
+ Var at(const Level &) const;
+ Level level(const Var &) const;
+
+private:
+ Module _module;
+
+private:
+ std::vector<VarID> _level;
+};
+
+} // namespace nest
+
+#endif // __NEST_SCHEDULE_H___
diff --git a/compiler/nest/core/include/nest/Stmt.h b/compiler/nest/core/include/nest/Stmt.h
new file mode 100644
index 000000000..4fff26ffa
--- /dev/null
+++ b/compiler/nest/core/include/nest/Stmt.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_STMT_H__
+#define __NEST_STMT_H__
+
+#include "nest/stmt/Node.h"
+#include "nest/stmt/Visitor.h"
+
+#include "nest/stmt/PushNode.h"
+
+#include <memory>
+
+namespace nest
+{
+
+using Stmt = std::shared_ptr<stmt::Node>;
+
+} // namespace nest
+
+#endif // __NEST_STMT_H__
diff --git a/compiler/nest/core/include/nest/Var.h b/compiler/nest/core/include/nest/Var.h
new file mode 100644
index 000000000..bb2c6c786
--- /dev/null
+++ b/compiler/nest/core/include/nest/Var.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_VAR_H__
+#define __NEST_VAR_H__
+
+#include "nest/VarID.h"
+#include "nest/Expr.h"
+
+namespace nest
+{
+
+class Var
+{
+public:
+ Var() = default;
+
+public:
+ Var(const VarID &id) : _id{id}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const VarID &id(void) const { return _id; }
+
+public:
+ operator Expr(void) const;
+
+private:
+ VarID const _id;
+};
+
+} // namespace nest
+
+#endif // __NEST_VAR_H__
diff --git a/compiler/nest/core/include/nest/VarContext.h b/compiler/nest/core/include/nest/VarContext.h
new file mode 100644
index 000000000..2438abfce
--- /dev/null
+++ b/compiler/nest/core/include/nest/VarContext.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_VAR_CONTEXT_H__
+#define __NEST_VAR_CONTEXT_H__
+
+#include "nest/Bound.h"
+#include "nest/Var.h"
+
+#include <vector>
+
+namespace nest
+{
+
+class VarContext
+{
+public:
+ uint32_t count(void) const;
+
+public:
+ Var make(void);
+
+public:
+ Bound &bound(const Var &);
+ const Bound &bound(const Var &) const;
+
+private:
+ std::vector<Bound> _bound;
+};
+
+} // namespace nest
+
+#endif // __NEST_VAR_CONTEXT_H__
diff --git a/compiler/nest/core/include/nest/VarID.h b/compiler/nest/core/include/nest/VarID.h
new file mode 100644
index 000000000..daf3e9ee4
--- /dev/null
+++ b/compiler/nest/core/include/nest/VarID.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#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/compiler/nest/core/include/nest/expr/AddNode.h b/compiler/nest/core/include/nest/expr/AddNode.h
new file mode 100644
index 000000000..b9b5afb22
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/AddNode.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_EXPR_ADD_NODE_H__
+#define __NEST_EXPR_ADD_NODE_H__
+
+#include "nest/expr/Node.h"
+
+#include <memory>
+
+namespace nest
+{
+namespace expr
+{
+
+class AddNode final : public Node
+{
+public:
+ AddNode(const std::shared_ptr<expr::Node> &lhs, const std::shared_ptr<expr::Node> &rhs)
+ : _lhs{lhs}, _rhs{rhs}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const AddNode *asAdd(void) const override { return this; }
+
+public:
+ const std::shared_ptr<expr::Node> &lhs(void) const { return _lhs; }
+ const std::shared_ptr<expr::Node> &rhs(void) const { return _rhs; }
+
+private:
+ std::shared_ptr<expr::Node> const _lhs;
+ std::shared_ptr<expr::Node> const _rhs;
+};
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEST_EXPR_ADD_NODE_H__
diff --git a/compiler/nest/core/include/nest/expr/DerefNode.h b/compiler/nest/core/include/nest/expr/DerefNode.h
new file mode 100644
index 000000000..19adfe3b3
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/DerefNode.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEXT_EXPR_DEREF_NODE_H__
+#define __NEXT_EXPR_DEREF_NODE_H__
+
+#include "nest/DomainID.h"
+
+#include "nest/expr/Subscript.h"
+
+namespace nest
+{
+namespace expr
+{
+
+class DerefNode final : public Node
+{
+public:
+ template <typename... Args>
+ DerefNode(const DomainID &id, Args &&... indicies)
+ : _id{id}, _sub{std::forward<Args>(indicies)...}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const DerefNode *asDeref(void) const override { return this; }
+
+public:
+ const DomainID &id(void) const { return _id; }
+ const Subscript &sub(void) const { return _sub; }
+
+private:
+ DomainID const _id;
+ Subscript const _sub;
+};
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEXT_EXPR_DEREF_NODE_H__
diff --git a/compiler/nest/core/include/nest/expr/Forward.h b/compiler/nest/core/include/nest/expr/Forward.h
new file mode 100644
index 000000000..ae15b13b4
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/Forward.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_EXPR_FORWARD_H__
+#define __NEST_EXPR_FORWARD_H__
+
+#include "nest/expr/Macro.h"
+
+namespace nest
+{
+namespace expr
+{
+
+#define EXPR(Tag) class NEST_EXPR_CLASS_NAME(Tag);
+#include "nest/expr/Node.def"
+#undef EXPR
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEST_EXPR_FORWARD_H__
diff --git a/compiler/nest/core/include/nest/expr/Macro.h b/compiler/nest/core/include/nest/expr/Macro.h
new file mode 100644
index 000000000..dca8bd344
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/Macro.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_EXPR_MACRO_H__
+#define __NEST_EXPR_MACRO_H__
+
+#ifndef NEST_EXPR_CLASS_NAME
+#define NEST_EXPR_CLASS_NAME(Tag) Tag##Node
+#endif // NEST_EXPR_CLASS_NAME
+
+#ifndef NEST_EXPR_CAST_METHOD_NAME
+#define NEST_EXPR_CAST_METHOD_NAME(Tag) as##Tag
+#endif // NEST_EXPR_CAST_METHOD_NAME
+
+#endif // __NEST_EXPR_MACRO_H__
diff --git a/compiler/nest/core/include/nest/expr/MulNode.h b/compiler/nest/core/include/nest/expr/MulNode.h
new file mode 100644
index 000000000..f388b33a3
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/MulNode.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_EXPR_MUL_NODE_H__
+#define __NEST_EXPR_MUL_NODE_H__
+
+#include "nest/expr/Node.h"
+
+#include <memory>
+
+namespace nest
+{
+namespace expr
+{
+
+class MulNode final : public Node
+{
+public:
+ MulNode(const std::shared_ptr<expr::Node> &lhs, const std::shared_ptr<expr::Node> &rhs)
+ : _lhs{lhs}, _rhs{rhs}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const MulNode *asMul(void) const override { return this; }
+
+public:
+ const std::shared_ptr<expr::Node> &lhs(void) const { return _lhs; }
+ const std::shared_ptr<expr::Node> &rhs(void) const { return _rhs; }
+
+private:
+ std::shared_ptr<expr::Node> const _lhs;
+ std::shared_ptr<expr::Node> const _rhs;
+};
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEST_EXPR_MUL_NODE_H__
diff --git a/compiler/nest/core/include/nest/expr/Node.def b/compiler/nest/core/include/nest/expr/Node.def
new file mode 100644
index 000000000..0429517a0
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/Node.def
@@ -0,0 +1,9 @@
+#ifndef EXPR
+#error EXPR is should be defined before include this file
+#endif
+
+// EXPR(Tag)
+EXPR(Var)
+EXPR(Deref)
+EXPR(Add)
+EXPR(Mul)
diff --git a/compiler/nest/core/include/nest/expr/Node.h b/compiler/nest/core/include/nest/expr/Node.h
new file mode 100644
index 000000000..d187c25fa
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/Node.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_EXPR_NODE_H__
+#define __NEST_EXPR_NODE_H__
+
+#include "nest/expr/Macro.h"
+#include "nest/expr/Forward.h"
+#include "nest/expr/Visitor.h"
+
+#include <stdexcept>
+
+namespace nest
+{
+namespace expr
+{
+
+struct Node
+{
+ virtual ~Node() = default;
+
+#define EXPR(Tag) \
+ virtual const NEST_EXPR_CLASS_NAME(Tag) * NEST_EXPR_CAST_METHOD_NAME(Tag)(void) const \
+ { \
+ return nullptr; \
+ }
+#include "nest/expr/Node.def"
+#undef EXPR
+
+ template <typename T> T accept(Visitor<T> *v)
+ {
+#define EXPR(Tag) \
+ if (auto e = NEST_EXPR_CAST_METHOD_NAME(Tag)()) \
+ { \
+ return v->visit(e); \
+ }
+#include "nest/expr/Node.def"
+#undef EXPR
+
+ throw std::runtime_error{"unreachable"};
+ }
+
+ template <typename T> T accept(Visitor<T> &v) { return accept(&v); }
+};
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEST_EXPR_NODE_H__
diff --git a/compiler/nest/core/include/nest/expr/Subscript.h b/compiler/nest/core/include/nest/expr/Subscript.h
new file mode 100644
index 000000000..1670b8094
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/Subscript.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_SUBSCRIPT_H__
+#define __NEST_SUBSCRIPT_H__
+
+#include "nest/expr/Node.h"
+
+#include <vector>
+#include <initializer_list>
+
+#include <memory>
+
+namespace nest
+{
+namespace expr
+{
+
+class Subscript
+{
+public:
+ Subscript(std::initializer_list<std::shared_ptr<Node>> indices) : _indices{indices}
+ {
+ // DO NOTHING
+ }
+
+public:
+ uint32_t rank(void) const { return _indices.size(); }
+
+public:
+ const std::shared_ptr<expr::Node> &at(uint32_t n) const { return _indices.at(n); }
+
+private:
+ std::vector<std::shared_ptr<expr::Node>> _indices;
+};
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEST_SUBSCRIPT_H__
diff --git a/compiler/nest/core/include/nest/expr/VarNode.h b/compiler/nest/core/include/nest/expr/VarNode.h
new file mode 100644
index 000000000..0767fed41
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/VarNode.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEXT_EXPR_VAR_NODE_H__
+#define __NEXT_EXPR_VAR_NODE_H__
+
+#include "nest/VarID.h"
+
+#include "nest/expr/Forward.h"
+#include "nest/expr/Visitor.h"
+#include "nest/expr/Node.h"
+
+namespace nest
+{
+namespace expr
+{
+
+class VarNode final : public Node
+{
+public:
+ VarNode(const VarID &id) : _id{id}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const VarNode *asVar(void) const override { return this; }
+
+public:
+ const VarID &id(void) const { return _id; }
+
+private:
+ VarID const _id;
+};
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEXT_EXPR_VAR_NODE_H__
diff --git a/compiler/nest/core/include/nest/expr/Visitor.h b/compiler/nest/core/include/nest/expr/Visitor.h
new file mode 100644
index 000000000..84f70e9f4
--- /dev/null
+++ b/compiler/nest/core/include/nest/expr/Visitor.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_EXPR_VISITOR_H__
+#define __NEST_EXPR_VISITOR_H__
+
+#include "nest/expr/Macro.h"
+#include "nest/expr/Forward.h"
+
+namespace nest
+{
+namespace expr
+{
+
+template <typename T> struct Visitor
+{
+ virtual ~Visitor() = default;
+
+#define EXPR(Tag) virtual T visit(const NEST_EXPR_CLASS_NAME(Tag) *) = 0;
+#include "nest/expr/Node.def"
+#undef EXPR
+};
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEST_EXPR_VISITOR_H__
diff --git a/compiler/nest/core/include/nest/stmt/Forward.h b/compiler/nest/core/include/nest/stmt/Forward.h
new file mode 100644
index 000000000..349898e42
--- /dev/null
+++ b/compiler/nest/core/include/nest/stmt/Forward.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_STMT_FORWARD_H__
+#define __NEST_STMT_FORWARD_H__
+
+#include "nest/stmt/Macro.h"
+
+namespace nest
+{
+namespace stmt
+{
+
+#define STMT(Tag) class NEST_STMT_CLASS_NAME(Tag);
+#include "nest/stmt/Node.def"
+#undef STMT
+
+} // namespace stmt
+} // namespace nest
+
+#endif // __NEST_STMT_FORWARD_H__
diff --git a/compiler/nest/core/include/nest/stmt/Macro.h b/compiler/nest/core/include/nest/stmt/Macro.h
new file mode 100644
index 000000000..f8cd8941e
--- /dev/null
+++ b/compiler/nest/core/include/nest/stmt/Macro.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_STMT_MACRO_H__
+#define __NEST_STMT_MACRO_H__
+
+#ifndef NEST_STMT_CLASS_NAME
+#define NEST_STMT_CLASS_NAME(Tag) Tag##Node
+#endif // NEST_STMT_CLASS_NAME
+
+#ifndef NEST_STMT_CAST_METHOD_NAME
+#define NEST_STMT_CAST_METHOD_NAME(Tag) as##Tag
+#endif // STMT_CAST_METHOD_NAME
+
+#endif // __NEST_STMT_MACRO_H__
diff --git a/compiler/nest/core/include/nest/stmt/Node.def b/compiler/nest/core/include/nest/stmt/Node.def
new file mode 100644
index 000000000..dcec9147f
--- /dev/null
+++ b/compiler/nest/core/include/nest/stmt/Node.def
@@ -0,0 +1,6 @@
+#ifndef STMT
+#error STMT is should be defined before including this file
+#endif
+
+// STMT(Tag)
+STMT(Push)
diff --git a/compiler/nest/core/include/nest/stmt/Node.h b/compiler/nest/core/include/nest/stmt/Node.h
new file mode 100644
index 000000000..593eb68a1
--- /dev/null
+++ b/compiler/nest/core/include/nest/stmt/Node.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_STMT_NODE_H__
+#define __NEST_STMT_NODE_H__
+
+#include "nest/stmt/Macro.h"
+#include "nest/stmt/Forward.h"
+#include "nest/stmt/Visitor.h"
+
+#include <stdexcept>
+
+namespace nest
+{
+namespace stmt
+{
+
+struct Node
+{
+ virtual ~Node() = default;
+
+#define STMT(Tag) \
+ virtual const NEST_STMT_CLASS_NAME(Tag) * NEST_STMT_CAST_METHOD_NAME(Tag)(void) const \
+ { \
+ return nullptr; \
+ }
+#include "nest/stmt/Node.def"
+#undef STMT
+
+ template <typename T> T accept(Visitor<T> *v)
+ {
+#define STMT(Tag) \
+ if (auto s = NEST_STMT_CAST_METHOD_NAME(Tag)()) \
+ { \
+ return v->visit(s); \
+ }
+#include "nest/stmt/Node.def"
+#undef STMT
+
+ throw std::runtime_error{"unreachable"};
+ }
+
+ template <typename T> T accept(Visitor<T> &v) { return accept(&v); }
+};
+
+} // namespace stmt
+} // namespace nest
+
+#endif // __NEST_STMT_NODE_H__
diff --git a/compiler/nest/core/include/nest/stmt/PushNode.h b/compiler/nest/core/include/nest/stmt/PushNode.h
new file mode 100644
index 000000000..8a6b3cd91
--- /dev/null
+++ b/compiler/nest/core/include/nest/stmt/PushNode.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_STMT_PUSH_NODE_H__
+#define __NEST_STMT_PUSH_NODE_H__
+
+#include "nest/stmt/Node.h"
+#include "nest/Expr.h"
+
+namespace nest
+{
+namespace stmt
+{
+
+class PushNode final : public Node
+{
+public:
+ PushNode(const Expr &expr) : _expr{expr}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const PushNode *asPush(void) const override { return this; }
+
+public:
+ const Expr &expr(void) const { return _expr; }
+
+private:
+ Expr const _expr;
+};
+
+} // namespace stmt
+} // namespace nest
+
+#endif // __NEST_STMT_PUSH_NODE_H__
diff --git a/compiler/nest/core/include/nest/stmt/Visitor.h b/compiler/nest/core/include/nest/stmt/Visitor.h
new file mode 100644
index 000000000..459f0c9d6
--- /dev/null
+++ b/compiler/nest/core/include/nest/stmt/Visitor.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEST_STMT_VISITOR_H__
+#define __NEST_STMT_VISITOR_H__
+
+#include "nest/stmt/Macro.h"
+#include "nest/stmt/Forward.h"
+
+namespace nest
+{
+namespace stmt
+{
+
+template <typename T> struct Visitor
+{
+ virtual ~Visitor() = default;
+
+#define STMT(Tag) virtual T visit(const NEST_STMT_CLASS_NAME(Tag) *) = 0;
+#include "nest/stmt/Node.def"
+#undef STMT
+};
+
+} // namespace stmt
+} // namespace nest
+
+#endif // __NEST_STMT_VISITOR_H__
diff --git a/compiler/nest/core/src/Block.test.cpp b/compiler/nest/core/src/Block.test.cpp
new file mode 100644
index 000000000..b40fbeaac
--- /dev/null
+++ b/compiler/nest/core/src/Block.test.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Block.h"
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyNode final : public nest::stmt::Node
+{
+ // Dummy Node for testing
+};
+}
+
+TEST(BLOCK, use_case_1)
+{
+ nest::Block block;
+
+ ASSERT_EQ(block.size(), 0);
+
+ auto stmt = std::make_shared<DummyNode>();
+
+ block.append(stmt);
+
+ ASSERT_EQ(block.size(), 1);
+ ASSERT_EQ(block.at(0), stmt);
+}
diff --git a/compiler/nest/core/src/Bound.test.cpp b/compiler/nest/core/src/Bound.test.cpp
new file mode 100644
index 000000000..7b2f0b62e
--- /dev/null
+++ b/compiler/nest/core/src/Bound.test.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Bound.h"
+
+#include <gtest/gtest.h>
+
+TEST(BOUND, ctor)
+{
+ const nest::Bound b{-10, 20};
+
+ ASSERT_EQ(b.min(), -10);
+ ASSERT_EQ(b.max(), 20);
+}
diff --git a/compiler/nest/core/src/Closure.cpp b/compiler/nest/core/src/Closure.cpp
new file mode 100644
index 000000000..253a612f8
--- /dev/null
+++ b/compiler/nest/core/src/Closure.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Closure.h"
+
+namespace nest
+{
+
+Closure::operator Expr(void) const { return std::make_shared<expr::DerefNode>(_id, _sub); }
+
+} // namespace nest
diff --git a/compiler/nest/core/src/Closure.test.cpp b/compiler/nest/core/src/Closure.test.cpp
new file mode 100644
index 000000000..1dae849a3
--- /dev/null
+++ b/compiler/nest/core/src/Closure.test.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Closure.h"
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+}
+
+TEST(Closure, ctor)
+{
+ nest::DomainID dom_id{0};
+ nest::Closure closure{dom_id, std::make_shared<DummyNode>()};
+
+ 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<DummyNode>()};
+
+ auto check = [](const nest::Expr &e) { ASSERT_NE(e.get(), nullptr); };
+
+ check(closure);
+}
diff --git a/compiler/nest/core/src/Domain.test.cpp b/compiler/nest/core/src/Domain.test.cpp
new file mode 100644
index 000000000..5f973ecf7
--- /dev/null
+++ b/compiler/nest/core/src/Domain.test.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Domain.h"
+
+#include <gtest/gtest.h>
+
+namespace
+{
+namespace expr
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+} // namespace expr
+} // namespace
+
+// NOTE Build failed when DOMAIN is used instead of _DOMAIN
+TEST(_DOMAIN, base_usecase)
+{
+ nest::DomainID dom_id{0};
+ nest::Domain dom{dom_id};
+
+ nest::Closure clo = dom(std::make_shared<::expr::DummyNode>());
+
+ ASSERT_EQ(clo.id(), dom_id);
+ ASSERT_EQ(clo.sub().rank(), 1);
+}
diff --git a/compiler/nest/core/src/DomainContext.cpp b/compiler/nest/core/src/DomainContext.cpp
new file mode 100644
index 000000000..4a7f223d4
--- /dev/null
+++ b/compiler/nest/core/src/DomainContext.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/DomainContext.h"
+
+namespace nest
+{
+
+uint32_t DomainContext::count(void) const { return _info.size(); }
+
+Domain DomainContext::make(std::initializer_list<uint32_t> dims)
+{
+ const DomainID domain_id{count()};
+
+ _info.emplace_back(dims);
+
+ return Domain{domain_id};
+}
+
+const DomainInfo &DomainContext::info(const Domain &dom) const
+{
+ return _info.at(dom.id().value());
+}
+
+} // namespace nest
diff --git a/compiler/nest/core/src/DomainContext.test.cpp b/compiler/nest/core/src/DomainContext.test.cpp
new file mode 100644
index 000000000..10882df70
--- /dev/null
+++ b/compiler/nest/core/src/DomainContext.test.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/DomainContext.h"
+
+#include <gtest/gtest.h>
+
+TEST(DOMAIN_CONTEXT, usecase)
+{
+ nest::DomainContext ctx;
+
+ auto dom_0 = ctx.make({1, 3, 4});
+
+ ASSERT_EQ(ctx.count(), 1);
+
+ auto check_dom_0 = [&](void) {
+ ASSERT_EQ(ctx.info(dom_0).rank(), 3);
+ ASSERT_EQ(ctx.info(dom_0).dim(0), 1);
+ ASSERT_EQ(ctx.info(dom_0).dim(1), 3);
+ ASSERT_EQ(ctx.info(dom_0).dim(2), 4);
+ };
+
+ check_dom_0();
+
+ auto dom_1 = ctx.make({7, 6, 2, 1});
+
+ ASSERT_EQ(ctx.count(), 2);
+
+ // Domain ID should be unique for each domain
+ ASSERT_FALSE(dom_0.id() == dom_1.id());
+
+ auto check_dom_1 = [&](void) {
+ ASSERT_EQ(ctx.info(dom_1).rank(), 4);
+ ASSERT_EQ(ctx.info(dom_1).dim(0), 7);
+ ASSERT_EQ(ctx.info(dom_1).dim(1), 6);
+ ASSERT_EQ(ctx.info(dom_1).dim(2), 2);
+ ASSERT_EQ(ctx.info(dom_1).dim(3), 1);
+ };
+
+ // make() SHOULD NOT affect the existing domain information
+ check_dom_0();
+ check_dom_1();
+}
diff --git a/compiler/nest/core/src/DomainID.cpp b/compiler/nest/core/src/DomainID.cpp
new file mode 100644
index 000000000..714f07b67
--- /dev/null
+++ b/compiler/nest/core/src/DomainID.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/DomainID.h"
+
+namespace nest
+{
+
+DomainID::DomainID() : _value{0xffffffff}
+{
+ // DO NOTHING
+}
+
+bool operator==(const DomainID &lhs, const DomainID &rhs) { return lhs.value() == rhs.value(); }
+bool operator<(const DomainID &lhs, const DomainID &rhs) { return lhs.value() < rhs.value(); }
+
+} // namespace nest
diff --git a/compiler/nest/core/src/DomainID.test.cpp b/compiler/nest/core/src/DomainID.test.cpp
new file mode 100644
index 000000000..6b1ce8360
--- /dev/null
+++ b/compiler/nest/core/src/DomainID.test.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/DomainID.h"
+
+#include <gtest/gtest.h>
+
+TEST(DOMAIN_ID, ctor)
+{
+ nest::DomainID id{0};
+
+ ASSERT_EQ(id.value(), 0);
+}
+
+TEST(DOMAIN_ID, operator_eq)
+{
+ ASSERT_TRUE(nest::DomainID(0) == nest::DomainID(0));
+ ASSERT_FALSE(nest::DomainID(0) == nest::DomainID(1));
+}
+
+TEST(DOMAIN_ID, operator_lt)
+{
+ ASSERT_TRUE(nest::DomainID(0) < nest::DomainID(1));
+ ASSERT_FALSE(nest::DomainID(1) < nest::DomainID(0));
+}
diff --git a/compiler/nest/core/src/DomainInfo.test.cpp b/compiler/nest/core/src/DomainInfo.test.cpp
new file mode 100644
index 000000000..7a5d81144
--- /dev/null
+++ b/compiler/nest/core/src/DomainInfo.test.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/DomainInfo.h"
+
+#include <gtest/gtest.h>
+
+TEST(DOMAIN_INFO, ctor)
+{
+ nest::DomainInfo info{1, 2, 3, 4};
+
+ ASSERT_EQ(info.rank(), 4);
+ ASSERT_EQ(info.dim(0), 1);
+ ASSERT_EQ(info.dim(1), 2);
+ ASSERT_EQ(info.dim(2), 3);
+ ASSERT_EQ(info.dim(3), 4);
+}
diff --git a/compiler/nest/core/src/Expr.cpp b/compiler/nest/core/src/Expr.cpp
new file mode 100644
index 000000000..6d35f4c5a
--- /dev/null
+++ b/compiler/nest/core/src/Expr.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Expr.h"
+
+nest::Expr operator+(const nest::Expr &lhs, const nest::Expr &rhs)
+{
+ return std::make_shared<nest::expr::AddNode>(lhs, rhs);
+}
+
+nest::Expr operator*(const nest::Expr &lhs, const nest::Expr &rhs)
+{
+ return std::make_shared<nest::expr::MulNode>(lhs, rhs);
+}
diff --git a/compiler/nest/core/src/Expr.test.cpp b/compiler/nest/core/src/Expr.test.cpp
new file mode 100644
index 000000000..0c96f7714
--- /dev/null
+++ b/compiler/nest/core/src/Expr.test.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Expr.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+}
+
+TEST(EXPR, operator_sum)
+{
+ auto left = std::make_shared<DummyNode>();
+ auto right = std::make_shared<DummyNode>();
+
+ auto expr = left + right;
+
+ ASSERT_NE(expr->asAdd(), nullptr);
+
+ auto add = expr->asAdd();
+
+ ASSERT_EQ(add->lhs().get(), left.get());
+ ASSERT_EQ(add->rhs().get(), right.get());
+}
+
+TEST(EXPR, operator_mul)
+{
+ auto left = std::make_shared<DummyNode>();
+ auto right = std::make_shared<DummyNode>();
+
+ auto expr = left * right;
+
+ ASSERT_NE(expr->asMul(), nullptr);
+
+ auto add = expr->asMul();
+
+ ASSERT_EQ(add->lhs().get(), left.get());
+ ASSERT_EQ(add->rhs().get(), right.get());
+}
diff --git a/compiler/nest/core/src/FV.cpp b/compiler/nest/core/src/FV.cpp
new file mode 100644
index 000000000..2b51d178c
--- /dev/null
+++ b/compiler/nest/core/src/FV.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/FV.h"
+
+namespace
+{
+
+using namespace nest;
+using namespace nest::expr;
+
+class Collector final : public Visitor<void>
+{
+public:
+ Collector(std::set<VarID> &out) : _out(out)
+ {
+ // DO NOTHING
+ }
+
+public:
+ void visit(const VarNode *e) override { _out.insert(e->id()); }
+
+ void visit(const DerefNode *e) override
+ {
+ for (uint32_t n = 0; n < e->sub().rank(); ++n)
+ {
+ e->sub().at(n)->accept(this);
+ }
+ }
+
+ void visit(const AddNode *e) override
+ {
+ e->lhs()->accept(this);
+ e->rhs()->accept(this);
+ }
+
+ void visit(const MulNode *e) override
+ {
+ e->lhs()->accept(this);
+ e->rhs()->accept(this);
+ }
+
+private:
+ std::set<nest::VarID> &_out;
+};
+
+} // namespace
+
+namespace nest
+{
+
+std::set<VarID> FV::in(const Expr &expr)
+{
+ std::set<VarID> res;
+
+ Collector collector{res};
+ expr->accept(collector);
+
+ return res;
+}
+
+} // namespace nest
diff --git a/compiler/nest/core/src/FV.test.cpp b/compiler/nest/core/src/FV.test.cpp
new file mode 100644
index 000000000..55f5f5877
--- /dev/null
+++ b/compiler/nest/core/src/FV.test.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/FV.h"
+#include "nest/Module.h"
+
+#include <gtest/gtest.h>
+
+TEST(FV, var_expr)
+{
+ nest::Module m;
+
+ auto var = m.var().make();
+
+ auto fvs = nest::FV::in(var);
+
+ ASSERT_EQ(fvs.size(), 1);
+ ASSERT_NE(fvs.find(var.id()), fvs.end());
+}
+
+TEST(FV, deref_expr)
+{
+ nest::Module m;
+
+ auto dom = m.domain().make({16});
+ auto var = m.var().make();
+
+ auto fvs = nest::FV::in(dom(var));
+
+ ASSERT_EQ(fvs.size(), 1);
+ ASSERT_NE(fvs.find(var.id()), fvs.end());
+}
+
+TEST(FV, add_expr)
+{
+ nest::Module m;
+
+ auto v_0 = m.var().make();
+ auto v_1 = m.var().make();
+
+ auto fvs = nest::FV::in(v_0 + v_1);
+
+ ASSERT_EQ(fvs.size(), 2);
+ ASSERT_NE(fvs.find(v_0.id()), fvs.end());
+ ASSERT_NE(fvs.find(v_1.id()), fvs.end());
+}
+
+TEST(FV, mul_expr)
+{
+ nest::Module m;
+
+ auto v_0 = m.var().make();
+ auto v_1 = m.var().make();
+
+ nest::FV fv;
+
+ auto fvs = nest::FV::in(v_0 * v_1);
+
+ ASSERT_EQ(fvs.size(), 2);
+ ASSERT_NE(fvs.find(v_0.id()), fvs.end());
+ ASSERT_NE(fvs.find(v_1.id()), fvs.end());
+}
diff --git a/compiler/nest/core/src/Level.cpp b/compiler/nest/core/src/Level.cpp
new file mode 100644
index 000000000..1adf4351d
--- /dev/null
+++ b/compiler/nest/core/src/Level.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Level.h"
+
+#include <cassert>
+
+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/compiler/nest/core/src/Level.test.cpp b/compiler/nest/core/src/Level.test.cpp
new file mode 100644
index 000000000..b9e203d9d
--- /dev/null
+++ b/compiler/nest/core/src/Level.test.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Level.h"
+
+#include <gtest/gtest.h>
+
+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));
+}
diff --git a/compiler/nest/core/src/Module.cpp b/compiler/nest/core/src/Module.cpp
new file mode 100644
index 000000000..060f94e3e
--- /dev/null
+++ b/compiler/nest/core/src/Module.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Module.h"
+
+#include <cassert>
+
+namespace nest
+{
+
+void Module::push(const Expr &expr)
+{
+ auto stmt = std::make_shared<stmt::PushNode>(expr);
+ _block.append(stmt);
+}
+
+void Module::ret(const Closure &clo)
+{
+ // Only one RET is allowed for each module
+ assert(_ret == nullptr);
+ _ret = std::make_shared<Ret>(clo.id(), clo.sub());
+}
+
+const Ret &Module::ret(void) const
+{
+ // Caller should NOT invoke this method before setting ret
+ assert(_ret != nullptr);
+ return *_ret;
+}
+
+} // namespace nest
diff --git a/compiler/nest/core/src/Module.test.cpp b/compiler/nest/core/src/Module.test.cpp
new file mode 100644
index 000000000..01e414d25
--- /dev/null
+++ b/compiler/nest/core/src/Module.test.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Module.h"
+
+#include <gtest/gtest.h>
+
+TEST(MODULE, create_var)
+{
+ nest::Module m;
+
+ auto create = [](nest::Module &m) {
+ // This code will invoke 'VarContext &var(void)' method
+ return m.var().make();
+ };
+
+ auto check = [](const nest::Module &m) {
+ // This code will invoke 'const VarContext &var(void) const' method
+ ASSERT_EQ(m.var().count(), 1);
+ };
+
+ create(m);
+ check(m);
+}
+
+TEST(MODULE, create_domain)
+{
+ nest::Module m;
+
+ auto create = [](nest::Module &m, std::initializer_list<uint32_t> dims) {
+ // This code will invoke 'DomainContext &domain(void)' method
+ return m.domain().make(dims);
+ };
+
+ auto check = [](const nest::Module &m) {
+ // This code will invoke 'const DomainContext &domain(void) const' method
+ ASSERT_EQ(m.domain().count(), 1);
+ };
+
+ create(m, {1, 3, 3});
+ check(m);
+}
+
+TEST(MODULE, push)
+{
+ nest::Module m;
+
+ auto ifm = m.domain().make({1, 3, 3});
+
+ auto var_ch = m.var().make();
+ auto var_row = m.var().make();
+ auto var_col = m.var().make();
+
+ m.push(ifm(var_ch, var_row, var_col));
+
+ ASSERT_EQ(m.block().size(), 1);
+ ASSERT_NE(m.block().at(0)->asPush(), nullptr);
+}
+
+TEST(MODULE, ret)
+{
+ nest::Module m;
+
+ auto ifm = m.domain().make({1});
+ auto ofm = m.domain().make({1});
+
+ auto ind = m.var().make();
+
+ m.push(ifm(ind));
+ m.ret(ofm(ind));
+
+ ASSERT_EQ(m.ret().id(), ofm.id());
+ ASSERT_EQ(m.ret().sub().rank(), 1);
+}
+
+TEST(MODULE, copy)
+{
+ nest::Module orig;
+ nest::Module copy;
+
+ orig = copy;
+
+ orig.var().make();
+
+ ASSERT_EQ(copy.var().count(), 0);
+}
diff --git a/compiler/nest/core/src/Ret.test.cpp b/compiler/nest/core/src/Ret.test.cpp
new file mode 100644
index 000000000..703f04901
--- /dev/null
+++ b/compiler/nest/core/src/Ret.test.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Ret.h"
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+}
+
+TEST(RET, ctor)
+{
+ nest::DomainID dom_id{0};
+ nest::expr::Subscript sub{std::make_shared<DummyNode>()};
+
+ nest::Ret ret{dom_id, sub};
+
+ ASSERT_EQ(ret.id().value(), 0);
+ ASSERT_EQ(ret.sub().rank(), 1);
+}
+
+TEST(RET, copy)
+{
+ nest::DomainID src_id{0};
+ nest::expr::Subscript src_sub{std::make_shared<DummyNode>()};
+
+ const nest::Ret src{src_id, src_sub};
+
+ nest::DomainID dst_id{1};
+ nest::expr::Subscript dst_sub{std::make_shared<DummyNode>(), std::make_shared<DummyNode>()};
+
+ nest::Ret dst{dst_id, dst_sub};
+
+ ASSERT_EQ(dst.id().value(), 1);
+ ASSERT_EQ(dst.sub().rank(), 2);
+
+ dst = src;
+
+ ASSERT_EQ(dst.id().value(), 0);
+ ASSERT_EQ(dst.sub().rank(), 1);
+}
diff --git a/compiler/nest/core/src/Schedule.cpp b/compiler/nest/core/src/Schedule.cpp
new file mode 100644
index 000000000..81f9cd26a
--- /dev/null
+++ b/compiler/nest/core/src/Schedule.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Schedule.h"
+
+#include <cassert>
+#include <stdexcept>
+
+namespace nest
+{
+
+Schedule::Schedule(const Module &module) : _module{module}
+{
+ // NOTE This implementation assumes that VarContext sequentially assigns VarID
+ for (uint32_t n = 0; n < _module.var().count(); ++n)
+ {
+ _level.emplace_back(VarID{n});
+ }
+
+ assert(_level.size() == _module.var().count());
+}
+
+Var Schedule::at(const Level &lv) const { return Var{_level.at(lv.value())}; }
+
+Level Schedule::level(const Var &var) const
+{
+ for (uint32_t lv = 0; lv < _level.size(); ++lv)
+ {
+ if (_level.at(lv) == var.id())
+ {
+ return Level{lv};
+ }
+ }
+
+ throw std::invalid_argument{"var"};
+}
+
+} // namespace nest
diff --git a/compiler/nest/core/src/Schedule.test.cpp b/compiler/nest/core/src/Schedule.test.cpp
new file mode 100644
index 000000000..8f0ddb23c
--- /dev/null
+++ b/compiler/nest/core/src/Schedule.test.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Schedule.h"
+
+#include <gtest/gtest.h>
+
+TEST(SCHEDULE, module)
+{
+ nest::Module m;
+
+ auto var_1 = m.var().make();
+
+ nest::Schedule sch{m};
+
+ ASSERT_EQ(sch.level(var_1).value(), 0);
+}
+
+TEST(SCHEDULE, module_copy)
+{
+ nest::Module m;
+
+ m.var().make();
+
+ nest::Schedule sch{m};
+
+ // Update on 'm' does not affect the schedule
+ m.var().make();
+
+ ASSERT_EQ(sch.var().count(), 1);
+}
diff --git a/compiler/nest/core/src/Var.cpp b/compiler/nest/core/src/Var.cpp
new file mode 100644
index 000000000..93ce6e43b
--- /dev/null
+++ b/compiler/nest/core/src/Var.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Var.h"
+
+namespace nest
+{
+
+Var::operator Expr(void) const { return std::make_shared<expr::VarNode>(_id); }
+
+} // namespace nest
diff --git a/compiler/nest/core/src/Var.test.cpp b/compiler/nest/core/src/Var.test.cpp
new file mode 100644
index 000000000..29f879558
--- /dev/null
+++ b/compiler/nest/core/src/Var.test.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/Var.h"
+
+#include <gtest/gtest.h>
+
+TEST(VAR, ctor)
+{
+ nest::VarID id{0};
+ nest::Var var{id};
+
+ ASSERT_EQ(var.id(), id);
+}
+
+TEST(VAR, cast)
+{
+ nest::VarID id{0};
+ nest::Var var{id};
+
+ nest::Expr expr = var;
+
+ ASSERT_NE(expr->asVar(), nullptr);
+ ASSERT_EQ(expr->asVar()->id(), id);
+}
diff --git a/compiler/nest/core/src/VarContext.cpp b/compiler/nest/core/src/VarContext.cpp
new file mode 100644
index 000000000..24b1336a7
--- /dev/null
+++ b/compiler/nest/core/src/VarContext.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/VarContext.h"
+
+namespace nest
+{
+
+uint32_t VarContext::count(void) const { return _bound.size(); }
+
+Var VarContext::make(void)
+{
+ const VarID vid{count()};
+
+ _bound.emplace_back(0, 0);
+
+ return Var{vid};
+}
+
+Bound &VarContext::bound(const Var &var) { return _bound.at(var.id().value()); }
+const Bound &VarContext::bound(const Var &var) const { return _bound.at(var.id().value()); }
+
+} // namespace nest
diff --git a/compiler/nest/core/src/VarContext.test.cpp b/compiler/nest/core/src/VarContext.test.cpp
new file mode 100644
index 000000000..169bd6126
--- /dev/null
+++ b/compiler/nest/core/src/VarContext.test.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/VarContext.h"
+
+#include <gtest/gtest.h>
+
+TEST(VAR_CONTEXT, make)
+{
+ nest::VarContext ctx;
+
+ auto var_0 = ctx.make();
+ auto var_1 = ctx.make();
+
+ ASSERT_FALSE(var_0.id() == var_1.id());
+}
+
+TEST(VAR_CONTEXT, count)
+{
+ nest::VarContext ctx;
+
+ ASSERT_EQ(ctx.count(), 0);
+
+ auto var_0 = ctx.make();
+
+ ASSERT_EQ(ctx.count(), 1);
+
+ auto var_1 = ctx.make();
+
+ ASSERT_EQ(ctx.count(), 2);
+}
+
+TEST(VAR_CONTEXT, bound_one)
+{
+ nest::VarContext ctx;
+
+ auto var_0 = ctx.make();
+
+ ASSERT_EQ(ctx.bound(var_0).min(), 0);
+ ASSERT_EQ(ctx.bound(var_0).max(), 0);
+
+ ctx.bound(var_0) = nest::Bound{-3, 5};
+
+ ASSERT_EQ(ctx.bound(var_0).min(), -3);
+ ASSERT_EQ(ctx.bound(var_0).max(), 5);
+}
+
+TEST(VAR_CONTEXT, bound_independent)
+{
+ nest::VarContext ctx;
+
+ auto var_0 = ctx.make();
+
+ ASSERT_EQ(ctx.bound(var_0).min(), 0);
+ ASSERT_EQ(ctx.bound(var_0).max(), 0);
+
+ auto var_1 = ctx.make();
+
+ ASSERT_EQ(ctx.bound(var_1).min(), 0);
+ ASSERT_EQ(ctx.bound(var_1).max(), 0);
+
+ ctx.bound(var_0) = nest::Bound{-3, 5};
+
+ ASSERT_EQ(ctx.bound(var_0).min(), -3);
+ ASSERT_EQ(ctx.bound(var_0).max(), 5);
+
+ ASSERT_EQ(ctx.bound(var_1).min(), 0);
+ ASSERT_EQ(ctx.bound(var_1).max(), 0);
+}
diff --git a/compiler/nest/core/src/VarID.cpp b/compiler/nest/core/src/VarID.cpp
new file mode 100644
index 000000000..23906764d
--- /dev/null
+++ b/compiler/nest/core/src/VarID.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#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/compiler/nest/core/src/VarID.test.cpp b/compiler/nest/core/src/VarID.test.cpp
new file mode 100644
index 000000000..e4a17a5c1
--- /dev/null
+++ b/compiler/nest/core/src/VarID.test.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#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));
+}
diff --git a/compiler/nest/core/src/expr/AddNode.test.cpp b/compiler/nest/core/src/expr/AddNode.test.cpp
new file mode 100644
index 000000000..5c44c4743
--- /dev/null
+++ b/compiler/nest/core/src/expr/AddNode.test.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/expr/AddNode.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+}
+
+TEST(ADD_NODE, cast)
+{
+ auto left = std::make_shared<DummyNode>();
+ auto right = std::make_shared<DummyNode>();
+
+ auto derived = std::make_shared<nest::expr::AddNode>(left, right);
+ std::shared_ptr<nest::expr::Node> base = derived;
+
+ ASSERT_NE(derived.get(), nullptr);
+ ASSERT_EQ(base->asAdd(), derived.get());
+
+ ASSERT_EQ(derived->lhs().get(), left.get());
+ ASSERT_EQ(derived->rhs().get(), right.get());
+}
diff --git a/compiler/nest/core/src/expr/DerefNode.test.cpp b/compiler/nest/core/src/expr/DerefNode.test.cpp
new file mode 100644
index 000000000..e02a7de0b
--- /dev/null
+++ b/compiler/nest/core/src/expr/DerefNode.test.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/expr/DerefNode.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+}
+
+TEST(DEREF_NODE, cast)
+{
+ const nest::DomainID dom_id{0};
+
+ auto derived = std::make_shared<nest::expr::DerefNode>(dom_id, std::make_shared<DummyNode>());
+ std::shared_ptr<nest::expr::Node> base = derived;
+
+ ASSERT_NE(derived.get(), nullptr);
+ ASSERT_EQ(base->asDeref(), derived.get());
+}
diff --git a/compiler/nest/core/src/expr/Macro.cpp b/compiler/nest/core/src/expr/Macro.cpp
new file mode 100644
index 000000000..4e7a13e08
--- /dev/null
+++ b/compiler/nest/core/src/expr/Macro.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/expr/Macro.h"
+
+// This file checkes the self-completeness of 'nest/expr/Macro.h'.
+//
+// NOTE Please do NOT remove this file.
diff --git a/compiler/nest/core/src/expr/MulNode.test.cpp b/compiler/nest/core/src/expr/MulNode.test.cpp
new file mode 100644
index 000000000..b2d29471c
--- /dev/null
+++ b/compiler/nest/core/src/expr/MulNode.test.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/expr/MulNode.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+}
+
+TEST(MUL_NODE, cast)
+{
+ auto left = std::make_shared<DummyNode>();
+ auto right = std::make_shared<DummyNode>();
+
+ auto derived = std::make_shared<nest::expr::MulNode>(left, right);
+ std::shared_ptr<nest::expr::Node> 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());
+}
diff --git a/compiler/nest/core/src/expr/Node.cpp b/compiler/nest/core/src/expr/Node.cpp
new file mode 100644
index 000000000..0c162428c
--- /dev/null
+++ b/compiler/nest/core/src/expr/Node.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/expr/Node.h"
+
+// This file checkes the self-completeness of 'nest/expr/Node.h'.
+//
+// NOTE Please do NOT remove this file.
diff --git a/compiler/nest/core/src/expr/Subscript.test.cpp b/compiler/nest/core/src/expr/Subscript.test.cpp
new file mode 100644
index 000000000..2f187b86c
--- /dev/null
+++ b/compiler/nest/core/src/expr/Subscript.test.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/expr/Subscript.h"
+#include "nest/expr/VarNode.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+TEST(SUBSCRIPT, ctor)
+{
+ nest::VarID id_0{0};
+ nest::VarID id_1{1};
+
+ auto expr_0 = std::make_shared<nest::expr::VarNode>(id_0);
+ auto expr_1 = std::make_shared<nest::expr::VarNode>(id_1);
+
+ nest::expr::Subscript sub{expr_0, expr_1};
+
+ ASSERT_EQ(sub.rank(), 2);
+ ASSERT_EQ(sub.at(0), expr_0);
+ ASSERT_EQ(sub.at(1), expr_1);
+}
diff --git a/compiler/nest/core/src/expr/VarNode.test.cpp b/compiler/nest/core/src/expr/VarNode.test.cpp
new file mode 100644
index 000000000..e8b2764e4
--- /dev/null
+++ b/compiler/nest/core/src/expr/VarNode.test.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/expr/VarNode.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+TEST(VAR_NODE, ctor)
+{
+ auto make = [](uint32_t n) {
+ const nest::VarID id{n};
+
+ return std::make_shared<nest::expr::VarNode>(id);
+ };
+
+ auto node = make(4);
+
+ // NOTE 'id' should be copied
+ ASSERT_EQ(node->id().value(), 4);
+}
+
+TEST(VAR_NODE, cast)
+{
+ const nest::VarID id{0};
+
+ auto derived = std::make_shared<nest::expr::VarNode>(id);
+ std::shared_ptr<nest::expr::Node> base = derived;
+
+ // NOTE Cast method should be overrided
+ ASSERT_NE(derived.get(), nullptr);
+ ASSERT_EQ(base->asVar(), derived.get());
+}
diff --git a/compiler/nest/core/src/expr/Visitor.cpp b/compiler/nest/core/src/expr/Visitor.cpp
new file mode 100644
index 000000000..531e68951
--- /dev/null
+++ b/compiler/nest/core/src/expr/Visitor.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/expr/Visitor.h"
+
+// This file checkes the self-completeness of 'nest/expr/Visitor.h'.
+//
+// NOTE Please do NOT remove this file.
diff --git a/compiler/nest/core/src/stmt/Macro.cpp b/compiler/nest/core/src/stmt/Macro.cpp
new file mode 100644
index 000000000..99adb436c
--- /dev/null
+++ b/compiler/nest/core/src/stmt/Macro.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/stmt/Macro.h"
+
+// This file checkes the self-completeness of 'nest/stmt/Macro.h'.
+//
+// NOTE Please do NOT remove this file.
diff --git a/compiler/nest/core/src/stmt/Node.cpp b/compiler/nest/core/src/stmt/Node.cpp
new file mode 100644
index 000000000..6265778d9
--- /dev/null
+++ b/compiler/nest/core/src/stmt/Node.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/stmt/Node.h"
+
+// This file checkes the self-completeness of 'nest/stmt/Node.h'.
+//
+// NOTE Please do NOT remove this file.
diff --git a/compiler/nest/core/src/stmt/PushNode.test.cpp b/compiler/nest/core/src/stmt/PushNode.test.cpp
new file mode 100644
index 000000000..a54efbb54
--- /dev/null
+++ b/compiler/nest/core/src/stmt/PushNode.test.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/stmt/PushNode.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyExprNode final : public nest::expr::Node
+{
+};
+}
+
+TEST(STMT_PUSH_NODE, cast)
+{
+ auto derived = std::make_shared<nest::stmt::PushNode>(std::make_shared<DummyExprNode>());
+ std::shared_ptr<nest::stmt::Node> base = derived;
+
+ ASSERT_NE(derived.get(), nullptr);
+ ASSERT_EQ(base->asPush(), derived.get());
+}
diff --git a/compiler/nest/core/src/stmt/Visitor.cpp b/compiler/nest/core/src/stmt/Visitor.cpp
new file mode 100644
index 000000000..621379bca
--- /dev/null
+++ b/compiler/nest/core/src/stmt/Visitor.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nest/stmt/Visitor.h"
+
+// This file checkes the self-completeness of 'nest/stmt/Visitor.h'.
+//
+// NOTE Please do NOT remove this file.