To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

zebu.py 84.2 KB
Newer Older
John Zhang's avatar
John Zhang committed
1
2
3
4
5
6
7
8
9
10
11
"""
Mu API RPython binding.
This file is auto-generated and then added a few minor modifications.
Note: environment variable $MU needs to be defined to point to the reference implementation!
"""

from rpython.rtyper.lltypesystem import rffi
from rpython.rtyper.lltypesystem import lltype
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rlib.objectmodel import specialize
import os
12
13
14
from rpython.tool.ansi_print import AnsiLogger

logger = AnsiLogger('ZebuPyAPI')
John Zhang's avatar
John Zhang committed
15

16
zebu_build = os.environ.get('ZEBU_BUILD', 'release')
17
libmu_dir = os.path.join(os.getenv('MU_ZEBU'), 'target', zebu_build)
John Zhang's avatar
John Zhang committed
18
19
eci = ExternalCompilationInfo(libraries=['mu'],
                              library_dirs=[libmu_dir])
John Zhang's avatar
John Zhang committed
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

# -------------------------------------------------------------------------------------------------------
# Type definitions
MuValue = rffi.VOIDP
MuValuePtr = rffi.CArrayPtr(MuValue)
MuSeqValue = MuValue
MuSeqValuePtr = rffi.CArrayPtr(MuSeqValue)
MuGenRefValue = MuValue
MuGenRefValuePtr = rffi.CArrayPtr(MuGenRefValue)
MuIntValue = MuValue
MuIntValuePtr = rffi.CArrayPtr(MuIntValue)
MuFloatValue = MuValue
MuFloatValuePtr = rffi.CArrayPtr(MuFloatValue)
MuDoubleValue = MuValue
MuDoubleValuePtr = rffi.CArrayPtr(MuDoubleValue)
MuUPtrValue = MuValue
MuUPtrValuePtr = rffi.CArrayPtr(MuUPtrValue)
MuUFPValue = MuValue
MuUFPValuePtr = rffi.CArrayPtr(MuUFPValue)
MuStructValue = MuValue
MuStructValuePtr = rffi.CArrayPtr(MuStructValue)
MuArrayValue = MuSeqValue
MuArrayValuePtr = rffi.CArrayPtr(MuArrayValue)
MuVectorValue = MuSeqValue
MuVectorValuePtr = rffi.CArrayPtr(MuVectorValue)
MuRefValue = MuGenRefValue
MuRefValuePtr = rffi.CArrayPtr(MuRefValue)
MuIRefValue = MuGenRefValue
MuIRefValuePtr = rffi.CArrayPtr(MuIRefValue)
MuTagRef64Value = MuGenRefValue
MuTagRef64ValuePtr = rffi.CArrayPtr(MuTagRef64Value)
MuFuncRefValue = MuGenRefValue
MuFuncRefValuePtr = rffi.CArrayPtr(MuFuncRefValue)
MuThreadRefValue = MuGenRefValue
MuThreadRefValuePtr = rffi.CArrayPtr(MuThreadRefValue)
MuStackRefValue = MuGenRefValue
MuStackRefValuePtr = rffi.CArrayPtr(MuStackRefValue)
MuFCRefValue = MuGenRefValue
MuFCRefValuePtr = rffi.CArrayPtr(MuFCRefValue)
MuIBRefValue = MuGenRefValue
MuIBRefValuePtr = rffi.CArrayPtr(MuIBRefValue)
MuCString = rffi.CCHARP
MuCStringPtr = rffi.CArrayPtr(MuCString)
MuID = rffi.UINT
MuIDPtr = rffi.CArrayPtr(MuID)
MuName = MuCString
MuNamePtr = rffi.CArrayPtr(MuName)
MuCPtr = rffi.VOIDP
MuCPtrPtr = rffi.CArrayPtr(MuCPtr)
MuCFP = rffi.VOIDP
MuCFPPtr = rffi.CArrayPtr(MuCFP)
MuBool = rffi.INT
MuBoolPtr = rffi.CArrayPtr(MuBool)
MuArraySize = rffi.UINTPTR_T
MuArraySizePtr = rffi.CArrayPtr(MuArraySize)
MuWPID = rffi.UINT
MuWPIDPtr = rffi.CArrayPtr(MuWPID)
MuFlag = rffi.UINT
MuFlagPtr = rffi.CArrayPtr(MuFlag)
MuTrapHandlerResult = MuFlag
MuTrapHandlerResultPtr = rffi.CArrayPtr(MuTrapHandlerResult)
MuBinOpStatus = MuFlag
MuBinOpStatusPtr = rffi.CArrayPtr(MuBinOpStatus)
MuTypeNode = MuID
MuTypeNodePtr = rffi.CArrayPtr(MuTypeNode)
MuFuncSigNode = MuID
MuFuncSigNodePtr = rffi.CArrayPtr(MuFuncSigNode)
MuVarNode = MuID
MuVarNodePtr = rffi.CArrayPtr(MuVarNode)
MuGlobalVarNode = MuID
MuGlobalVarNodePtr = rffi.CArrayPtr(MuGlobalVarNode)
MuLocalVarNode = MuID
MuLocalVarNodePtr = rffi.CArrayPtr(MuLocalVarNode)
MuConstNode = MuID
MuConstNodePtr = rffi.CArrayPtr(MuConstNode)
MuFuncNode = MuID
MuFuncNodePtr = rffi.CArrayPtr(MuFuncNode)
MuFuncVerNode = MuID
MuFuncVerNodePtr = rffi.CArrayPtr(MuFuncVerNode)
MuBBNode = MuID
MuBBNodePtr = rffi.CArrayPtr(MuBBNode)
MuInstNode = MuID
MuInstNodePtr = rffi.CArrayPtr(MuInstNode)
MuDestClause = MuID
MuDestClausePtr = rffi.CArrayPtr(MuDestClause)
MuExcClause = MuID
MuExcClausePtr = rffi.CArrayPtr(MuExcClause)
MuKeepaliveClause = MuID
MuKeepaliveClausePtr = rffi.CArrayPtr(MuKeepaliveClause)
MuCurStackClause = MuID
MuCurStackClausePtr = rffi.CArrayPtr(MuCurStackClause)
MuNewStackClause = MuID
MuNewStackClausePtr = rffi.CArrayPtr(MuNewStackClause)
_MuVM = lltype.ForwardReference()
_MuVMPtr = lltype.Ptr(_MuVM)
_MuCtx = lltype.ForwardReference()
_MuCtxPtr = lltype.Ptr(_MuCtx)
_MuIRBuilder = lltype.ForwardReference()
_MuIRBuilderPtr = lltype.Ptr(_MuIRBuilder)
MuValuesFreer = rffi.CCallback([MuValuePtr, MuCPtr], lltype.Void)
MuValuesFreerPtr = rffi.CArrayPtr(MuValuesFreer)
MuTrapHandler = rffi.CCallback([
122
123
124
125
126
    _MuCtxPtr, MuThreadRefValue, MuStackRefValue, MuWPID,  # input
    MuTrapHandlerResultPtr, MuStackRefValuePtr, rffi.CArray(
        MuValuePtr), MuArraySizePtr,
    MuValuesFreerPtr, MuCPtrPtr, MuRefValuePtr,  # output
    MuCPtr  # input
John Zhang's avatar
John Zhang committed
127
128
], lltype.Void)
MuTrapHandlerPtr = rffi.CArrayPtr(MuTrapHandler)
129
130
131
132
133
# rtmu-specific
MuAttrPtr = MuValue
MuFutexPtr = MuValue
MuTimerPtr = MuValue
MuRegionPtr = MuValue
John Zhang's avatar
John Zhang committed
134
135
136

# -------------------------------------------------------------------------------------------------------
# Flags
137
138


John Zhang's avatar
John Zhang committed
139
140
141
142
class MuTrapHandlerResult:
    THREAD_EXIT = rffi.cast(MuFlag, 0x00)
    REBIND_PASS_VALUES = rffi.cast(MuFlag, 0x01)
    REBIND_THROW_EXC = rffi.cast(MuFlag, 0x02)
143
144


John Zhang's avatar
John Zhang committed
145
146
147
148
149
class MuBinOpStatus:
    N = rffi.cast(MuFlag, 0x01)
    Z = rffi.cast(MuFlag, 0x02)
    C = rffi.cast(MuFlag, 0x04)
    V = rffi.cast(MuFlag, 0x08)
150
151


John Zhang's avatar
John Zhang committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
class MuBinOptr:
    ADD = rffi.cast(MuFlag, 0x01)
    SUB = rffi.cast(MuFlag, 0x02)
    MUL = rffi.cast(MuFlag, 0x03)
    SDIV = rffi.cast(MuFlag, 0x04)
    SREM = rffi.cast(MuFlag, 0x05)
    UDIV = rffi.cast(MuFlag, 0x06)
    UREM = rffi.cast(MuFlag, 0x07)
    SHL = rffi.cast(MuFlag, 0x08)
    LSHR = rffi.cast(MuFlag, 0x09)
    ASHR = rffi.cast(MuFlag, 0x0A)
    AND = rffi.cast(MuFlag, 0x0B)
    OR = rffi.cast(MuFlag, 0x0C)
    XOR = rffi.cast(MuFlag, 0x0D)
    FADD = rffi.cast(MuFlag, 0xB0)
    FSUB = rffi.cast(MuFlag, 0xB1)
    FMUL = rffi.cast(MuFlag, 0xB2)
    FDIV = rffi.cast(MuFlag, 0xB3)
    FREM = rffi.cast(MuFlag, 0xB4)
171
172


John Zhang's avatar
John Zhang committed
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
class MuCmpOptr:
    EQ = rffi.cast(MuFlag, 0x20)
    NE = rffi.cast(MuFlag, 0x21)
    SGE = rffi.cast(MuFlag, 0x22)
    SGT = rffi.cast(MuFlag, 0x23)
    SLE = rffi.cast(MuFlag, 0x24)
    SLT = rffi.cast(MuFlag, 0x25)
    UGE = rffi.cast(MuFlag, 0x26)
    UGT = rffi.cast(MuFlag, 0x27)
    ULE = rffi.cast(MuFlag, 0x28)
    ULT = rffi.cast(MuFlag, 0x29)
    FFALSE = rffi.cast(MuFlag, 0xC0)
    FTRUE = rffi.cast(MuFlag, 0xC1)
    FUNO = rffi.cast(MuFlag, 0xC2)
    FUEQ = rffi.cast(MuFlag, 0xC3)
    FUNE = rffi.cast(MuFlag, 0xC4)
    FUGT = rffi.cast(MuFlag, 0xC5)
    FUGE = rffi.cast(MuFlag, 0xC6)
    FULT = rffi.cast(MuFlag, 0xC7)
    FULE = rffi.cast(MuFlag, 0xC8)
    FORD = rffi.cast(MuFlag, 0xC9)
    FOEQ = rffi.cast(MuFlag, 0xCA)
    FONE = rffi.cast(MuFlag, 0xCB)
    FOGT = rffi.cast(MuFlag, 0xCC)
    FOGE = rffi.cast(MuFlag, 0xCD)
    FOLT = rffi.cast(MuFlag, 0xCE)
    FOLE = rffi.cast(MuFlag, 0xCF)
200
201


John Zhang's avatar
John Zhang committed
202
203
204
205
206
207
208
209
210
211
212
213
214
class MuConvOptr:
    TRUNC = rffi.cast(MuFlag, 0x30)
    ZEXT = rffi.cast(MuFlag, 0x31)
    SEXT = rffi.cast(MuFlag, 0x32)
    FPTRUNC = rffi.cast(MuFlag, 0x33)
    FPEXT = rffi.cast(MuFlag, 0x34)
    FPTOUI = rffi.cast(MuFlag, 0x35)
    FPTOSI = rffi.cast(MuFlag, 0x36)
    UITOFP = rffi.cast(MuFlag, 0x37)
    SITOFP = rffi.cast(MuFlag, 0x38)
    BITCAST = rffi.cast(MuFlag, 0x39)
    REFCAST = rffi.cast(MuFlag, 0x3A)
    PTRCAST = rffi.cast(MuFlag, 0x3B)
215
216


John Zhang's avatar
John Zhang committed
217
218
219
220
221
222
223
224
class MuMemOrd:
    NOT_ATOMIC = rffi.cast(MuFlag, 0x00)
    RELAXED = rffi.cast(MuFlag, 0x01)
    CONSUME = rffi.cast(MuFlag, 0x02)
    ACQUIRE = rffi.cast(MuFlag, 0x03)
    RELEASE = rffi.cast(MuFlag, 0x04)
    ACQ_REL = rffi.cast(MuFlag, 0x05)
    SEQ_CST = rffi.cast(MuFlag, 0x06)
