BenchGen
BenchGen is a tool for generating benchmarks to stress-test a computing system.
Loading...
Searching...
No Matches
Generator Class Reference

The Generator class handles the generation of code and files for benchmarks. More...

#include <generator.h>

Collaboration diagram for Generator:

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< GeneratorFunctionfunctions
 
std::stack< GeneratorFunction * > currentFunction
 
std::stack< int > ifCounter
 
int varCounter
 
int loopLevel
 
int loopCounter
 
std::string varType
 
std::map< int, GeneratorVariable * > variables
 
std::stack< GeneratorScopecurrentScope
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Generator()

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.

Parameters
variableTypeThe type of variable to be used in code generation.

◆ ~Generator()

Generator::~Generator ( )
inline

Destructor for the Generator class.

Cleans up dynamically allocated variables.

Member Function Documentation

◆ addLine() [1/2]

void Generator::addLine ( std::string line,
int d = 0 )

Adds a line of code to the current function with optional indentation.

Parameters
lineThe line of code to add.
dAdditional depth for indentation (default is 0).

◆ addLine() [2/2]

void Generator::addLine ( std::vector< std::string > lines,
int d = 0 )

Adds multiple lines of code to the current function with optional indentation.

Parameters
linesA vector of lines of code to add.
dAdditional depth for indentation (default is 0).

◆ addVar()

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.

Parameters
typeThe type of variable to create.
Returns
The ID of the newly created variable.

◆ callFunc()

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.

Parameters
funcIdThe ID of the function to call.
nParametersThe number of parameters to pass to the function.

◆ endFunc()

void Generator::endFunc ( )

Ends the current function.

Ends the current function scope, pops the function from the stack, and updates the if counter.

◆ endScope()

void Generator::endScope ( )

Ends the current scope.

Pops the current scope from the stack and adds a closing brace to the code.

◆ freeVars()

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.

Parameters
hasReturnSpecifies whether there is a return variable (default is false).
returnVarPosThe position of the return variable to keep (default is 0).

◆ functionExists()

bool Generator::functionExists ( int funcId)

Checks if a function with a given ID already exists.

Parameters
funcIdThe ID of the function to check.
Returns
True if the function exists, false otherwise.

◆ generateFiles()

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.

Parameters
benchmarkNameThe name of the benchmark to generate files for.

◆ returnFunc()

void Generator::returnFunc ( int returnVarPos)

Returns a value from a function.

Adds a return statement to the function, returning the specified variable.

Parameters
returnVarPosThe position of the variable to return.

◆ startFunc()

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.

Parameters
funcIdThe ID of the function to create.
nParametersThe number of parameters the function takes.

◆ startScope()

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.

Member Data Documentation

◆ currentFunction

std::stack<GeneratorFunction*> Generator::currentFunction

◆ currentScope

std::stack<GeneratorScope> Generator::currentScope

◆ functions

std::list<GeneratorFunction> Generator::functions

◆ ifCounter

std::stack<int> Generator::ifCounter

◆ loopCounter

int Generator::loopCounter

◆ loopLevel

int Generator::loopLevel

◆ mainFunction

GeneratorFunction Generator::mainFunction

◆ varCounter

int Generator::varCounter

◆ variables

std::map<int, GeneratorVariable*> Generator::variables

◆ varType

std::string Generator::varType

The documentation for this class was generated from the following files: