Phasor 3.3.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
BytecodeDeserializer.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#include <phsint.hpp>
9
11namespace Phasor
12{
13
19{
20 public:
22 Bytecode deserialize(const std::vector<u8> &data);
23
25 Bytecode loadFromFile(const std::filesystem::path &filename);
26
27 private:
28 const u8 *_data;
29 size_t position;
30 size_t dataSize;
31
32 u8 readUInt8();
33 u16 readUInt16();
34 u32 readUInt32();
35 i32 readInt32();
36 i64 readInt64();
37 f64 readDouble();
38 std::string readString();
39
42
43 void readHeader(u32 &checksum);
44 void readConstantPool(Bytecode &bytecode);
45 void readVariableMapping(Bytecode &bytecode);
46 void readInstructions(Bytecode &bytecode);
47 void readFunctionEntries(Bytecode &bytecode);
48 void readStructSection(Bytecode &bytecode);
49
51 static u32 calculateCRC32(const u8 *data, size_t size);
52};
53} // namespace Phasor
Bytecode binary format deserializer.
void readInstructions(Bytecode &bytecode)
Helper method to read Instructions Table.
i64 readInt64()
Helper method to read Int64.
void readConstantPool(Bytecode &bytecode)
Helper method to read Constants Table.
Value readValue()
Read a single Value (recursive — handles nested structs/arrays).
Bytecode deserialize(const std::vector< u8 > &data)
Deserialize bytecode from binary buffer.
Bytecode loadFromFile(const std::filesystem::path &filename)
Load bytecode from .phsb file.
void readFunctionEntries(Bytecode &bytecode)
Helper method to read Function Entries.
u16 readUInt16()
Helper method to read UInt16.
u32 readUInt32()
Helper method to read UInt32.
static u32 calculateCRC32(const u8 *data, size_t size)
Calculate CRC32 checksum.
void readStructSection(Bytecode &bytecode)
Helper method to read Struct Section.
u8 readUInt8()
Helper method to read UInt8.
void readVariableMapping(Bytecode &bytecode)
Helper method to read Variable Table.
f64 readDouble()
Helper method to read Double.
void readHeader(u32 &checksum)
Helper method to read Header.
i32 readInt32()
Helper method to read Int32.
std::string readString()
Helper method to read String.
A value in the Phasor VM.
Definition Value.hpp:59
The Phasor Programming Language and Runtime.
Definition AST.hpp:13
int64_t i64
Definition phsint.hpp:16
uint8_t u8
Definition phsint.hpp:9
double f64
Definition phsint.hpp:7
int32_t i32
Definition phsint.hpp:15
uint16_t u16
Definition phsint.hpp:10
uint32_t u32
Definition phsint.hpp:11
Complete bytecode structure.
Definition CodeGen.hpp:50