#ifndef HALIDE_ARGUMENT_H
#define HALIDE_ARGUMENT_H
#include "Error.h"
#include "Expr.h"
#include "Type.h"
#include "Buffer.h"
#include "runtime/HalideRuntime.h"
namespace Halide {
struct Argument {
std::string name;
enum Kind {
InputScalar = halide_argument_kind_input_scalar,
InputBuffer = halide_argument_kind_input_buffer,
OutputBuffer = halide_argument_kind_output_buffer
};
Kind kind;
uint8_t dimensions;
Type type;
Expr def, min, max;
Argument() : kind(InputScalar), dimensions(0) {}
Argument(const std::string &_name, Kind _kind, const Type &_type, int _dimensions,
Expr _def = Expr(),
Expr _min = Expr(),
Expr _max = Expr()) :
name(_name), kind(_kind), dimensions((uint8_t) _dimensions), type(_type), def(_def), min(_min), max(_max) {
internal_assert(_dimensions >= 0 && _dimensions <= 255);
user_assert(!(is_scalar() && dimensions != 0))
<< "Scalar Arguments must specify dimensions of 0";
user_assert(!(is_buffer() && def.defined()))
<< "Scalar default must not be defined for Buffer Arguments";
user_assert(!(is_buffer() && min.defined()))
<< "Scalar min must not be defined for Buffer Arguments";
user_assert(!(is_buffer() && max.defined()))
<< "Scalar max must not be defined for Buffer Arguments";
}
template<typename T>
Argument(Buffer<T> im) :
name(im.name()),
kind(InputBuffer),
dimensions(im.dimensions()),
type(im.type()) {}
bool is_buffer() const { return kind == InputBuffer || kind == OutputBuffer; }
bool is_scalar() const { return kind == InputScalar; }
bool is_input() const { return kind == InputScalar || kind == InputBuffer; }
bool is_output() const { return kind == OutputBuffer; }
bool operator==(const Argument &rhs) const {
return name == rhs.name &&
kind == rhs.kind &&
dimensions == rhs.dimensions &&
type == rhs.type &&
def.same_as(rhs.def) &&
min.same_as(rhs.min) &&
max.same_as(rhs.max);
}
};
}
#endif