program.hpp 1.12 KB
Newer Older
Paul's avatar
Paul committed
1
#ifndef RTG_GUARD_RTGLIB_PROGRAM_HPP
Paul's avatar
Paul committed
2
#define RTG_GUARD_RTGLIB_PROGRAM_HPP
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
#include <list>
Paul's avatar
Paul committed
5
#include <unordered_map>
Paul's avatar
Paul committed
6
#include <rtg/operation.hpp>
Paul's avatar
Paul committed
7
#include <rtg/literal.hpp>
Paul's avatar
Paul committed
8
#include <rtg/builtin.hpp>
Paul's avatar
Paul committed
9
#include <algorithm>
Paul's avatar
Paul committed
10
11
12

namespace rtg {

Paul's avatar
Paul committed
13
14
15
struct instruction;
struct program_impl;

Paul's avatar
Paul committed
16
17
struct program
{
Paul's avatar
Paul committed
18
19
20
    program();
    program(program&&) noexcept;
    program& operator=(program&&);
Paul's avatar
Paul committed
21
    ~program();
Paul's avatar
Paul committed
22

Paul's avatar
Paul committed
23
    template <class... Ts>
Paul's avatar
Paul committed
24
    instruction* add_instruction(operation op, Ts*... args)
Paul's avatar
Paul committed
25
    {
Paul's avatar
Paul committed
26
        return add_instruction(op, {args...});
Paul's avatar
Paul committed
27
    }
Paul's avatar
Paul committed
28
    instruction* add_instruction(operation op, std::vector<instruction*> args);
Paul's avatar
Paul committed
29
30
    template <class... Ts>
    instruction* add_literal(Ts&&... xs)
Paul's avatar
Paul committed
31
    {
Paul's avatar
Paul committed
32
        return add_literal(literal{std::forward<Ts>(xs)...});
Paul's avatar
Paul committed
33
34
    }

Paul's avatar
Paul committed
35
36
37
    instruction* add_literal(literal l);

    instruction* add_parameter(std::string name, shape s);
Paul's avatar
Paul committed
38
39

    literal eval(std::unordered_map<std::string, argument> params) const;
Paul's avatar
Paul committed
40

Paul's avatar
Paul committed
41
42
43
    // TODO: Change to stream operator
    void print() const;

Paul's avatar
Paul committed
44
    bool has_instruction(const instruction* ins) const;
Paul's avatar
Paul committed
45

Paul's avatar
Paul committed
46
    private:
Paul's avatar
Paul committed
47
    std::unique_ptr<program_impl> impl;
Paul's avatar
Paul committed
48
49
};

Paul's avatar
Paul committed
50
} // namespace rtg
Paul's avatar
Paul committed
51
52

#endif