GEGELATI
programGenerationEngine.h
1
37#ifdef CODE_GENERATION
38
39#ifndef PROGRAM_GENERATION_ENGINE_H
40#define PROGRAM_GENERATION_ENGINE_H
41#include <fstream>
42
43#include "data/dataHandlerPrinter.h"
44#include "data/primitiveTypeArray.h"
45#include "instructions/instruction.h"
46#include "program/programEngine.h"
47
48namespace CodeGen {
63 {
64 protected:
67 static const std::regex operand_regex;
68
76 static const std::string nameDataVariable;
77
79 static const std::string nameRegVariable;
80
82 static const std::string nameConstantVariable;
83
85 static const std::string nameOperandVariable;
86
88 std::ofstream fileC;
90 std::ofstream fileH;
91
94
95 public:
97 virtual void processLine() override;
98
117 ProgramGenerationEngine(const std::string& filename,
118 const Environment& env,
119 const std::string& path = "./")
120 : ProgramEngine(env), dataPrinter()
121 {
122 openFile(filename, path, env.getNbConstant());
123 }
124
143 ProgramGenerationEngine(const std::string& filename,
144 const Program::Program& p,
145 const std::string& path = "./")
147 {
148 openFile(filename, path, p.getEnvironment().getNbConstant());
149 setProgram(p);
150 }
151
158 {
159 fileH << "#endif" << std::endl;
160 fileC.close();
161 fileH.close();
162 }
163
170 void generateCurrentLine();
171
192 void generateProgram(uint64_t progID,
193 const bool ignoreException = false);
194
195 protected:
207 void initGlobalVar(size_t nbConstant);
208
222 std::string completeFormat(
223 const Instructions::Instruction& instruction) const;
224
237 void openFile(const std::string& filename, const std::string& path,
238 size_t nbConstant);
239
248
258 std::string getNameSourceData(const uint64_t& idx);
259 };
260
261} // namespace CodeGen
262
263#endif // PROGRAMGENERATIONENGINE_H
264
265#endif // CODE_GENERATION
Class in charge of generating inference C code for all the Program of a TPG.
Definition: programGenerationEngine.h:63
std::string getNameSourceData(const uint64_t &idx)
Method returning the name of the data source in the file generated.
Definition: programGenerationEngine.cpp:203
void initGlobalVar(size_t nbConstant)
Set global variables in the file holding the programs.
Definition: programGenerationEngine.cpp:134
ProgramGenerationEngine(const std::string &filename, const Program::Program &p, const std::string &path="./")
Constructor of the class.
Definition: programGenerationEngine.h:143
ProgramGenerationEngine(const std::string &filename, const Environment &env, const std::string &path="./")
Constructor of the class.
Definition: programGenerationEngine.h:117
std::string completeFormat(const Instructions::Instruction &instruction) const
Generates the line of C code that implements the instruction in parameter.
Definition: programGenerationEngine.cpp:104
virtual void processLine() override
inherited from Program::ProgramEngine
Definition: programGenerationEngine.cpp:223
void initOperandCurrentLine()
Function called to generate the initialization of all operands of an instruction.
Definition: programGenerationEngine.cpp:181
static const std::string nameOperandVariable
name of the temporary operand used in the TPG's programs.
Definition: programGenerationEngine.h:85
static const std::string nameConstantVariable
name of the array of constants in the TPG's programs.
Definition: programGenerationEngine.h:82
void generateCurrentLine()
Generate the current line of the program.
Definition: programGenerationEngine.cpp:46
static const std::regex operand_regex
Definition: programGenerationEngine.h:67
std::ofstream fileC
The file in which programs will be added.
Definition: programGenerationEngine.h:88
static const std::string nameRegVariable
name of the registers in the TPG's programs.
Definition: programGenerationEngine.h:79
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:154
~ProgramGenerationEngine()
Destructor of the class.
Definition: programGenerationEngine.h:157
Data::DataHandlerPrinter dataPrinter
Utility class used to print data accesses in generated code.
Definition: programGenerationEngine.h:93
std::ofstream fileH
The file in which prototypes of programs will be added.
Definition: programGenerationEngine.h:90
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:65
static const std::string nameDataVariable
Name given to the global variable in generated files.
Definition: programGenerationEngine.h:76
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:84
size_t getNbConstant() const
Get the number of constants used by programs.
Definition: environment.cpp:172
This abstract class is the base class for any instruction to be used in a Program.
Definition: instruction.h:59
This abstract class is the base class for any program engine (generation and execution)
Definition: programEngine.h:54
void setProgram(const Program &prog)
Method for changing the Program executed by a ProgramExecutionEngin.
Definition: programEngine.cpp:41
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:53
const Environment & getEnvironment() const
Get the environment associated to the Program at construction.
Definition: program.cpp:110
Definition: programGenerationEngine.h:48