225
226


John Zhang's avatar
John Zhang committed
227
228
229
230
231
232
233
234
235
236
237
238
class MuAtomicRMWOptr:
    XCHG = rffi.cast(MuFlag, 0x00)
    ADD = rffi.cast(MuFlag, 0x01)
    SUB = rffi.cast(MuFlag, 0x02)
    AND = rffi.cast(MuFlag, 0x03)
    NAND = rffi.cast(MuFlag, 0x04)
    OR = rffi.cast(MuFlag, 0x05)
    XOR = rffi.cast(MuFlag, 0x06)
    MAX = rffi.cast(MuFlag, 0x07)
    MIN = rffi.cast(MuFlag, 0x08)
    UMAX = rffi.cast(MuFlag, 0x09)
    UMIN = rffi.cast(MuFlag, 0x0A)
239
240


John Zhang's avatar
John Zhang committed
241
242
class MuCallConv:
    DEFAULT = rffi.cast(MuFlag, 0x00)
243
244


John Zhang's avatar
John Zhang committed
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
class MuCommInst:
    NEW_STACK = rffi.cast(MuFlag, 0x201)
    KILL_STACK = rffi.cast(MuFlag, 0x202)
    THREAD_EXIT = rffi.cast(MuFlag, 0x203)
    CURRENT_STACK = rffi.cast(MuFlag, 0x204)
    SET_THREADLOCAL = rffi.cast(MuFlag, 0x205)
    GET_THREADLOCAL = rffi.cast(MuFlag, 0x206)
    TR64_IS_FP = rffi.cast(MuFlag, 0x211)
    TR64_IS_INT = rffi.cast(MuFlag, 0x212)
    TR64_IS_REF = rffi.cast(MuFlag, 0x213)
    TR64_FROM_FP = rffi.cast(MuFlag, 0x214)
    TR64_FROM_INT = rffi.cast(MuFlag, 0x215)
    TR64_FROM_REF = rffi.cast(MuFlag, 0x216)
    TR64_TO_FP = rffi.cast(MuFlag, 0x217)
    TR64_TO_INT = rffi.cast(MuFlag, 0x218)
    TR64_TO_REF = rffi.cast(MuFlag, 0x219)
    TR64_TO_TAG = rffi.cast(MuFlag, 0x21a)
    FUTEX_WAIT = rffi.cast(MuFlag, 0x220)
    FUTEX_WAIT_TIMEOUT = rffi.cast(MuFlag, 0x221)
    FUTEX_WAKE = rffi.cast(MuFlag, 0x222)
    FUTEX_CMP_REQUEUE = rffi.cast(MuFlag, 0x223)
    KILL_DEPENDENCY = rffi.cast(MuFlag, 0x230)
    NATIVE_PIN = rffi.cast(MuFlag, 0x240)
    NATIVE_UNPIN = rffi.cast(MuFlag, 0x241)
    NATIVE_GET_ADDR = rffi.cast(MuFlag, 0x242)
    NATIVE_EXPOSE = rffi.cast(MuFlag, 0x243)
    NATIVE_UNEXPOSE = rffi.cast(MuFlag, 0x244)
    NATIVE_GET_COOKIE = rffi.cast(MuFlag, 0x245)
    META_ID_OF = rffi.cast(MuFlag, 0x250)
    META_NAME_OF = rffi.cast(MuFlag, 0x251)
    META_LOAD_BUNDLE = rffi.cast(MuFlag, 0x252)
    META_LOAD_HAIL = rffi.cast(MuFlag, 0x253)
    META_NEW_CURSOR = rffi.cast(MuFlag, 0x254)
    META_NEXT_FRAME = rffi.cast(MuFlag, 0x255)
    META_COPY_CURSOR = rffi.cast(MuFlag, 0x256)
    META_CLOSE_CURSOR = rffi.cast(MuFlag, 0x257)
    META_CUR_FUNC = rffi.cast(MuFlag, 0x258)
    META_CUR_FUNC_VER = rffi.cast(MuFlag, 0x259)
    META_CUR_INST = rffi.cast(MuFlag, 0x25a)
    META_DUMP_KEEPALIVES = rffi.cast(MuFlag, 0x25b)
    META_POP_FRAMES_TO = rffi.cast(MuFlag, 0x25c)
    META_PUSH_FRAME = rffi.cast(MuFlag, 0x25d)
    META_ENABLE_WATCHPOINT = rffi.cast(MuFlag, 0x25e)
    META_DISABLE_WATCHPOINT = rffi.cast(MuFlag, 0x25f)
    META_SET_TRAP_HANDLER = rffi.cast(MuFlag, 0x260)
    IRBUILDER_NEW_IR_BUILDER = rffi.cast(MuFlag, 0x270)
    IRBUILDER_LOAD = rffi.cast(MuFlag, 0x300)
    IRBUILDER_ABORT = rffi.cast(MuFlag, 0x301)
    IRBUILDER_GEN_SYM = rffi.cast(MuFlag, 0x302)
    IRBUILDER_NEW_TYPE_INT = rffi.cast(MuFlag, 0x303)
    IRBUILDER_NEW_TYPE_FLOAT = rffi.cast(MuFlag, 0x304)
    IRBUILDER_NEW_TYPE_DOUBLE = rffi.cast(MuFlag, 0x305)
    IRBUILDER_NEW_TYPE_UPTR = rffi.cast(MuFlag, 0x306)
    IRBUILDER_NEW_TYPE_UFUNCPTR = rffi.cast(MuFlag, 0x307)
    IRBUILDER_NEW_TYPE_STRUCT = rffi.cast(MuFlag, 0x308)
    IRBUILDER_NEW_TYPE_HYBRID = rffi.cast(MuFlag, 0x309)
    IRBUILDER_NEW_TYPE_ARRAY = rffi.cast(MuFlag, 0x30a)
    IRBUILDER_NEW_TYPE_VECTOR = rffi.cast(MuFlag, 0x30b)
    IRBUILDER_NEW_TYPE_VOID = rffi.cast(MuFlag, 0x30c)
    IRBUILDER_NEW_TYPE_REF = rffi.cast(MuFlag, 0x30d)
    IRBUILDER_NEW_TYPE_IREF = rffi.cast(MuFlag, 0x30e)
    IRBUILDER_NEW_TYPE_WEAKREF = rffi.cast(MuFlag, 0x30f)
    IRBUILDER_NEW_TYPE_FUNCREF = rffi.cast(MuFlag, 0x310)
    IRBUILDER_NEW_TYPE_TAGREF64 = rffi.cast(MuFlag, 0x311)
    IRBUILDER_NEW_TYPE_THREADREF = rffi.cast(MuFlag, 0x312)
    IRBUILDER_NEW_TYPE_STACKREF = rffi.cast(MuFlag, 0x313)
    IRBUILDER_NEW_TYPE_FRAMECURSORREF = rffi.cast(MuFlag, 0x314)
    IRBUILDER_NEW_TYPE_IRBUILDERREF = rffi.cast(MuFlag, 0x315)
    IRBUILDER_NEW_FUNCSIG = rffi.cast(MuFlag, 0x316)
    IRBUILDER_NEW_CONST_INT = rffi.cast(MuFlag, 0x317)
    IRBUILDER_NEW_CONST_INT_EX = rffi.cast(MuFlag, 0x318)
    IRBUILDER_NEW_CONST_FLOAT = rffi.cast(MuFlag, 0x319)
    IRBUILDER_NEW_CONST_DOUBLE = rffi.cast(MuFlag, 0x31a)
    IRBUILDER_NEW_CONST_NULL = rffi.cast(MuFlag, 0x31b)
    IRBUILDER_NEW_CONST_SEQ = rffi.cast(MuFlag, 0x31c)
    IRBUILDER_NEW_CONST_EXTERN = rffi.cast(MuFlag, 0x31d)
    IRBUILDER_NEW_GLOBAL_CELL = rffi.cast(MuFlag, 0x31e)
    IRBUILDER_NEW_FUNC = rffi.cast(MuFlag, 0x31f)
    IRBUILDER_NEW_EXP_FUNC = rffi.cast(MuFlag, 0x320)
    IRBUILDER_NEW_FUNC_VER = rffi.cast(MuFlag, 0x321)
    IRBUILDER_NEW_BB = rffi.cast(MuFlag, 0x322)
    IRBUILDER_NEW_DEST_CLAUSE = rffi.cast(MuFlag, 0x323)
    IRBUILDER_NEW_EXC_CLAUSE = rffi.cast(MuFlag, 0x324)
    IRBUILDER_NEW_KEEPALIVE_CLAUSE = rffi.cast(MuFlag, 0x325)
    IRBUILDER_NEW_CSC_RET_WITH = rffi.cast(MuFlag, 0x326)
    IRBUILDER_NEW_CSC_KILL_OLD = rffi.cast(MuFlag, 0x327)
    IRBUILDER_NEW_NSC_PASS_VALUES = rffi.cast(MuFlag, 0x328)
    IRBUILDER_NEW_NSC_THROW_EXC = rffi.cast(MuFlag, 0x329)
    IRBUILDER_NEW_BINOP = rffi.cast(MuFlag, 0x32a)
    IRBUILDER_NEW_BINOP_WITH_STATUS = rffi.cast(MuFlag, 0x32b)
    IRBUILDER_NEW_CMP = rffi.cast(MuFlag, 0x32c)
    IRBUILDER_NEW_CONV = rffi.cast(MuFlag, 0x32d)
    IRBUILDER_NEW_SELECT = rffi.cast(MuFlag, 0x32e)
    IRBUILDER_NEW_BRANCH = rffi.cast(MuFlag, 0x32f)
    IRBUILDER_NEW_BRANCH2 = rffi.cast(MuFlag, 0x330)
    IRBUILDER_NEW_SWITCH = rffi.cast(MuFlag, 0x331)
    IRBUILDER_NEW_CALL = rffi.cast(MuFlag, 0x332)
    IRBUILDER_NEW_TAILCALL = rffi.cast(MuFlag, 0x333)
    IRBUILDER_NEW_RET = rffi.cast(MuFlag, 0x334)
    IRBUILDER_NEW_THROW = rffi.cast(MuFlag, 0x335)
    IRBUILDER_NEW_EXTRACTVALUE = rffi.cast(MuFlag, 0x336)
    IRBUILDER_NEW_INSERTVALUE = rffi.cast(MuFlag, 0x337)
    IRBUILDER_NEW_EXTRACTELEMENT = rffi.cast(MuFlag, 0x338)
    IRBUILDER_NEW_INSERTELEMENT = rffi.cast(MuFlag, 0x339)
    IRBUILDER_NEW_SHUFFLEVECTOR = rffi.cast(MuFlag, 0x33a)
    IRBUILDER_NEW_NEW = rffi.cast(MuFlag, 0x33b)
    IRBUILDER_NEW_NEWHYBRID = rffi.cast(MuFlag, 0x33c)
    IRBUILDER_NEW_ALLOCA = rffi.cast(MuFlag, 0x33d)
    IRBUILDER_NEW_ALLOCAHYBRID = rffi.cast(MuFlag, 0x33e)
    IRBUILDER_NEW_GETIREF = rffi.cast(MuFlag, 0x33f)
    IRBUILDER_NEW_GETFIELDIREF = rffi.cast(MuFlag, 0x340)
    IRBUILDER_NEW_GETELEMIREF = rffi.cast(MuFlag, 0x341)
    IRBUILDER_NEW_SHIFTIREF = rffi.cast(MuFlag, 0x342)
    IRBUILDER_NEW_GETVARPARTIREF = rffi.cast(MuFlag, 0x343)
    IRBUILDER_NEW_LOAD = rffi.cast(MuFlag, 0x344)
    IRBUILDER_NEW_STORE = rffi.cast(MuFlag, 0x345)
    IRBUILDER_NEW_CMPXCHG = rffi.cast(MuFlag, 0x346)
    IRBUILDER_NEW_ATOMICRMW = rffi.cast(MuFlag, 0x347)
    IRBUILDER_NEW_FENCE = rffi.cast(MuFlag, 0x348)
    IRBUILDER_NEW_TRAP = rffi.cast(MuFlag, 0x349)
    IRBUILDER_NEW_WATCHPOINT = rffi.cast(MuFlag, 0x34a)
    IRBUILDER_NEW_WPBRANCH = rffi.cast(MuFlag, 0x34b)
    IRBUILDER_NEW_CCALL = rffi.cast(MuFlag, 0x34c)
    IRBUILDER_NEW_NEWTHREAD = rffi.cast(MuFlag, 0x34d)
    IRBUILDER_NEW_SWAPSTACK = rffi.cast(MuFlag, 0x34e)
    IRBUILDER_NEW_COMMINST = rffi.cast(MuFlag, 0x34f)
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
    IRBUILDER_EMM_EALLOCPA = rffi.cast(MuFlag, 0x400)
    IRBUILDER_EMM_EALLOCHYBRIDPA = rffi.cast(MuFlag, 0x401)
    IRBUILDER_EMM_BINDOBJECT = rffi.cast(MuFlag, 0x402)
    IRBUILDER_EMM_UNBINDOBJECT = rffi.cast(MuFlag, 0x403)
    IRBUILDER_REGIONS_NEWREGIONPA = rffi.cast(MuFlag, 0x408)
    IRBUILDER_REGIONS_BINDREGION = rffi.cast(MuFlag, 0x409)
    IRBUILDER_REGIONS_UNBINDREGION = rffi.cast(MuFlag, 0x40a)
    IRBUILDER_SCHED_FIFO = rffi.cast(MuFlag, 0x410)
    IRBUILDER_SCHED_RM = rffi.cast(MuFlag, 0x411)
    IRBUILDER_SCHED_EDF = rffi.cast(MuFlag, 0x412)
    IRBUILDER_THREAD_SETPRIORITY = rffi.cast(MuFlag, 0x418)
    IRBUILDER_THREAD_GETPRIORITY = rffi.cast(MuFlag, 0x419)
    IRBUILDER_THREAD_SETCPU = rffi.cast(MuFlag, 0x41a)
    IRBUILDER_THREAD_CLEARCPU = rffi.cast(MuFlag, 0x41b)
    IRBUILDER_THREAD_ISSETCPU = rffi.cast(MuFlag, 0x41c)
    IRBUILDER_THREAD_SETDEADLINE = rffi.cast(MuFlag, 0x41d)
    IRBUILDER_THREAD_GETDEADLINE = rffi.cast(MuFlag, 0x41e)
    IRBUILDER_ATTR_SETPRIORITY = rffi.cast(MuFlag, 0x428)
    IRBUILDER_ATTR_GETPRIORITY = rffi.cast(MuFlag, 0x429)
    IRBUILDER_ATTR_SETCPU = rffi.cast(MuFlag, 0x42a)
    IRBUILDER_ATTR_CLEARCPU = rffi.cast(MuFlag, 0x42b)
    IRBUILDER_ATTR_ISSETCPU = rffi.cast(MuFlag, 0x42c)
    IRBUILDER_ATTR_ZEROCPU = rffi.cast(MuFlag, 0x42d)
    IRBUILDER_ATTR_SETDEADLINE = rffi.cast(MuFlag, 0x42e)
    IRBUILDER_ATTR_GETDEADLINE = rffi.cast(MuFlag, 0x42f)
    IRBUILDER_PIFUTEX_WAIT = rffi.cast(MuFlag, 0x438)
    IRBUILDER_PIFUTEX_WAIT_TIMEOUT = rffi.cast(MuFlag, 0x439)
    IRBUILDER_PIFUTEX_WAKE = rffi.cast(MuFlag, 0x43a)
    IRBUILDER_NEW_TYPE_REGIONREF = rffi.cast(MuFlag, 0x440)
    IRBUILDER_NEW_TYPE_ATTRREF = rffi.cast(MuFlag, 0x441)
    IRBUILDER_NEW_TYPE_FUTEXREF = rffi.cast(MuFlag, 0x442)
    IRBUILDER_NEW_TYPE_TIMERREF = rffi.cast(MuFlag, 0x443F)

