2
2
3
3
#ifndef WAC_H
4
4
#define WAC_H
5
+
5
6
#include < limits.h>
6
7
#include < stdbool.h>
7
8
#include < stdint.h>
@@ -49,9 +50,13 @@ typedef struct Type {
49
50
50
51
typedef union FuncPtr {
51
52
void (*void_void)();
53
+
52
54
void (*void_i32)(uint32_t );
55
+
53
56
void (*void_i64)(uint64_t );
57
+
54
58
void (*void_f32)(float );
59
+
55
60
void (*void_f64)(double );
56
61
57
62
double (*f64_f64)(double );
@@ -60,11 +65,11 @@ typedef union FuncPtr {
60
65
// A block or function
61
66
typedef struct Block {
62
67
uint8_t block_type; // 0x00: function, 0x01: init_exp
63
- // 0x02: block, 0x03: loop, 0x04: if
68
+ // 0x02: block, 0x03: loop, 0x04: if
64
69
uint32_t fidx; // function only (index)
65
70
Type *type; // params/results type
66
71
uint32_t local_count; // function only
67
- uint32_t *local_value_type; // types of locals (function only)
72
+ uint8_t *local_value_type; // types of locals (function only)
68
73
uint8_t *start_ptr;
69
74
uint8_t *end_ptr;
70
75
uint8_t *else_ptr; // if block only
@@ -128,7 +133,7 @@ typedef struct Options {
128
133
class WARDuino ; // predeclare for it work in the module decl
129
134
130
135
typedef struct Module {
131
- WARDuino* warduino;
136
+ WARDuino * warduino;
132
137
char *path; // file path of the wasm module
133
138
Options options; // Config options
134
139
@@ -142,8 +147,8 @@ typedef struct Module {
142
147
uint32_t function_count; // number of function (including imports)
143
148
Block *functions; // imported and locally defined functions
144
149
std::map<uint8_t *, Block *>
145
- block_lookup; // map of module byte position to Blocks
146
- // same length as byte_count
150
+ block_lookup; // map of module byte position to Blocks
151
+ // same length as byte_count
147
152
uint32_t start_function; // function to run on module load
148
153
Table table;
149
154
Memory memory;
@@ -160,17 +165,20 @@ typedef struct Module {
160
165
} Module;
161
166
162
167
typedef void (*Primitive)(Module *);
168
+
163
169
typedef struct PrimitiveEntry {
164
170
const char *name;
165
171
Primitive f;
166
172
Type t;
167
173
} PrimitiveEntry;
168
174
169
175
170
- enum RunningState { WARDUINOrun, WARDUINOpause, WARDUINOstep };
176
+ enum RunningState {
177
+ WARDUINOrun, WARDUINOpause, WARDUINOstep
178
+ };
171
179
172
180
class WARDuino {
173
- private:
181
+ private:
174
182
std::vector<Module *> modules = {};
175
183
std::deque<uint8_t *> parsedInterrups = {};
176
184
@@ -184,26 +192,35 @@ class WARDuino {
184
192
std::vector<uint8_t > interruptBuffer;
185
193
long interruptSize;
186
194
187
- public:
195
+ public:
188
196
189
197
// vector, we expect few breakpoints
190
198
std::set<uint8_t *> breakpoints = {};
191
199
192
200
WARDuino ();
193
- int run_module (Module* m);
201
+
202
+ int run_module (Module *m);
203
+
194
204
Module *load_module (uint8_t *bytes, uint32_t byte_count, Options options);
195
- void unload_module (Module* m);
205
+
206
+ void unload_module (Module *m);
207
+
196
208
bool invoke (Module *m, uint32_t fidx);
209
+
197
210
uint32_t get_export_fidx (Module *m, const char *name);
211
+
198
212
void handleInterrupt (size_t len, uint8_t *buff);
199
213
200
214
// breakpoints
201
- void addBreakpoint (uint8_t * loc);
202
- void delBreakpoint (uint8_t * loc);
203
- bool isBreakpoint (uint8_t * loc);
204
-
215
+ void addBreakpoint (uint8_t *loc);
216
+
217
+ void delBreakpoint (uint8_t *loc);
218
+
219
+ bool isBreakpoint (uint8_t *loc);
220
+
205
221
// Get interrupt or NULL if none
206
- uint8_t * getInterrupt ();
222
+ uint8_t * getInterrupt ();
207
223
208
224
};
225
+
209
226
#endif
0 commit comments