Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
memory_dump.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <sysio/vm/opcodes.hpp>
4#include <sysio/vm/variant.hpp>
5
6#include <cstddef>
7#include <cstdint>
8#include <utility>
9
10namespace sysio { namespace vm {
11
12#define MEMORY_DUMP_OP_VISIT(name, code) \
13 void operator()(const SYS_VM_OPCODE_T(name)& op) { \
14 stream << #name << "\n"; \
15 }
16
17#define MEMORY_DUMP_CONTROL_FLOW_VISIT(name, code) \
18 void operator()(const SYS_VM_OPCODE_T(name)& op) { \
19 stream << #name << " : { " << op.data << ", " << op.pc << ", " << op.index << ", " << op.op_index << " }\n"; \
20 }
21
22#define MEMORY_DUMP_BR_TABLE_VISIT(name, code) \
23 void operator()(const SYS_VM_OPCODE_T(name)& op) { \
24 stream << #name << " : { [ "; \
25 for (uint32_t i=0; i < op.size; i++) { \
26 stream << op.table[i].pc; \
27 if (i < op.size-1) { \
28 stream << ", "; \
29 } \
30 } \
31 stream << " ] }\n"; \
32 index += op.offset; \
33 }
34
35#define MEMORY_DUMP_CALL_VISIT(name, code) \
36 void operator()(const name##_t& op) { \
37 stream << #name << " : { " << op.index << " }\n"; \
38 }
39
40#define MEMORY_DUMP_VARIABLE_ACCESS_VISIT(name, code) \
41 void operator()(const name##_t& op) { \
42 stream << #name << " : { " << op.index << " }\n"; \
43 }
44
45#define MEMORY_DUMP_MEMORY_VISIT(name, code) \
46 void operator()(const name##_t& op) { \
47 stream << #name << " : { " << op.flags_align << ", " << op.offset << " }\n"; \
48 }
49
50#define MEMORY_DUMP_CONST_VISIT(name, code) \
51 void operator()(const name##_t& op) { \
52 stream << #name << " : { " << op.data.ui << " }\n"; \
53 }
54
55 template <typename Stream>
56 struct memory_dump_visitor {
57 memory_dump_visitor(Stream&& stream, size_t& i) : stream(stream), index(i) {}
75 template <typename T>
76 inline void operator()(T) { stream << "invalid opcode\n"; }
78 size_t& index;
79 };
80
81 template <typename Opcode>
82 class memory_dump {
83 public:
84 memory_dump(Opcode* opcodes, size_t size) : _opcodes(opcodes), _size(size) {}
85
86 template <typename Stream>
87 void write(Stream&& stream) {
88 size_t index=0;
89 memory_dump_visitor<Stream> md(std::forward<Stream>(stream), index);
90 for (; index < _size; index++) {
91 sysio::vm::visit(std::move(md), std::move(_opcodes[index]));
92 }
93 }
94 private:
95 Opcode* _opcodes = nullptr;
96 size_t _size = 0;
97 };
98}} // ns sysio::vm
Concept for reading and writing characters.
memory_dump(Opcode *opcodes, size_t size)
void write(Stream &&stream)
constexpr auto visit(Visitor &&vis, Variant &&var)
Definition variant.hpp:156
#define T(meth, val, expected)
memory_dump_visitor(Stream &&stream, size_t &i)
#define MEMORY_DUMP_CONST_VISIT(name, code)
#define MEMORY_DUMP_CALL_VISIT(name, code)
#define MEMORY_DUMP_VARIABLE_ACCESS_VISIT(name, code)
#define MEMORY_DUMP_BR_TABLE_VISIT(name, code)
#define MEMORY_DUMP_CONTROL_FLOW_VISIT(name, code)
#define MEMORY_DUMP_OP_VISIT(name, code)
#define SYS_VM_F64_CONSTANT_OPS(opcode_macro)
#define SYS_VM_RETURN_OP(opcode_macro)
#define SYS_VM_EXIT_OP(opcode_macro)
#define SYS_VM_COMPARISON_OPS(opcode_macro)
#define SYS_VM_I64_CONSTANT_OPS(opcode_macro)
#define SYS_VM_I32_CONSTANT_OPS(opcode_macro)
#define SYS_VM_CALL_OPS(opcode_macro)
#define SYS_VM_NUMERIC_OPS(opcode_macro)
#define SYS_VM_CONVERSION_OPS(opcode_macro)
#define SYS_VM_VARIABLE_ACCESS_OPS(opcode_macro)
#define SYS_VM_EMPTY_OPS(opcode_macro)
#define SYS_VM_CALL_IMM_OPS(opcode_macro)
#define SYS_VM_CONTROL_FLOW_OPS(opcode_macro)
#define SYS_VM_ERROR_OPS(opcode_macro)
#define SYS_VM_PARAMETRIC_OPS(opcode_macro)
#define SYS_VM_F32_CONSTANT_OPS(opcode_macro)
#define SYS_VM_BR_TABLE_OP(opcode_macro)