BenchGen
BenchGen is a tool for generating benchmarks to stress-test a computing system.
|
The Generator class handles the generation of code and files for benchmarks. More...
#include <generator.h>
Public Member Functions | |
Generator (std::string variableType) | |
Constructs a Generator object with a specified variable type. | |
~Generator () | |
Destructor for the Generator class. | |
void | addLine (std::string, int=0) |
Adds a line of code to the current function with optional indentation. | |
void | addLine (std::vector< std::string >, int=0) |
Adds multiple lines of code to the current function with optional indentation. | |
void | startScope () |
Starts a new scope for variable declarations. | |
void | startFunc (int, int) |
Starts the definition of a new function. | |
bool | functionExists (int) |
Checks if a function with a given ID already exists. | |
void | callFunc (int, int) |
Calls a function with the specified ID and parameters. | |
int | addVar (std::string) |
Adds a new variable of the specified type to the current scope. | |
void | freeVars (bool=false, int=0) |
Frees variables in the current scope. | |
void | returnFunc (int) |
Returns a value from a function. | |
void | endScope () |
Ends the current scope. | |
void | endFunc () |
Ends the current function. | |
void | generateFiles (std::string) |
Generates source and header files for the benchmark. | |
Public Attributes | |
GeneratorFunction | mainFunction |
std::list< GeneratorFunction > | functions |
std::stack< GeneratorFunction * > | currentFunction |
std::stack< int > | ifCounter |
int | varCounter |
int | loopLevel |
int | loopCounter |
std::string | varType |
std::map< int, GeneratorVariable * > | variables |
std::stack< GeneratorScope > | currentScope |
The Generator class handles the generation of code and files for benchmarks.
This class manages the creation of variables, functions, scopes, and file outputs required for generating complete benchmark programs.
Generator::Generator | ( | std::string | variableType | ) |
Constructs a Generator object with a specified variable type.
Initializes various counters, sets the variable type, and prepares the initial scope. Generates necessary includes, global variables, random number generator, and the main function.
variableType | The type of variable to be used in code generation. |
|
inline |
Destructor for the Generator class.
Cleans up dynamically allocated variables.
void Generator::addLine | ( | std::string | line, |
int | d = 0 ) |
Adds a line of code to the current function with optional indentation.
line | The line of code to add. |
d | Additional depth for indentation (default is 0). |
void Generator::addLine | ( | std::vector< std::string > | lines, |
int | d = 0 ) |
Adds multiple lines of code to the current function with optional indentation.
lines | A vector of lines of code to add. |
d | Additional depth for indentation (default is 0). |
int Generator::addVar | ( | std::string | type | ) |
Adds a new variable of the specified type to the current scope.
Creates a new variable, adds it to the list of variables, and returns its ID.
type | The type of variable to create. |
void Generator::callFunc | ( | int | funcId, |
int | nParameters ) |
Calls a function with the specified ID and parameters.
Generates the necessary code to call a function, passing parameters and handling the return value.
funcId | The ID of the function to call. |
nParameters | The number of parameters to pass to the function. |
void Generator::endFunc | ( | ) |
Ends the current function.
Ends the current function scope, pops the function from the stack, and updates the if counter.
void Generator::endScope | ( | ) |
Ends the current scope.
Pops the current scope from the stack and adds a closing brace to the code.
void Generator::freeVars | ( | bool | hasReturn = false, |
int | returnVarPos = 0 ) |
Frees variables in the current scope.
Frees all variables added in the current scope, except the return variable if specified.
hasReturn | Specifies whether there is a return variable (default is false). |
returnVarPos | The position of the return variable to keep (default is 0). |
bool Generator::functionExists | ( | int | funcId | ) |
Checks if a function with a given ID already exists.
funcId | The ID of the function to check. |
void Generator::generateFiles | ( | std::string | benchmarkName | ) |
Generates source and header files for the benchmark.
Creates the necessary directory structure and writes the generated code to files.
benchmarkName | The name of the benchmark to generate files for. |
void Generator::returnFunc | ( | int | returnVarPos | ) |
Returns a value from a function.
Adds a return statement to the function, returning the specified variable.
returnVarPos | The position of the variable to return. |
void Generator::startFunc | ( | int | funcId, |
int | nParameters ) |
Starts the definition of a new function.
Creates a function header with specified parameters and starts a new scope for the function body.
funcId | The ID of the function to create. |
nParameters | The number of parameters the function takes. |
void Generator::startScope | ( | ) |
Starts a new scope for variable declarations.
Pushes a new GeneratorScope onto the scope stack, inheriting the current scope's variables and indentation.
std::stack<GeneratorFunction*> Generator::currentFunction |
std::stack<GeneratorScope> Generator::currentScope |
std::list<GeneratorFunction> Generator::functions |
std::stack<int> Generator::ifCounter |
int Generator::loopCounter |
int Generator::loopLevel |
GeneratorFunction Generator::mainFunction |
int Generator::varCounter |
std::map<int, GeneratorVariable*> Generator::variables |
std::string Generator::varType |