John Zhang's avatar
John Zhang committed
404
405
406

MU_NO_ID = rffi.cast(MuID, 0)

407

John Zhang's avatar
John Zhang committed
408
409
# -------------------------------------------------------------------------------------------------------
# OO wrappers
410
411


John Zhang's avatar
John Zhang committed
412
413
class MuVM:
    def __init__(self, config_str=""):
John Zhang's avatar
John Zhang committed
414
415
        with rffi.scoped_str2charp('init_mu ' + config_str) as buf:
            self._mu = mu_fastimpl_new_with_opts(buf)
John Zhang's avatar
John Zhang committed
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436

    def new_context(self):
        # type: () -> MuCtx
        res = MuCtx(self, self._mu.c_new_context(self._mu))
        return res

    def id_of(self, name):
        # type: (str) -> MuID
        with rffi.scoped_str2charp(name) as name_buf:
            res = self._mu.c_id_of(self._mu, name_buf)
            return res

    def name_of(self, id):
        # type: (MuID) -> str
        res = rffi.charp2str(self._mu.c_name_of(self._mu, id))
        return res

    def set_trap_handler(self, trap_handler, userdata):
        # type: (MuTrapHandler, MuCPtr) -> None
        self._mu.c_set_trap_handler(self._mu, trap_handler, userdata)

John Zhang's avatar
John Zhang committed
437
438
439
440
    def compile_to_sharedlib(self, lib_name, extra_srcs):
        # type: (str, [MuCString]) -> None
        with rffi.scoped_str2charp(lib_name) as lib_name_buf:
            extra_srcs_arr, extra_srcs_sz = lst2arr(MuCString, extra_srcs)
441
442
            self._mu.c_compile_to_sharedlib(
                self._mu, lib_name_buf, extra_srcs_arr, extra_srcs_sz)
John Zhang's avatar
John Zhang committed
443
444
            if extra_srcs_arr:
                rffi.free_charpp(extra_srcs_arr)
John Zhang's avatar
John Zhang committed
445

446
447
448
449
450
451
452
453
454
    # def compile_to_executable(self, entry_func, exec_name, extra_srcs):
    #     # type: (str, [MuCString]) -> None
    #     with rffi.scoped_str2charp(lib_name) as lib_name_buf:
    #         extra_srcs_arr, extra_srcs_sz = lst2arr(MuCString, extra_srcs)
    #         self._mu.c_compile_to_sharedlib(
    #             self._mu, lib_name_buf, extra_srcs_arr, extra_srcs_sz)
    #         if extra_srcs_arr:
    #             rffi.free_charpp(extra_srcs_arr)

John Zhang's avatar
John Zhang committed
455
456
457
    def current_thread_as_mu_thread(self, threadlocal):
        # type: (MuCPtr) -> None
        self._mu.c_current_thread_as_mu_thread(self._mu, threadlocal)
John Zhang's avatar
John Zhang committed
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551


class MuCtx:
    def __init__(self, mu, rffi_ctx_ptr):
        self._mu = mu
        self._ctx = rffi_ctx_ptr

    def id_of(self, name):
        # type: (str) -> MuID
        with rffi.scoped_str2charp(name) as name_buf:
            res = self._ctx.c_id_of(self._ctx, name_buf)
            return res

    def name_of(self, id):
        # type: (MuID) -> str
        res = rffi.charp2str(self._ctx.c_name_of(self._ctx, id))
        return res

    def close_context(self):
        # type: () -> None
        self._ctx.c_close_context(self._ctx)

    def load_bundle(self, buf):
        # type: (str) -> None
        with rffi.scoped_str2charp(buf) as buf_buf:
            sz = rffi.cast(MuArraySize, len(buf))
            self._ctx.c_load_bundle(self._ctx, buf_buf, sz)

    def load_hail(self, buf):
        # type: (str) -> None
        with rffi.scoped_str2charp(buf) as buf_buf:
            sz = rffi.cast(MuArraySize, len(buf))
            self._ctx.c_load_hail(self._ctx, buf_buf, sz)

    def handle_from_sint8(self, num, len):
        # type: (int, int) -> MuIntValue
        num_c = rffi.cast(rffi.CHAR, num)
        len_c = rffi.cast(rffi.INT, len)
        res = self._ctx.c_handle_from_sint8(self._ctx, num_c, len_c)
        return res

    def handle_from_uint8(self, num, len):
        # type: (int, int) -> MuIntValue
        num_c = rffi.cast(rffi.UCHAR, num)
        len_c = rffi.cast(rffi.INT, len)
        res = self._ctx.c_handle_from_uint8(self._ctx, num_c, len_c)
        return res

    def handle_from_sint16(self, num, len):
        # type: (int, int) -> MuIntValue
        num_c = rffi.cast(rffi.SHORT, num)
        len_c = rffi.cast(rffi.INT, len)
        res = self._ctx.c_handle_from_sint16(self._ctx, num_c, len_c)
        return res

    def handle_from_uint16(self, num, len):
        # type: (int, int) -> MuIntValue
        num_c = rffi.cast(rffi.USHORT, num)
        len_c = rffi.cast(rffi.INT, len)
        res = self._ctx.c_handle_from_uint16(self._ctx, num_c, len_c)
        return res

    def handle_from_sint32(self, num, len):
        # type: (int, int) -> MuIntValue
        num_c = rffi.cast(rffi.INT, num)
        len_c = rffi.cast(rffi.INT, len)
        res = self._ctx.c_handle_from_sint32(self._ctx, num_c, len_c)
        return res

    def handle_from_uint32(self, num, len):
        # type: (int, int) -> MuIntValue
        num_c = rffi.cast(rffi.UINT, num)
        len_c = rffi.cast(rffi.INT, len)
        res = self._ctx.c_handle_from_uint32(self._ctx, num_c, len_c)
        return res

    def handle_from_sint64(self, num, len):
        # type: (int, int) -> MuIntValue
        num_c = rffi.cast(rffi.LONG, num)
        len_c = rffi.cast(rffi.INT, len)
        res = self._ctx.c_handle_from_sint64(self._ctx, num_c, len_c)
        return res

    def handle_from_uint64(self, num, len):
        # type: (int, int) -> MuIntValue
        num_c = rffi.cast(rffi.ULONG, num)
        len_c = rffi.cast(rffi.INT, len)
        res = self._ctx.c_handle_from_uint64(self._ctx, num_c, len_c)
        return res

    def handle_from_uint64s(self, nums, len):
        # type: ([rffi.ULONG], int) -> MuIntValue
        nums_arr, nums_sz = lst2arr(rffi.ULONG, nums)
        len_c = rffi.cast(rffi.INT, len)
552
553
        res = self._ctx.c_handle_from_uint64s(
            self._ctx, nums_arr, nums_sz, len_c)
John Zhang's avatar
John Zhang committed
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
        if nums_arr:
            lltype.free(nums_arr, flavor='raw')
        return res

    def handle_from_float(self, num):
        # type: (float) -> MuFloatValue
        num_c = rffi.cast(rffi.FLOAT, num)
        res = self._ctx.c_handle_from_float(self._ctx, num_c)
        return res

    def handle_from_double(self, num):
        # type: (float) -> MuDoubleValue
        num_c = rffi.cast(rffi.DOUBLE, num)
        res = self._ctx.c_handle_from_double(self._ctx, num_c)
        return res

    def handle_from_ptr(self, mu_type, ptr):
        # type: (MuID, MuCPtr) -> MuUPtrValue
        res = self._ctx.c_handle_from_ptr(self._ctx, mu_type, ptr)
        return res

    def handle_from_fp(self, mu_type, fp):
        # type: (MuID, MuCFP) -> MuUFPValue
        res = self._ctx.c_handle_from_fp(self._ctx, mu_type, fp)
        return res

    def handle_to_sint8(self, opnd):
        # type: (MuIntValue) -> int
        res = int(self._ctx.c_handle_to_sint8(self._ctx, opnd))
        return res

    def handle_to_uint8(self, opnd):
        # type: (MuIntValue) -> int
        res = int(self._ctx.c_handle_to_uint8(self._ctx, opnd))
        return res

    def handle_to_sint16(self, opnd):
        # type: (MuIntValue) -> int
        res = int(self._ctx.c_handle_to_sint16(self._ctx, opnd))
        return res

    def handle_to_uint16(self, opnd):
        # type: (MuIntValue) -> int
        res = int(self._ctx.c_handle_to_uint16(self._ctx, opnd))
        return res

    def handle_to_sint32(self, opnd):
        # type: (MuIntValue) -> int
        res = int(self._ctx.c_handle_to_sint32(self._ctx, opnd))
        return res

    def handle_to_uint32(self, opnd):
        # type: (MuIntValue) -> int
        res = int(self._ctx.c_handle_to_uint32(self._ctx, opnd))
        return res

    def handle_to_sint64(self, opnd):
        # type: (MuIntValue) -> int
        res = int(self._ctx.c_handle_to_sint64(self._ctx, opnd))
        return res

    def handle_to_uint64(self, opnd):
        # type: (MuIntValue) -> int
        res = int(self._ctx.c_handle_to_uint64(self._ctx, opnd))
        return res

    def handle_to_float(self, opnd):
        # type: (MuFloatValue) -> float
        res = float(self._ctx.c_handle_to_float(self._ctx, opnd))
        return res

    def handle_to_double(self, opnd):
        # type: (MuDoubleValue) -> float
        res = float(self._ctx.c_handle_to_double(self._ctx, opnd))
        return res

    def handle_to_ptr(self, opnd):
        # type: (MuUPtrValue) -> MuCPtr
        res = self._ctx.c_handle_to_ptr(self._ctx, opnd)
        return res

    def handle_to_fp(self, opnd):
        # type: (MuUFPValue) -> MuCFP
        res = self._ctx.c_handle_to_fp(self._ctx, opnd)
        return res

    def handle_from_const(self, id):
        # type: (MuID) -> MuValue
        res = self._ctx.c_handle_from_const(self._ctx, id)
        return res

    def handle_from_global(self, id):
        # type: (MuID) -> MuIRefValue
        res = self._ctx.c_handle_from_global(self._ctx, id)
        return res

    def handle_from_func(self, id):
        # type: (MuID) -> MuFuncRefValue
        res = self._ctx.c_handle_from_func(self._ctx, id)
        return res

    def handle_from_expose(self, id):
        # type: (MuID) -> MuValue
        res = self._ctx.c_handle_from_expose(self._ctx, id)
        return res

    def delete_value(self, opnd):
        # type: (MuValue) -> None
        self._ctx.c_delete_value(self._ctx, opnd)

    def ref_eq(self, lhs, rhs):
        # type: (MuGenRefValue, MuGenRefValue) -> bool
        res = bool(self._ctx.c_ref_eq(self._ctx, lhs, rhs))
        return res

    def ref_ult(self, lhs, rhs):
        # type: (MuIRefValue, MuIRefValue) -> bool
        res = bool(self._ctx.c_ref_ult(self._ctx, lhs, rhs))
        return res

    def extract_value(self, str, index):
        # type: (MuStructValue, int) -> MuValue
        index_c = rffi.cast(rffi.INT, index)
        res = self._ctx.c_extract_value(self._ctx, str, index_c)
        return res

    def insert_value(self, str, index, newval):
        # type: (MuStructValue, int, MuValue) -> MuStructValue
        index_c = rffi.cast(rffi.INT, index)
        res = self._ctx.c_insert_value(self._ctx, str, index_c, newval)
        return res

    def extract_element(self, str, index):
        # type: (MuSeqValue, MuIntValue) -> MuValue
        res = self._ctx.c_extract_element(self._ctx, str, index)
        return res

    def insert_element(self, str, index, newval):
        # type: (MuSeqValue, MuIntValue, MuValue) -> MuSeqValue
        res = self._ctx.c_insert_element(self._ctx, str, index, newval)
        return res

    def new_fixed(self, mu_type):
        # type: (MuID) -> MuRefValue
        res = self._ctx.c_new_fixed(self._ctx, mu_type)
        return res

    def new_hybrid(self, mu_type, length):
        # type: (MuID, MuIntValue) -> MuRefValue
        res = self._ctx.c_new_hybrid(self._ctx, mu_type, length)
        return res

    def refcast(self, opnd, new_type):
        # type: (MuGenRefValue, MuID) -> MuGenRefValue
        res = self._ctx.c_refcast(self._ctx, opnd, new_type)
        return res

    def get_iref(self, opnd):
        # type: (MuRefValue) -> MuIRefValue
        res = self._ctx.c_get_iref(self._ctx, opnd)
        return res

    def get_field_iref(self, opnd, field):
        # type: (MuIRefValue, int) -> MuIRefValue
        field_c = rffi.cast(rffi.INT, field)
        res = self._ctx.c_get_field_iref(self._ctx, opnd, field_c)
        return res

    def get_elem_iref(self, opnd, index):
        # type: (MuIRefValue, MuIntValue) -> MuIRefValue
        res = self._ctx.c_get_elem_iref(self._ctx, opnd, index)
        return res

    def shift_iref(self, opnd, offset):
        # type: (MuIRefValue, MuIntValue) -> MuIRefValue
        res = self._ctx.c_shift_iref(self._ctx, opnd, offset)
        return res

    def get_var_part_iref(self, opnd):
        # type: (MuIRefValue) -> MuIRefValue
        res = self._ctx.c_get_var_part_iref(self._ctx, opnd)
        return res

    def load(self, ord, loc):
        # type: (MuFlag, MuIRefValue) -> MuValue
        res = self._ctx.c_load(self._ctx, ord, loc)
        return res

    def store(self, ord, loc, newval):
        # type: (MuFlag, MuIRefValue, MuValue) -> None
        self._ctx.c_store(self._ctx, ord, loc, newval)

    def cmpxchg(self, ord_succ, ord_fail, weak, loc, expected, desired, is_succ):
        # type: (MuFlag, MuFlag, bool, MuIRefValue, MuValue, MuValue, MuBoolPtr) -> MuValue
        weak_c = rffi.cast(MuBool, weak)
749
750
        res = self._ctx.c_cmpxchg(
            self._ctx, ord_succ, ord_fail, weak_c, loc, expected, desired, is_succ)
John Zhang's avatar
John Zhang committed
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
        return res

    def atomicrmw(self, ord, op, loc, opnd):
        # type: (MuFlag, MuFlag, MuIRefValue, MuValue) -> MuValue
        res = self._ctx.c_atomicrmw(self._ctx, ord, op, loc, opnd)
        return res

    def fence(self, ord):
        # type: (MuFlag) -> None
        self._ctx.c_fence(self._ctx, ord)

    def new_stack(self, func):
        # type: (MuFuncRefValue) -> MuStackRefValue
        res = self._ctx.c_new_stack(self._ctx, func)
        return res

    def new_thread_nor(self, stack, threadlocal, vals):
        # type: (MuStackRefValue, MuRefValue, [MuValue]) -> MuThreadRefValue
        vals_arr, vals_sz = lst2arr(MuValue, vals)
770
771
        res = self._ctx.c_new_thread_nor(
            self._ctx, stack, threadlocal, vals_arr, vals_sz)
John Zhang's avatar
John Zhang committed
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
        if vals_arr:
            lltype.free(vals_arr, flavor='raw')
        return res

    def new_thread_exc(self, stack, threadlocal, exc):
        # type: (MuStackRefValue, MuRefValue, MuRefValue) -> MuThreadRefValue
        res = self._ctx.c_new_thread_exc(self._ctx, stack, threadlocal, exc)
        return res

    def kill_stack(self, stack):
        # type: (MuStackRefValue) -> None
        self._ctx.c_kill_stack(self._ctx, stack)

    def set_threadlocal(self, thread, threadlocal):
        # type: (MuThreadRefValue, MuRefValue) -> None
        self._ctx.c_set_threadlocal(self._ctx, thread, threadlocal)

    def get_threadlocal(self, thread):
        # type: (MuThreadRefValue) -> MuRefValue
        res = self._ctx.c_get_threadlocal(self._ctx, thread)
        return res

    def new_cursor(self, stack):
        # type: (MuStackRefValue) -> MuFCRefValue
        res = self._ctx.c_new_cursor(self._ctx, stack)
        return res

    def next_frame(self, cursor):
        # type: (MuFCRefValue) -> None
        self._ctx.c_next_frame(self._ctx, cursor)

    def copy_cursor(self, cursor):
        # type: (MuFCRefValue) -> MuFCRefValue
        res = self._ctx.c_copy_cursor(self._ctx, cursor)
        return res

    def close_cursor(self, cursor):
        # type: (MuFCRefValue) -> None
        self._ctx.c_close_cursor(self._ctx, cursor)

    def cur_func(self, cursor):
        # type: (MuFCRefValue) -> MuID
        res = self._ctx.c_cur_func(self._ctx, cursor)
        return res

    def cur_func_ver(self, cursor):
        # type: (MuFCRefValue) -> MuID
        res = self._ctx.c_cur_func_ver(self._ctx, cursor)
        return res

    def cur_inst(self, cursor):
        # type: (MuFCRefValue) -> MuID
        res = self._ctx.c_cur_inst(self._ctx, cursor)
        return res

    def dump_keepalives(self, cursor, results):
        # type: (MuFCRefValue, MuValuePtr) -> None
        self._ctx.c_dump_keepalives(self._ctx, cursor, results)

    def pop_frames_to(self, cursor):
        # type: (MuFCRefValue) -> None
        self._ctx.c_pop_frames_to(self._ctx, cursor)

    def push_frame(self, stack, func):
        # type: (MuStackRefValue, MuFuncRefValue) -> None
        self._ctx.c_push_frame(self._ctx, stack, func)

    def tr64_is_fp(self, value):
        # type: (MuTagRef64Value) -> bool
        res = bool(self._ctx.c_tr64_is_fp(self._ctx, value))
        return res

    def tr64_is_int(self, value):
        # type: (MuTagRef64Value) -> bool
        res = bool(self._ctx.c_tr64_is_int(self._ctx, value))
        return res

    def tr64_is_ref(self, value):
        # type: (MuTagRef64Value) -> bool
        res = bool(self._ctx.c_tr64_is_ref(self._ctx, value))
        return res

    def tr64_to_fp(self, value):
        # type: (MuTagRef64Value) -> MuDoubleValue
        res = self._ctx.c_tr64_to_fp(self._ctx, value)
        return res

    def tr64_to_int(self, value):
        # type: (MuTagRef64Value) -> MuIntValue
        res = self._ctx.c_tr64_to_int(self._ctx, value)
        return res

    def tr64_to_ref(self, value):
        # type: (MuTagRef64Value) -> MuRefValue
        res = self._ctx.c_tr64_to_ref(self._ctx, value)
        return res

    def tr64_to_tag(self, value):
        # type: (MuTagRef64Value) -> MuIntValue
        res = self._ctx.c_tr64_to_tag(self._ctx, value)
        return res

    def tr64_from_fp(self, value):
        # type: (MuDoubleValue) -> MuTagRef64Value
        res = self._ctx.c_tr64_from_fp(self._ctx, value)
        return res

    def tr64_from_int(self, value):
        # type: (MuIntValue) -> MuTagRef64Value
        res = self._ctx.c_tr64_from_int(self._ctx, value)
        return res

    def tr64_from_ref(self, ref, tag):
        # type: (MuRefValue, MuIntValue) -> MuTagRef64Value
        res = self._ctx.c_tr64_from_ref(self._ctx, ref, tag)
        return res

    def enable_watchpoint(self, wpid):
        # type: (MuWPID) -> None
        self._ctx.c_enable_watchpoint(self._ctx, wpid)

    def disable_watchpoint(self, wpid):
        # type: (MuWPID) -> None
        self._ctx.c_disable_watchpoint(self._ctx, wpid)

    def pin(self, loc):
        # type: (MuValue) -> MuUPtrValue
        res = self._ctx.c_pin(self._ctx, loc)
        return res

    def unpin(self, loc):
        # type: (MuValue) -> None
        self._ctx.c_unpin(self._ctx, loc)

    def get_addr(self, loc):
        # type: (MuValue) -> MuUPtrValue
        res = self._ctx.c_get_addr(self._ctx, loc)
        return res

    def expose(self, func, call_conv, cookie):
        # type: (MuFuncRefValue, MuFlag, MuIntValue) -> MuValue
        res = self._ctx.c_expose(self._ctx, func, call_conv, cookie)
        return res

    def unexpose(self, call_conv, value):
        # type: (MuFlag, MuValue) -> None
        self._ctx.c_unexpose(self._ctx, call_conv, value)

    def new_ir_builder(self):
        # type: () -> MuIRBuilder
        res = MuIRBuilder(self, self._ctx.c_new_ir_builder(self._ctx))
        return res

925
926
    def make_boot_image(self, whitelist, primordial_func, primordial_stack, primordial_threadlocal, sym_fields,
                        sym_strings, reloc_fields, reloc_strings, output_file):
John Zhang's avatar
John Zhang committed
927
928
929
930
931
932
933
        # type: ([MuID], MuFuncRefValue, MuStackRefValue, MuRefValue, [MuIRefValue], [MuCString], [MuIRefValue], [MuCString], str) -> None
        whitelist_arr, whitelist_sz = lst2arr(MuID, whitelist)
        sym_fields_arr, sym_fields_sz = lst2arr(MuIRefValue, sym_fields)
        sym_strings_arr, sym_strings_sz = lst2arr(MuCString, sym_strings)
        reloc_fields_arr, reloc_fields_sz = lst2arr(MuIRefValue, reloc_fields)
        reloc_strings_arr, reloc_strings_sz = lst2arr(MuCString, reloc_strings)
        with rffi.scoped_str2charp(output_file) as output_file_buf:
934
935
936
937
            self._ctx.c_make_boot_image(self._ctx, whitelist_arr, whitelist_sz, primordial_func, primordial_stack,
                                        primordial_threadlocal,
                                        sym_fields_arr, sym_strings_arr, sym_strings_sz, reloc_fields_arr,
                                        reloc_strings_arr, reloc_strings_sz, output_file_buf)
John Zhang's avatar
John Zhang committed
938
939
940
941
942
            if whitelist_arr:
                lltype.free(whitelist_arr, flavor='raw')
            if sym_fields_arr:
                lltype.free(sym_fields_arr, flavor='raw')
            if sym_strings_arr:
John Zhang's avatar
John Zhang committed
943
                rffi.free_charpp(sym_strings_arr)
John Zhang's avatar
John Zhang committed
944
945
946
            if reloc_fields_arr:
                lltype.free(reloc_fields_arr, flavor='raw')
            if reloc_strings_arr:
John Zhang's avatar
John Zhang committed
947
                rffi.free_charpp(reloc_strings_arr)
John Zhang's avatar
John Zhang committed
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999


class MuIRBuilder:
    def __init__(self, ctx, rffi_bldr_ptr):
        self._mu = ctx._mu
        self._bldr = rffi_bldr_ptr

    def load(self):
        # type: () -> None
        self._bldr.c_load(self._bldr)

    def abort(self):
        # type: () -> None
        self._bldr.c_abort(self._bldr)

    def gen_sym(self, name=None):
        # type: (str) -> MuID
        with rffi.scoped_str2charp(name) as name_buf:
            res = self._bldr.c_gen_sym(self._bldr, name_buf)
            return res

    def new_type_int(self, id, len):
        # type: (MuID, int) -> None
        len_c = rffi.cast(rffi.INT, len)
        self._bldr.c_new_type_int(self._bldr, id, len_c)

    def new_type_float(self, id):
        # type: (MuID) -> None
        self._bldr.c_new_type_float(self._bldr, id)

    def new_type_double(self, id):
        # type: (MuID) -> None
        self._bldr.c_new_type_double(self._bldr, id)

    def new_type_uptr(self, id, ty):
        # type: (MuID, MuTypeNode) -> None
        self._bldr.c_new_type_uptr(self._bldr, id, ty)

    def new_type_ufuncptr(self, id, sig):
        # type: (MuID, MuFuncSigNode) -> None
        self._bldr.c_new_type_ufuncptr(self._bldr, id, sig)

    def new_type_struct(self, id, fieldtys):
        # type: (MuID, [MuTypeNode]) -> None
        fieldtys_arr, fieldtys_sz = lst2arr(MuTypeNode, fieldtys)
        self._bldr.c_new_type_struct(self._bldr, id, fieldtys_arr, fieldtys_sz)
        if fieldtys_arr:
            lltype.free(fieldtys_arr, flavor='raw')

    def new_type_hybrid(self, id, fixedtys, varty):
        # type: (MuID, [MuTypeNode], MuTypeNode) -> None
        fixedtys_arr, fixedtys_sz = lst2arr(MuTypeNode, fixedtys)
1000
1001
        self._bldr.c_new_type_hybrid(
            self._bldr, id, fixedtys_arr, fixedtys_sz, varty)
John Zhang's avatar
John Zhang committed
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
        if fixedtys_arr:
            lltype.free(fixedtys_arr, flavor='raw')

    def new_type_array(self, id, elemty, len):
        # type: (MuID, MuTypeNode, int) -> None
        len_c = rffi.cast(rffi.ULONG, len)
        self._bldr.c_new_type_array(self._bldr, id, elemty, len_c)

    def new_type_vector(self, id, elemty, len):
        # type: (MuID, MuTypeNode, int) -> None
        len_c = rffi.cast(rffi.ULONG, len)
        self._bldr.c_new_type_vector(self._bldr, id, elemty, len_c)

    def new_type_void(self, id):
        # type: (MuID) -> None
        self._bldr.c_new_type_void(self._bldr, id)

    def new_type_ref(self, id, ty):
        # type: (MuID, MuTypeNode) -> None
        self._bldr.c_new_type_ref(self._bldr, id, ty)

    def new_type_iref(self, id, ty):
        # type: (MuID, MuTypeNode) -> None
        self._bldr.c_new_type_iref(self._bldr, id, ty)

    def new_type_weakref(self, id, ty):
        # type: (MuID, MuTypeNode) -> None
        self._bldr.c_new_type_weakref(self._bldr, id, ty)

    def new_type_funcref(self, id, sig):
        # type: (MuID, MuFuncSigNode) -> None
        self._bldr.c_new_type_funcref(self._bldr, id, sig)

    def new_type_tagref64(self, id):
        # type: (MuID) -> None
        self._bldr.c_new_type_tagref64(self._bldr, id)

    def new_type_threadref(self, id):
        # type: (MuID) -> None
        self._bldr.c_new_type_threadref(self._bldr, id)

    def new_type_stackref(self, id):
        # type: (MuID) -> None
        self._bldr.c_new_type_stackref(self._bldr, id)

    def new_type_framecursorref(self, id):
        # type: (MuID) -> None
        self._bldr.c_new_type_framecursorref(self._bldr, id)

    def new_type_irbuilderref(self, id):
        # type: (MuID) -> None
        self._bldr.c_new_type_irbuilderref(self._bldr, id)

1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
    def new_type_regionref(self, id):
        self._bldr.c_new_type_regionref(self._bldr, id)

    def new_type_attrref(self, id):
        self._bldr.c_new_type_attrref(self._bldr, id)

    def new_type_futexref(self, id):
        self._bldr.c_new_type_futexref(self._bldr, id)

    def new_type_timerref(self, id):
        self._bldr.c_new_type_timerref(self._bldr, id)

John Zhang's avatar
John Zhang committed
1067
1068
1069
1070
    def new_funcsig(self, id, paramtys, rettys):
        # type: (MuID, [MuTypeNode], [MuTypeNode]) -> None
        paramtys_arr, paramtys_sz = lst2arr(MuTypeNode, paramtys)
        rettys_arr, rettys_sz = lst2arr(MuTypeNode, rettys)
1071
1072
        self._bldr.c_new_funcsig(
            self._bldr, id, paramtys_arr, paramtys_sz, rettys_arr, rettys_sz)
John Zhang's avatar
John Zhang committed
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
        if paramtys_arr:
            lltype.free(paramtys_arr, flavor='raw')
        if rettys_arr:
            lltype.free(rettys_arr, flavor='raw')

    def new_const_int(self, id, ty, value):
        # type: (MuID, MuTypeNode, int) -> None
        value_c = rffi.cast(rffi.ULONG, value)
        self._bldr.c_new_const_int(self._bldr, id, ty, value_c)

    def new_const_int_ex(self, id, ty, values):
        # type: (MuID, MuTypeNode, [rffi.ULONG]) -> None
        values_arr, values_sz = lst2arr(rffi.ULONG, values)
1086
1087
        self._bldr.c_new_const_int_ex(
            self._bldr, id, ty, values_arr, values_sz)
John Zhang's avatar
John Zhang committed
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
        if values_arr:
            lltype.free(values_arr, flavor='raw')

    def new_const_float(self, id, ty, value):
        # type: (MuID, MuTypeNode, float) -> None
        value_c = rffi.cast(rffi.FLOAT, value)
        self._bldr.c_new_const_float(self._bldr, id, ty, value_c)

    def new_const_double(self, id, ty, value):
        # type: (MuID, MuTypeNode, float) -> None
        value_c = rffi.cast(rffi.DOUBLE, value)
        self._bldr.c_new_const_double(self._bldr, id, ty, value_c)

    def new_const_null(self, id, ty):
        # type: (MuID, MuTypeNode) -> None
        self._bldr.c_new_const_null(self._bldr, id, ty)

    def new_const_seq(self, id, ty, elems):
        # type: (MuID, MuTypeNode, [MuGlobalVarNode]) -> None
        elems_arr, elems_sz = lst2arr(MuGlobalVarNode, elems)
        self._bldr.c_new_const_seq(self._bldr, id, ty, elems_arr, elems_sz)
        if elems_arr:
            lltype.free(elems_arr, flavor='raw')

    def new_const_extern(self, id, ty, symbol):
        # type: (MuID, MuTypeNode, str) -> None
        with rffi.scoped_str2charp(symbol) as symbol_buf:
            self._bldr.c_new_const_extern(self._bldr, id, ty, symbol_buf)

    def new_global_cell(self, id, ty):
        # type: (MuID, MuTypeNode) -> None
        self._bldr.c_new_global_cell(self._bldr, id, ty)

    def new_func(self, id, sig):
        # type: (MuID, MuFuncSigNode) -> None
        self._bldr.c_new_func(self._bldr, id, sig)

    def new_exp_func(self, id, func, callconv, cookie):
        # type: (MuID, MuFuncNode, MuFlag, MuConstNode) -> None
        self._bldr.c_new_exp_func(self._bldr, id, func, callconv, cookie)

    def new_func_ver(self, id, func, bbs):
        # type: (MuID, MuFuncNode, [MuBBNode]) -> None
        bbs_arr, bbs_sz = lst2arr(MuBBNode, bbs)
        self._bldr.c_new_func_ver(self._bldr, id, func, bbs_arr, bbs_sz)
        if bbs_arr:
            lltype.free(bbs_arr, flavor='raw')

    def new_bb(self, id, nor_param_ids, nor_param_types, exc_param_id, insts):
        # type: (MuID, [MuID], [MuTypeNode], MuID, [MuInstNode]) -> None
1138
        logger.info("zebu_api new bb")
John Zhang's avatar
John Zhang committed
1139
        nor_param_ids_arr, nor_param_ids_sz = lst2arr(MuID, nor_param_ids)
1140
1141
        nor_param_types_arr, nor_param_types_sz = lst2arr(
            MuTypeNode, nor_param_types)
John Zhang's avatar
John Zhang committed
1142
        insts_arr, insts_sz = lst2arr(MuInstNode, insts)
1143
1144
1145
1146
        logger.info("calling muirbuilder")
        self._bldr.c_new_bb(self._bldr, id, nor_param_ids_arr, nor_param_types_arr,
                            nor_param_types_sz, exc_param_id, insts_arr, insts_sz)
        logger.info("freeing some stuff")
John Zhang's avatar
John Zhang committed
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
        if nor_param_ids_arr:
            lltype.free(nor_param_ids_arr, flavor='raw')
        if nor_param_types_arr:
            lltype.free(nor_param_types_arr, flavor='raw')
        if insts_arr:
            lltype.free(insts_arr, flavor='raw')

    def new_dest_clause(self, id, dest, vars):
        # type: (MuID, MuBBNode, [MuVarNode]) -> None
        vars_arr, vars_sz = lst2arr(MuVarNode, vars)
        self._bldr.c_new_dest_clause(self._bldr, id, dest, vars_arr, vars_sz)
        if vars_arr:
            lltype.free(vars_arr, flavor='raw')

    def new_exc_clause(self, id, nor, exc):
        # type: (MuID, MuDestClause, MuDestClause) -> None
        self._bldr.c_new_exc_clause(self._bldr, id, nor, exc)

    def new_keepalive_clause(self, id, vars):
        # type: (MuID, [MuLocalVarNode]) -> None
        vars_arr, vars_sz = lst2arr(MuLocalVarNode, vars)
        self._bldr.c_new_keepalive_clause(self._bldr, id, vars_arr, vars_sz)
        if vars_arr:
            lltype.free(vars_arr, flavor='raw')

    def new_csc_ret_with(self, id, rettys):
        # type: (MuID, [MuTypeNode]) -> None
        rettys_arr, rettys_sz = lst2arr(MuTypeNode, rettys)
        self._bldr.c_new_csc_ret_with(self._bldr, id, rettys_arr, rettys_sz)
        if rettys_arr:
            lltype.free(rettys_arr, flavor='raw')

    def new_csc_kill_old(self, id):
        # type: (MuID) -> None
        self._bldr.c_new_csc_kill_old(self._bldr, id)

    def new_nsc_pass_values(self, id, tys, vars):
        # type: (MuID, [MuTypeNode], [MuVarNode]) -> None
        tys_arr, tys_sz = lst2arr(MuTypeNode, tys)
        vars_arr, vars_sz = lst2arr(MuVarNode, vars)
1187
1188
        self._bldr.c_new_nsc_pass_values(
            self._bldr, id, tys_arr, vars_arr, vars_sz)
John Zhang's avatar
John Zhang committed
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
        if tys_arr:
            lltype.free(tys_arr, flavor='raw')
        if vars_arr:
            lltype.free(vars_arr, flavor='raw')

    def new_nsc_throw_exc(self, id, exc):
        # type: (MuID, MuVarNode) -> None
        self._bldr.c_new_nsc_throw_exc(self._bldr, id, exc)

    def new_binop(self, id, result_id, optr, ty, opnd1, opnd2, exc_clause=MU_NO_ID):
        # type: (MuID, MuID, MuFlag, MuTypeNode, MuVarNode, MuVarNode, MuExcClause) -> None
