BenchGen
BenchGen is a tool for generating benchmarks to stress-test a computing system.
Loading...
Searching...
No Matches
ast.h
Go to the documentation of this file.
1#ifndef AST_H
2#define AST_H
3
4#include <cmath>
5
7#include "../shared/enums.h"
9
17void printIndentationSpaces(int indent);
18
28std::string generateIfCondition(Generator& generator);
29
35class Node {
36 public:
37 virtual ~Node() = default;
38
44 virtual void gen(Generator&) = 0;
45
51 virtual void print(int indent = 0) = 0;
52};
53
59class StatementCode : public Node {
60 private:
61 std::shared_ptr<Node> stmt; // The statement node
62 std::shared_ptr<Node> code; // The following code block
63
64 public:
65 StatementCode(std::shared_ptr<Node> stmt, std::shared_ptr<Node> code) : stmt(stmt), code(code) {
66 }
67
68 void gen(Generator&) override;
69
70 void print(int) override;
71};
72
78class LambdaCode : public Node {
79 public:
80 void gen(Generator&) override;
81
82 void print(int indent) override;
83};
84
90class Id : public Node {
91 private:
92 std::string id; // The identifier's name
93
94 public:
95 Id(std::string id) : id(id) {
96 }
97
98 void gen(Generator&) override;
99
100 void print(int indent) override;
101};
102
108class Insert : public Node {
109 public:
110 void gen(Generator&) override;
111
112 void print(int indent) override;
113};
114
120class Remove : public Node {
121 public:
122 void gen(Generator&) override;
123
124 void print(int indent) override;
125};
126
132class New : public Node {
133 public:
134 void gen(Generator&) override;
135
136 void print(int indent) override;
137};
138
144class Contains : public Node {
145 public:
146 void gen(Generator&) override;
147
148 void print(int indent) override;
149};
150
156class Loop : public Node {
157 private:
158 std::shared_ptr<Node> code; // The code block to be executed in the loop
159
160 public:
161 Loop(std::shared_ptr<Node> code) : code(code) {
162 }
163
164 void gen(Generator&) override;
165
166 void print(int indent) override;
167};
168
174class Call : public Node {
175 private:
176 int id; // The ID of the function being called
177 std::shared_ptr<Node> code; // The code block of the function
178
179 public:
180 int conditionalCounts; // Tracks the number of conditional statements in the call
181
182 Call(int id, std::shared_ptr<Node> code) : id(id), code(code), conditionalCounts(0) {
183 }
184
186 }
187
193 void setId(int id) {
194 this->id = id;
195 }
196
202 void setCode(std::shared_ptr<Node> code) {
203 this->code = code;
204 }
205
206 void gen(Generator&) override;
207
208 void print(int indent) override;
209};
210
216class Seq : public Node {
217 private:
218 std::shared_ptr<Node> code; // The code block for the sequence
219
220 public:
221 Seq(std::shared_ptr<Node> code) : code(code) {
222 }
223
224 void gen(Generator&) override;
225
226 void print(int indent) override;
227};
228
234class If : public Node {
235 private:
236 std::shared_ptr<Node> ifParam; // The parameters for the if statement
237
238 public:
239 If(std::shared_ptr<Node> ifParam) : ifParam(ifParam) {
240 }
241
242 void gen(Generator&) override;
243
244 void print(int indent) override;
245};
246
252class IfParam : public Node {
253 private:
254 std::shared_ptr<Node> code; // The code block for the if statement
255 std::shared_ptr<Node> else_; // The else clause
256
257 public:
258 IfParam(std::shared_ptr<Node> code, std::shared_ptr<Node> else_) : code(code), else_(else_) {
259 }
260
261 void gen(Generator&) override;
262
263 void print(int indent) override;
264};
265
271class CodeElse : public Node {
272 private:
273 std::shared_ptr<Node> code; // The code block for the else clause
274
275 public:
276 CodeElse(std::shared_ptr<Node> code) : code(code) {
277 }
278
279 void gen(Generator&) override;
280
281 void print(int indent) override;
282};
283
284#endif
std::string generateIfCondition(Generator &generator)
Generates a condition string for an if statement.
Definition ast.cpp:9
void printIndentationSpaces(int indent)
Prints a specified number of indentation spaces.
Definition ast.cpp:3
Represents a function call in the AST.
Definition ast.h:174
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:94
Call()
Definition ast.h:185
Call(int id, std::shared_ptr< Node > code)
Definition ast.h:182
int conditionalCounts
Definition ast.h:180
void setId(int id)
Sets the ID of the function being called.
Definition ast.h:193
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:187
void setCode(std::shared_ptr< Node > code)
Sets the code block of the function being called.
Definition ast.h:202
Represents an else clause with a code block in the AST.
Definition ast.h:271
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:211
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:133
CodeElse(std::shared_ptr< Node > code)
Definition ast.h:276
Represents a contains operation in the AST.
Definition ast.h:144
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:62
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:176
The Generator class handles the generation of code and files for benchmarks.
Definition generator.h:20
Represents an identifier in the AST.
Definition ast.h:90
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:32
Id(std::string id)
Definition ast.h:95
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:156
Represents the parameters of an if statement in the AST.
Definition ast.h:252
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:121
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:204
IfParam(std::shared_ptr< Node > code, std::shared_ptr< Node > else_)
Definition ast.h:258
Represents an if statement in the AST.
Definition ast.h:234
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:198
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:117
If(std::shared_ptr< Node > ifParam)
Definition ast.h:239
Represents an insert operation in the AST.
Definition ast.h:108
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:161
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:36
Represents a lambda expression in the AST.
Definition ast.h:78
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:28
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:151
Represents a loop in the AST.
Definition ast.h:156
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:181
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:72
Loop(std::shared_ptr< Node > code)
Definition ast.h:161
Represents a new variable creation in the AST.
Definition ast.h:132
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:56
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:171
Base class for all nodes in the abstract syntax tree (AST).
Definition ast.h:35
virtual void gen(Generator &)=0
Generates code for this AST node.
virtual void print(int indent=0)=0
Prints the structure of this AST node.
virtual ~Node()=default
Represents a remove operation in the AST.
Definition ast.h:120
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:46
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:166
Represents a sequence of operations in the AST.
Definition ast.h:216
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:113
Seq(std::shared_ptr< Node > code)
Definition ast.h:221
void print(int indent) override
Prints the structure of this AST node.
Definition ast.cpp:193
Represents a block of statements in the AST.
Definition ast.h:59
StatementCode(std::shared_ptr< Node > stmt, std::shared_ptr< Node > code)
Definition ast.h:65
void gen(Generator &) override
Generates code for this AST node.
Definition ast.cpp:23
void print(int) override
Prints the structure of this AST node.
Definition ast.cpp:144