Skip to content

Commit 7d22cd4

Browse files
authored
Internal API for stateful Wasm operations (#233)
* Add store API * Move store API to separate file * πŸ› Fix store operation * 🎨 Clang format * Fix build * πŸ”¨ Add `Interpreter` class and `internals.h` * Add general load function to interpreter * Fix load instruction * Fix offset in load
1 parent 05bbfa8 commit 7d22cd4

File tree

16 files changed

+832
-456
lines changed

16 files changed

+832
-456
lines changed

β€ŽCMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if (BUILD_EMULATOR)
4545
src/WARDuino/CallbackHandler.cpp
4646
src/Primitives/emulated.cpp
4747
src/Interpreter/instructions.cpp
48+
src/Interpreter/interpreter.cpp
4849
src/Memory/mem.cpp
4950
src/Utils/util.cpp
5051
src/Utils/util_arduino.cpp
@@ -84,6 +85,7 @@ if (BUILD_UNITTEST)
8485
src/WARDuino/CallbackHandler.cpp
8586
src/Primitives/emulated.cpp
8687
src/Interpreter/instructions.cpp
88+
src/Interpreter/interpreter.cpp
8789
src/Memory/mem.cpp
8890
src/Utils/util.cpp
8991
src/Utils/util_arduino.cpp

β€Žplatforms/ESP-IDF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(SOURCE_FILES
22
../../src/Debug/debugger.cpp
33
../../src/Interpreter/instructions.cpp
4+
../../src/Interpreter/interpreter.cpp
45
../../src/Memory/mem.cpp
56
../../src/Primitives/idf.cpp
67
../../src/Edward/proxy.cpp

β€Žsrc/Debug/debugger.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../Memory/mem.h"
1313
#include "../Utils//util.h"
1414
#include "../Utils/macros.h"
15+
#include "../WARDuino/CallbackHandler.h"
1516

1617
// Debugger
1718

@@ -1211,6 +1212,8 @@ void Debugger::sendProxyCallResult(Module *m) {
12111212
this->proxy->returnResult(m);
12121213
}
12131214

1215+
bool Debugger::isProxy() const { return this->proxy != nullptr; }
1216+
12141217
bool Debugger::isProxied(uint32_t fidx) const {
12151218
return this->supervisor != nullptr && this->supervisor->isProxied(fidx);
12161219
}

β€Žsrc/Debug/debugger.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ struct Module;
1818
struct Block;
1919
struct StackValue;
2020

21+
enum operation {
22+
STORE = 0,
23+
LOAD = 1,
24+
};
25+
2126
enum RunningState {
2227
WARDUINOinit,
2328
WARDUINOrun,
@@ -80,7 +85,12 @@ enum InterruptTypes {
8085
interruptPOPEvent = 0x72,
8186
interruptPUSHEvent = 0x73,
8287
interruptDUMPCallbackmapping = 0x74,
83-
interruptRecvCallbackmapping = 0x75
88+
interruptRecvCallbackmapping = 0x75,
89+
90+
// Operations
91+
interruptStore = 0xa0,
92+
interruptStored = 0xa1,
93+
8494
};
8595

8696
class Debugger {
@@ -171,6 +181,8 @@ class Debugger {
171181

172182
static void updateCallbackmapping(Module *m, const char *interruptData);
173183

184+
bool operation(Module *m, operation op);
185+
174186
public:
175187
// Public fields
176188
std::mutex messageQueueMutex; // mutual exclude debugMessages
@@ -229,6 +241,8 @@ class Debugger {
229241

230242
void sendProxyCallResult(Module *m);
231243

244+
bool isProxy() const;
245+
232246
bool isProxied(uint32_t fidx) const;
233247

234248
void startProxySupervisor(Channel *socket);

β€Žsrc/Edward/proxy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void Proxy::pushRFC(Module *m, RFC *rfc) {
3939
}
4040

4141
// push function to callstack
42-
setup_call(m, rfc->fidx);
42+
m->warduino->interpreter->setup_call(m, rfc->fidx);
4343
// push proxy guard block to stack
4444
this->pushProxyGuard(m);
4545

@@ -115,5 +115,5 @@ void Proxy::pushProxyGuard(Module *m) {
115115
}
116116
auto *guard = (Block *)malloc(sizeof(struct Block));
117117
guard->block_type = 0xfe; // 0xfe proxy guard
118-
push_block(m, guard, m->sp);
118+
m->warduino->interpreter->push_block(m, guard, m->sp);
119119
}

β€Žsrc/Edward/proxy_supervisor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "../Utils/macros.h"
1717
#include "../Utils/util.h"
18+
#include "../WARDuino/CallbackHandler.h"
1819

1920
// TODO exception msg
2021
const char SUCCESS[] = ""; // Empty denotes success

0 commit comments

Comments
Β (0)