1200
1201
        self._bldr.c_new_binop(self._bldr, id, result_id,
                               optr, ty, opnd1, opnd2, exc_clause)
John Zhang's avatar
John Zhang committed
1202

1203
1204
    def new_binop_with_status(self, id, result_id, status_result_ids, optr, status_flags, ty, opnd1, opnd2,
                              exc_clause=MU_NO_ID):
John Zhang's avatar
John Zhang committed
1205
        # type: (MuID, MuID, [MuID], MuFlag, MuBinOpStatus, MuTypeNode, MuVarNode, MuVarNode, MuExcClause) -> None
1206
1207
1208
1209
        status_result_ids_arr, status_result_ids_sz = lst2arr(
            MuID, status_result_ids)
        self._bldr.c_new_binop_with_status(self._bldr, id, result_id, status_result_ids_arr,
                                           status_result_ids_sz, optr, status_flags, ty, opnd1, opnd2, exc_clause)
John Zhang's avatar
John Zhang committed
1210
1211
1212
1213
1214
        if status_result_ids_arr:
            lltype.free(status_result_ids_arr, flavor='raw')

    def new_cmp(self, id, result_id, optr, ty, opnd1, opnd2):
        # type: (MuID, MuID, MuFlag, MuTypeNode, MuVarNode, MuVarNode) -> None
1215
        logger.info("calling _bdlr.c_new_cmp")
John Zhang's avatar
John Zhang committed
1216
1217
1218
1219
        self._bldr.c_new_cmp(self._bldr, id, result_id, optr, ty, opnd1, opnd2)

    def new_conv(self, id, result_id, optr, from_ty, to_ty, opnd):
        # type: (MuID, MuID, MuFlag, MuTypeNode, MuTypeNode, MuVarNode) -> None
1220
1221
        self._bldr.c_new_conv(self._bldr, id, result_id,
                              optr, from_ty, to_ty, opnd)
John Zhang's avatar
John Zhang committed
1222
1223
1224

    def new_select(self, id, result_id, cond_ty, opnd_ty, cond, if_true, if_false):
        # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode, MuVarNode) -> None
1225
1226
        self._bldr.c_new_select(self._bldr, id, result_id,
                                cond_ty, opnd_ty, cond, if_true, if_false)
John Zhang's avatar
John Zhang committed
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239

    def new_branch(self, id, dest):
        # type: (MuID, MuDestClause) -> None
        self._bldr.c_new_branch(self._bldr, id, dest)

    def new_branch2(self, id, cond, if_true, if_false):
        # type: (MuID, MuVarNode, MuDestClause, MuDestClause) -> None
        self._bldr.c_new_branch2(self._bldr, id, cond, if_true, if_false)

    def new_switch(self, id, opnd_ty, opnd, default_dest, cases, dests):
        # type: (MuID, MuTypeNode, MuVarNode, MuDestClause, [MuConstNode], [MuDestClause]) -> None
        cases_arr, cases_sz = lst2arr(MuConstNode, cases)
        dests_arr, dests_sz = lst2arr(MuDestClause, dests)
1240
1241
        self._bldr.c_new_switch(
            self._bldr, id, opnd_ty, opnd, default_dest, cases_arr, dests_arr, dests_sz)
John Zhang's avatar
John Zhang committed
1242
1243
1244
1245
1246
1247
1248
1249
1250
        if cases_arr:
            lltype.free(cases_arr, flavor='raw')
        if dests_arr:
            lltype.free(dests_arr, flavor='raw')

    def new_call(self, id, result_ids, sig, callee, args, exc_clause=MU_NO_ID, keepalive_clause=MU_NO_ID):
        # type: (MuID, [MuID], MuFuncSigNode, MuVarNode, [MuVarNode], MuExcClause, MuKeepaliveClause) -> None
        result_ids_arr, result_ids_sz = lst2arr(MuID, result_ids)
        args_arr, args_sz = lst2arr(MuVarNode, args)
1251
1252
        self._bldr.c_new_call(self._bldr, id, result_ids_arr, result_ids_sz,
                              sig, callee, args_arr, args_sz, exc_clause, keepalive_clause)
John Zhang's avatar
John Zhang committed
1253
1254
1255
1256
1257
1258
1259
1260
        if result_ids_arr:
            lltype.free(result_ids_arr, flavor='raw')
        if args_arr:
            lltype.free(args_arr, flavor='raw')

    def new_tailcall(self, id, sig, callee, args):
        # type: (MuID, MuFuncSigNode, MuVarNode, [MuVarNode]) -> None
        args_arr, args_sz = lst2arr(MuVarNode, args)
1261
1262
        self._bldr.c_new_tailcall(
            self._bldr, id, sig, callee, args_arr, args_sz)
John Zhang's avatar
John Zhang committed
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
        if args_arr:
            lltype.free(args_arr, flavor='raw')

    def new_ret(self, id, rvs):
        # type: (MuID, [MuVarNode]) -> None
        rvs_arr, rvs_sz = lst2arr(MuVarNode, rvs)
        self._bldr.c_new_ret(self._bldr, id, rvs_arr, rvs_sz)
        if rvs_arr:
            lltype.free(rvs_arr, flavor='raw')

    def new_throw(self, id, exc):
        # type: (MuID, MuVarNode) -> None
        self._bldr.c_new_throw(self._bldr, id, exc)

    def new_extractvalue(self, id, result_id, strty, index, opnd):
        # type: (MuID, MuID, MuTypeNode, int, MuVarNode) -> None
        index_c = rffi.cast(rffi.INT, index)
1280
1281
        self._bldr.c_new_extractvalue(
            self._bldr, id, result_id, strty, index_c, opnd)
John Zhang's avatar
John Zhang committed
1282
1283
1284
1285

    def new_insertvalue(self, id, result_id, strty, index, opnd, newval):
        # type: (MuID, MuID, MuTypeNode, int, MuVarNode, MuVarNode) -> None
        index_c = rffi.cast(rffi.INT, index)
1286
1287
        self._bldr.c_new_insertvalue(
            self._bldr, id, result_id, strty, index_c, opnd, newval)
John Zhang's avatar
John Zhang committed
1288
1289
1290

    def new_extractelement(self, id, result_id, seqty, indty, opnd, index):
        # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode) -> None
1291
1292
        self._bldr.c_new_extractelement(
            self._bldr, id, result_id, seqty, indty, opnd, index)
John Zhang's avatar
John Zhang committed
1293
1294
1295

    def new_insertelement(self, id, result_id, seqty, indty, opnd, index, newval):
        # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode, MuVarNode) -> None
1296
1297
        self._bldr.c_new_insertelement(
            self._bldr, id, result_id, seqty, indty, opnd, index, newval)
John Zhang's avatar
John Zhang committed
1298
1299
1300

    def new_shufflevector(self, id, result_id, vecty, maskty, vec1, vec2, mask):
        # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode, MuVarNode) -> None
1301
1302
        self._bldr.c_new_shufflevector(
            self._bldr, id, result_id, vecty, maskty, vec1, vec2, mask)
John Zhang's avatar
John Zhang committed
1303
1304
1305
1306
1307
1308
1309

    def new_new(self, id, result_id, allocty, exc_clause=MU_NO_ID):
        # type: (MuID, MuID, MuTypeNode, MuExcClause) -> None
        self._bldr.c_new_new(self._bldr, id, result_id, allocty, exc_clause)

    def new_newhybrid(self, id, result_id, allocty, lenty, length, exc_clause=MU_NO_ID):
        # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuExcClause) -> None
1310
1311
        self._bldr.c_new_newhybrid(
            self._bldr, id, result_id, allocty, lenty, length, exc_clause)
John Zhang's avatar
John Zhang committed
1312
1313
1314
1315
1316
1317
1318

    def new_alloca(self, id, result_id, allocty, exc_clause=MU_NO_ID):
        # type: (MuID, MuID, MuTypeNode, MuExcClause) -> None
        self._bldr.c_new_alloca(self._bldr, id, result_id, allocty, exc_clause)

    def new_allocahybrid(self, id, result_id, allocty, lenty, length, exc_clause=MU_NO_ID):
        # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuExcClause) -> None
1319
1320
        self._bldr.c_new_allocahybrid(
            self._bldr, id, result_id, allocty, lenty, length, exc_clause)
John Zhang's avatar
John Zhang committed
1321
1322
1323
1324
1325
1326
1327
1328
1329

    def new_getiref(self, id, result_id, refty, opnd):
        # type: (MuID, MuID, MuTypeNode, MuVarNode) -> None
        self._bldr.c_new_getiref(self._bldr, id, result_id, refty, opnd)

    def new_getfieldiref(self, id, result_id, is_ptr, refty, index, opnd):
        # type: (MuID, MuID, bool, MuTypeNode, int, MuVarNode) -> None
        is_ptr_c = rffi.cast(MuBool, is_ptr)
        index_c = rffi.cast(rffi.INT, index)
1330
1331
        self._bldr.c_new_getfieldiref(
            self._bldr, id, result_id, is_ptr_c, refty, index_c, opnd)
John Zhang's avatar
John Zhang committed
1332
1333
1334
1335

    def new_getelemiref(self, id, result_id, is_ptr, refty, indty, opnd, index):
        # type: (MuID, MuID, bool, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode) -> None
        is_ptr_c = rffi.cast(MuBool, is_ptr)
1336
1337
        self._bldr.c_new_getelemiref(
            self._bldr, id, result_id, is_ptr_c, refty, indty, opnd, index)
John Zhang's avatar
John Zhang committed
1338
1339
1340
1341

    def new_shiftiref(self, id, result_id, is_ptr, refty, offty, opnd, offset):
        # type: (MuID, MuID, bool, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode) -> None
        is_ptr_c = rffi.cast(MuBool, is_ptr)
1342
1343
        self._bldr.c_new_shiftiref(
            self._bldr, id, result_id, is_ptr_c, refty, offty, opnd, offset)
John Zhang's avatar
John Zhang committed
1344
1345
1346
1347

    def new_getvarpartiref(self, id, result_id, is_ptr, refty, opnd):
        # type: (MuID, MuID, bool, MuTypeNode, MuVarNode) -> None
        is_ptr_c = rffi.cast(MuBool, is_ptr)
1348
1349
        self._bldr.c_new_getvarpartiref(
            self._bldr, id, result_id, is_ptr_c, refty, opnd)
John Zhang's avatar
John Zhang committed
1350
1351
1352
1353

    def new_load(self, id, result_id, is_ptr, ord, refty, loc, exc_clause=MU_NO_ID):
        # type: (MuID, MuID, bool, MuFlag, MuTypeNode, MuVarNode, MuExcClause) -> None
        is_ptr_c = rffi.cast(MuBool, is_ptr)
1354
1355
        self._bldr.c_new_load(self._bldr, id, result_id,
                              is_ptr_c, ord, refty, loc, exc_clause)
John Zhang's avatar
John Zhang committed
1356
1357
1358
1359

    def new_store(self, id, is_ptr, ord, refty, loc, newval, exc_clause=MU_NO_ID):
        # type: (MuID, bool, MuFlag, MuTypeNode, MuVarNode, MuVarNode, MuExcClause) -> None
        is_ptr_c = rffi.cast(MuBool, is_ptr)
1360
1361
        self._bldr.c_new_store(self._bldr, id, is_ptr_c,
                               ord, refty, loc, newval, exc_clause)
John Zhang's avatar
John Zhang committed
1362

1363
1364
    def new_cmpxchg(self, id, value_result_id, succ_result_id, is_ptr, is_weak, ord_succ, ord_fail, refty, loc,
                    expected, desired, exc_clause=MU_NO_ID):
John Zhang's avatar
John Zhang committed
1365
1366
1367
        # type: (MuID, MuID, MuID, bool, bool, MuFlag, MuFlag, MuTypeNode, MuVarNode, MuVarNode, MuVarNode, MuExcClause) -> None
        is_ptr_c = rffi.cast(MuBool, is_ptr)
        is_weak_c = rffi.cast(MuBool, is_weak)
1368
1369
        self._bldr.c_new_cmpxchg(self._bldr, id, value_result_id, succ_result_id, is_ptr_c,
                                 is_weak_c, ord_succ, ord_fail, refty, loc, expected, desired, exc_clause)
John Zhang's avatar
John Zhang committed
1370
1371
1372
1373

    def new_atomicrmw(self, id, result_id, is_ptr, ord, optr, ref_ty, loc, opnd, exc_clause=MU_NO_ID):
        # type: (MuID, MuID, bool, MuFlag, MuFlag, MuTypeNode, MuVarNode, MuVarNode, MuExcClause) -> None
        is_ptr_c = rffi.cast(MuBool, is_ptr)
1374
1375
        self._bldr.c_new_atomicrmw(
            self._bldr, id, result_id, is_ptr_c, ord, optr, ref_ty, loc, opnd, exc_clause)
John Zhang's avatar
John Zhang committed
1376
1377
1378
1379
1380
1381
1382
1383
1384

    def new_fence(self, id, ord):
        # type: (MuID, MuFlag) -> None
        self._bldr.c_new_fence(self._bldr, id, ord)

    def new_trap(self, id, result_ids, rettys, exc_clause=MU_NO_ID, keepalive_clause=MU_NO_ID):
        # type: (MuID, [MuID], [MuTypeNode], MuExcClause, MuKeepaliveClause) -> None
        result_ids_arr, result_ids_sz = lst2arr(MuID, result_ids)
        rettys_arr, rettys_sz = lst2arr(MuTypeNode, rettys)
1385
1386
        self._bldr.c_new_trap(self._bldr, id, result_ids_arr,
                              rettys_arr, rettys_sz, exc_clause, keepalive_clause)
John Zhang's avatar
John Zhang committed
1387
1388
1389
1390
1391
1392
1393
1394
1395
        if result_ids_arr:
            lltype.free(result_ids_arr, flavor='raw')
        if rettys_arr:
            lltype.free(rettys_arr, flavor='raw')

    def new_watchpoint(self, id, wpid, result_ids, rettys, dis, ena, exc=MU_NO_ID, keepalive_clause=MU_NO_ID):
        # type: (MuID, MuWPID, [MuID], [MuTypeNode], MuDestClause, MuDestClause, MuDestClause, MuKeepaliveClause) -> None
        result_ids_arr, result_ids_sz = lst2arr(MuID, result_ids)
        rettys_arr, rettys_sz = lst2arr(MuTypeNode, rettys)
1396
1397
        self._bldr.c_new_watchpoint(
            self._bldr, id, wpid, result_ids_arr, rettys_arr, rettys_sz, dis, ena, exc, keepalive_clause)
John Zhang's avatar
John Zhang committed
1398
1399
1400
1401
1402
1403
1404
1405
1406
        if result_ids_arr:
            lltype.free(result_ids_arr, flavor='raw')
        if rettys_arr:
            lltype.free(rettys_arr, flavor='raw')

    def new_wpbranch(self, id, wpid, dis, ena):
        # type: (MuID, MuWPID, MuDestClause, MuDestClause) -> None
        self._bldr.c_new_wpbranch(self._bldr, id, wpid, dis, ena)

1407
1408
    def new_ccall(self, id, result_ids, callconv, callee_ty, sig, callee, args, exc_clause=MU_NO_ID,
                  keepalive_clause=MU_NO_ID):
John Zhang's avatar
John Zhang committed
1409
1410
1411
        # type: (MuID, [MuID], MuFlag, MuTypeNode, MuFuncSigNode, MuVarNode, [MuVarNode], MuExcClause, MuKeepaliveClause) -> None
        result_ids_arr, result_ids_sz = lst2arr(MuID, result_ids)
        args_arr, args_sz = lst2arr(MuVarNode, args)
1412
1413
        self._bldr.c_new_ccall(self._bldr, id, result_ids_arr, result_ids_sz, callconv,
                               callee_ty, sig, callee, args_arr, args_sz, exc_clause, keepalive_clause)
John Zhang's avatar
John Zhang committed
1414
1415
1416
1417
1418
1419
1420
        if result_ids_arr:
            lltype.free(result_ids_arr, flavor='raw')
        if args_arr:
            lltype.free(args_arr, flavor='raw')

    def new_newthread(self, id, result_id, stack, threadlocal, new_stack_clause, exc_clause=MU_NO_ID):
        # type: (MuID, MuID, MuVarNode, MuVarNode, MuNewStackClause, MuExcClause) -> None
1421
1422
        self._bldr.c_new_newthread(
            self._bldr, id, result_id, stack, threadlocal, new_stack_clause, exc_clause)
John Zhang's avatar
John Zhang committed
1423

1424
1425
    def new_swapstack(self, id, result_ids, swappee, cur_stack_clause, new_stack_clause, exc_clause=MU_NO_ID,
                      keepalive_clause=MU_NO_ID):
John Zhang's avatar
John Zhang committed
1426
1427
        # type: (MuID, [MuID], MuVarNode, MuCurStackClause, MuNewStackClause, MuExcClause, MuKeepaliveClause) -> None
        result_ids_arr, result_ids_sz = lst2arr(MuID, result_ids)
1428
1429
        self._bldr.c_new_swapstack(self._bldr, id, result_ids_arr, result_ids_sz,
                                   swappee, cur_stack_clause, new_stack_clause, exc_clause, keepalive_clause)
John Zhang's avatar
John Zhang committed
1430
1431
1432
        if result_ids_arr:
            lltype.free(result_ids_arr, flavor='raw')

1433
1434
    def new_comminst(self, id, result_ids, opcode, flags, tys, sigs, args, exc_clause=MU_NO_ID,
                     keepalive_clause=MU_NO_ID):
John Zhang's avatar
John Zhang committed
1435
1436
1437
1438
1439
1440
        # type: (MuID, [MuID], MuFlag, [MuFlag], [MuTypeNode], [MuFuncSigNode], [MuVarNode], MuExcClause, MuKeepaliveClause) -> None
        result_ids_arr, result_ids_sz = lst2arr(MuID, result_ids)
        flags_arr, flags_sz = lst2arr(MuFlag, flags)
        tys_arr, tys_sz = lst2arr(MuTypeNode, tys)
        sigs_arr, sigs_sz = lst2arr(MuFuncSigNode, sigs)
        args_arr, args_sz = lst2arr(MuVarNode, args)
1441
1442
1443
        self._bldr.c_new_comminst(self._bldr, id, result_ids_arr, result_ids_sz, opcode, flags_arr,
                                  flags_sz, tys_arr, tys_sz, sigs_arr, sigs_sz, args_arr, args_sz, exc_clause,
                                  keepalive_clause)
John Zhang's avatar
John Zhang committed
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
        if result_ids_arr:
            lltype.free(result_ids_arr, flavor='raw')
        if flags_arr:
            lltype.free(flags_arr, flavor='raw')
        if tys_arr:
            lltype.free(tys_arr, flavor='raw')
        if sigs_arr:
            lltype.free(sigs_arr, flavor='raw')
        if args_arr:
            lltype.free(args_arr, flavor='raw')

1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
    def new_newrtthread(self, id, result_id, attr, stack, threadlocal, new_stack_clause, exc_clause=MU_NO_ID):
        # type: (MuID, MuID, MuVarNode, MuVarNode, MuVarNode, MuNewStackClause, MuExcClause) -> None
        self._bldr.c_new_newrtthread(
            self._bldr, id, result_id, attr, stack, threadlocal, new_stack_clause, exc_clause)

    def new_allocau(self, id, result_id, allocty, exc_clause=MU_NO_ID):
        self._bldr.c_new_allocau(
            self._bldr, id, result_id, allocty, exc_clause)

    def new_allocauhyrid(self, id, result_id, allocty, lenty, length, exc_clause=MU_NO_ID):
        self._bldr.c_new_allocauhybrid(
            self._bldr, id, result_id, allocty, lenty, length, exc_clause)

    def new_ealloc(self, id, result_id, allocty, exc_clause=MU_NO_ID):
        self._bldr.c_new_ealloc(self._bldr, id, result_id, allocty, exc_clause)

    def new_eallochyrid(self, id, result_id, allocty, lenty, length, exc_clause=MU_NO_ID):
        self._bldr.c_new_eallochybrid(
            self._bldr, id, result_id, allocty, lenty, length, exc_clause)

    def new_edelete(self, id, ptrty, ptr, exc_clause=MU_NO_ID):
        logger.info('zebu.py new_edelete ptrty = %d exc_id = %d' % (ptrty, exc_clause))
        self._bldr.c_new_edelete(self._bldr, id, ptrty, ptr, exc_clause)

    def new_newregion(self, id, result_id, size, exc_clause=MU_NO_ID):
        self._bldr.c_new_newregion(self._bldr, id, result_id, size, exc_clause)

    def new_deleteregion(self, id, ptr, exc_clause=MU_NO_ID):
        self._bldr.c_new_deleteregion(self._bldr, id, ptr, exc_clause)

    def new_ralloc(self, id, result_id, allocty, reg, exc_clause=MU_NO_ID):
        self._bldr.c_new_ralloc(
            self._bldr, id, result_id, allocty, reg, exc_clause)

    def new_rallochyrid(self, id, result_id, allocty, lenty, length, reg, exc_clause=MU_NO_ID):
        self._bldr.c_new_rallochybrid(
            self._bldr, id, result_id, allocty, lenty, length, reg, exc_clause)

    def new_exitthread(self, id, tref, exc_clause=MU_NO_ID):
        self._bldr.c_new_exitthread(self._bldr, id, tref, exc_clause)

    def new_yield(self, id, exc_clause=MU_NO_ID):
        self._bldr.c_new_yield(self._bldr, id, exc_clause)

    def new_newattr(self, id, result_id):
        self._bldr.c_new_newattr(self._bldr, id, result_id)

    def new_setattr(self, id, tref, aref, exc_clause=MU_NO_ID):
        self._bldr.c_new_setattr(self._bldr, id, tref, aref, exc_clause)

    def new_getattr(self, id, result_id, tref, exc_clause=MU_NO_ID):
        self._bldr.c_new_getattr(self._bldr, id, result_id, tref, exc_clause)

    def new_gettime(self, id, result_id):
        self._bldr.c_new_gettime(self._bldr, id, result_id)

    def new_settime(self, id, tm, exc_clause=MU_NO_ID):
        self._bldr.c_new_settime(self._bldr, id, tm, exc_clause)

    def new_newtimer(self, id, result_id, exc_clause=MU_NO_ID):
        self._bldr.c_new_newtimer(self._bldr, id, result_id, exc_clause)

    def new_deletetimer(self, id, tmr, exc_clause=MU_NO_ID):
        self._bldr.c_new_deletetimer(self._bldr, id, tmr, exc_clause)

    def new_settimer(self, id, tmr, tm, prd, fsig, func, args, exc_clause=MU_NO_ID):
        # type: (MuID, MuVarNode, MuVarNode, MuVarNode, MuFuncSigNode, MuFuncNode, [MuVarNode], MuExcClause) -> None
        args_arr, args_sz = lst2arr(MuVarNode, args)
        self._bldr.c_new_settimer(self._bldr, id, tmr, tm, prd, fsig, func, args_arr, args_sz, exc_clause)

    def new_canceltimer(self, id, tmr):
        self._bldr.c_new_canceltimer(self._bldr, id, tmr)

    def new_newfutex(self, id, result_id):
        self._bldr.c_new_newfutex(self._bldr, id, result_id)

John Zhang's avatar
John Zhang committed
1531
1532
1533
1534
1535
1536
1537
1538
1539

# -------------------------------------------------------------------------------------------------------
# Structs
_MuVM.become(rffi.CStruct(
    'MuVM',
    ('header', rffi.VOIDP),
    ('new_context', rffi.CCallback([_MuVMPtr], _MuCtxPtr)),
    ('id_of', rffi.CCallback([_MuVMPtr, MuName], MuID)),
    ('name_of', rffi.CCallback([_MuVMPtr, MuID], MuName)),
1540
1541
1542
1543
1544
1545
    ('set_trap_handler', rffi.CCallback(
        [_MuVMPtr, MuTrapHandler, MuCPtr], lltype.Void)),
    ('compile_to_sharedlib', rffi.CCallback(
        [_MuVMPtr, MuCString, MuCStringPtr, MuArraySize], lltype.Void)),
    ('current_thread_as_mu_thread', rffi.CCallback(
        [_MuVMPtr, MuCPtr], lltype.Void)),
John Zhang's avatar
John Zhang committed
1546
1547
1548
1549
1550
1551
1552
))
_MuCtx.become(rffi.CStruct(
    'MuCtx',
    ('header', rffi.VOIDP),
    ('id_of', rffi.CCallback([_MuCtxPtr, MuName], MuID)),
    ('name_of', rffi.CCallback([_MuCtxPtr, MuID], MuName)),
    ('close_context', rffi.CCallback([_MuCtxPtr], lltype.Void)),
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
    ('load_bundle', rffi.CCallback(
        [_MuCtxPtr, rffi.CCHARP, MuArraySize], lltype.Void)),
    ('load_hail', rffi.CCallback(
        [_MuCtxPtr, rffi.CCHARP, MuArraySize], lltype.Void)),
    ('handle_from_sint8', rffi.CCallback(
        [_MuCtxPtr, rffi.CHAR, rffi.INT], MuIntValue)),
    ('handle_from_uint8', rffi.CCallback(
        [_MuCtxPtr, rffi.UCHAR, rffi.INT], MuIntValue)),
    ('handle_from_sint16', rffi.CCallback(
        [_MuCtxPtr, rffi.SHORT, rffi.INT], MuIntValue)),
    ('handle_from_uint16', rffi.CCallback(
        [_MuCtxPtr, rffi.USHORT, rffi.INT], MuIntValue)),
    ('handle_from_sint32', rffi.CCallback(
        [_MuCtxPtr, rffi.INT, rffi.INT], MuIntValue)),
    ('handle_from_uint32', rffi.CCallback(
        [_MuCtxPtr, rffi.UINT, rffi.INT], MuIntValue)),
    ('handle_from_sint64', rffi.CCallback(
        [_MuCtxPtr, rffi.LONG, rffi.INT], MuIntValue)),
    ('handle_from_uint64', rffi.CCallback(
        [_MuCtxPtr, rffi.ULONG, rffi.INT], MuIntValue)),
    ('handle_from_uint64s', rffi.CCallback(
        [_MuCtxPtr, rffi.ULONGP, MuArraySize, rffi.INT], MuIntValue)),
    ('handle_from_float', rffi.CCallback(
        [_MuCtxPtr, rffi.FLOAT], MuFloatValue)),
    ('handle_from_double', rffi.CCallback(
        [_MuCtxPtr, rffi.DOUBLE], MuDoubleValue)),
    ('handle_from_ptr', rffi.CCallback(
        [_MuCtxPtr, MuID, MuCPtr], MuUPtrValue)),
John Zhang's avatar
John Zhang committed
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
    ('handle_from_fp', rffi.CCallback([_MuCtxPtr, MuID, MuCFP], MuUFPValue)),
    ('handle_to_sint8', rffi.CCallback([_MuCtxPtr, MuIntValue], rffi.CHAR)),
    ('handle_to_uint8', rffi.CCallback([_MuCtxPtr, MuIntValue], rffi.UCHAR)),
    ('handle_to_sint16', rffi.CCallback([_MuCtxPtr, MuIntValue], rffi.SHORT)),
    ('handle_to_uint16', rffi.CCallback([_MuCtxPtr, MuIntValue], rffi.USHORT)),
    ('handle_to_sint32', rffi.CCallback([_MuCtxPtr, MuIntValue], rffi.INT)),
    ('handle_to_uint32', rffi.CCallback([_MuCtxPtr, MuIntValue], rffi.UINT)),
    ('handle_to_sint64', rffi.CCallback([_MuCtxPtr, MuIntValue], rffi.LONG)),
    ('handle_to_uint64', rffi.CCallback([_MuCtxPtr, MuIntValue], rffi.ULONG)),
    ('handle_to_float', rffi.CCallback([_MuCtxPtr, MuFloatValue], rffi.FLOAT)),
1591
1592
    ('handle_to_double', rffi.CCallback(
        [_MuCtxPtr, MuDoubleValue], rffi.DOUBLE)),
John Zhang's avatar
John Zhang committed
1593
1594
1595
1596
1597
1598
1599
    ('handle_to_ptr', rffi.CCallback([_MuCtxPtr, MuUPtrValue], MuCPtr)),
    ('handle_to_fp', rffi.CCallback([_MuCtxPtr, MuUFPValue], MuCFP)),
    ('handle_from_const', rffi.CCallback([_MuCtxPtr, MuID], MuValue)),
    ('handle_from_global', rffi.CCallback([_MuCtxPtr, MuID], MuIRefValue)),
    ('handle_from_func', rffi.CCallback([_MuCtxPtr, MuID], MuFuncRefValue)),
    ('handle_from_expose', rffi.CCallback([_MuCtxPtr, MuID], MuValue)),
    ('delete_value', rffi.CCallback([_MuCtxPtr, MuValue], lltype.Void)),
1600
1601
    ('ref_eq', rffi.CCallback(
        [_MuCtxPtr, MuGenRefValue, MuGenRefValue], MuBool)),
John Zhang's avatar
John Zhang committed
1602
    ('ref_ult', rffi.CCallback([_MuCtxPtr, MuIRefValue, MuIRefValue], MuBool)),
1603
1604
1605
1606
1607
1608
1609
1610
    ('extract_value', rffi.CCallback(
        [_MuCtxPtr, MuStructValue, rffi.INT], MuValue)),
    ('insert_value', rffi.CCallback(
        [_MuCtxPtr, MuStructValue, rffi.INT, MuValue], MuStructValue)),
    ('extract_element', rffi.CCallback(
        [_MuCtxPtr, MuSeqValue, MuIntValue], MuValue)),
    ('insert_element', rffi.CCallback(
        [_MuCtxPtr, MuSeqValue, MuIntValue, MuValue], MuSeqValue)),
John Zhang's avatar
John Zhang committed
1611
1612
    ('new_fixed', rffi.CCallback([_MuCtxPtr, MuID], MuRefValue)),
    ('new_hybrid', rffi.CCallback([_MuCtxPtr, MuID, MuIntValue], MuRefValue)),
1613
1614
    ('refcast', rffi.CCallback(
        [_MuCtxPtr, MuGenRefValue, MuID], MuGenRefValue)),
John Zhang's avatar
John Zhang committed
1615
    ('get_iref', rffi.CCallback([_MuCtxPtr, MuRefValue], MuIRefValue)),
1616
1617
1618
1619
1620
1621
1622
1623
    ('get_field_iref', rffi.CCallback(
        [_MuCtxPtr, MuIRefValue, rffi.INT], MuIRefValue)),
    ('get_elem_iref', rffi.CCallback(
        [_MuCtxPtr, MuIRefValue, MuIntValue], MuIRefValue)),
    ('shift_iref', rffi.CCallback(
        [_MuCtxPtr, MuIRefValue, MuIntValue], MuIRefValue)),
    ('get_var_part_iref', rffi.CCallback(
        [_MuCtxPtr, MuIRefValue], MuIRefValue)),
John Zhang's avatar
John Zhang committed
1624
    ('load', rffi.CCallback([_MuCtxPtr, MuFlag, MuIRefValue], MuValue)),
1625
1626
1627
1628
1629
1630
    ('store', rffi.CCallback(
        [_MuCtxPtr, MuFlag, MuIRefValue, MuValue], lltype.Void)),
    ('cmpxchg', rffi.CCallback([_MuCtxPtr, MuFlag, MuFlag,
                                MuBool, MuIRefValue, MuValue, MuValue, MuBoolPtr], MuValue)),
    ('atomicrmw', rffi.CCallback(
        [_MuCtxPtr, MuFlag, MuFlag, MuIRefValue, MuValue], MuValue)),
John Zhang's avatar
John Zhang committed
1631
    ('fence', rffi.CCallback([_MuCtxPtr, MuFlag], lltype.Void)),
1632
1633
1634
1635
1636
1637
    ('new_stack', rffi.CCallback(
        [_MuCtxPtr, MuFuncRefValue], MuStackRefValue)),
    ('new_thread_nor', rffi.CCallback(
        [_MuCtxPtr, MuStackRefValue, MuRefValue, MuValuePtr, MuArraySize], MuThreadRefValue)),
    ('new_thread_exc', rffi.CCallback(
        [_MuCtxPtr, MuStackRefValue, MuRefValue, MuRefValue], MuThreadRefValue)),
John Zhang's avatar
John Zhang committed
1638
    ('kill_stack', rffi.CCallback([_MuCtxPtr, MuStackRefValue], lltype.Void)),
1639
1640
1641
1642
    ('set_threadlocal', rffi.CCallback(
        [_MuCtxPtr, MuThreadRefValue, MuRefValue], lltype.Void)),
    ('get_threadlocal', rffi.CCallback(
        [_MuCtxPtr, MuThreadRefValue], MuRefValue)),
John Zhang's avatar
John Zhang committed
1643
1644
1645
1646
1647
1648
1649
    ('new_cursor', rffi.CCallback([_MuCtxPtr, MuStackRefValue], MuFCRefValue)),
    ('next_frame', rffi.CCallback([_MuCtxPtr, MuFCRefValue], lltype.Void)),
    ('copy_cursor', rffi.CCallback([_MuCtxPtr, MuFCRefValue], MuFCRefValue)),
    ('close_cursor', rffi.CCallback([_MuCtxPtr, MuFCRefValue], lltype.Void)),
    ('cur_func', rffi.CCallback([_MuCtxPtr, MuFCRefValue], MuID)),
    ('cur_func_ver', rffi.CCallback([_MuCtxPtr, MuFCRefValue], MuID)),
    ('cur_inst', rffi.CCallback([_MuCtxPtr, MuFCRefValue], MuID)),
1650
1651
    ('dump_keepalives', rffi.CCallback(
        [_MuCtxPtr, MuFCRefValue, MuValuePtr], lltype.Void)),
John Zhang's avatar
John Zhang committed
1652
    ('pop_frames_to', rffi.CCallback([_MuCtxPtr, MuFCRefValue], lltype.Void)),
1653
1654
    ('push_frame', rffi.CCallback(
        [_MuCtxPtr, MuStackRefValue, MuFuncRefValue], lltype.Void)),
John Zhang's avatar
John Zhang committed
1655
1656
1657
    ('tr64_is_fp', rffi.CCallback([_MuCtxPtr, MuTagRef64Value], MuBool)),
    ('tr64_is_int', rffi.CCallback([_MuCtxPtr, MuTagRef64Value], MuBool)),
    ('tr64_is_ref', rffi.CCallback([_MuCtxPtr, MuTagRef64Value], MuBool)),
1658
1659
    ('tr64_to_fp', rffi.CCallback(
        [_MuCtxPtr, MuTagRef64Value], MuDoubleValue)),
John Zhang's avatar
John Zhang committed
1660
1661
1662
    ('tr64_to_int', rffi.CCallback([_MuCtxPtr, MuTagRef64Value], MuIntValue)),
    ('tr64_to_ref', rffi.CCallback([_MuCtxPtr, MuTagRef64Value], MuRefValue)),
    ('tr64_to_tag', rffi.CCallback([_MuCtxPtr, MuTagRef64Value], MuIntValue)),
1663
1664
1665
1666
1667
1668
    ('tr64_from_fp', rffi.CCallback(
        [_MuCtxPtr, MuDoubleValue], MuTagRef64Value)),
    ('tr64_from_int', rffi.CCallback(
        [_MuCtxPtr, MuIntValue], MuTagRef64Value)),
    ('tr64_from_ref', rffi.CCallback(
        [_MuCtxPtr, MuRefValue, MuIntValue], MuTagRef64Value)),
John Zhang's avatar
John Zhang committed
1669
1670
1671
1672
1673
    ('enable_watchpoint', rffi.CCallback([_MuCtxPtr, MuWPID], lltype.Void)),
    ('disable_watchpoint', rffi.CCallback([_MuCtxPtr, MuWPID], lltype.Void)),
    ('pin', rffi.CCallback([_MuCtxPtr, MuValue], MuUPtrValue)),
    ('unpin', rffi.CCallback([_MuCtxPtr, MuValue], lltype.Void)),
    ('get_addr', rffi.CCallback([_MuCtxPtr, MuValue], MuUPtrValue)),
1674
1675
    ('expose', rffi.CCallback(
        [_MuCtxPtr, MuFuncRefValue, MuFlag, MuIntValue], MuValue)),
John Zhang's avatar
John Zhang committed
1676
1677
    ('unexpose', rffi.CCallback([_MuCtxPtr, MuFlag, MuValue], lltype.Void)),
    ('new_ir_builder', rffi.CCallback([_MuCtxPtr], _MuIRBuilderPtr)),
1678
1679
1680
    ('make_boot_image', rffi.CCallback([_MuCtxPtr, MuIDPtr, MuArraySize, MuFuncRefValue, MuStackRefValue, MuRefValue,
                                        MuIRefValuePtr, MuCStringPtr, MuArraySize, MuIRefValuePtr, MuCStringPtr,
                                        MuArraySize, MuCString], lltype.Void)),
John Zhang's avatar
John Zhang committed
1681
1682
1683
1684
1685
1686
1687
))
_MuIRBuilder.become(rffi.CStruct(
    'MuIRBuilder',
    ('header', rffi.VOIDP),
    ('load', rffi.CCallback([_MuIRBuilderPtr], lltype.Void)),
    ('abort', rffi.CCallback([_MuIRBuilderPtr], lltype.Void)),
    ('gen_sym', rffi.CCallback([_MuIRBuilderPtr, MuCString], MuID)),
1688
1689
    ('new_type_int', rffi.CCallback(
        [_MuIRBuilderPtr, MuID, rffi.INT],