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
13d_m3BeginExternC
14
15typedef struct M3CodePage
16{
17 M3CodePageHeader info;
18 code_t code [1];
19}
20M3CodePage;
21
22typedef M3CodePage * IM3CodePage;
23
24
25IM3CodePage NewCodePage (IM3Runtime i_runtime, u32 i_minNumLines);
26
27void FreeCodePages (IM3CodePage * io_list);
28
29u32 NumFreeLines (IM3CodePage i_page);
30pc_t GetPageStartPC (IM3CodePage i_page);
31pc_t GetPagePC (IM3CodePage i_page);
32void EmitWord_impl (IM3CodePage i_page, void* i_word);
33void EmitWord32 (IM3CodePage i_page, u32 i_word);
34void EmitWord64 (IM3CodePage i_page, u64 i_word);
35# if d_m3RecordBacktraces
36void EmitMappingEntry (IM3CodePage i_page, u32 i_moduleOffset);
37# endif // d_m3RecordBacktraces
38
39void PushCodePage (IM3CodePage * io_list, IM3CodePage i_codePage);
40IM3CodePage PopCodePage (IM3CodePage * io_list);
41
42IM3CodePage GetEndCodePage (IM3CodePage i_list); // i_list = NULL is valid
43u32 CountCodePages (IM3CodePage i_list); // i_list = NULL is valid
44
45# if d_m3RecordBacktraces
46bool ContainsPC (IM3CodePage i_page, pc_t i_pc);
47bool MapPCToOffset (IM3CodePage i_page, pc_t i_pc, u32 * o_moduleOffset);
48# endif // d_m3RecordBacktraces
49
50# ifdef DEBUG
51void 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
60typedef struct M3CodeMapEntry
61{
62 u32 pcOffset;
63 u32 moduleOffset;
64}
65M3CodeMapEntry;
66
67typedef struct M3CodeMappingPage
68{
69 pc_t basePC;
70 u32 size;
71 u32 capacity;
72 M3CodeMapEntry entries [];
73}
74M3CodeMappingPage;
75
76# endif // d_m3RecordBacktraces
77
78d_m3EndExternC
79
80#endif // m3_code_h
81