-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwasm_main.cpp
83 lines (53 loc) · 1.66 KB
/
wasm_main.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "vcd_parser.h"
using namespace std;
static struct vcd_parser_s* state;
// returns context
int init(void) {
state = (struct vcd_parser_s*) malloc(sizeof *state);
const int32_t error = vcd_parser_init(state);
if (error) {
cout << "ERROR: " << error << "\n";
return -1;
}
return 0;
}
int main(void) {
cout << "main()\n";
return 0;
}
/// Typedef used as part of c->js call
typedef void externalJsMethodOne(const int sz);
typedef void externalJsMethodTwo(const char*, const uint64_t time, const uint8_t command, const int dnc0, const int dnc1);
typedef int externalJsGetProperty(const char* name, const size_t len);
typedef void externalJsSetProperty(const char* name, const size_t len, const int value);
/// function pointer for c->js
static externalJsMethodOne* externalOne = 0;
static externalJsMethodTwo* externalTwo = 0;
static externalJsSetProperty* bound_set_property = 0;
static externalJsGetProperty* bound_get_property = 0;
static void set_property(const char* name, const int value) {
bound_set_property(name, strlen(name), value);
}
static int get_property(const char* name) {
return bound_get_property(name, strlen(name));
}
extern "C" {
void execute(
const int context,
externalJsMethodOne* f1,
externalJsMethodTwo* f2,
externalJsSetProperty* sfn,
externalJsGetProperty* gfn,
char* chunk
) {
// cout << "execute got " << p << "\n";
cout << "execute " << (int)sfn << " and got " << chunk << "\n";
bound_set_property = sfn;
bound_get_property = gfn;
int got = get_property("bar");
cout << "got " << got << " for bar\n";
}
} // extern C