Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / exo / src / Dialect / IR / CircleNodeVisitor.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __LOCOEX_IR_CIRCLENODE_VISITOR_H__
18 #define __LOCOEX_IR_CIRCLENODE_VISITOR_H__
19
20 #include "CircleNode.h"
21
22 #include <oops/InternalExn.h>
23
24 namespace locoex
25 {
26
27 /**
28  * DO NOT use this class. Use CircleNodeVisitor instead.
29  */
30 template <typename T> struct CircleNodeVisitorBase
31 {
32   virtual ~CircleNodeVisitorBase() = default;
33
34 #define CIRCLE_NODE(OPCODE, Circle_CLASS) virtual T visit(const Circle_CLASS *) = 0;
35
36 #include "CircleNodes.lst"
37 #undef CIRCLE_NODE
38 };
39
40 template <typename T> struct CircleNodeVisitor : public CircleNodeVisitorBase<T>
41 {
42   virtual ~CircleNodeVisitor() = default;
43
44 #define CIRCLE_NODE(OPCODE, Circle_CLASS) \
45                                           \
46   virtual T visit(const Circle_CLASS *node) { return visit(static_cast<const CircleNode *>(node)); }
47
48 #include "CircleNodes.lst"
49 #undef CIRCLE_NODE
50
51   /// @brief Default fallback
52   virtual T visit(const CircleNode *) { INTERNAL_EXN("CircleNodeVisistor: NYI node"); }
53 };
54
55 /**
56  * DO NOT use this class. Use CircleNodeMutableVisitor instead.
57  */
58 template <typename T> struct CircleNodeMutableVisitorBase
59 {
60   virtual ~CircleNodeMutableVisitorBase() = default;
61
62 #define CIRCLE_NODE(OPCODE, Circle_CLASS) virtual T visit(Circle_CLASS *) = 0;
63
64 #include "CircleNodes.lst"
65 #undef CIRCLE_NODE
66 };
67
68 template <typename T> struct CircleNodeMutableVisitor : public CircleNodeMutableVisitorBase<T>
69 {
70   virtual ~CircleNodeMutableVisitor() = default;
71
72 #define CIRCLE_NODE(OPCODE, Circle_CLASS) \
73                                           \
74   virtual T visit(Circle_CLASS *node) { return visit(static_cast<CircleNode *>(node)); }
75
76 #include "CircleNodes.lst"
77 #undef CIRCLE_NODE
78
79   /// @brief Default fallback
80   virtual T visit(CircleNode *) { INTERNAL_EXN("CircleMutableNodeVisistor: NYI node"); }
81 };
82
83 } // namespace locoex
84
85 #endif // __LOCOEX_IR_CIRCLENODE_VISITOR_H__