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
49namespace CodeGen {
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
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 = "./")
152 {
153 openFile(filename, path,
155 setProgram(p);
156 }
157
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
254
264 std::string getNameSourceData(const uint64_t& idx);
265 };
266
267} // namespace CodeGen
268
269#endif // PROGRAMGENERATIONENGINE_H
270
271#endif // CODE_GENERATION
Class in charge of generating inference C code for all the Program of a TPG.
Definition programGenerationEngine.h:64
std::string getNameSourceData(const uint64_t &idx)
Method returning the name of the data source in the file generated.
Definition programGenerationEngine.cpp:255
void initGlobalVar(size_t nbConstant)
Set global variables in the file holding the programs.
Definition programGenerationEngine.cpp:172
ProgramGenerationEngine(const std::string &filename, const Program::Program &p, const std::string &path="./")
Constructor of the class.
Definition programGenerationEngine.h:148
ProgramGenerationEngine(const std::string &filename, const Environment &env, const std::string &path="./")
Constructor of the class.
Definition programGenerationEngine.h:122
std::string completeFormat(const Instructions::Instruction &instruction) const
Generates the line of C code that implements the instruction in parameter.
Definition programGenerationEngine.cpp:142
virtual void processLine() override
inherited from Program::ProgramEngine
Definition programGenerationEngine.cpp:277
void initOperandCurrentLine()
Function called to generate the initialization of all operands of an instruction.
Definition programGenerationEngine.cpp:233
static const std::string nameOperandVariable
name of the temporary operand used in the TPG's programs.
Definition programGenerationEngine.h:90
static const std::regex constant_regex
Definition programGenerationEngine.h:72
static const std::string nameConstantVariable
name of the array of constants in the TPG's programs.
Definition programGenerationEngine.h:87
void generateCurrentLine()
Generate the current line of the program.
Definition programGenerationEngine.cpp:50
static const std::regex operand_regex
Definition programGenerationEngine.h:68
std::ofstream fileC
The file in which programs will be added.
Definition programGenerationEngine.h:93
static const std::string nameRegVariable
name of the registers in the TPG's programs.
Definition programGenerationEngine.h:84
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
~ProgramGenerationEngine()
Destructor of the class.
Definition programGenerationEngine.h:163
Data::DataHandlerPrinter dataPrinter
Utility class used to print data accesses in generated code.
Definition programGenerationEngine.h:98
std::ofstream fileH
The file in which prototypes of programs will be added.
Definition programGenerationEngine.h:95
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
static const std::string nameDataVariable
Name given to the global variable in generated files.
Definition programGenerationEngine.h:81
Class used to generate the declaration of operands of a line for the code gen.
Definition dataHandlerPrinter.h:50
The Environment class contains all information needed to execute a Program.
Definition environment.h:86
const Learn::LearningParameters & getParams() const
Get the instance of parameters used.
Definition environment.cpp:168
This abstract class is the base class for any instruction to be used in a Program.
Definition instruction.h:61
This abstract class is the base class for any program engine (generation and execution)
Definition programEngine.h:55
void setProgram(const Program &prog)
Method for changing the Program executed by a ProgramExecutionEngin.
Definition programEngine.cpp:43
ProgramEngine()=delete
Default constructor is deleted.
The Program class contains a list of program lines that can be executed within a well defined Environ...
Definition program.h:57
const Environment & getEnvironment() const
Get the environment associated to the Program at construction.
Definition program.cpp:126
Definition programGenerationEngine.h:49
size_t nbProgramConstant
Number of Constants available in a program.
Definition learningParameters.h:143