Phasor 2.2.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
Phasor::CppCodeGenerator Class Reference

Generates C++ header files with embedded Phasor bytecode. More...

#include <CppCodeGenerator.hpp>

Collaboration diagram for Phasor::CppCodeGenerator:
[legend]

Public Member Functions

bool generate (const Bytecode &bytecode, const std::filesystem::path &outputPath, const std::string &moduleName="")
 Generate C++ header file from bytecode.
Bytecode generateBytecodeFromEmbedded (const std::string &input)
 Generate Bytecode object from embedded bytecode string.

Private Member Functions

void generateFileHeader ()
void generateModuleName ()
void generateIncludes ()
void generateEmbeddedBytecode ()
void generateTempFileWriter ()
void generateMainFunction ()
std::vector< unsigned char > parseEmbeddedBytecode (const std::string &input)
std::string escapeString (const std::string &str)
std::string getValueTypeString (ValueType type)
std::string sanitizeModuleName (const std::string &name)

Private Attributes

std::ostringstream output
 Output stream for generated code.
const Bytecodebytecode = nullptr
std::string moduleName
std::vector< uint8_t > serializedBytecode
 Serialized bytecode in .phsb format.

Detailed Description

Generates C++ header files with embedded Phasor bytecode.

This class takes compiled Phasor bytecode and generates a C++ header file that embeds the bytecode as inline data. The header is designed to be included in CppRuntime_main.cpp to provide the module name, bytecode array, and bytecode size.

Definition at line 19 of file CppCodeGenerator.hpp.

Member Function Documentation

◆ escapeString()

std::string Phasor::CppCodeGenerator::escapeString ( const std::string & str)
private

Definition at line 123 of file CppCodeGenerator.cpp.

◆ generate()

bool Phasor::CppCodeGenerator::generate ( const Bytecode & bytecode,
const std::filesystem::path & outputPath,
const std::string & moduleName = "" )

Generate C++ header file from bytecode.

Parameters
bytecodeThe compiled bytecode to embed
outputPathPath to the output header file
moduleNameOptional module name (defaults to filename without extension)
Returns
true if generation succeeded, false otherwise

Definition at line 11 of file CppCodeGenerator.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateBytecodeFromEmbedded()

Bytecode Phasor::CppCodeGenerator::generateBytecodeFromEmbedded ( const std::string & input)

Generate Bytecode object from embedded bytecode string.

Parameters
inputThe string containing the embedded bytecode array
Returns
Deserialized Bytecode object

Definition at line 56 of file CppCodeGenerator.cpp.

Here is the call graph for this function:

◆ generateEmbeddedBytecode()

void Phasor::CppCodeGenerator::generateEmbeddedBytecode ( )
private

Definition at line 77 of file CppCodeGenerator.cpp.

Here is the caller graph for this function:

◆ generateFileHeader()

void Phasor::CppCodeGenerator::generateFileHeader ( )
private

Definition at line 63 of file CppCodeGenerator.cpp.

Here is the caller graph for this function:

◆ generateIncludes()

void Phasor::CppCodeGenerator::generateIncludes ( )
private

◆ generateMainFunction()

void Phasor::CppCodeGenerator::generateMainFunction ( )
private

◆ generateModuleName()

void Phasor::CppCodeGenerator::generateModuleName ( )
private

Definition at line 72 of file CppCodeGenerator.cpp.

Here is the caller graph for this function:

◆ generateTempFileWriter()

void Phasor::CppCodeGenerator::generateTempFileWriter ( )
private

◆ getValueTypeString()

std::string Phasor::CppCodeGenerator::getValueTypeString ( ValueType type)
private

Definition at line 157 of file CppCodeGenerator.cpp.

◆ parseEmbeddedBytecode()

std::vector< unsigned char > Phasor::CppCodeGenerator::parseEmbeddedBytecode ( const std::string & input)
private

Definition at line 102 of file CppCodeGenerator.cpp.

Here is the caller graph for this function:

◆ sanitizeModuleName()

std::string Phasor::CppCodeGenerator::sanitizeModuleName ( const std::string & name)
private

Definition at line 176 of file CppCodeGenerator.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ bytecode

const Bytecode* Phasor::CppCodeGenerator::bytecode = nullptr
private

Definition at line 43 of file CppCodeGenerator.hpp.

◆ moduleName

std::string Phasor::CppCodeGenerator::moduleName
private

Definition at line 44 of file CppCodeGenerator.hpp.

◆ output

std::ostringstream Phasor::CppCodeGenerator::output
private

Output stream for generated code.

Definition at line 42 of file CppCodeGenerator.hpp.

◆ serializedBytecode

std::vector<uint8_t> Phasor::CppCodeGenerator::serializedBytecode
private

Serialized bytecode in .phsb format.

Definition at line 45 of file CppCodeGenerator.hpp.


The documentation for this class was generated from the following files: