| 1 | // Copyright (c) 2023 l-m.dev. All rights reserved. |
| 2 | // Use of this source code is governed by an MIT license |
| 3 | // that can be found in the LICENSE file. |
| 4 | module wasm |
| 5 | |
| 6 | struct ImportCallPatch { |
| 7 | mod string |
| 8 | name string |
| 9 | mut: |
| 10 | pos int |
| 11 | } |
| 12 | |
| 13 | struct FunctionCallPatch { |
| 14 | name string |
| 15 | mut: |
| 16 | pos int |
| 17 | } |
| 18 | |
| 19 | type CallPatch = FunctionCallPatch | ImportCallPatch |
| 20 | |
| 21 | struct FunctionGlobalPatch { |
| 22 | idx GlobalIndex |
| 23 | mut: |
| 24 | pos int |
| 25 | } |
| 26 | |
| 27 | type FunctionPatch = CallPatch | FunctionGlobalPatch |
| 28 | |
| 29 | struct FunctionLocal { |
| 30 | typ ValType |
| 31 | name ?string |
| 32 | } |
| 33 | |
| 34 | pub struct Function { |
| 35 | tidx int |
| 36 | idx int |
| 37 | mut: |
| 38 | patches []FunctionPatch // sorted |
| 39 | label int |
| 40 | export bool |
| 41 | mod &Module = unsafe { nil } |
| 42 | code []u8 |
| 43 | locals []FunctionLocal |
| 44 | pub: |
| 45 | name string |
| 46 | pub mut: |
| 47 | export_name ?string |
| 48 | } |
| 49 | |
| 50 | // export_name sets the export name of the function to `name` |
| 51 | pub fn (mut func Function) export_name(name string) { |
| 52 | func.export_name = name |
| 53 | } |
| 54 | |