-
Notifications
You must be signed in to change notification settings - Fork 497
/
nodes.h
148 lines (121 loc) · 4.52 KB
/
nodes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (C) 2022-2024 Exaloop Inc. <https://exaloop.io>
#pragma once
#include <memory>
#include "codon/cir/base.h"
#include "codon/cir/const.h"
#include "codon/cir/instr.h"
#include "codon/cir/util/side_effect.h"
namespace codon {
namespace ir {
namespace util {
class CloneVisitor;
} // namespace util
namespace dsl {
namespace codegen {
struct CFBuilder;
struct TypeBuilder;
struct ValueBuilder;
} // namespace codegen
namespace types {
/// DSL type.
class CustomType : public AcceptorExtend<CustomType, ir::types::Type> {
public:
static const char NodeId;
using AcceptorExtend::AcceptorExtend;
/// @return the type builder
virtual std::unique_ptr<codegen::TypeBuilder> getBuilder() const = 0;
/// Compares DSL nodes.
/// @param v the other node
/// @return true if they match
virtual bool match(const Type *v) const = 0;
/// Format the DSL node.
/// @param os the output stream
virtual std::ostream &doFormat(std::ostream &os) const = 0;
};
} // namespace types
/// DSL constant.
class CustomConst : public AcceptorExtend<CustomConst, Const> {
public:
static const char NodeId;
using AcceptorExtend::AcceptorExtend;
/// @return the value builder
virtual std::unique_ptr<codegen::ValueBuilder> getBuilder() const = 0;
/// Compares DSL nodes.
/// @param v the other node
/// @return true if they match
virtual bool match(const Value *v) const = 0;
/// Clones the value.
/// @param cv the clone visitor
/// @return a clone of the object
virtual Value *doClone(util::CloneVisitor &cv) const = 0;
/// Format the DSL node.
/// @param os the output stream
virtual std::ostream &doFormat(std::ostream &os) const = 0;
};
/// DSL flow.
class CustomFlow : public AcceptorExtend<CustomFlow, Flow> {
public:
static const char NodeId;
using AcceptorExtend::AcceptorExtend;
/// @return the value builder
virtual std::unique_ptr<codegen::ValueBuilder> getBuilder() const = 0;
/// Compares DSL nodes.
/// @param v the other node
/// @return true if they match
virtual bool match(const Value *v) const = 0;
/// Clones the value.
/// @param cv the clone visitor
/// @return a clone of the object
virtual Value *doClone(util::CloneVisitor &cv) const = 0;
/// @return the control-flow builder
virtual std::unique_ptr<codegen::CFBuilder> getCFBuilder() const = 0;
/// Query this custom node for its side effect properties. If "local"
/// is true, then the return value should reflect this node and this
/// node alone, otherwise the value should reflect functions containing
/// this node in their bodies. For example, a "break" instruction has
/// side effects locally, but functions containing "break" might still
/// be side effect free, hence the distinction.
/// @param local true if result should reflect only this node
/// @return this node's side effect status
virtual util::SideEffectStatus getSideEffectStatus(bool local = true) const {
return util::SideEffectStatus::UNKNOWN;
}
/// Format the DSL node.
/// @param os the output stream
virtual std::ostream &doFormat(std::ostream &os) const = 0;
};
/// DSL instruction.
class CustomInstr : public AcceptorExtend<CustomInstr, Instr> {
public:
static const char NodeId;
using AcceptorExtend::AcceptorExtend;
/// @return the value builder
virtual std::unique_ptr<codegen::ValueBuilder> getBuilder() const = 0;
/// Compares DSL nodes.
/// @param v the other node
/// @return true if they match
virtual bool match(const Value *v) const = 0;
/// Clones the value.
/// @param cv the clone visitor
/// @return a clone of the object
virtual Value *doClone(util::CloneVisitor &cv) const = 0;
/// @return the control-flow builder
virtual std::unique_ptr<codegen::CFBuilder> getCFBuilder() const = 0;
/// Query this custom node for its side effect properties. If "local"
/// is true, then the return value should reflect this node and this
/// node alone, otherwise the value should reflect functions containing
/// this node in their bodies. For example, a "break" instruction has
/// side effects locally, but functions containing "break" might still
/// be side effect free, hence the distinction.
/// @param local true if result should reflect only this node
/// @return this node's side effect status
virtual util::SideEffectStatus getSideEffectStatus(bool local = true) const {
return util::SideEffectStatus::UNKNOWN;
}
/// Format the DSL node.
/// @param os the output stream
virtual std::ostream &doFormat(std::ostream &os) const = 0;
};
} // namespace dsl
} // namespace ir
} // namespace codon