BenchGen
BenchGen is a tool for generating benchmarks to stress-test a computing system.
Loading...
Searching...
No Matches
generator.h
Go to the documentation of this file.
1#ifndef GENERATOR_H
2#define GENERATOR_H
3#include <filesystem>
4#include <fstream>
5#include <iostream>
6
7#include "../shared/enums.h"
10#include "generatorFunction.h"
11#include "generatorScope.h"
12#include "generatorVariable.h"
13
20class Generator {
21 private:
22 std::vector<std::string> includes; // List of include statements for the generated code
23 std::vector<std::string> globalVars; // List of global variable declarations
24
30 void generateIncludes();
31
37 void generateGlobalVars();
38
44 void generateMainFunction();
45
51 void generateRandomNumberGenerator();
52
60 std::string createParams();
61
70 void genMakefile(std::string dir, std::string target);
71
72 public:
73 GeneratorFunction mainFunction; // Main function for the generated program
74 std::list<GeneratorFunction> functions; // List of all functions in the generated program
75 std::stack<GeneratorFunction*> currentFunction; // Stack of current functions being generated
76 std::stack<int> ifCounter; // Counter for managing nested if statements
77 int varCounter; // Counter for variables
78 int loopLevel; // Current nesting level of loops
79 int loopCounter; // Counter for loop iterations
80 std::string varType; // Type of variables to use in the generated code
81 std::map<int, GeneratorVariable*> variables; // Map of variables by their ID
82 std::stack<GeneratorScope> currentScope; // Stack of current scopes
83
92 Generator(std::string variableType);
93
100 for (auto& vpair : variables) {
101 delete vpair.second;
102 }
103 }
104
111 void addLine(std::string, int = 0);
112
119 void addLine(std::vector<std::string>, int = 0);
120
126 void startScope();
127
136 void startFunc(int, int);
137
144 bool functionExists(int);
145
154 void callFunc(int, int);
155
164 int addVar(std::string);
165
174 void freeVars(bool = false, int = 0);
175
183 void returnFunc(int);
184
190 void endScope();
191
197 void endFunc();
198
206 void generateFiles(std::string);
207};
208
209#endif
The GeneratorFunction class represents a function in the generated code.
Definition generatorFunction.h:13
The Generator class handles the generation of code and files for benchmarks.
Definition generator.h:20
void addLine(std::string, int=0)
Adds a line of code to the current function with optional indentation.
Definition generator.cpp:60
std::stack< int > ifCounter
Definition generator.h:76
Generator(std::string variableType)
Constructs a Generator object with a specified variable type.
Definition generator.cpp:3
int addVar(std::string)
Adds a new variable of the specified type to the current scope.
Definition generator.cpp:130
bool functionExists(int)
Checks if a function with a given ID already exists.
Definition generator.cpp:93
int loopLevel
Definition generator.h:78
void startScope()
Starts a new scope for variable declarations.
Definition generator.cpp:71
std::stack< GeneratorScope > currentScope
Definition generator.h:82
std::stack< GeneratorFunction * > currentFunction
Definition generator.h:75
std::string varType
Definition generator.h:80
GeneratorFunction mainFunction
Definition generator.h:73
std::list< GeneratorFunction > functions
Definition generator.h:74
std::map< int, GeneratorVariable * > variables
Definition generator.h:81
void endFunc()
Ends the current function.
Definition generator.cpp:159
void returnFunc(int)
Returns a value from a function.
Definition generator.cpp:148
void endScope()
Ends the current scope.
Definition generator.cpp:153
~Generator()
Destructor for the Generator class.
Definition generator.h:99
int varCounter
Definition generator.h:77
void startFunc(int, int)
Starts the definition of a new function.
Definition generator.cpp:76
int loopCounter
Definition generator.h:79
void callFunc(int, int)
Calls a function with the specified ID and parameters.
Definition generator.cpp:113
void generateFiles(std::string)
Generates source and header files for the benchmark.
Definition generator.cpp:192
void freeVars(bool=false, int=0)
Frees variables in the current scope.
Definition generator.cpp:136