virtual ~Op();
/**
+ * @brief Return the number of arguments (# of child Ops)
+ */
+ virtual uint32_t arity(void) const = 0;
+
+ /**
+ * @brief Return N-th argument
+ *
+ * @note The behavior of arg(n) is defined only when n < artiy()
+ */
+ virtual Op *arg(uint32_t n) const = 0;
+
+ /**
* @brief Return a set of object(s) used during execution
*
* NOTE There is no 'def' method as Op is not allowed to define a new object
virtual ~UnaryOp() = default;
public:
+ uint32_t arity(void) const final;
+ Op *arg(uint32_t n) const final;
+
std::set<Object *> uses(void) const final;
public:
virtual ~BinaryOp() = default;
public:
+ uint32_t arity(void) const final;
+ Op *arg(uint32_t n) const final;
+
std::set<Object *> uses(void) const final;
public:
Load(Load &&) = delete;
public:
+ uint32_t arity(void) const final;
+ Op *arg(uint32_t n) const final;
+
std::set<Object *> uses(void) const override;
public:
explicit Conv2D();
public:
+ uint32_t arity(void) const final;
+ Op *arg(uint32_t n) const final;
+
std::set<Object *> uses(void) const override;
public:
// DO NOTHING
}
+uint32_t Conv2D::arity(void) const
+{
+ // Conv2D has one argument (IFM)
+ // NOTE This design is subject to change
+ return 1;
+}
+
+Op *Conv2D::arg(uint32_t n) const
+{
+ assert(n < arity());
+ return arg();
+}
+
std::set<Object *> Conv2D::uses(void) const
{
std::set<Object *> res;
// DO NOTHING
}
+uint32_t Load::arity(void) const
+{
+ // Load has no child Op
+ return 0;
+}
+
+Op *Load::arg(uint32_t) const
+{
+ assert(!"Load has no argument");
+ return nullptr;
+}
+
std::set<Object *> Load::uses(void) const
{
std::set<Object *> res;
// DO NOTHING
}
+uint32_t UnaryOp::arity(void) const
+{
+ // There is only one argument
+ return 1;
+}
+
+Op *UnaryOp::arg(uint32_t n) const
+{
+ assert(n < 1);
+ return arg();
+}
+
std::set<Object *> UnaryOp::uses(void) const
{
std::set<Object *> res;
// DO NOTHING
}
+uint32_t BinaryOp::arity(void) const
+{
+ // There are two arguments
+ return 2;
+}
+
+Op *BinaryOp::arg(uint32_t n) const
+{
+ assert(n < arity());
+
+ return (n == 0) ? left() : right();
+}
+
std::set<Object *> BinaryOp::uses(void) const
{
std::set<Object *> res;
namespace mock
{
+// TODO Inherit UnaryOp instead of Op
struct Op final : public coco::Op
{
public:
}
public:
+ uint32_t arity(void) const final { return 1; }
+ coco::Op *arg(uint32_t n) const final { return arg(); }
+
std::set<coco::Object *> uses() const override { throw std::runtime_error{"Not supported"}; }
public: