Phasor 2.2.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
9namespace Phasor
10{
11
17{
18 public:
20 Bytecode deserialize(const std::vector<uint8_t> &data);
21
23 Bytecode loadFromFile(const std::filesystem::path &filename);
24
25 private:
26 const uint8_t *_data;
27 size_t position;
28 size_t dataSize;
29
30 uint8_t readUInt8();
31 uint16_t readUInt16();
32 uint32_t readUInt32();
33 int32_t readInt32();
34 int64_t readInt64(); //< Helper method to read Int64
35 double readDouble(); //< Helper method to read Double
36 std::string readString(); //< Helper method to read String
37
38 void readHeader(uint32_t &checksum);
39 void readConstantPool(Bytecode &bytecode);
40 void readVariableMapping(Bytecode &bytecode);
41 void readInstructions(Bytecode &bytecode);
42 void readFunctionEntries(Bytecode &bytecode);
43
45 void validateHeader(uint32_t expectedChecksum);
46
48 uint32_t calculateCRC32(const uint8_t *data, size_t size);
49};
50} // namespace Phasor
Bytecode binary format deserializer.
uint32_t readUInt32()
Helper method to read UInt32.
void readInstructions(Bytecode &bytecode)
Helper method to read Instuctions Table.
uint32_t calculateCRC32(const uint8_t *data, size_t size)
Calculate CRC32 checksum.
void validateHeader(uint32_t expectedChecksum)
Validate header.
void readHeader(uint32_t &checksum)
Helper method to read Header.
void readConstantPool(Bytecode &bytecode)
Helper method to read Constants Table.
Bytecode loadFromFile(const std::filesystem::path &filename)
Load bytecode from .phsb file.
void readFunctionEntries(Bytecode &bytecode)
Helper method to read Function Entries.
uint16_t readUInt16()
Helper method to read UInt16.
Bytecode deserialize(const std::vector< uint8_t > &data)
Deserialize bytecode from binary buffer.
void readVariableMapping(Bytecode &bytecode)
Helper method to read Variable Table.
uint8_t readUInt8()
Helper method to read UInt8.
int32_t readInt32()
Helper method to read Int32.
The Phasor Programming Language and Runtime.
Definition AST.hpp:8
Complete bytecode structure.
Definition CodeGen.hpp:201