These commit adds basic classes for TFLDialect.
Namespace is 'locoex' since this is an extension of `loco`.
Signed-off-by: Hyun Sik Yoon <hyunsik.yoon@samsung.com>
--- /dev/null
+/*
+ * Copyright (c) 2019 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 "TFLDialect.h"
+
+namespace locoex
+{
+
+loco::Dialect *TFLDialect::get(void)
+{
+ static TFLDialect d;
+ return &d;
+}
+
+} // namespace locoex
--- /dev/null
+/*
+ * Copyright (c) 2019 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 __LOCOEX_IR_TFLDIALECT_H__
+#define __LOCOEX_IR_TFLDIALECT_H__
+
+#include <loco/IR/Dialect.h>
+
+namespace locoex
+{
+
+class TFLDialect final : public loco::Dialect
+{
+private:
+ TFLDialect() = default;
+
+public:
+ TFLDialect(const TFLDialect &) = delete;
+ TFLDialect(TFLDialect &&) = delete;
+
+public:
+ static loco::Dialect *get(void);
+};
+
+} // namespace locoex
+
+#endif // __LOCOEX_IR_TFLDIALECT_H__
--- /dev/null
+/*
+ * Copyright (c) 2019 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 "TFLDialect.h"
+
+#include <gtest/gtest.h>
+
+TEST(TFLDialectTest, get)
+{
+ using locoex::TFLDialect;
+
+ auto d = TFLDialect::get();
+
+ // get() SHOULD return a valid(non-null) pointer
+ ASSERT_NE(d, nullptr);
+ // The return value SHOULD be stable across multiple invocations
+ ASSERT_EQ(d, TFLDialect::get());
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 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 "TFLNode.h"
+
+#include "TFLDialect.h"
+
+namespace locoex
+{
+
+const loco::Dialect *TFLNode::dialect(void) const { return TFLDialect::get(); }
+
+} // namespace locoex
--- /dev/null
+/*
+ * Copyright (c) 2019 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 __LOCOEX_IR_TFLNODE_H__
+#define __LOCOEX_IR_TFLNODE_H__
+
+#include "TFLNodeDecl.h"
+#include "TFLNodeImpl.h"
+
+#endif // __LOCOEX_IR_TFLNODE_H__
--- /dev/null
+/*
+ * Copyright (c) 2019 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 __LOCOEX_IR_TFLNODEDECL_H__
+#define __LOCOEX_IR_TFLNODEDECL_H__
+
+#include <loco/IR/Node.h>
+#include <loco/IR/Dialect.h>
+
+#include "TFLOpcode.h"
+#include "TFLNodeVisitor.forward.h"
+
+namespace locoex
+{
+
+struct TFLNode : public loco::Node
+{
+ virtual ~TFLNode() = default;
+
+ const loco::Dialect *dialect(void) const final;
+ virtual TFLOpcode opcode(void) const = 0;
+
+ template <typename T> T accept(TFLNodeVisitorBase<T> *) const;
+ template <typename T> T accept(TFLNodeMutableVisitorBase<T> *);
+};
+
+template <TFLOpcode Code> struct TFLNodeImpl : public TFLNode
+{
+ virtual ~TFLNodeImpl() = default;
+
+ uint32_t opnum(void) const final { return static_cast<uint32_t>(Code); }
+ TFLOpcode opcode(void) const final { return Code; }
+};
+
+} // namespace locoex
+
+#endif // __LOCOEX_IR_TFLNODEDECL_H__
--- /dev/null
+/*
+ * Copyright (c) 2019 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 __LOCOEX_IR_TFLNODEIMPL_H__
+#define __LOCOEX_IR_TFLNODEIMPL_H__
+
+#include "TFLNode.h"
+#include "TFLNodes.h"
+#include "TFLNodeVisitor.h"
+
+#include <cassert>
+
+namespace locoex
+{
+
+template <typename T> T TFLNode::accept(TFLNodeVisitorBase<T> *v) const
+{
+ switch (this->opcode())
+ {
+#define TFL_NODE(OPCODE, CLASS) \
+ \
+ case TFLOpcode::OPCODE: \
+ return v->visit(dynamic_cast<const CLASS *>(this));
+
+#include "TFLNodes.lst"
+#undef TFL_NODE
+
+ default:
+ break;
+ }
+
+ assert(false);
+}
+
+template <typename T> T TFLNode::accept(TFLNodeMutableVisitorBase<T> *v)
+{
+ switch (this->opcode())
+ {
+#define TFL_NODE(OPCODE, CLASS) \
+ \
+ case TFLOpcode::OPCODE: \
+ return v->visit(dynamic_cast<CLASS *>(this));
+
+#include "TFLNodes.lst"
+#undef TFL_NODE
+
+ default:
+ break;
+ }
+
+ assert(false);
+}
+
+} // namespace locoex
+
+#endif // __LOCOEX_IR_TFLNODEIMPL_H__
--- /dev/null
+/*
+ * Copyright (c) 2019 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 __LOCOEX_IR_TFLNODE_VISITOR_FORWARD_H__
+#define __LOCOEX_IR_TFLNODE_VISITOR_FORWARD_H__
+
+namespace locoex
+{
+
+// NOTE These forward declarations SHOULD BE aligned with Node delcarations in
+// "TFLNodeVisitor.h"
+template <typename T> struct TFLNodeVisitorBase;
+template <typename T> struct TFLNodeMutableVisitorBase;
+
+} // namespace locoex
+
+#endif // __LOCOEX_IR_TFLNODE_VISITOR_FORWARD_H__
--- /dev/null
+/*
+ * Copyright (c) 2019 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 __LOCOEX_IR_TFLNODE_VISITOR_H__
+#define __LOCOEX_IR_TFLNODE_VISITOR_H__
+
+#include "TFLNode.h"
+#include "TFLNodes.h"
+
+#include <cassert>
+
+namespace locoex
+{
+
+/**
+ * DO NOT use this class. Use TFLNodeVisitor instead.
+ */
+template <typename T> struct TFLNodeVisitorBase
+{
+ virtual ~TFLNodeVisitorBase() = default;
+
+#define TFL_NODE(OPCODE, TFL_CLASS) virtual T visit(const TFL_CLASS *) = 0;
+
+#include "TFLNodes.lst"
+#undef TFL_NODE
+};
+
+template <typename T> struct TFLNodeVisitor : public TFLNodeVisitorBase<T>
+{
+ virtual ~TFLNodeVisitor() = default;
+
+#define TFL_NODE(OPCODE, TFL_CLASS) \
+ \
+ virtual T visit(const TFL_CLASS *node) { return visit(static_cast<const TFLNode *>(node)); }
+
+#include "TFLNodes.lst"
+#undef TFL_NODE
+
+ /// @brief Default fallback
+ virtual T visit(const TFLNode *node) { assert(false); }
+};
+
+/**
+ * DO NOT use this class. Use TFLNodeMutableVisitor instead.
+ */
+template <typename T> struct TFLNodeMutableVisitorBase
+{
+ virtual ~TFLNodeMutableVisitorBase() = default;
+
+#define TFL_NODE(OPCODE, TFL_CLASS) virtual T visit(TFL_CLASS *) = 0;
+
+#include "TFLNodes.lst"
+#undef TFL_NODE
+};
+
+template <typename T> struct TFLNodeMutableVisitor : public TFLNodeMutableVisitorBase<T>
+{
+ virtual ~TFLNodeMutableVisitor() = default;
+
+#define TFL_NODE(OPCODE, TFL_CLASS) \
+ \
+ virtual T visit(TFL_CLASS *node) { return visit(static_cast<TFLNode *>(node)); }
+
+#include "TFLNodes.lst"
+#undef TFL_NODE
+
+ /// @brief Default fallback
+ virtual T visit(TFLNode *node) { assert(false); }
+};
+
+} // namespace locoex
+
+#endif // __LOCOEX_IR_TFLNODE_VISITOR_H__
--- /dev/null
+/*
+ * Copyright (c) 2019 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 __LOCOEX_IR_TFLNODES_H__
+#define __LOCOEX_IR_TFLNODES_H__
+
+#include "TFLNodeDecl.h"
+#include "TFLOpcode.h"
+
+#include <loco/IR/Node.h>
+#include <loco/IR/NodeMixins.h>
+
+namespace locoex
+{
+
+// TODO define TFLNodes here
+
+} // namespace locoex
+
+#endif // __LOCOEX_IR_TFLNODES_H__
--- /dev/null
+#ifndef TFL_NODE
+#error "Define TFL_NODE"
+#endif // TFL_NODE
+
+//
+// PLEASE SORT NODE DECLS IN ALPHABETICAL ORDER
+//
+// Example)
+// TFL_NODE(Relu, locoex::TFLRelu)
--- /dev/null
+/*
+ * Copyright (c) 2019 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 __LOCOEX_IR_TFLOPCODE_H__
+#define __LOCOEX_IR_TFLOPCODE_H__
+
+namespace locoex
+{
+
+enum class TFLOpcode
+{
+#define TFL_NODE(OPCODE, CLASS) OPCODE,
+#include "TFLNodes.lst"
+#undef TFL_NODE
+};
+
+} // namespace locoex
+
+#endif // __LOCOEX_IR_TFLOPCODE_H__