Phasor 3.3.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
Phasor::BytecodeSerializer Class Reference

Bytecode binary format serializer. More...

#include <BytecodeSerializer.hpp>

Collaboration diagram for Phasor::BytecodeSerializer:
[legend]

Public Member Functions

std::vector< u8serialize (const Bytecode &bytecode)
 Serialize bytecode to binary buffer.
bool saveToFile (const Bytecode &bytecode, const std::filesystem::path &filename)
 Save bytecode to .phsb file.

Private Member Functions

void writeUInt8 (u8 value)
 Helper method to write UInt8.
void writeUInt16 (u16 value)
 Helper method to write UInt16.
void writeUInt32 (u32 value)
 Helper method to write UInt32.
void writeInt32 (i32 value)
 Helper method to write Int32.
void writeInt64 (i64 value)
 Helper method to write Int64.
void writeDouble (f64 value)
 Helper method to write Double.
void writeString (const std::string &str)
 Helper method to write String.
void writeValue (const Value &val)
 Write a single Value (recursive — handles nested structs/arrays).
void writeHeader (u32 dataChecksum)
 Section writers.
void writeConstantPool (const std::vector< Value > &constants)
 Helper method to write Constants Table.
void writeVariableMapping (const std::unordered_map< std::string, int > &variables, int nextVarIndex)
 Helper method to write Variable Map Table.
void writeInstructions (const std::vector< Instruction > &instructions)
 Helper method to write Instruction Table.
void writeFunctionEntries (const std::unordered_map< std::string, int > &functionEntries)
 Helper method to write Function Table.
void writeStructSection (const std::vector< StructInfo > &structs)
 Helper method to write Struct Section.

Static Private Member Functions

static u32 calculateCRC32 (const std::vector< u8 > &data)
 Calculate CRC32 checksum.

Private Attributes

std::vector< u8buffer

Detailed Description

Bytecode binary format serializer.

Definition at line 19 of file BytecodeSerializer.hpp.

Member Function Documentation

◆ calculateCRC32()

u32 Phasor::BytecodeSerializer::calculateCRC32 ( const std::vector< u8 > & data)
staticprivate

Calculate CRC32 checksum.

Definition at line 39 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveToFile()

bool Phasor::BytecodeSerializer::saveToFile ( const Bytecode & bytecode,
const std::filesystem::path & filename )

Save bytecode to .phsb file.

Definition at line 281 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ serialize()

std::vector< u8 > Phasor::BytecodeSerializer::serialize ( const Bytecode & bytecode)

Serialize bytecode to binary buffer.

Definition at line 255 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeConstantPool()

void Phasor::BytecodeSerializer::writeConstantPool ( const std::vector< Value > & constants)
private

Helper method to write Constants Table.

Definition at line 180 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeDouble()

void Phasor::BytecodeSerializer::writeDouble ( f64 value)
private

Helper method to write Double.

Definition at line 84 of file BytecodeSerializer.cpp.

Here is the caller graph for this function:

◆ writeFunctionEntries()

void Phasor::BytecodeSerializer::writeFunctionEntries ( const std::unordered_map< std::string, int > & functionEntries)
private

Helper method to write Function Table.

Definition at line 214 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeHeader()

void Phasor::BytecodeSerializer::writeHeader ( u32 dataChecksum)
private

Section writers.

Helper method to write header

Definition at line 172 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeInstructions()

void Phasor::BytecodeSerializer::writeInstructions ( const std::vector< Instruction > & instructions)
private

Helper method to write Instruction Table.

Definition at line 201 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeInt32()

void Phasor::BytecodeSerializer::writeInt32 ( i32 value)
private

Helper method to write Int32.

Definition at line 73 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeInt64()

void Phasor::BytecodeSerializer::writeInt64 ( i64 value)
private

Helper method to write Int64.

Definition at line 78 of file BytecodeSerializer.cpp.

Here is the caller graph for this function:

◆ writeString()

void Phasor::BytecodeSerializer::writeString ( const std::string & str)
private

Helper method to write String.

Definition at line 92 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeStructSection()

void Phasor::BytecodeSerializer::writeStructSection ( const std::vector< StructInfo > & structs)
private

Helper method to write Struct Section.

Write struct type definitions section (0x05).

Binary layout: u8 section_id = 0x05 u32 structCount for each StructInfo: string name i32 firstConstIndex i32 fieldCount string fieldName[0..fieldCount-1]

Definition at line 237 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeUInt16()

void Phasor::BytecodeSerializer::writeUInt16 ( u16 value)
private

Helper method to write UInt16.

Definition at line 59 of file BytecodeSerializer.cpp.

Here is the caller graph for this function:

◆ writeUInt32()

void Phasor::BytecodeSerializer::writeUInt32 ( u32 value)
private

Helper method to write UInt32.

Definition at line 65 of file BytecodeSerializer.cpp.

Here is the caller graph for this function:

◆ writeUInt8()

void Phasor::BytecodeSerializer::writeUInt8 ( u8 value)
private

Helper method to write UInt8.

Definition at line 54 of file BytecodeSerializer.cpp.

Here is the caller graph for this function:

◆ writeValue()

void Phasor::BytecodeSerializer::writeValue ( const Value & val)
private

Write a single Value (recursive — handles nested structs/arrays).

Definition at line 111 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeVariableMapping()

void Phasor::BytecodeSerializer::writeVariableMapping ( const std::unordered_map< std::string, int > & variables,
int nextVarIndex )
private

Helper method to write Variable Map Table.

Definition at line 188 of file BytecodeSerializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ buffer

std::vector<u8> Phasor::BytecodeSerializer::buffer
private

Definition at line 29 of file BytecodeSerializer.hpp.


The documentation for this class was generated from the following files: