From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Mon, 16 Jul 2018 08:40:51 +0000 (+0900) Subject: [nest] Add variable expression node (#664) X-Git-Tag: nncc_backup~2415 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e020b9480f2faba9fce76cb7acf584eee8aba845;p=platform%2Fcore%2Fml%2Fnnfw.git [nest] Add variable expression node (#664) This commit adds 'nest::expr::VarNode' class which represents index variable exression in nest IR. Signed-off-by: Jonghyun Park --- diff --git a/contrib/nest/include/nest/Expr.h b/contrib/nest/include/nest/Expr.h index d7447d3..8c84c06 100644 --- a/contrib/nest/include/nest/Expr.h +++ b/contrib/nest/include/nest/Expr.h @@ -4,4 +4,6 @@ #include "nest/expr/Node.h" #include "nest/expr/Visitor.h" +#include "nest/expr/VarNode.h" + #endif // __NEST_EXPR_H__ diff --git a/contrib/nest/include/nest/expr/Node.def b/contrib/nest/include/nest/expr/Node.def index 64c522f..a2c0a0c 100644 --- a/contrib/nest/include/nest/expr/Node.def +++ b/contrib/nest/include/nest/expr/Node.def @@ -3,3 +3,4 @@ #endif // EXPR(Tag) +EXPR(Var) diff --git a/contrib/nest/include/nest/expr/VarNode.h b/contrib/nest/include/nest/expr/VarNode.h new file mode 100644 index 0000000..dcd13e6 --- /dev/null +++ b/contrib/nest/include/nest/expr/VarNode.h @@ -0,0 +1,36 @@ +#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/contrib/nest/src/expr/VarNode.test.cpp b/contrib/nest/src/expr/VarNode.test.cpp new file mode 100644 index 0000000..810490c --- /dev/null +++ b/contrib/nest/src/expr/VarNode.test.cpp @@ -0,0 +1,31 @@ +#include "nest/expr/VarNode.h" + +#include + +#include + +TEST(VAR_NODE, ctor) +{ + auto make = [](uint32_t n) { + const nest::VarID id{n}; + + return std::make_shared(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(id); + std::shared_ptr base = derived; + + // NOTE Cast method should be overrided + ASSERT_NE(derived.get(), nullptr); + ASSERT_EQ(base->asVar(), derived.get()); +}