-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_wasm.h
88 lines (73 loc) · 1.62 KB
/
s_wasm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef __S_WASM_H__
#define __S_WASM_H__
#include <stdlib.h>
#include "wasm_types.h"
#define S_WASM_INDEX 0x88
#define VEC_DEFAULT_SIZE 0xA
typedef struct _vector vector_t;
typedef struct {
vector_t *parameters;
vector_t *results;
} functype_t;
typedef struct {
byte *name;
byte desc;
u32 idx;
} export_t;
typedef struct {
u32 size;
u32 num_i32_locals;
u32 num_i64_locals;
u32 num_f32_locals;
u32 num_f64_locals;
u32 num_funcref_locals;
u32 num_externref_locals;
u32 num_vec_locals;
instr_t *instr;
} code_t;
typedef struct {
byte type;
union {
u32 u_32;
/* more types NYI */
};
} valtype_t;
/*
* Vectors contain homogenous items. Every vector instance gets VEC_DEFAULT_SIZE bytes of storage, so
* we don't have to dynamically allocate storage as we parse vectors. The vector payload will point into
* __storage unless nelts > VEC_DEFAULT_SIZE, in which case we will malloc() the storage.
*/
struct _vector {
u32 nelts;
byte type;
union {
functype_t **pfuncs;
export_t **pexports;
code_t **pcodes;
u32 *pindices;
valtype_t *pvalues;
byte *pvaltypes;
};
void *__storage[VEC_DEFAULT_SIZE];
};
/*
* section = 1byte (type encoding) : u32 (length in bytes) : vec(<content>)
*/
typedef struct {
size_t offset;
size_t len;
byte type;
vector_t *v;
} section_t;
typedef struct {
unsigned int magic:1;
unsigned int version:1;
section_t *typesec;
section_t *funcsec;
section_t *exportssec;
section_t *codesec;
} module_t;
byte read_one_byte(FILE *fp);
void pretty_print_module(module_t *);
instr_t *read_instructions(FILE *fp);
#endif /* __S_WASM_H__ */