Phasor 2.2.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
BytecodeSerializer.hpp
Go to the documentation of this file.
1#pragma once
2#include "../CodeGen.hpp"
3#include <cstdint>
4#include <fstream>
5#include <string>
6#include <vector>
7#include <filesystem>
8
9namespace Phasor
10{
11
17{
18 public:
20 std::vector<uint8_t> serialize(const Bytecode &bytecode);
21
23 bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename);
24
25 private:
26 std::vector<uint8_t> buffer;
27
28 void writeUInt8(uint8_t value);
29 void writeUInt16(uint16_t value);
30 void writeUInt32(uint32_t value);
31 void writeInt32(int32_t value);
32 void writeInt64(int64_t value);
33 void writeDouble(double value);
34 void writeString(const std::string &str);
35
37 void writeHeader(uint32_t dataChecksum);
38 void writeConstantPool(const std::vector<Value> &constants);
39 void writeVariableMapping(const std::map<std::string, int> &variables,
40 int nextVarIndex);
41 void writeInstructions(const std::vector<Instruction> &instructions);
43 const std::map<std::string, int> &functionEntries);
44
46 uint32_t calculateCRC32(const std::vector<uint8_t> &data);
47};
48} // namespace Phasor
Bytecode binary format serializer.
void writeUInt16(uint16_t value)
Helper method to write UInt16.
void writeInstructions(const std::vector< Instruction > &instructions)
Helper method to write Instruction Table.
void writeString(const std::string &str)
Helper method to write String.
void writeInt64(int64_t value)
Helper method to write Int64.
void writeFunctionEntries(const std::map< std::string, int > &functionEntries)
Helper method to write Function Table.
void writeUInt8(uint8_t value)
Helper method to write UInt8.
bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename)
Save bytecode to .phsb file.
std::vector< uint8_t > buffer
void writeInt32(int32_t value)
Helper method to write Int32.
uint32_t calculateCRC32(const std::vector< uint8_t > &data)
Calculate CRC32 checksum.
std::vector< uint8_t > serialize(const Bytecode &bytecode)
Serialize bytecode to binary buffer.
void writeHeader(uint32_t dataChecksum)
Section writers.
void writeConstantPool(const std::vector< Value > &constants)
Helper method to write Constants Table.
void writeUInt32(uint32_t value)
Helper method to write UInt32.
void writeDouble(double value)
Helper method to write Double.
void writeVariableMapping(const std::map< std::string, int > &variables, int nextVarIndex)
Helper method to write Variable Map Table.
The Phasor Programming Language and Runtime.
Definition AST.hpp:8
Complete bytecode structure.
Definition CodeGen.hpp:201