-
Notifications
You must be signed in to change notification settings - Fork 0
/
mightstone.h
404 lines (317 loc) · 8.36 KB
/
mightstone.h
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#ifndef MST_H
#define MST_H
#include <vector>
#include <string>
#include <queue>
#include "hashtable.cpp"
using namespace std;
struct MST_Object;
typedef struct MST_Object MST_Object;
struct MST_Str;
typedef struct MST_Str MST_Str;
struct MST_SVLog;
typedef struct MST_SVLog MST_SVLog;
struct MST_Expr;
typedef struct MST_Expr MST_Expr;
struct MST_SVExpr;
typedef struct MST_SVExpr MST_SVExpr;
struct MST_ObjRef;
typedef struct MST_ObjRef MST_ObjRef;
struct MST_Lst;
typedef struct MST_Lst MST_Lst;
struct MST_Sym;
typedef struct MST_Sym MST_Sym;
struct MST_Trigger;
typedef struct MST_Trigger MST_Trigger;
struct MST_TrgTask;
typedef struct MST_TrgTask MST_TrgTask;
struct MST_Func;
typedef struct MST_Func MST_Func;
struct MST_Task;
typedef struct MST_Task MST_Task;
class MST_ClassDef;
class MST_TrgTask;
class MST_Env;
#define MST_DEF_DIM 16
#define MST_STRLEN 32
enum MST_ObjType {
MST_Value,
MST_Class,
MST_Expression,
MST_SVLogic,
MST_ObjectReference,
MST_SVExpression,
MST_String,
MST_Symbol,
MST_SymbolReference,
MST_List,
MST_Function,
nMST_Task,
MST_ExternalFunction,
MST_Error
};
struct MST_Object {
void* Ptr;
enum MST_ObjType Type;
};
struct MST_Str {
MST_Object Object;
int cLen;
int mLen;
char* Data;
};
enum MST_IOType {
MST_Internal,
MST_Input,
MST_Output,
MST_Inout
};
struct MST_SVLog {
MST_Object Object;
enum MST_IOType IO;
MST_Str* Name;
MST_Trigger* Triggers;
int Changed;
int Closed;
void* Reg;
void* Wire;
int nScope;
int ItemWidth;
int nDim;
int nItems[];
};
string AddIndent(string src, int n = 1);
MST_Object* SolveMST_Object(MST_Object* obj);
MST_SVExpr SVRefMST_Object(MST_Object* obj);
string SVDecMST_Object(MST_SVLog* obj);
int FreeMST_Object(MST_Object* obj);
MST_Object* CopyMST_Object(MST_Object* obj);
string MST_ToStr(MST_Object* obj);
MST_Str* AllocMST_Str(int l);
MST_Object* AllocMST_Val(int w);
MST_Object* AllocMST_Array(int w, vector<int> dim);
pair<MST_Object*, vector<int>> GetIndex_MSTObjRef(MST_ObjRef* ref);
int GetIntMST_Obj(MST_Object* obj);
struct MST_Val {
MST_Object Object;
string* ArrName;
int ItemWidth;
int nDim;
int nItems[];
};
struct MST_MemRef {
MST_Object* obj;
uint8_t* ptr;
int boff;
int wid;
};
enum MST_Operator {
MST_Set,
MST_Add,
MST_Sub,
MST_Mul,
MST_Div,
MST_Pow,
MST_BAnd,
MST_BOr,
MST_Xor,
MST_LAnd,
MST_LOr,
MST_BNot,
MST_LNot,
MST_Equal,
MST_NE,
MST_Greater,
MST_GE,
MST_Lesser,
MST_LE,
MST_ShiftL,
MST_ShiftR,
MST_Call,
MST_NewObj,
MST_NewPort,
MST_Bind,
MST_AddTrgTask,
MST_NewFunc,
MST_If,
MST_Progn,
MST_For,
MST_NewTask,
MST_GetInt,
MST_MCall
};
struct MST_Expr {
MST_Object Object;
enum MST_Operator Operator;
int nOperand;
MST_Object* Operands[];
};
MST_SVExpr SVCodeMST_Expr(MST_Expr* expr);
MST_SVExpr SVCodeMST_ExprIF(MST_Expr* expr);
MST_SVExpr SVCodeMST_ExprProgn(MST_Expr* expr);
MST_SVExpr SVCodeMST_Expr1(MST_Expr* expr);
MST_SVExpr SVCodeMST_Expr2(MST_Expr* expr);
MST_Expr* AllocMST_Expr(int n);
MST_Object* MST_Expr2(enum MST_Operator oprt, MST_Object* oprd1, MST_Object* oprd2);
int FreeMST_Expr(MST_Expr* expr);
MST_Object* MST_ObjExpr(MST_Expr* expr);
MST_Object* EvalMST_Expr(MST_Expr* expr, int sim);
int MSTOprt_1Arg(enum MST_Operator oprt, int oprd);
int MSTOprt_2Arg(enum MST_Operator oprt, int oprd1, int oprd2);
MST_MemRef MST_GetMemRef(MST_ObjRef* ref);
int MST_SetInt(MST_Object* obj, int n);
struct MST_SVExpr {
MST_Object Object;
string* Prev;
string* Ref;
};
struct MST_ObjRef {
MST_Object Object;
MST_Object* Width;
MST_Object* Index;
};
MST_ObjRef* AllocMST_ObjRef();
struct MST_Lst {
MST_Object Object;
int nItems;
int mItems;
MST_Object** Items;
};
MST_Lst* AllocMST_Lst(int n);
MST_Object* Push_MST_Lst(int nargs, MST_Object** args);
MST_Object* MST_ConvertListToArray(MST_Lst* lst);
MST_Object* MST_MakeArray(int nargs, MST_Object** args);
int MST_TransArglst(MST_Lst* dst, MST_Lst* src);
int MST_BindArgs(MST_Lst* arglst, int nargs, MST_Object** args);
struct MST_Func {
MST_Object Object;
MST_Str* Name;
MST_Lst* Args;
int nExpr;
MST_Expr* Expr[];
};
MST_Func* AllocMST_Func(int nargs, int nexpr);
MST_Object* CallMST_Func(MST_Func* func, int nargs, MST_Object** args);
struct MST_Task {
MST_Object Object;
MST_Str* Name;
MST_Lst* Args;
int nExpr;
MST_Expr* Expr[];
};
MST_Task* AllocMST_Task(int nargs, int nexpr);
MST_Object* SolveMST_Task(MST_Task* task, int nargs, MST_Object** args);
struct MST_ExFunc {
MST_Object Object;
MST_Str* Name;
MST_Object* (*pFunc)(int nargs, MST_Object** args);
};
MST_ExFunc* AllocMST_ExFunc();
struct MST_Sym {
MST_Object Object;
MST_Object* Val;
MST_Str* Name;
};
enum MST_Edge {
MST_atchange,
MST_posedge,
MST_negedge
};
struct MST_Trigger {
enum MST_Edge Edge;
MST_SVLog* Log;
MST_Trigger* LinkByLog;
MST_Trigger* LinkByTask;
MST_TrgTask* Task;
};
struct MST_TrgTask {
MST_Trigger* Trg;
int nExpr;
MST_Expr* Expr[];
};
MST_Trigger* AddTrgMST_TrgTask(MST_TrgTask* task, enum MST_Edge edge, MST_Object* obj);
MST_Trigger* AddTrgMST_TrgTask(MST_TrgTask* task, enum MST_Edge edge, MST_SVLog* obj);
int FreeMST_TrgTask(MST_TrgTask* task);
string SVCodeMST_TrgTask(MST_TrgTask* task);
int EvalMST_TrgTask(MST_TrgTask* task);
class MST_Scope {
private:
MST_Scope* Par;
HashTable<MST_Object*> Table;
public:
MST_Scope();
MST_Scope(MST_Scope* par);
~MST_Scope();
MST_Object* Get(MST_Str* str);
int Add(MST_Str* str, MST_Object* obj);
};
class MST_Env {
private:
vector<vector<MST_SVLog*>> Objects;
vector<MST_TrgTask*> TrgTasks;
vector<MST_SVLog*> Changes;
vector<HashTable<MST_Sym*>*> Tables;
vector<vector<MST_Sym*>> Symbols;
vector<vector<MST_Sym*>> SpecialSym;
vector<MST_Func*> Functions;
vector<MST_Task*> Tasks;
vector<MST_ExFunc*> ExFunctions;
HashTable<MST_Object*> SVNameTable;
vector<MST_Val*> Arrays;
int Error;
int Mode;
public:
MST_Env();
~MST_Env();
int AddScope();
int CloseScope();
MST_SVLog* AddObject(int ndim);
MST_TrgTask* AddTrgTask(int n);
MST_Func* AddFunction(MST_Object* name, int nargs, int nexpr);
MST_Task* AddTask(MST_Object* name, int nargs, int nexpr);
MST_ExFunc* AddExFunc(MST_Object* name, MST_Object* (*pfunc)(int nargs, MST_Object** args));
MST_ExFunc* AddExFunc(char* name, MST_Object* (*pfunc)(int nargs, MST_Object** args));
MST_ExFunc* AddExFunc(string name, MST_Object* (*pfunc)(int nargs, MST_Object** args));
int AllocObjects();
int NotifyChange(MST_SVLog* log);
int WaitTask();
int Bind(MST_Object* sym, MST_Object* obj);
MST_Sym* GetSym(MST_Object* sym);
MST_Object* GetSymVal(MST_Object* sym);
MST_Sym* AddSpecialSym(MST_Object* sym, MST_Object* val);
int DelSpecialSym();
int BindSVName(string name, MST_Object* obj);
int FindSVName(string name);
int AddArray(MST_Val* array);
int SetErrorFlag(int f);
int GetErrorFlag();
int SetMode(int m);
int GetMode();
string SVCode();
};
MST_SVLog* MST_AddObject(int ndim);
int MST_AllocObjects();
MST_TrgTask* AddTrgTask(int n);
int MST_NotifyChange(MST_SVLog* log);
int MST_WaitTask();
int MST_BindSym(MST_Object* sym, MST_Object* obj);
MST_Sym* MST_GetSym(MST_Object* sym);
MST_Object* MST_GetSymVal(MST_Object* sym);
MST_Func* AddMST_Function(MST_Object* name, int nargs, int nexpr);
MST_Task* AddMST_Task(MST_Object* name, int nargs, int nexpr);
MST_ExFunc* AddMST_ExFunc(MST_Object* name, MST_Object* (*pfunc)(int nargs, MST_Object** args));
MST_ExFunc* AddMST_ExFunc(char* name, MST_Object* (*pfunc)(int nargs, MST_Object** args));
MST_ExFunc* AddMST_ExFunc(string name, MST_Object* (*pfunc)(int nargs, MST_Object** args));
string MST_SVCode();
int MST_OpenScope();
int MST_CloseScope();
MST_Sym* MST_AddSpecialSym(MST_Object* sym, MST_Object* val);
int MST_DelSpecialSym();
int MST_BindSVName(string name, MST_Object* obj);
int MST_FindSVName(string name);
int MST_AddArray(MST_Val* array);
int MST_SetErrorFlag(int f);
int MST_GetErrorFlag();
int MST_SetMode(int m);
int MST_GetMode();
#endif