-
Notifications
You must be signed in to change notification settings - Fork 10
Start code generation
Julien SOYSOUVANH edited this page Nov 23, 2021
·
4 revisions
Once you have setup the CodeGenMgr, FileParser and CodeGenUnit, with some code that may look like this:
//You can implement your own logger with the kodgen::ILogger interface
#include <Kodgen/Misc/DefaultLogger.h>
#include <Kodgen/Parsing/FileParser.h>
#include <Kodgen/CodeGen/CodeGenManager.h>
#include <Kodgen/CodeGen/Macro/MacroCodeGenUnit.h>
#include <Kodgen/CodeGen/Macro/MacroCodeGenUnitSettings.h>
#include "ExampleCodeGenModule.h"
//...
kodgen::DefaultLogger logger;
//FileParser
kodgen::FileParser fileParser;
fileParser.logger = &logger;
//Setup the FileParser here
//CodeGenUnit
kodgen::MacroCodeGenUnitSettings codeGenUnitSettings;
kodgen::MacroCodeGenUnit codeGenUnit;
codeGenUnit.logger = &logger;
codeGenUnit.setSettings(codeGenUnitSettings);
//Setup your code gen unit here
//CodeGenModule
ExampleCodeGenModule codeGenModule;
codeGenUnit.addModule(codeGenModule);
//CodeGenMgr
kodgen::CodeGenManager codeGenMgr; //optionally takes the number of threads to use
codeGenMgr.logger = &logger;
//Setup the CodeGenManager here
You can kick-off the generation process by calling the CodeGenMgr::run method:
kodgen::CodeGenResult genResult = codeGenMgr.run(fileParser, codeGenUnit);
The 3rd parameter is optional, and gives the possibility to force the regeneration of all files (whether they are up-to-date or not).
Check the CodeGenResult to get information about the generation:
if (genResult.completed)
{
logger.log("Generation completed successfully in " + std::to_string(genResult.duration) + " seconds.");
}
else
{
logger.log("An error happened during code generation. Check the logs for more information.", kodgen::ILogger::ELogSeverity::Error);
}