GEGELATI

Loading...
Searching...
No Matches
programGenerationEngine.h
1
38#ifdef CODE_GENERATION
39
40#ifndef PROGRAM_GENERATION_ENGINE_H
41#define PROGRAM_GENERATION_ENGINE_H
42#include <fstream>
43
44#include "data/dataHandlerPrinter.h"
45#include "data/primitiveTypeArray.h"
46#include "instructions/instruction.h"
47#include "program/programEngine.h"
48
49 namespace CodeGen {
63 class ProgramGenerationEngine : public Program::ProgramEngine
64 {
65 protected:
68 static const std::regex operand_regex;
69
72 static const std::regex constant_regex;
73
81 static const std::string nameDataVariable;
82
84 static const std::string nameRegVariable;
85
87 static const std::string nameConstantVariable;
88
90 static const std::string nameOperandVariable;
91
93 std::ofstream fileC;
95 std::ofstream fileH;
96
98 Data::DataHandlerPrinter dataPrinter;
99
100 public:
102 virtual void processLine() override;
103
122 ProgramGenerationEngine(const std::string& filename,
123 const Environment& env,
124 const std::string& path = "./")
125 : ProgramEngine(env), dataPrinter()
126 {
127 openFile(filename, path, env.getParams().nbProgramConstant);
128 }
129
148 ProgramGenerationEngine(const std::string& filename,
149 const Program::Program& p,
150 const std::string& path = "./")
151 : ProgramEngine(p), dataPrinter()
152 {
153 openFile(filename, path,
154 p.getEnvironment().getParams().nbProgramConstant);
155 setProgram(p);
156 }
157
163 ~ProgramGenerationEngine()
164 {
165 fileH << "#endif" << std::endl;
166 fileC.close();
167 fileH.close();
168 }
169
176 void generateCurrentLine();
177
198 void generateProgram(uint64_t progID,
199 const bool ignoreException = false);
200
201 protected:
213 void initGlobalVar(size_t nbConstant);
214
228 std::string completeFormat(
229 const Instructions::Instruction& instruction) const;
230
243 void openFile(const std::string& filename, const std::string& path,
244 size_t nbConstant);
245
253 void initOperandCurrentLine();
254
264 std::string getNameSourceData(const uint64_t& idx);
265 };
266
267} // namespace CodeGen
268
269#endif // PROGRAMGENERATIONENGINE_H
270
271#endif // CODE_GENERATION
CodeGen::ProgramGenerationEngine
Class in charge of generating inference C code for all the Program of a TPG.
Definition programGenerationEngine.h:64
CodeGen::ProgramGenerationEngine::getNameSourceData
std::string getNameSourceData(const uint64_t &idx)
Method returning the name of the data source in the file generated.
Definition programGenerationEngine.cpp:255
CodeGen::ProgramGenerationEngine::initGlobalVar
void initGlobalVar(size_t nbConstant)
Set global variables in the file holding the programs.
Definition programGenerationEngine.cpp:172
CodeGen::ProgramGenerationEngine::ProgramGenerationEngine
ProgramGenerationEngine(const std::string &filename, const Program::Program &p, const std::string &path="./")
Constructor of the class.
Definition programGenerationEngine.h:148
CodeGen::ProgramGenerationEngine::ProgramGenerationEngine
ProgramGenerationEngine(const std::string &filename, const Environment &env, const std::string &path="./")
Constructor of the class.
Definition programGenerationEngine.h:122
CodeGen::ProgramGenerationEngine::completeFormat
std::string completeFormat(const Instructions::Instruction &instruction) const
Generates the line of C code that implements the instruction in parameter.
Definition programGenerationEngine.cpp:142
CodeGen::ProgramGenerationEngine::processLine
virtual void processLine() override
inherited from Program::ProgramEngine
Definition programGenerationEngine.cpp:277
CodeGen::ProgramGenerationEngine::initOperandCurrentLine
void initOperandCurrentLine()
Function called to generate the initialization of all operands of an instruction.
Definition programGenerationEngine.cpp:233
CodeGen::ProgramGenerationEngine::nameOperandVariable
static const std::string nameOperandVariable
name of the temporary operand used in the TPG's programs.
Definition programGenerationEngine.h:90
CodeGen::ProgramGenerationEngine::constant_regex
static const std::regex constant_regex
Definition programGenerationEngine.h:72
CodeGen::ProgramGenerationEngine::nameConstantVariable
static const std::string nameConstantVariable
name of the array of constants in the TPG's programs.
Definition programGenerationEngine.h:87
CodeGen::ProgramGenerationEngine::generateCurrentLine
void generateCurrentLine()
Generate the current line of the program.
Definition programGenerationEngine.cpp:50
CodeGen::ProgramGenerationEngine::operand_regex
static const std::regex operand_regex
Definition programGenerationEngine.h:68
CodeGen::ProgramGenerationEngine::fileC
std::ofstream fileC
The file in which programs will be added.
Definition programGenerationEngine.h:93
CodeGen::ProgramGenerationEngine::nameRegVariable
static const std::string nameRegVariable
name of the registers in the TPG's programs.
Definition programGenerationEngine.h:84
CodeGen::ProgramGenerationEngine::openFile
void openFile(const std::string &filename, const std::string &path, size_t nbConstant)
Function used to open the file that is generated.
Definition programGenerationEngine.cpp:192
CodeGen::ProgramGenerationEngine::~ProgramGenerationEngine
~ProgramGenerationEngine()
Destructor of the class.
Definition programGenerationEngine.h:163
CodeGen::ProgramGenerationEngine::dataPrinter
Data::DataHandlerPrinter dataPrinter
Utility class used to print data accesses in generated code.
Definition programGenerationEngine.h:98
CodeGen::ProgramGenerationEngine::fileH
std::ofstream fileH
The file in which prototypes of programs will be added.
Definition programGenerationEngine.h:95
CodeGen::ProgramGenerationEngine::generateProgram
void generateProgram(uint64_t progID, const bool ignoreException=false)
Generate the C code that corresponds to the member program of the class.
Definition programGenerationEngine.cpp:69
CodeGen::ProgramGenerationEngine::nameDataVariable
static const std::string nameDataVariable
Name given to the global variable in generated files.
Definition programGenerationEngine.h:81
Data::DataHandlerPrinter
Class used to generate the declaration of operands of a line for the code gen.
Definition dataHandlerPrinter.h:50
Environment
The Environment class contains all information needed to execute a Program.
Definition environment.h:86
Environment::getParams
const Learn::LearningParameters & getParams() const
Get the instance of parameters used.
Definition environment.cpp:168
Instructions::Instruction
This abstract class is the base class for any instruction to be used in a Program.
Definition instruction.h:61
Program::ProgramEngine
This abstract class is the base class for any program engine (generation and execution)
Definition programEngine.h:55
Program::ProgramEngine::setProgram
void setProgram(const Program &prog)
Method for changing the Program executed by a ProgramExecutionEngin.
Definition programEngine.cpp:43
Program::ProgramEngine::ProgramEngine
ProgramEngine()=delete
Default constructor is deleted.
Program::Program
The Program class contains a list of program lines that can be executed within a well defined Environ...
Definition program.h:57
Program::Program::getEnvironment
const Environment & getEnvironment() const
Get the environment associated to the Program at construction.
Definition program.cpp:117
CodeGen
Definition programGenerationEngine.h:49
Learn::LearningParameters::nbProgramConstant
size_t nbProgramConstant
Number of Constants available in a program.
Definition learningParameters.h:194