39 std::ofstream file(outputPath);
50 catch (
const std::exception &)
65 output <<
"// Phasor VM Program\n";
67 output <<
"#pragma once\n";
68 output <<
"#include <cstddef>\n";
69 output <<
"#include <string>\n\n";
79 output <<
"inline const unsigned char embeddedBytecode[] = {\n";
98 output << std::dec <<
"\n};\n";
104 std::vector<unsigned char> result;
105 std::istringstream stream(input);
108 while (stream >> token)
111 if (token.size() >= 3 && token[0] ==
'0' && (token[1] ==
'x' || token[1] ==
'X'))
114 std::istringstream hexStream(token);
115 hexStream >> std::hex >> byte;
116 result.push_back(
static_cast<unsigned char>(
byte));
125 std::ostringstream escaped;
146 if (c >= 32 && c <= 126)
149 escaped <<
"\\x" << std::hex << std::setw(2) << std::setfill(
'0')
150 <<
static_cast<int>(
static_cast<unsigned char>(c));
154 return escaped.str();
181 if (std::isalnum(c) || c ==
'_')
188 if (!result.empty() && std::isdigit(result[0]))
189 result =
"_" + result;
191 return result.empty() ?
"PhasorModule" : result;
Bytecode binary format deserializer.
Bytecode deserialize(const std::vector< uint8_t > &data)
Deserialize bytecode from binary buffer.
Bytecode binary format serializer.
std::vector< uint8_t > serialize(const Bytecode &bytecode)
Serialize bytecode to binary buffer.
std::vector< uint8_t > serializedBytecode
Serialized bytecode in .phsb format.
void generateFileHeader()
std::string getValueTypeString(ValueType type)
void generateModuleName()
bool generate(const Bytecode &bytecode, const std::filesystem::path &outputPath, const std::string &moduleName="")
Generate C++ header file from bytecode.
std::string escapeString(const std::string &str)
void generateEmbeddedBytecode()
std::vector< unsigned char > parseEmbeddedBytecode(const std::string &input)
const Bytecode * bytecode
std::ostringstream output
Output stream for generated code.
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.
ValueType
Runtime value types for the VM.
Complete bytecode structure.