Phasor 3.1.1
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
10namespace Phasor
11{
12
18{
19 public:
21 static std::vector<uint8_t> serialize(const Bytecode &bytecode);
22
24 static Bytecode deserialize(const std::vector<uint8_t> &data);
25
27 static bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename);
28
30 static Bytecode loadFromFile(const std::filesystem::path &filename);
31
33 static std::string escapeString(const std::string &str);
34
36 static std::string unescapeString(const std::string &str);
37
38 private:
49
50 static int getOperandCount(OpCode op);
51 static OperandType getOperandType(OpCode op, int operandIndex);
52
53 static const std::unordered_map<OpCode, std::string> opCodeToStringMap;
54 static const std::unordered_map<std::string, OpCode> stringToOpCodeMap;
55};
56
57} // namespace Phasor
Phasor IR Serializer/Deserializer.
Definition PhasorIR.hpp:18
static std::vector< uint8_t > serialize(const Bytecode &bytecode)
Serialize bytecode to Phasor IR format.
Definition PhasorIR.cpp:283
static std::string unescapeString(const std::string &str)
Helper to unescape strings from text format.
Definition PhasorIR.cpp:244
static Bytecode deserialize(const std::vector< uint8_t > &data)
Deserialize Phasor IR format to bytecode.
Definition PhasorIR.cpp:454
OperandType
Operand types for instructions.
Definition PhasorIR.hpp:41
@ VARIABLE_IDX
Index into variable mapping.
Definition PhasorIR.hpp:46
@ CONSTANT_IDX
Index into constant pool.
Definition PhasorIR.hpp:45
@ FUNCTION_IDX
Index into function entries.
Definition PhasorIR.hpp:47
@ REGISTER
Register operand.
Definition PhasorIR.hpp:44
static const std::unordered_map< std::string, OpCode > stringToOpCodeMap
Definition PhasorIR.hpp:54
static OperandType getOperandType(OpCode op, int operandIndex)
Definition PhasorIR.cpp:158
static Bytecode loadFromFile(const std::filesystem::path &filename)
Load bytecode from .phir file.
Definition PhasorIR.cpp:641
static const std::unordered_map< OpCode, std::string > opCodeToStringMap
Definition PhasorIR.hpp:53
static int getOperandCount(OpCode op)
Definition PhasorIR.cpp:24
static std::string escapeString(const std::string &str)
Helper to escape strings for text format.
Definition PhasorIR.cpp:214
static bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename)
Save bytecode to .phir file.
Definition PhasorIR.cpp:624
The Phasor Programming Language and Runtime.
Definition AST.hpp:11
OpCode
Definition ISA.hpp:12
Complete bytecode structure.
Definition CodeGen.hpp:47