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
|
/*
* nanowasm, a tiny WebAssembly/Wasm interpreter
* Copyright (C) 2023-2024 Xavier Del Campo Romero
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef WASM_TYPES_H
#define WASM_TYPES_H
#include <nanowasm/nw.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
typedef bool varuint1;
typedef signed char varint7;
typedef unsigned char varuint7;
typedef unsigned long varuint32;
typedef long varint32;
typedef unsigned long long varuint64;
typedef long long varint64;
#define VALUE_TYPES \
X(VALUE_TYPE_I32) \
X(VALUE_TYPE_I64) \
X(VALUE_TYPE_F32) \
X(VALUE_TYPE_F64)
enum value_type
{
#define X(x) x,
VALUE_TYPES
#undef X
};
struct retval
{
bool returns;
enum value_type type;
};
struct nw_block
{
long pc;
struct nw_block *prev;
};
struct nw_locals
{
enum value_type type;
unsigned long n;
struct nw_locals *next;
};
struct nw_frame
{
struct retval retval;
struct nw_locals *locals;
struct nw_block *last_block;
struct nw_frame *prev, *next;
};
struct nw_gframe
{
enum value_type type;
bool mutable;
struct nw_gframe *next;
};
int varuint1_read(FILE *f, varuint1 *out);
int varint7_read(FILE *f, varint7 *out);
int varuint7_read(FILE *f, varuint7 *out);
int varuint32_read(FILE *f, varuint32 *out);
int varint32_read(FILE *f, varint32 *out);
int varuint64_read(FILE *f, varuint64 *out);
int varint64_read(FILE *f, varint64 *out);
int get_value_type(varint7 type, enum value_type *vtype);
size_t get_type_size(enum value_type type);
const char *value_type_tostr(enum value_type v);
int32_t htoni32(int32_t in);
int32_t ntohi32(int32_t in);
#endif
|