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
13d_m3BeginExternC
14
15//---------------------------------------------------------------------------------------------------------------------------------
16
17typedef struct M3FuncType
18{
19 struct M3FuncType * next;
20
21 u16 numRets;
22 u16 numArgs;
23 u8 types []; // returns, then args
24}
25M3FuncType;
26
27typedef M3FuncType * IM3FuncType;
28
29
30M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i_numTypes);
31bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB);
32
33u16 GetFuncTypeNumParams (const IM3FuncType i_funcType);
34u8 GetFuncTypeParamType (const IM3FuncType i_funcType, u16 i_index);
35
36u16 GetFuncTypeNumResults (const IM3FuncType i_funcType);
37u8 GetFuncTypeResultType (const IM3FuncType i_funcType, u16 i_index);
38
39//---------------------------------------------------------------------------------------------------------------------------------
40
41typedef 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}
80M3Function;
81
82void Function_Release (IM3Function i_function);
83void Function_FreeCompiledCode (IM3Function i_function);
84
85cstr_t GetFunctionImportModuleName (IM3Function i_function);
86cstr_t * GetFunctionNames (IM3Function i_function, u16 * o_numNames);
87u16 GetFunctionNumArgs (IM3Function i_function);
88u8 GetFunctionArgType (IM3Function i_function, u32 i_index);
89
90u16 GetFunctionNumReturns (IM3Function i_function);
91u8 GetFunctionReturnType (const IM3Function i_function, u16 i_index);
92
93u32 GetFunctionNumArgsAndLocals (IM3Function i_function);
94
95cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp);
96
97//---------------------------------------------------------------------------------------------------------------------------------
98
99
100d_m3EndExternC
101
102#endif /* m3_function_h */
103