Phasor 3.3.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
PhasorIR.hpp
Go to the documentation of this file.
1#pragma once
2#include "../CodeGen.hpp"
3#include <cstdint>
4#include <filesystem>
5#include <string>
6#include <unordered_map>
7#include <vector>
8#include <phsint.hpp>
9
11namespace Phasor
12{
13
19{
20 public:
22 static std::vector<u8> serialize(const Bytecode &bytecode);
23
25 static Bytecode deserialize(const std::vector<u8> &data);
26
28 static bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename);
29
31 static Bytecode loadFromFile(const std::filesystem::path &filename);
32
34 static std::string escapeString(const std::string &str);
35
37 static std::string unescapeString(const std::string &str);
38
39 private:
50
51 static int getOperandCount(OpCode op);
52 static OperandType getOperandType(OpCode op, int operandIndex);
53
54 static const std::unordered_map<OpCode, std::string> opCodeToStringMap;
55 static const std::unordered_map<std::string, OpCode> stringToOpCodeMap;
56};
57
58} // namespace Phasor
Phasor IR Serializer/Deserializer.
Definition PhasorIR.hpp:19
static std::string unescapeString(const std::string &str)
Helper to unescape strings from text format.
Definition PhasorIR.cpp:235
OperandType
Operand types for instructions.
Definition PhasorIR.hpp:42
@ VARIABLE_IDX
Index into variable mapping.
Definition PhasorIR.hpp:47
@ CONSTANT_IDX
Index into constant pool.
Definition PhasorIR.hpp:46
@ FUNCTION_IDX
Index into function entries.
Definition PhasorIR.hpp:48
@ REGISTER
Register operand.
Definition PhasorIR.hpp:45
static std::vector< u8 > serialize(const Bytecode &bytecode)
Serialize bytecode to Phasor IR format.
Definition PhasorIR.cpp:478
static const std::unordered_map< std::string, OpCode > stringToOpCodeMap
Definition PhasorIR.hpp:55
static OperandType getOperandType(OpCode op, int operandIndex)
Definition PhasorIR.cpp:154
static Bytecode loadFromFile(const std::filesystem::path &filename)
Load bytecode from .phir file.
Definition PhasorIR.cpp:738
static const std::unordered_map< OpCode, std::string > opCodeToStringMap
Definition PhasorIR.hpp:54
static int getOperandCount(OpCode op)
Definition PhasorIR.cpp:20
static std::string escapeString(const std::string &str)
Helper to escape strings for text format.
Definition PhasorIR.cpp:201
static Bytecode deserialize(const std::vector< u8 > &data)
Deserialize Phasor IR format to bytecode.
Definition PhasorIR.cpp:597
static bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename)
Save bytecode to .phir file.
Definition PhasorIR.cpp:721
The Phasor Programming Language and Runtime.
Definition AST.hpp:13
uint8_t u8
Definition phsint.hpp:9
OpCode
Definition ISA.hpp:12
Complete bytecode structure.
Definition CodeGen.hpp:50