Phasor 3.3.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
CppCodeGenerator.hpp
Go to the documentation of this file.
1#pragma once
2#include "../CodeGen.hpp"
3#include <filesystem>
4#include <sstream>
5#include <string>
6#include <phsint.hpp>
7
9namespace Phasor
10{
11
22{
23 public:
32 bool generate(const Bytecode &bytecode, const std::filesystem::path &outputPath,
33 const std::string &moduleName = "");
34
41 Bytecode generateBytecodeFromEmbedded(const std::string &input);
42
43 private:
44 std::ostringstream output;
45 const Bytecode *bytecode = nullptr;
46 std::string moduleName;
47 std::vector<u8> serializedBytecode;
48
49 // Code generation methods
50 void generateFileHeader();
51 void generateModuleName();
56
57 // Deserialization helper
58 static std::vector<unsigned char> parseEmbeddedBytecode(const std::string &input);
59
60 // Helper methods
61 static std::string escapeString(const std::string &str);
62 static std::string getValueTypeString(ValueType type);
63 static std::string sanitizeModuleName(const std::string &name);
64};
65
66} // namespace Phasor
Generates C++ header files with embedded Phasor bytecode.
static std::string getValueTypeString(ValueType type)
std::vector< u8 > serializedBytecode
Serialized bytecode in .phsb format.
bool generate(const Bytecode &bytecode, const std::filesystem::path &outputPath, const std::string &moduleName="")
Generate C++ header file from bytecode.
static std::string escapeString(const std::string &str)
static std::vector< unsigned char > parseEmbeddedBytecode(const std::string &input)
std::ostringstream output
Output stream for generated code.
static std::string sanitizeModuleName(const std::string &name)
Bytecode generateBytecodeFromEmbedded(const std::string &input)
Generate Bytecode object from embedded bytecode string.
The Phasor Programming Language and Runtime.
Definition AST.hpp:13
ValueType
Runtime value types for the VM.
Definition Value.hpp:43
Complete bytecode structure.
Definition CodeGen.hpp:50