GEGELATI
tpgGenerationEngine.h
1
37#ifdef CODE_GENERATION
38
39#ifndef TPG_GENERATION_ENGINE_H
40#define TPG_GENERATION_ENGINE_H
41#include <ios>
42#include <iostream>
43#include <string>
44
45#include "codeGen/programGenerationEngine.h"
46#include "tpg/tpgAbstractEngine.h"
47#include "tpg/tpgEdge.h"
48#include "tpg/tpgGraph.h"
49#include "tpg/tpgTeam.h"
50
51namespace CodeGen {
69 {
70 protected:
75 inline static const std::string filenameProg = "program";
76
78 std::ofstream fileMain;
80 std::ofstream fileMainH;
81
89
97 uint64_t stackSize;
98
105 void initTpgFile();
106
115 void initHeaderFile();
116
117 public:
133 TPGGenerationEngine(const std::string& filename,
134 const TPG::TPGGraph& tpg,
135 const std::string& path = "./",
136 const uint64_t& stackSize = 8)
137 : TPGAbstractEngine(tpg), progGenerationEngine{filename + "_" +
139 tpg.getEnvironment(),
140 path},
142 {
143 if (stackSize == 0) {
144 throw std::runtime_error(
145 "error the size of the call stack is equal to 0");
146 }
147 this->fileMain.open(path + filename + ".c", std::ofstream::out);
148 this->fileMainH.open(path + filename + ".h", std::ofstream::out);
149 if (!fileMain.is_open() || !fileMainH.is_open()) {
150 throw std::runtime_error(
151 "Error can't open " + std::string(path + filename) +
152 ".c or " + std::string(path + filename) + ".h");
153 }
154 fileMain << "#include \"" << filename << ".h\"" << std::endl;
155 fileMain << "#include \"" << filename << "_" << filenameProg
156 << ".h\"" << std::endl;
157 initTpgFile();
158 fileMainH << "#ifndef C_" << filename << "_H" << std::endl;
159 fileMainH << "#define C_" << filename << "_H\n" << std::endl;
161 };
162
169 {
170 fileMainH << "\n#endif" << std::endl;
171 fileMain.close();
172 fileMainH.close();
173 }
174
188 void generateEdge(const TPG::TPGEdge& edge);
189
200 void generateTeam(const TPG::TPGTeam& team);
201
212 void generateAction(const TPG::TPGAction& action);
213
220 void setRoot(const TPG::TPGVertex& root);
221
229 void generateTPGGraph();
230 };
231} // namespace CodeGen
232
233#endif // TPGGENERATIONENGINE_H
234
235#endif // CODE_GENERATION
Class in charge of generating inference C code for all the Program of a TPG.
Definition: programGenerationEngine.h:63
Class in charge of generating the C code of a TPGGraph.
Definition: tpgGenerationEngine.h:69
void initTpgFile()
function printing generic code in the main file.
Definition: tpgGenerationEngine.cpp:125
TPGGenerationEngine(const std::string &filename, const TPG::TPGGraph &tpg, const std::string &path="./", const uint64_t &stackSize=8)
Main constructor of the class.
Definition: tpgGenerationEngine.h:133
std::ofstream fileMain
File holding the functions in charge of iterating through the TPG.
Definition: tpgGenerationEngine.h:78
void generateEdge(const TPG::TPGEdge &edge)
Method for generating the code for an edge of the graph.
Definition: tpgGenerationEngine.cpp:43
uint64_t stackSize
Size of the stack of visited edges.
Definition: tpgGenerationEngine.h:97
void generateTPGGraph()
function that creates the C files required to execute the TPG without gegelati.
Definition: tpgGenerationEngine.cpp:109
std::ofstream fileMainH
header file for the function that iterates through the TPG.
Definition: tpgGenerationEngine.h:80
void generateTeam(const TPG::TPGTeam &team)
Method for generating the code for a team of the graph.
Definition: tpgGenerationEngine.cpp:64
~TPGGenerationEngine()
destructor of the class.
Definition: tpgGenerationEngine.h:168
static const std::string filenameProg
Definition: tpgGenerationEngine.h:75
void setRoot(const TPG::TPGVertex &root)
define the function pointer root to the vertex given in parameter.
Definition: tpgGenerationEngine.cpp:102
void initHeaderFile()
function printing generic code declaration in the main file header.
Definition: tpgGenerationEngine.cpp:215
void generateAction(const TPG::TPGAction &action)
Method for generating a action of the graph.
Definition: tpgGenerationEngine.cpp:90
CodeGen::ProgramGenerationEngine progGenerationEngine
ProgramGenerationEngine for generating Programs of edges.
Definition: tpgGenerationEngine.h:88
Abstract Class in charge of managing maps to give a unique ID for vertex and a program of a TPGGraph.
Definition: tpgAbstractEngine.h:49
const TPG::TPGGraph & tpg
Reference to the TPGGraph whose content will be used to fill the maps.
Definition: tpgAbstractEngine.h:56
TPGAbstractEngine(const TPG::TPGGraph &tpg)
Constructor for the abstract engine.
Definition: tpgAbstractEngine.h:110
Class representing an Action of a TPGGraph.
Definition: tpgAction.h:52
Class representing edges of the Tangled Program Graphs.
Definition: tpgEdge.h:51
Class for storing a Tangled-Program-Graph.
Definition: tpgGraph.h:54
Definition: tpgTeam.h:48
Abstract class representing the vertices of a TPGGraph.
Definition: tpgVertex.h:49
Definition: programGenerationEngine.h:48