#ifndef __LOCO_IR_GRAPH_H__
#define __LOCO_IR_GRAPH_H__
+#include "loco/IR/DataType.h"
#include "loco/IR/Nodes.h"
#include "loco/ADT/ObjectPool.h"
namespace loco
{
+// TODO Introduce Named trait
+enum class Trait
+{
+ // Any "DataTyped" class has the following methods
+ // - DataType dtype(void) const;
+ // - void dtype(const DataType &value);
+ DataTyped,
+};
+
+template <Trait T> class Mixin;
+
+// TODO Re-implement NodeMixin<NodeTrait::DataType> using this mixin
+template <> class Mixin<Trait::DataTyped>
+{
+public:
+ Mixin() = default;
+
+public:
+ const DataType &dtype(void) const { return _dtype; }
+ void dtype(const DataType &value) { _dtype = value; }
+
+private:
+ DataType _dtype = DataType::Unknown;
+};
+
/**
* @brief Trait for elements with name
*/
/**
* @brief Graph-level Input Metadata
*/
-class GraphInput final : private NamedEntity
+class GraphInput final : private NamedEntity, public Mixin<Trait::DataTyped>
{
public:
LOCO_NAMED_ENTITY_EXPOSE;
/**
* @brief Graph-level Output Metadata
*/
-class GraphOutput final : private NamedEntity
+class GraphOutput final : private NamedEntity, public Mixin<Trait::DataTyped>
{
public:
LOCO_NAMED_ENTITY_EXPOSE;
ASSERT_EQ(elem.name(), "name");
}
+TEST(DataTypedMixinTest, constructor)
+{
+ loco::Mixin<loco::Trait::DataTyped> mixin;
+
+ ASSERT_EQ(mixin.dtype(), loco::DataType::Unknown);
+}
+
+TEST(DataTypedMixinTest, setter_and_getter)
+{
+ loco::Mixin<loco::Trait::DataTyped> mixin;
+
+ mixin.dtype(loco::DataType::FLOAT32);
+ ASSERT_EQ(mixin.dtype(), loco::DataType::FLOAT32);
+}
+
TEST(GraphTest, create_and_destroy_node)
{
auto g = loco::make_graph();