Phasor 2.2.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
9namespace Phasor
10{
11
17{
18 public:
20 static std::vector<uint8_t> serialize(const Bytecode &bytecode);
21
23 static Bytecode deserialize(const std::vector<uint8_t> &data);
24
26 static bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename);
27
29 static Bytecode loadFromFile(const std::filesystem::path &filename);
30
32 static std::string opCodeToString(OpCode op);
33
35 static OpCode stringToOpCode(const std::string &str);
36
38 static std::string escapeString(const std::string &str);
39
41 static std::string unescapeString(const std::string &str);
42
43 private:
53
54 static int getOperandCount(OpCode op);
55 static OperandType getOperandType(OpCode op, int operandIndex);
56
57 static const std::unordered_map<OpCode, std::string> opCodeToStringMap;
58 static const std::unordered_map<std::string, OpCode> stringToOpCodeMap;
59};
60
61} // namespace Phasor
Phasor IR Serializer/Deserializer.
Definition PhasorIR.hpp:17
static std::vector< uint8_t > serialize(const Bytecode &bytecode)
Serialize bytecode to Phasor IR format.
Definition PhasorIR.cpp:422
static std::string unescapeString(const std::string &str)
Helper to unescape strings from text format.
Definition PhasorIR.cpp:383
static const std::unordered_map< OpCode, std::string > opCodeToStringMap
Definition PhasorIR.hpp:57
static Bytecode deserialize(const std::vector< uint8_t > &data)
Deserialize Phasor IR format to bytecode.
Definition PhasorIR.cpp:594
static const std::unordered_map< std::string, OpCode > stringToOpCodeMap
Definition PhasorIR.hpp:58
static OperandType getOperandType(OpCode op, int operandIndex)
Definition PhasorIR.cpp:277
static Bytecode loadFromFile(const std::filesystem::path &filename)
Load bytecode from .phir file.
Definition PhasorIR.cpp:781
static std::string opCodeToString(OpCode op)
Helper to convert OpCode to string.
Definition PhasorIR.cpp:333
static int getOperandCount(OpCode op)
Definition PhasorIR.cpp:143
static std::string escapeString(const std::string &str)
Helper to escape strings for text format.
Definition PhasorIR.cpp:353
static bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename)
Save bytecode to .phir file.
Definition PhasorIR.cpp:764
static OpCode stringToOpCode(const std::string &str)
Helper to convert string to OpCode.
Definition PhasorIR.cpp:343
The Phasor Programming Language and Runtime.
Definition AST.hpp:8
Complete bytecode structure.
Definition CodeGen.hpp:201