-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwasm_main.cpp
165 lines (115 loc) · 3.58 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "vcd_parser.h"
using namespace std;
/// Typedef used as part of c->js call
typedef void externalJsMethodZero(const char* name, const size_t len);
typedef void externalJsMethodOne (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 type, const int v0, const int v1);
/// function pointer for c->js
static externalJsMethodZero* externalZero = 0;
static externalJsMethodOne* externalOne = 0;
static externalJsSetProperty* bound_set_property = 0;
static externalJsGetProperty* bound_get_property = 0;
static struct vcd_parser_s* state;
extern "C" {
void set_property_int(const char* name, const int value) {
bound_set_property(name, strlen(name), 0, value, 0);
}
void set_property_string(const char* name, const char* value) {
bound_set_property(name, strlen(name), 1, (int)value, strlen(value));
}
void set_path_string(const char* name, const char* value) {
bound_set_property(name, strlen(name), 2, (int)value, strlen(value));
}
int get_property_int(const char* name) {
return bound_get_property(name, strlen(name));
}
void emit_lifee(const char* name) {
externalZero(name, strlen(name));
}
// returns context
int init(
externalJsMethodZero* f0,
externalJsMethodOne* f1,
externalJsSetProperty* sfn,
externalJsGetProperty* gfn
) {
state = (struct vcd_parser_s*) malloc(sizeof *state);
const int32_t error = vcd_parser_init(state);
if (error) {
cout << "ERROR: " << error << "\n";
return -1;
}
bound_set_property = sfn;
bound_get_property = gfn;
externalZero = f0;
externalOne = f1;
state->lifee = (void*) externalZero;
state->triee = (void*) externalOne;
static char triggerString [4096] = " ";
static char tmpStr [4096] = " ";
static uint64_t valueBuf [4096] = {};
static uint64_t maskBuf [4096] = {};
state->trigger = triggerString;
state->reason = "NO REASON";
state->napi_env = 0;
state->tmpStr = tmpStr;
state->value = valueBuf;
state->mask = maskBuf;
state->digitCount = 0;
set_property_string("status", "declaration");
static int context = 0;
context++;
return context;
}
int32_t execute(
const int context,
externalJsMethodZero* f0,
externalJsMethodOne* f1,
externalJsSetProperty* sfn,
externalJsGetProperty* gfn,
char* p
) {
// cout << "execute got " << p << "\n";
// cout << "execute " << (int)sfn << " and got " << p << "\n";
bound_set_property = sfn;
bound_get_property = gfn;
externalZero = f0;
externalOne = f1;
const size_t plen = strlen(p);
const int32_t error = vcd_parser_execute(state, p, p + plen);
return error;
}
int setTrigger(const int context, char* triggerString) {
cout << "setTrigger() got " << triggerString << "\n";
return 0;
}
int getTime(const int context) {
return state->time;
}
// void execute(
// const int context,
// externalJsMethodZero* f0,
// externalJsMethodOne* f1,
// 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;
// externalZero = f0;
// externalOne = f1;
// set_property_int("foo", 10);
// int got = get_property_int("bar");
// cout << "got " << got << " for bar\n";
// }
int main(void) {
cout << "main()\n";
return 0;
}
} // extern C