-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_prog.hpp
67 lines (55 loc) · 1.35 KB
/
plot_prog.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* SPDX-License-Identifier: MIT */
/* SPDX-FileCopyrightText: 2022 Glib Novodran <[email protected]> */
struct PlopData : sxData {
enum class Op : uint32_t {
_BASE_ = 100,
#if defined(PLOP_OP)
# undef PLOP_OP
#endif
#define PLOP_OP(SYM, ID) SYM = ID ,
#include "plop_op.inc"
#undef PLOP_OP
};
struct BlockEntry {
uint32_t mOffs;
uint32_t mLen;
};
uint32_t mHeadTag;
uint32_t mBlkNum;
uint32_t mBodyOffs;
BlockEntry mBlks[1];
uint32_t* get_block_code(const uint32_t bkid) const {
uint32_t offs = mBlks[bkid].mOffs;
uint8_t* pCodeBytes = XD_INCR_PTR(this, offs);
return reinterpret_cast<uint32_t*>(pCodeBytes);
}
size_t get_plop_size() const {
uint32_t* pLast = get_block_code(mBlkNum - 1);
size_t len = mBlks[mBlkNum - 1].mLen;
uint8_t* pEnd = XD_INCR_PTR(pLast, len * sizeof(uint32_t));
ptrdiff_t diff = pEnd - reinterpret_cast<const uint8_t*>(this);
return diff;
}
void disasm(FILE* pOut);
void disasm(const char* pOutPath) {
FILE* pOut = nxSys::fopen_w_bin(pOutPath);
if (!pOut) {
return;
}
disasm(pOut);
::fclose(pOut);
}
void save(FILE* pOut) {
size_t sz = get_plop_size();
::fwrite(reinterpret_cast<void*>(this), sz, 1, pOut);
}
void save(const char* pOutPath) {
FILE* pOut = nxSys::fopen_w_bin(pOutPath);
if (!pOut) {
return;
}
save(pOut);
::fclose(pOut);
}
static const uint32_t KIND;
};