1 | // |
2 | // m3_function.h |
3 | // |
4 | // Created by Steven Massey on 4/7/21. |
5 | // Copyright © 2021 Steven Massey. All rights reserved. |
6 | // |
7 | |
8 | #ifndef m3_function_h |
9 | #define m3_function_h |
10 | |
11 | #include "m3_core.h" |
12 | |
13 | d_m3BeginExternC |
14 | |
15 | //--------------------------------------------------------------------------------------------------------------------------------- |
16 | |
17 | typedef struct M3FuncType |
18 | { |
19 | struct M3FuncType * next; |
20 | |
21 | u16 numRets; |
22 | u16 numArgs; |
23 | u8 types []; // returns, then args |
24 | } |
25 | M3FuncType; |
26 | |
27 | typedef M3FuncType * IM3FuncType; |
28 | |
29 | |
30 | M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i_numTypes); |
31 | bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB); |
32 | |
33 | u16 GetFuncTypeNumParams (const IM3FuncType i_funcType); |
34 | u8 GetFuncTypeParamType (const IM3FuncType i_funcType, u16 i_index); |
35 | |
36 | u16 GetFuncTypeNumResults (const IM3FuncType i_funcType); |
37 | u8 GetFuncTypeResultType (const IM3FuncType i_funcType, u16 i_index); |
38 | |
39 | //--------------------------------------------------------------------------------------------------------------------------------- |
40 | |
41 | typedef struct M3Function |
42 | { |
43 | struct M3Module * module; |
44 | |
45 | M3ImportInfo import; |
46 | |
47 | bytes_t wasm; |
48 | bytes_t wasmEnd; |
49 | |
50 | cstr_t names[d_m3MaxDuplicateFunctionImpl]; |
51 | u16 numNames; // maximum of d_m3MaxDuplicateFunctionImpl |
52 | |
53 | IM3FuncType funcType; |
54 | |
55 | pc_t compiled; |
56 | |
57 | # if (d_m3EnableCodePageRefCounting) |
58 | IM3CodePage * codePageRefs; // array of all pages used |
59 | u32 numCodePageRefs; |
60 | # endif |
61 | |
62 | # if defined (DEBUG) |
63 | u32 hits; |
64 | u32 index; |
65 | # endif |
66 | |
67 | u16 maxStackSlots; |
68 | |
69 | u16 numRetSlots; |
70 | u16 numRetAndArgSlots; |
71 | |
72 | u16 numLocals; // not including args |
73 | u16 numLocalBytes; |
74 | |
75 | bool ownsWasmCode; |
76 | |
77 | u16 numConstantBytes; |
78 | void * constants; |
79 | } |
80 | M3Function; |
81 | |
82 | void Function_Release (IM3Function i_function); |
83 | void Function_FreeCompiledCode (IM3Function i_function); |
84 | |
85 | cstr_t GetFunctionImportModuleName (IM3Function i_function); |
86 | cstr_t * GetFunctionNames (IM3Function i_function, u16 * o_numNames); |
87 | u16 GetFunctionNumArgs (IM3Function i_function); |
88 | u8 GetFunctionArgType (IM3Function i_function, u32 i_index); |
89 | |
90 | u16 GetFunctionNumReturns (IM3Function i_function); |
91 | u8 GetFunctionReturnType (const IM3Function i_function, u16 i_index); |
92 | |
93 | u32 GetFunctionNumArgsAndLocals (IM3Function i_function); |
94 | |
95 | cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp); |
96 | |
97 | //--------------------------------------------------------------------------------------------------------------------------------- |
98 | |
99 | |
100 | d_m3EndExternC |
101 | |
102 | #endif /* m3_function_h */ |
103 | |