1 | // |
2 | // m3_code.h |
3 | // |
4 | // Created by Steven Massey on 4/19/19. |
5 | // Copyright © 2019 Steven Massey. All rights reserved. |
6 | // |
7 | |
8 | #ifndef m3_code_h |
9 | #define m3_code_h |
10 | |
11 | #include "m3_core.h" |
12 | |
13 | d_m3BeginExternC |
14 | |
15 | typedef struct M3CodePage |
16 | { |
17 | M3CodePageHeader info; |
18 | code_t code [1]; |
19 | } |
20 | M3CodePage; |
21 | |
22 | typedef M3CodePage * IM3CodePage; |
23 | |
24 | |
25 | IM3CodePage NewCodePage (IM3Runtime i_runtime, u32 i_minNumLines); |
26 | |
27 | void FreeCodePages (IM3CodePage * io_list); |
28 | |
29 | u32 NumFreeLines (IM3CodePage i_page); |
30 | pc_t GetPageStartPC (IM3CodePage i_page); |
31 | pc_t GetPagePC (IM3CodePage i_page); |
32 | void EmitWord_impl (IM3CodePage i_page, void* i_word); |
33 | void EmitWord32 (IM3CodePage i_page, u32 i_word); |
34 | void EmitWord64 (IM3CodePage i_page, u64 i_word); |
35 | # if d_m3RecordBacktraces |
36 | void EmitMappingEntry (IM3CodePage i_page, u32 i_moduleOffset); |
37 | # endif // d_m3RecordBacktraces |
38 | |
39 | void PushCodePage (IM3CodePage * io_list, IM3CodePage i_codePage); |
40 | IM3CodePage PopCodePage (IM3CodePage * io_list); |
41 | |
42 | IM3CodePage GetEndCodePage (IM3CodePage i_list); // i_list = NULL is valid |
43 | u32 CountCodePages (IM3CodePage i_list); // i_list = NULL is valid |
44 | |
45 | # if d_m3RecordBacktraces |
46 | bool ContainsPC (IM3CodePage i_page, pc_t i_pc); |
47 | bool MapPCToOffset (IM3CodePage i_page, pc_t i_pc, u32 * o_moduleOffset); |
48 | # endif // d_m3RecordBacktraces |
49 | |
50 | # ifdef DEBUG |
51 | void dump_code_page (IM3CodePage i_codePage, pc_t i_startPC); |
52 | # endif |
53 | |
54 | #define EmitWord(page, val) EmitWord_impl(page, (void*)(val)) |
55 | |
56 | //--------------------------------------------------------------------------------------------------------------------------------- |
57 | |
58 | # if d_m3RecordBacktraces |
59 | |
60 | typedef struct M3CodeMapEntry |
61 | { |
62 | u32 pcOffset; |
63 | u32 moduleOffset; |
64 | } |
65 | M3CodeMapEntry; |
66 | |
67 | typedef struct M3CodeMappingPage |
68 | { |
69 | pc_t basePC; |
70 | u32 size; |
71 | u32 capacity; |
72 | M3CodeMapEntry entries []; |
73 | } |
74 | M3CodeMappingPage; |
75 | |
76 | # endif // d_m3RecordBacktraces |
77 | |
78 | d_m3EndExternC |
79 | |
80 | #endif // m3_code_h |
81 | |