#ifndef GUARD_RTGLIB_PROGRAM_HPP #define GUARD_RTGLIB_PROGRAM_HPP #include #include #include #include namespace rtg { struct program { template instruction * add_instruction(std::string name, Ts*... args) { auto&& op = ops.at(name); shape r = op.compute_shape({args->result...}); instructions.push_back({name, r, {args...}}); return std::addressof(instructions.back()); } template instruction * add_literal(Ts&&... xs) { instructions.emplace_back(literal{std::forward(xs)...}); return std::addressof(instructions.back()); } instruction * add_parameter(std::string name, shape s) { instructions.push_back({"param:"+std::move(name), s, {}}); return std::addressof(instructions.back()); } template void add_operator(std::string name, Op op, Shape s) { operand result; result.name = name; result.compute = op; result.compute_shape = s; ops.emplace(name, result); } literal eval(std::unordered_map params) const; private: // A list is used to keep references to an instruction stable std::list instructions; std::unordered_map ops; }; } #endif