Best Python code snippet using fMBT_python
rmu_genc.py
Source:rmu_genc.py
1"""2Mu API RPython binding with C backend.3This file is auto-generated and then added a few minor modifications.4NOTE: THIS FILE IS *NOT* RPYTHON.5"""6from rpython.rtyper.lltypesystem import rffi7from rpython.rtyper.lltypesystem import lltype8class CCall(object):9 __slots__ = ('fnc_name', 'args', 'rtn_var', 'context', 'check_err')10 def __init__(self, fnc_name, args, rtn_var, context=None, check_err=True):11 self.fnc_name = fnc_name12 self.args = args13 self.rtn_var = rtn_var14 self.context = context15 self.check_err = check_err16 def __str__(self):17 s = '{rtn_stm}{ctx}{fnc}({arg_lst})'.format(rtn_stm='%s = ' % self.rtn_var if self.rtn_var else '',18 fnc=self.fnc_name,19 arg_lst=', '.join(map(str, self.args)),20 ctx='%s->' % self.context if self.context else '')21 if self.check_err:22 s = "CHECK(%s)" % s23 else:24 s = s + ";"25 return s26 __repr__ = __str__27class CStr(object):28 __slots__ = ('string', )29 def __init__(self, string):30 self.string = string31 def __str__(self):32 return '"%s"' % self.string33 def __len__(self):34 return len(self.string) - self.string.count('\\n')35 __repr__ = __str__36NULL = 'NULL'37class CArrayConst(object):38 def __init__(self, c_elm_t, lst):39 self.c_elm_t = c_elm_t40 self.lst = lst41 def __str__(self):42 if self.c_elm_t == 'MuCString':43 return '({type}){value}'.format(type='char*[]',44 value='{%s}' % ', '.join(map(lambda s: "&%s" % CStr(s), self.lst)))45 else:46 return '({type}){value}'.format(type='%s [%d]' % (self.c_elm_t, len(self.lst)),47 value='{%s}' % ', '.join(map(str, self.lst)))48 __repr__ = __str__49class CVar(object):50 __slots__ = ('type', 'name')51 _name_dic = {}52 @staticmethod53 def new_name(base='var'):54 nd = CVar._name_dic55 if base in nd:56 count = nd[base]57 nd[base] += 158 return '%(base)s_%(count)d' % locals()59 else:60 count = 261 nd[base] = count62 return base63 def __init__(self, c_type, var_name=None):64 self.type = c_type65 if var_name:66 self.name = CVar.new_name(var_name)67 else:68 self.name = CVar.new_name()69 def __str__(self):70 return self.name71 def decl(self):72 return '%s %s;' % (self.type, self.name)73 __repr__ = __str__74class APILogger:75 def __init__(self):76 self.ccalls = []77 self.decl_vars = []78 def logcall(self, fnc_name, args, rtn_var, context=None, check_err=True):79 self.ccalls.append(CCall(fnc_name, args, rtn_var, context, check_err))80 if rtn_var:81 self.decl_vars.append(rtn_var)82 def clear(self):83 APILogger.__init__(self)84 def genc(self, fp, exitcode=0):85 fp.write('\n'86 '// Compile with flag -std=c99\n'87 '#include <stdio.h>\n'88 '#include <stdlib.h>\n'89 '#include <stdbool.h>\n'90 '#include "muapi.h"\n'91 '#include "refimpl2-start.h"\n')92 fp.write('''93#define CHECK(line) line; \\94 if (*muerrno) {\\95 fprintf(stderr, "Line %d: Error thrown in Mu: %d\\n", \\96 __LINE__, *muerrno); \\97 exit(1); \\98 }\99'''100 )101 fp.write('int main(int argc, char** argv) {\n')102 idt = ' ' * 4103 for var in self.decl_vars:104 fp.write(idt + var.decl() + '\n')105 for ccall in self.ccalls:106 fp.write(idt + '%(ccall)s\n' % locals())107 fp.write(idt + 'return %(exitcode)s;\n' % locals())108 fp.write('}\n')109_apilog = APILogger()110def get_global_apilogger():111 return _apilog112# -------------------------------------------------------------------------------------------------------113# Type definitions114MuValue = rffi.VOIDP115MuValuePtr = rffi.CArrayPtr(MuValue)116MuSeqValue = MuValue117MuSeqValuePtr = rffi.CArrayPtr(MuSeqValue)118MuGenRefValue = MuValue119MuGenRefValuePtr = rffi.CArrayPtr(MuGenRefValue)120MuIntValue = MuValue121MuIntValuePtr = rffi.CArrayPtr(MuIntValue)122MuFloatValue = MuValue123MuFloatValuePtr = rffi.CArrayPtr(MuFloatValue)124MuDoubleValue = MuValue125MuDoubleValuePtr = rffi.CArrayPtr(MuDoubleValue)126MuUPtrValue = MuValue127MuUPtrValuePtr = rffi.CArrayPtr(MuUPtrValue)128MuUFPValue = MuValue129MuUFPValuePtr = rffi.CArrayPtr(MuUFPValue)130MuStructValue = MuValue131MuStructValuePtr = rffi.CArrayPtr(MuStructValue)132MuArrayValue = MuSeqValue133MuArrayValuePtr = rffi.CArrayPtr(MuArrayValue)134MuVectorValue = MuSeqValue135MuVectorValuePtr = rffi.CArrayPtr(MuVectorValue)136MuRefValue = MuGenRefValue137MuRefValuePtr = rffi.CArrayPtr(MuRefValue)138MuIRefValue = MuGenRefValue139MuIRefValuePtr = rffi.CArrayPtr(MuIRefValue)140MuTagRef64Value = MuGenRefValue141MuTagRef64ValuePtr = rffi.CArrayPtr(MuTagRef64Value)142MuFuncRefValue = MuGenRefValue143MuFuncRefValuePtr = rffi.CArrayPtr(MuFuncRefValue)144MuThreadRefValue = MuGenRefValue145MuThreadRefValuePtr = rffi.CArrayPtr(MuThreadRefValue)146MuStackRefValue = MuGenRefValue147MuStackRefValuePtr = rffi.CArrayPtr(MuStackRefValue)148MuFCRefValue = MuGenRefValue149MuFCRefValuePtr = rffi.CArrayPtr(MuFCRefValue)150MuIBRefValue = MuGenRefValue151MuIBRefValuePtr = rffi.CArrayPtr(MuIBRefValue)152MuCString = rffi.CCHARP153MuCStringPtr = rffi.CArrayPtr(MuCString)154MuID = rffi.UINT155MuIDPtr = rffi.CArrayPtr(MuID)156MuName = MuCString157MuNamePtr = rffi.CArrayPtr(MuName)158MuCPtr = rffi.VOIDP159MuCPtrPtr = rffi.CArrayPtr(MuCPtr)160MuCFP = rffi.VOIDP161MuCFPPtr = rffi.CArrayPtr(MuCFP)162MuBool = rffi.INT163MuBoolPtr = rffi.CArrayPtr(MuBool)164MuArraySize = rffi.UINTPTR_T165MuArraySizePtr = rffi.CArrayPtr(MuArraySize)166MuWPID = rffi.UINT167MuWPIDPtr = rffi.CArrayPtr(MuWPID)168MuFlag = rffi.UINT169MuFlagPtr = rffi.CArrayPtr(MuFlag)170MuTrapHandlerResult = MuFlag171MuTrapHandlerResultPtr = rffi.CArrayPtr(MuTrapHandlerResult)172MuBinOpStatus = MuFlag173MuBinOpStatusPtr = rffi.CArrayPtr(MuBinOpStatus)174MuTypeNode = MuID175MuTypeNodePtr = rffi.CArrayPtr(MuTypeNode)176MuFuncSigNode = MuID177MuFuncSigNodePtr = rffi.CArrayPtr(MuFuncSigNode)178MuVarNode = MuID179MuVarNodePtr = rffi.CArrayPtr(MuVarNode)180MuGlobalVarNode = MuID181MuGlobalVarNodePtr = rffi.CArrayPtr(MuGlobalVarNode)182MuLocalVarNode = MuID183MuLocalVarNodePtr = rffi.CArrayPtr(MuLocalVarNode)184MuConstNode = MuID185MuConstNodePtr = rffi.CArrayPtr(MuConstNode)186MuFuncNode = MuID187MuFuncNodePtr = rffi.CArrayPtr(MuFuncNode)188MuFuncVerNode = MuID189MuFuncVerNodePtr = rffi.CArrayPtr(MuFuncVerNode)190MuBBNode = MuID191MuBBNodePtr = rffi.CArrayPtr(MuBBNode)192MuInstNode = MuID193MuInstNodePtr = rffi.CArrayPtr(MuInstNode)194MuDestClause = MuID195MuDestClausePtr = rffi.CArrayPtr(MuDestClause)196MuExcClause = MuID197MuExcClausePtr = rffi.CArrayPtr(MuExcClause)198MuKeepaliveClause = MuID199MuKeepaliveClausePtr = rffi.CArrayPtr(MuKeepaliveClause)200MuCurStackClause = MuID201MuCurStackClausePtr = rffi.CArrayPtr(MuCurStackClause)202MuNewStackClause = MuID203MuNewStackClausePtr = rffi.CArrayPtr(MuNewStackClause)204_MuVM = lltype.ForwardReference()205_MuVMPtr = lltype.Ptr(_MuVM)206_MuCtx = lltype.ForwardReference()207_MuCtxPtr = lltype.Ptr(_MuCtx)208_MuIRBuilder = lltype.ForwardReference()209_MuIRBuilderPtr = lltype.Ptr(_MuIRBuilder)210MuValuesFreer = rffi.CCallback([MuValuePtr, MuCPtr], lltype.Void)211MuValuesFreerPtr = rffi.CArrayPtr(MuValuesFreer)212MuTrapHandler = rffi.CCallback([213 _MuCtxPtr, MuThreadRefValue, MuStackRefValue, MuWPID, # input214 MuTrapHandlerResultPtr, MuStackRefValuePtr, rffi.CArray(MuValuePtr), MuArraySizePtr,215 MuValuesFreerPtr, MuCPtrPtr, MuRefValuePtr, # output216 MuCPtr #input217], lltype.Void)218MuTrapHandlerPtr = rffi.CArrayPtr(MuTrapHandler)219# -------------------------------------------------------------------------------------------------------220# Flags221class MuTrapHandlerResult:222 THREAD_EXIT = "MU_THREAD_EXIT"223 REBIND_PASS_VALUES = "MU_REBIND_PASS_VALUES"224 REBIND_THROW_EXC = "MU_REBIND_THROW_EXC"225class MuBinOpStatus:226 N = "MU_BOS_N"227 Z = "MU_BOS_Z"228 C = "MU_BOS_C"229 V = "MU_BOS_V"230class MuBinOptr:231 ADD = "MU_BINOP_ADD"232 SUB = "MU_BINOP_SUB"233 MUL = "MU_BINOP_MUL"234 SDIV = "MU_BINOP_SDIV"235 SREM = "MU_BINOP_SREM"236 UDIV = "MU_BINOP_UDIV"237 UREM = "MU_BINOP_UREM"238 SHL = "MU_BINOP_SHL"239 LSHR = "MU_BINOP_LSHR"240 ASHR = "MU_BINOP_ASHR"241 AND = "MU_BINOP_AND"242 OR = "MU_BINOP_OR"243 XOR = "MU_BINOP_XOR"244 FADD = "MU_BINOP_FADD"245 FSUB = "MU_BINOP_FSUB"246 FMUL = "MU_BINOP_FMUL"247 FDIV = "MU_BINOP_FDIV"248 FREM = "MU_BINOP_FREM"249class MuCmpOptr:250 EQ = "MU_CMP_EQ"251 NE = "MU_CMP_NE"252 SGE = "MU_CMP_SGE"253 SGT = "MU_CMP_SGT"254 SLE = "MU_CMP_SLE"255 SLT = "MU_CMP_SLT"256 UGE = "MU_CMP_UGE"257 UGT = "MU_CMP_UGT"258 ULE = "MU_CMP_ULE"259 ULT = "MU_CMP_ULT"260 FFALSE = "MU_CMP_FFALSE"261 FTRUE = "MU_CMP_FTRUE"262 FUNO = "MU_CMP_FUNO"263 FUEQ = "MU_CMP_FUEQ"264 FUNE = "MU_CMP_FUNE"265 FUGT = "MU_CMP_FUGT"266 FUGE = "MU_CMP_FUGE"267 FULT = "MU_CMP_FULT"268 FULE = "MU_CMP_FULE"269 FORD = "MU_CMP_FORD"270 FOEQ = "MU_CMP_FOEQ"271 FONE = "MU_CMP_FONE"272 FOGT = "MU_CMP_FOGT"273 FOGE = "MU_CMP_FOGE"274 FOLT = "MU_CMP_FOLT"275 FOLE = "MU_CMP_FOLE"276class MuConvOptr:277 TRUNC = "MU_CONV_TRUNC"278 ZEXT = "MU_CONV_ZEXT"279 SEXT = "MU_CONV_SEXT"280 FPTRUNC = "MU_CONV_FPTRUNC"281 FPEXT = "MU_CONV_FPEXT"282 FPTOUI = "MU_CONV_FPTOUI"283 FPTOSI = "MU_CONV_FPTOSI"284 UITOFP = "MU_CONV_UITOFP"285 SITOFP = "MU_CONV_SITOFP"286 BITCAST = "MU_CONV_BITCAST"287 REFCAST = "MU_CONV_REFCAST"288 PTRCAST = "MU_CONV_PTRCAST"289class MuMemOrd:290 NOT_ATOMIC = "MU_ORD_NOT_ATOMIC"291 RELAXED = "MU_ORD_RELAXED"292 CONSUME = "MU_ORD_CONSUME"293 ACQUIRE = "MU_ORD_ACQUIRE"294 RELEASE = "MU_ORD_RELEASE"295 ACQ_REL = "MU_ORD_ACQ_REL"296 SEQ_CST = "MU_ORD_SEQ_CST"297class MuAtomicRMWOptr:298 XCHG = "MU_ARMW_XCHG"299 ADD = "MU_ARMW_ADD"300 SUB = "MU_ARMW_SUB"301 AND = "MU_ARMW_AND"302 NAND = "MU_ARMW_NAND"303 OR = "MU_ARMW_OR"304 XOR = "MU_ARMW_XOR"305 MAX = "MU_ARMW_MAX"306 MIN = "MU_ARMW_MIN"307 UMAX = "MU_ARMW_UMAX"308 UMIN = "MU_ARMW_UMIN"309class MuCallConv:310 DEFAULT = "MU_CC_DEFAULT"311class MuCommInst:312 NEW_STACK = "MU_CI_UVM_NEW_STACK"313 KILL_STACK = "MU_CI_UVM_KILL_STACK"314 THREAD_EXIT = "MU_CI_UVM_THREAD_EXIT"315 CURRENT_STACK = "MU_CI_UVM_CURRENT_STACK"316 SET_THREADLOCAL = "MU_CI_UVM_SET_THREADLOCAL"317 GET_THREADLOCAL = "MU_CI_UVM_GET_THREADLOCAL"318 TR64_IS_FP = "MU_CI_UVM_TR64_IS_FP"319 TR64_IS_INT = "MU_CI_UVM_TR64_IS_INT"320 TR64_IS_REF = "MU_CI_UVM_TR64_IS_REF"321 TR64_FROM_FP = "MU_CI_UVM_TR64_FROM_FP"322 TR64_FROM_INT = "MU_CI_UVM_TR64_FROM_INT"323 TR64_FROM_REF = "MU_CI_UVM_TR64_FROM_REF"324 TR64_TO_FP = "MU_CI_UVM_TR64_TO_FP"325 TR64_TO_INT = "MU_CI_UVM_TR64_TO_INT"326 TR64_TO_REF = "MU_CI_UVM_TR64_TO_REF"327 TR64_TO_TAG = "MU_CI_UVM_TR64_TO_TAG"328 FUTEX_WAIT = "MU_CI_UVM_FUTEX_WAIT"329 FUTEX_WAIT_TIMEOUT = "MU_CI_UVM_FUTEX_WAIT_TIMEOUT"330 FUTEX_WAKE = "MU_CI_UVM_FUTEX_WAKE"331 FUTEX_CMP_REQUEUE = "MU_CI_UVM_FUTEX_CMP_REQUEUE"332 KILL_DEPENDENCY = "MU_CI_UVM_KILL_DEPENDENCY"333 NATIVE_PIN = "MU_CI_UVM_NATIVE_PIN"334 NATIVE_UNPIN = "MU_CI_UVM_NATIVE_UNPIN"335 NATIVE_GET_ADDR = "MU_CI_UVM_NATIVE_GET_ADDR"336 NATIVE_EXPOSE = "MU_CI_UVM_NATIVE_EXPOSE"337 NATIVE_UNEXPOSE = "MU_CI_UVM_NATIVE_UNEXPOSE"338 NATIVE_GET_COOKIE = "MU_CI_UVM_NATIVE_GET_COOKIE"339 META_ID_OF = "MU_CI_UVM_META_ID_OF"340 META_NAME_OF = "MU_CI_UVM_META_NAME_OF"341 META_LOAD_BUNDLE = "MU_CI_UVM_META_LOAD_BUNDLE"342 META_LOAD_HAIL = "MU_CI_UVM_META_LOAD_HAIL"343 META_NEW_CURSOR = "MU_CI_UVM_META_NEW_CURSOR"344 META_NEXT_FRAME = "MU_CI_UVM_META_NEXT_FRAME"345 META_COPY_CURSOR = "MU_CI_UVM_META_COPY_CURSOR"346 META_CLOSE_CURSOR = "MU_CI_UVM_META_CLOSE_CURSOR"347 META_CUR_FUNC = "MU_CI_UVM_META_CUR_FUNC"348 META_CUR_FUNC_VER = "MU_CI_UVM_META_CUR_FUNC_VER"349 META_CUR_INST = "MU_CI_UVM_META_CUR_INST"350 META_DUMP_KEEPALIVES = "MU_CI_UVM_META_DUMP_KEEPALIVES"351 META_POP_FRAMES_TO = "MU_CI_UVM_META_POP_FRAMES_TO"352 META_PUSH_FRAME = "MU_CI_UVM_META_PUSH_FRAME"353 META_ENABLE_WATCHPOINT = "MU_CI_UVM_META_ENABLE_WATCHPOINT"354 META_DISABLE_WATCHPOINT = "MU_CI_UVM_META_DISABLE_WATCHPOINT"355 META_SET_TRAP_HANDLER = "MU_CI_UVM_META_SET_TRAP_HANDLER"356 IRBUILDER_NEW_IR_BUILDER = "MU_CI_UVM_IRBUILDER_NEW_IR_BUILDER"357 IRBUILDER_LOAD = "MU_CI_UVM_IRBUILDER_LOAD"358 IRBUILDER_ABORT = "MU_CI_UVM_IRBUILDER_ABORT"359 IRBUILDER_GEN_SYM = "MU_CI_UVM_IRBUILDER_GEN_SYM"360 IRBUILDER_NEW_TYPE_INT = "MU_CI_UVM_IRBUILDER_NEW_TYPE_INT"361 IRBUILDER_NEW_TYPE_FLOAT = "MU_CI_UVM_IRBUILDER_NEW_TYPE_FLOAT"362 IRBUILDER_NEW_TYPE_DOUBLE = "MU_CI_UVM_IRBUILDER_NEW_TYPE_DOUBLE"363 IRBUILDER_NEW_TYPE_UPTR = "MU_CI_UVM_IRBUILDER_NEW_TYPE_UPTR"364 IRBUILDER_NEW_TYPE_UFUNCPTR = "MU_CI_UVM_IRBUILDER_NEW_TYPE_UFUNCPTR"365 IRBUILDER_NEW_TYPE_STRUCT = "MU_CI_UVM_IRBUILDER_NEW_TYPE_STRUCT"366 IRBUILDER_NEW_TYPE_HYBRID = "MU_CI_UVM_IRBUILDER_NEW_TYPE_HYBRID"367 IRBUILDER_NEW_TYPE_ARRAY = "MU_CI_UVM_IRBUILDER_NEW_TYPE_ARRAY"368 IRBUILDER_NEW_TYPE_VECTOR = "MU_CI_UVM_IRBUILDER_NEW_TYPE_VECTOR"369 IRBUILDER_NEW_TYPE_VOID = "MU_CI_UVM_IRBUILDER_NEW_TYPE_VOID"370 IRBUILDER_NEW_TYPE_REF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_REF"371 IRBUILDER_NEW_TYPE_IREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_IREF"372 IRBUILDER_NEW_TYPE_WEAKREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_WEAKREF"373 IRBUILDER_NEW_TYPE_FUNCREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_FUNCREF"374 IRBUILDER_NEW_TYPE_TAGREF64 = "MU_CI_UVM_IRBUILDER_NEW_TYPE_TAGREF64"375 IRBUILDER_NEW_TYPE_THREADREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_THREADREF"376 IRBUILDER_NEW_TYPE_STACKREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_STACKREF"377 IRBUILDER_NEW_TYPE_FRAMECURSORREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_FRAMECURSORREF"378 IRBUILDER_NEW_TYPE_IRBUILDERREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_IRBUILDERREF"379 IRBUILDER_NEW_FUNCSIG = "MU_CI_UVM_IRBUILDER_NEW_FUNCSIG"380 IRBUILDER_NEW_CONST_INT = "MU_CI_UVM_IRBUILDER_NEW_CONST_INT"381 IRBUILDER_NEW_CONST_INT_EX = "MU_CI_UVM_IRBUILDER_NEW_CONST_INT_EX"382 IRBUILDER_NEW_CONST_FLOAT = "MU_CI_UVM_IRBUILDER_NEW_CONST_FLOAT"383 IRBUILDER_NEW_CONST_DOUBLE = "MU_CI_UVM_IRBUILDER_NEW_CONST_DOUBLE"384 IRBUILDER_NEW_CONST_NULL = "MU_CI_UVM_IRBUILDER_NEW_CONST_NULL"385 IRBUILDER_NEW_CONST_SEQ = "MU_CI_UVM_IRBUILDER_NEW_CONST_SEQ"386 IRBUILDER_NEW_CONST_EXTERN = "MU_CI_UVM_IRBUILDER_NEW_CONST_EXTERN"387 IRBUILDER_NEW_GLOBAL_CELL = "MU_CI_UVM_IRBUILDER_NEW_GLOBAL_CELL"388 IRBUILDER_NEW_FUNC = "MU_CI_UVM_IRBUILDER_NEW_FUNC"389 IRBUILDER_NEW_EXP_FUNC = "MU_CI_UVM_IRBUILDER_NEW_EXP_FUNC"390 IRBUILDER_NEW_FUNC_VER = "MU_CI_UVM_IRBUILDER_NEW_FUNC_VER"391 IRBUILDER_NEW_BB = "MU_CI_UVM_IRBUILDER_NEW_BB"392 IRBUILDER_NEW_DEST_CLAUSE = "MU_CI_UVM_IRBUILDER_NEW_DEST_CLAUSE"393 IRBUILDER_NEW_EXC_CLAUSE = "MU_CI_UVM_IRBUILDER_NEW_EXC_CLAUSE"394 IRBUILDER_NEW_KEEPALIVE_CLAUSE = "MU_CI_UVM_IRBUILDER_NEW_KEEPALIVE_CLAUSE"395 IRBUILDER_NEW_CSC_RET_WITH = "MU_CI_UVM_IRBUILDER_NEW_CSC_RET_WITH"396 IRBUILDER_NEW_CSC_KILL_OLD = "MU_CI_UVM_IRBUILDER_NEW_CSC_KILL_OLD"397 IRBUILDER_NEW_NSC_PASS_VALUES = "MU_CI_UVM_IRBUILDER_NEW_NSC_PASS_VALUES"398 IRBUILDER_NEW_NSC_THROW_EXC = "MU_CI_UVM_IRBUILDER_NEW_NSC_THROW_EXC"399 IRBUILDER_NEW_BINOP = "MU_CI_UVM_IRBUILDER_NEW_BINOP"400 IRBUILDER_NEW_BINOP_WITH_STATUS = "MU_CI_UVM_IRBUILDER_NEW_BINOP_WITH_STATUS"401 IRBUILDER_NEW_CMP = "MU_CI_UVM_IRBUILDER_NEW_CMP"402 IRBUILDER_NEW_CONV = "MU_CI_UVM_IRBUILDER_NEW_CONV"403 IRBUILDER_NEW_SELECT = "MU_CI_UVM_IRBUILDER_NEW_SELECT"404 IRBUILDER_NEW_BRANCH = "MU_CI_UVM_IRBUILDER_NEW_BRANCH"405 IRBUILDER_NEW_BRANCH2 = "MU_CI_UVM_IRBUILDER_NEW_BRANCH2"406 IRBUILDER_NEW_SWITCH = "MU_CI_UVM_IRBUILDER_NEW_SWITCH"407 IRBUILDER_NEW_CALL = "MU_CI_UVM_IRBUILDER_NEW_CALL"408 IRBUILDER_NEW_TAILCALL = "MU_CI_UVM_IRBUILDER_NEW_TAILCALL"409 IRBUILDER_NEW_RET = "MU_CI_UVM_IRBUILDER_NEW_RET"410 IRBUILDER_NEW_THROW = "MU_CI_UVM_IRBUILDER_NEW_THROW"411 IRBUILDER_NEW_EXTRACTVALUE = "MU_CI_UVM_IRBUILDER_NEW_EXTRACTVALUE"412 IRBUILDER_NEW_INSERTVALUE = "MU_CI_UVM_IRBUILDER_NEW_INSERTVALUE"413 IRBUILDER_NEW_EXTRACTELEMENT = "MU_CI_UVM_IRBUILDER_NEW_EXTRACTELEMENT"414 IRBUILDER_NEW_INSERTELEMENT = "MU_CI_UVM_IRBUILDER_NEW_INSERTELEMENT"415 IRBUILDER_NEW_SHUFFLEVECTOR = "MU_CI_UVM_IRBUILDER_NEW_SHUFFLEVECTOR"416 IRBUILDER_NEW_NEW = "MU_CI_UVM_IRBUILDER_NEW_NEW"417 IRBUILDER_NEW_NEWHYBRID = "MU_CI_UVM_IRBUILDER_NEW_NEWHYBRID"418 IRBUILDER_NEW_ALLOCA = "MU_CI_UVM_IRBUILDER_NEW_ALLOCA"419 IRBUILDER_NEW_ALLOCAHYBRID = "MU_CI_UVM_IRBUILDER_NEW_ALLOCAHYBRID"420 IRBUILDER_NEW_GETIREF = "MU_CI_UVM_IRBUILDER_NEW_GETIREF"421 IRBUILDER_NEW_GETFIELDIREF = "MU_CI_UVM_IRBUILDER_NEW_GETFIELDIREF"422 IRBUILDER_NEW_GETELEMIREF = "MU_CI_UVM_IRBUILDER_NEW_GETELEMIREF"423 IRBUILDER_NEW_SHIFTIREF = "MU_CI_UVM_IRBUILDER_NEW_SHIFTIREF"424 IRBUILDER_NEW_GETVARPARTIREF = "MU_CI_UVM_IRBUILDER_NEW_GETVARPARTIREF"425 IRBUILDER_NEW_LOAD = "MU_CI_UVM_IRBUILDER_NEW_LOAD"426 IRBUILDER_NEW_STORE = "MU_CI_UVM_IRBUILDER_NEW_STORE"427 IRBUILDER_NEW_CMPXCHG = "MU_CI_UVM_IRBUILDER_NEW_CMPXCHG"428 IRBUILDER_NEW_ATOMICRMW = "MU_CI_UVM_IRBUILDER_NEW_ATOMICRMW"429 IRBUILDER_NEW_FENCE = "MU_CI_UVM_IRBUILDER_NEW_FENCE"430 IRBUILDER_NEW_TRAP = "MU_CI_UVM_IRBUILDER_NEW_TRAP"431 IRBUILDER_NEW_WATCHPOINT = "MU_CI_UVM_IRBUILDER_NEW_WATCHPOINT"432 IRBUILDER_NEW_WPBRANCH = "MU_CI_UVM_IRBUILDER_NEW_WPBRANCH"433 IRBUILDER_NEW_CCALL = "MU_CI_UVM_IRBUILDER_NEW_CCALL"434 IRBUILDER_NEW_NEWTHREAD = "MU_CI_UVM_IRBUILDER_NEW_NEWTHREAD"435 IRBUILDER_NEW_SWAPSTACK = "MU_CI_UVM_IRBUILDER_NEW_SWAPSTACK"436 IRBUILDER_NEW_COMMINST = "MU_CI_UVM_IRBUILDER_NEW_COMMINST"437 EXT_PRINT_STATS = "MU_CI_UVM_EXT_PRINT_STATS"438 EXT_CLEAR_STATS = "MU_CI_UVM_EXT_CLEAR_STATS"439MU_NO_ID = "MU_NO_ID"440# -------------------------------------------------------------------------------------------------------441# OO wrappers442class MuVM:443 def __init__(self, config_str=""):444 self._mu = CVar('MuVM*', 'mu')445 _apilog.logcall('mu_refimpl2_new_ex', [CStr(config_str)], self._mu, check_err=False)446 muerrno = CVar('int*', 'muerrno')447 _apilog.logcall('get_mu_error_ptr', [self._mu], muerrno, self._mu, check_err=False)448 def new_context(self):449 # type: () -> MuCtx450 res_var = CVar('MuCtx*', 'ctx')451 _apilog.logcall('new_context', [self._mu], res_var, self._mu)452 return MuCtx(res_var)453 def id_of(self, name):454 # type: (str) -> MuID455 name_cstr = CStr(name) if name else NULL456 res_var = CVar('MuID', 'id')457 _apilog.logcall('id_of', [self._mu, name_cstr], res_var, self._mu)458 return res_var459 def name_of(self, id):460 # type: (MuID) -> str461 # NOTE: runtime dependent method, the return value should not be examined in Python.462 res_var = CVar('MuName', 'var')463 _apilog.logcall('name_of', [self._mu, id], res_var, self._mu)464 return res_var465 def set_trap_handler(self, trap_handler, userdata):466 # type: (MuTrapHandler, MuCPtr) -> None467 _apilog.logcall('set_trap_handler', [self._mu, trap_handler, userdata], None, self._mu)468 def execute(self):469 # type: () -> None470 _apilog.logcall('execute', [self._mu], None, self._mu)471 def get_mu_error_ptr(self):472 # type: () -> rffi.INTP473 res_var = CVar('int*', 'var')474 _apilog.logcall('get_mu_error_ptr', [self._mu], res_var, self._mu)475 return res_var476 def close(self):477 _apilog.logcall('mu_refimpl2_close', [self._mu], None)478class MuCtx:479 def __init__(self, ctx_var):480 self._ctx = ctx_var481 def id_of(self, name):482 # type: (str) -> MuID483 name_cstr = CStr(name) if name else NULL484 res_var = CVar('MuID', 'id')485 _apilog.logcall('id_of', [self._ctx, name_cstr], res_var, self._ctx)486 return res_var487 def name_of(self, id):488 # type: (MuID) -> str489 # NOTE: runtime dependent method, the return value should not be examined in Python.490 res_var = CVar('MuName', 'var')491 _apilog.logcall('name_of', [self._ctx, id], res_var, self._ctx)492 return res_var493 def close_context(self):494 # type: () -> None495 _apilog.logcall('close_context', [self._ctx], None, self._ctx)496 def load_bundle(self, buf):497 # type: (str) -> None498 buf_cstr = CStr(buf) if buf else NULL499 sz = len(buf_cstr)500 _apilog.logcall('load_bundle', [self._ctx, buf_cstr, sz], None, self._ctx)501 def load_hail(self, buf):502 # type: (str) -> None503 buf_cstr = CStr(buf) if buf else NULL504 sz = len(buf_cstr)505 _apilog.logcall('load_hail', [self._ctx, buf_cstr, sz], None, self._ctx)506 def handle_from_sint8(self, num, len):507 # type: (int, int) -> MuIntValue508 res_var = CVar('MuIntValue', 'hintval')509 _apilog.logcall('handle_from_sint8', [self._ctx, num, len], res_var, self._ctx)510 return res_var511 def handle_from_uint8(self, num, len):512 # type: (int, int) -> MuIntValue513 res_var = CVar('MuIntValue', 'hintval')514 _apilog.logcall('handle_from_uint8', [self._ctx, num, len], res_var, self._ctx)515 return res_var516 def handle_from_sint16(self, num, len):517 # type: (int, int) -> MuIntValue518 res_var = CVar('MuIntValue', 'hintval')519 _apilog.logcall('handle_from_sint16', [self._ctx, num, len], res_var, self._ctx)520 return res_var521 def handle_from_uint16(self, num, len):522 # type: (int, int) -> MuIntValue523 res_var = CVar('MuIntValue', 'hintval')524 _apilog.logcall('handle_from_uint16', [self._ctx, num, len], res_var, self._ctx)525 return res_var526 def handle_from_sint32(self, num, len):527 # type: (int, int) -> MuIntValue528 res_var = CVar('MuIntValue', 'hintval')529 _apilog.logcall('handle_from_sint32', [self._ctx, num, len], res_var, self._ctx)530 return res_var531 def handle_from_uint32(self, num, len):532 # type: (int, int) -> MuIntValue533 res_var = CVar('MuIntValue', 'hintval')534 _apilog.logcall('handle_from_uint32', [self._ctx, num, len], res_var, self._ctx)535 return res_var536 def handle_from_sint64(self, num, len):537 # type: (int, int) -> MuIntValue538 res_var = CVar('MuIntValue', 'hintval')539 _apilog.logcall('handle_from_sint64', [self._ctx, num, len], res_var, self._ctx)540 return res_var541 def handle_from_uint64(self, num, len):542 # type: (int, int) -> MuIntValue543 res_var = CVar('MuIntValue', 'hintval')544 _apilog.logcall('handle_from_uint64', [self._ctx, num, len], res_var, self._ctx)545 return res_var546 def handle_from_uint64s(self, nums, len):547 # type: ([rffi.ULONG], int) -> MuIntValue548 nums_arr, nums_sz = lst2arr('uint64_t', nums)549 res_var = CVar('MuIntValue', 'hintval')550 _apilog.logcall('handle_from_uint64s', [self._ctx, nums_arr, nums_sz, len], res_var, self._ctx)551 return res_var552 def handle_from_float(self, num):553 # type: (float) -> MuFloatValue554 num_fltstr = '%.20f' % num555 res_var = CVar('MuFloatValue', 'hfltval')556 _apilog.logcall('handle_from_float', [self._ctx, num_fltstr], res_var, self._ctx)557 return res_var558 def handle_from_double(self, num):559 # type: (float) -> MuDoubleValue560 num_fltstr = '%.20f' % num561 res_var = CVar('MuDoubleValue', 'hdblval')562 _apilog.logcall('handle_from_double', [self._ctx, num_fltstr], res_var, self._ctx)563 return res_var564 def handle_from_ptr(self, mu_type, ptr):565 # type: (MuID, MuCPtr) -> MuUPtrValue566 res_var = CVar('MuUPtrValue', 'huptrval')567 _apilog.logcall('handle_from_ptr', [self._ctx, mu_type, ptr], res_var, self._ctx)568 return res_var569 def handle_from_fp(self, mu_type, fp):570 # type: (MuID, MuCFP) -> MuUFPValue571 res_var = CVar('MuUFPValue', 'hufpval')572 _apilog.logcall('handle_from_fp', [self._ctx, mu_type, fp], res_var, self._ctx)573 return res_var574 def handle_to_sint8(self, opnd):575 # type: (MuIntValue) -> int576 # NOTE: runtime dependent method, the return value should not be examined in Python.577 res_var = CVar('int8_t', 'var')578 _apilog.logcall('handle_to_sint8', [self._ctx, opnd], res_var, self._ctx)579 return res_var580 def handle_to_uint8(self, opnd):581 # type: (MuIntValue) -> int582 # NOTE: runtime dependent method, the return value should not be examined in Python.583 res_var = CVar('uint8_t', 'var')584 _apilog.logcall('handle_to_uint8', [self._ctx, opnd], res_var, self._ctx)585 return res_var586 def handle_to_sint16(self, opnd):587 # type: (MuIntValue) -> int588 # NOTE: runtime dependent method, the return value should not be examined in Python.589 res_var = CVar('int16_t', 'var')590 _apilog.logcall('handle_to_sint16', [self._ctx, opnd], res_var, self._ctx)591 return res_var592 def handle_to_uint16(self, opnd):593 # type: (MuIntValue) -> int594 # NOTE: runtime dependent method, the return value should not be examined in Python.595 res_var = CVar('uint16_t', 'var')596 _apilog.logcall('handle_to_uint16', [self._ctx, opnd], res_var, self._ctx)597 return res_var598 def handle_to_sint32(self, opnd):599 # type: (MuIntValue) -> int600 # NOTE: runtime dependent method, the return value should not be examined in Python.601 res_var = CVar('int32_t', 'var')602 _apilog.logcall('handle_to_sint32', [self._ctx, opnd], res_var, self._ctx)603 return res_var604 def handle_to_uint32(self, opnd):605 # type: (MuIntValue) -> int606 # NOTE: runtime dependent method, the return value should not be examined in Python.607 res_var = CVar('uint32_t', 'var')608 _apilog.logcall('handle_to_uint32', [self._ctx, opnd], res_var, self._ctx)609 return res_var610 def handle_to_sint64(self, opnd):611 # type: (MuIntValue) -> int612 # NOTE: runtime dependent method, the return value should not be examined in Python.613 res_var = CVar('int64_t', 'var')614 _apilog.logcall('handle_to_sint64', [self._ctx, opnd], res_var, self._ctx)615 return res_var616 def handle_to_uint64(self, opnd):617 # type: (MuIntValue) -> int618 # NOTE: runtime dependent method, the return value should not be examined in Python.619 res_var = CVar('uint64_t', 'var')620 _apilog.logcall('handle_to_uint64', [self._ctx, opnd], res_var, self._ctx)621 return res_var622 def handle_to_float(self, opnd):623 # type: (MuFloatValue) -> float624 # NOTE: runtime dependent method, the return value should not be examined in Python.625 res_var = CVar('float', 'var')626 _apilog.logcall('handle_to_float', [self._ctx, opnd], res_var, self._ctx)627 return res_var628 def handle_to_double(self, opnd):629 # type: (MuDoubleValue) -> float630 # NOTE: runtime dependent method, the return value should not be examined in Python.631 res_var = CVar('double', 'var')632 _apilog.logcall('handle_to_double', [self._ctx, opnd], res_var, self._ctx)633 return res_var634 def handle_to_ptr(self, opnd):635 # type: (MuUPtrValue) -> MuCPtr636 res_var = CVar('MuCPtr', 'var')637 _apilog.logcall('handle_to_ptr', [self._ctx, opnd], res_var, self._ctx)638 return res_var639 def handle_to_fp(self, opnd):640 # type: (MuUFPValue) -> MuCFP641 res_var = CVar('MuCFP', 'var')642 _apilog.logcall('handle_to_fp', [self._ctx, opnd], res_var, self._ctx)643 return res_var644 def handle_from_const(self, id):645 # type: (MuID) -> MuValue646 res_var = CVar('MuValue', 'hdl')647 _apilog.logcall('handle_from_const', [self._ctx, id], res_var, self._ctx)648 return res_var649 def handle_from_global(self, id):650 # type: (MuID) -> MuIRefValue651 res_var = CVar('MuIRefValue', 'hiref')652 _apilog.logcall('handle_from_global', [self._ctx, id], res_var, self._ctx)653 return res_var654 def handle_from_func(self, id):655 # type: (MuID) -> MuFuncRefValue656 res_var = CVar('MuFuncRefValue', 'hfncref')657 _apilog.logcall('handle_from_func', [self._ctx, id], res_var, self._ctx)658 return res_var659 def handle_from_expose(self, id):660 # type: (MuID) -> MuValue661 res_var = CVar('MuValue', 'hdl')662 _apilog.logcall('handle_from_expose', [self._ctx, id], res_var, self._ctx)663 return res_var664 def delete_value(self, opnd):665 # type: (MuValue) -> None666 _apilog.logcall('delete_value', [self._ctx, opnd], None, self._ctx)667 def ref_eq(self, lhs, rhs):668 # type: (MuGenRefValue, MuGenRefValue) -> bool669 # NOTE: runtime dependent method, the return value should not be examined in Python.670 res_var = CVar('MuBool', 'var')671 _apilog.logcall('ref_eq', [self._ctx, lhs, rhs], res_var, self._ctx)672 return res_var673 def ref_ult(self, lhs, rhs):674 # type: (MuIRefValue, MuIRefValue) -> bool675 # NOTE: runtime dependent method, the return value should not be examined in Python.676 res_var = CVar('MuBool', 'var')677 _apilog.logcall('ref_ult', [self._ctx, lhs, rhs], res_var, self._ctx)678 return res_var679 def extract_value(self, str, index):680 # type: (MuStructValue, int) -> MuValue681 res_var = CVar('MuValue', 'hdl')682 _apilog.logcall('extract_value', [self._ctx, str, index], res_var, self._ctx)683 return res_var684 def insert_value(self, str, index, newval):685 # type: (MuStructValue, int, MuValue) -> MuStructValue686 res_var = CVar('MuStructValue', 'hstt')687 _apilog.logcall('insert_value', [self._ctx, str, index, newval], res_var, self._ctx)688 return res_var689 def extract_element(self, str, index):690 # type: (MuSeqValue, MuIntValue) -> MuValue691 res_var = CVar('MuValue', 'hdl')692 _apilog.logcall('extract_element', [self._ctx, str, index], res_var, self._ctx)693 return res_var694 def insert_element(self, str, index, newval):695 # type: (MuSeqValue, MuIntValue, MuValue) -> MuSeqValue696 res_var = CVar('MuSeqValue', 'hseq')697 _apilog.logcall('insert_element', [self._ctx, str, index, newval], res_var, self._ctx)698 return res_var699 def new_fixed(self, mu_type):700 # type: (MuID) -> MuRefValue701 res_var = CVar('MuRefValue', 'href')702 _apilog.logcall('new_fixed', [self._ctx, mu_type], res_var, self._ctx)703 return res_var704 def new_hybrid(self, mu_type, length):705 # type: (MuID, MuIntValue) -> MuRefValue706 res_var = CVar('MuRefValue', 'href')707 _apilog.logcall('new_hybrid', [self._ctx, mu_type, length], res_var, self._ctx)708 return res_var709 def refcast(self, opnd, new_type):710 # type: (MuGenRefValue, MuID) -> MuGenRefValue711 res_var = CVar('MuGenRefValue', 'var')712 _apilog.logcall('refcast', [self._ctx, opnd, new_type], res_var, self._ctx)713 return res_var714 def get_iref(self, opnd):715 # type: (MuRefValue) -> MuIRefValue716 res_var = CVar('MuIRefValue', 'hiref')717 _apilog.logcall('get_iref', [self._ctx, opnd], res_var, self._ctx)718 return res_var719 def get_field_iref(self, opnd, field):720 # type: (MuIRefValue, int) -> MuIRefValue721 res_var = CVar('MuIRefValue', 'hiref')722 _apilog.logcall('get_field_iref', [self._ctx, opnd, field], res_var, self._ctx)723 return res_var724 def get_elem_iref(self, opnd, index):725 # type: (MuIRefValue, MuIntValue) -> MuIRefValue726 res_var = CVar('MuIRefValue', 'hiref')727 _apilog.logcall('get_elem_iref', [self._ctx, opnd, index], res_var, self._ctx)728 return res_var729 def shift_iref(self, opnd, offset):730 # type: (MuIRefValue, MuIntValue) -> MuIRefValue731 res_var = CVar('MuIRefValue', 'hiref')732 _apilog.logcall('shift_iref', [self._ctx, opnd, offset], res_var, self._ctx)733 return res_var734 def get_var_part_iref(self, opnd):735 # type: (MuIRefValue) -> MuIRefValue736 res_var = CVar('MuIRefValue', 'hiref')737 _apilog.logcall('get_var_part_iref', [self._ctx, opnd], res_var, self._ctx)738 return res_var739 def load(self, ord, loc):740 # type: (MuFlag, MuIRefValue) -> MuValue741 res_var = CVar('MuValue', 'hdl')742 _apilog.logcall('load', [self._ctx, ord, loc], res_var, self._ctx)743 return res_var744 def store(self, ord, loc, newval):745 # type: (MuFlag, MuIRefValue, MuValue) -> None746 _apilog.logcall('store', [self._ctx, ord, loc, newval], None, self._ctx)747 def cmpxchg(self, ord_succ, ord_fail, weak, loc, expected, desired, is_succ):748 # type: (MuFlag, MuFlag, bool, MuIRefValue, MuValue, MuValue, MuBoolPtr) -> MuValue749 weak_bool = 'true' if weak else 'false'750 res_var = CVar('MuValue', 'hdl')751 _apilog.logcall('cmpxchg', [self._ctx, ord_succ, ord_fail, weak_bool, loc, expected, desired, is_succ], res_var, self._ctx)752 return res_var753 def atomicrmw(self, ord, op, loc, opnd):754 # type: (MuFlag, MuFlag, MuIRefValue, MuValue) -> MuValue755 res_var = CVar('MuValue', 'hdl')756 _apilog.logcall('atomicrmw', [self._ctx, ord, op, loc, opnd], res_var, self._ctx)757 return res_var758 def fence(self, ord):759 # type: (MuFlag) -> None760 _apilog.logcall('fence', [self._ctx, ord], None, self._ctx)761 def new_stack(self, func):762 # type: (MuFuncRefValue) -> MuStackRefValue763 res_var = CVar('MuStackRefValue', 'hstkref')764 _apilog.logcall('new_stack', [self._ctx, func], res_var, self._ctx)765 return res_var766 def new_thread_nor(self, stack, threadlocal, vals):767 # type: (MuStackRefValue, MuRefValue, [MuValue]) -> MuThreadRefValue768 vals_arr, vals_sz = lst2arr('MuValue', vals)769 res_var = CVar('MuThreadRefValue', 'hthdref')770 _apilog.logcall('new_thread_nor', [self._ctx, stack, threadlocal, vals_arr, vals_sz], res_var, self._ctx)771 return res_var772 def new_thread_exc(self, stack, threadlocal, exc):773 # type: (MuStackRefValue, MuRefValue, MuRefValue) -> MuThreadRefValue774 res_var = CVar('MuThreadRefValue', 'hthdref')775 _apilog.logcall('new_thread_exc', [self._ctx, stack, threadlocal, exc], res_var, self._ctx)776 return res_var777 def kill_stack(self, stack):778 # type: (MuStackRefValue) -> None779 _apilog.logcall('kill_stack', [self._ctx, stack], None, self._ctx)780 def set_threadlocal(self, thread, threadlocal):781 # type: (MuThreadRefValue, MuRefValue) -> None782 _apilog.logcall('set_threadlocal', [self._ctx, thread, threadlocal], None, self._ctx)783 def get_threadlocal(self, thread):784 # type: (MuThreadRefValue) -> MuRefValue785 res_var = CVar('MuRefValue', 'href')786 _apilog.logcall('get_threadlocal', [self._ctx, thread], res_var, self._ctx)787 return res_var788 def new_cursor(self, stack):789 # type: (MuStackRefValue) -> MuFCRefValue790 res_var = CVar('MuFCRefValue', 'hfcr')791 _apilog.logcall('new_cursor', [self._ctx, stack], res_var, self._ctx)792 return res_var793 def next_frame(self, cursor):794 # type: (MuFCRefValue) -> None795 _apilog.logcall('next_frame', [self._ctx, cursor], None, self._ctx)796 def copy_cursor(self, cursor):797 # type: (MuFCRefValue) -> MuFCRefValue798 res_var = CVar('MuFCRefValue', 'hfcr')799 _apilog.logcall('copy_cursor', [self._ctx, cursor], res_var, self._ctx)800 return res_var801 def close_cursor(self, cursor):802 # type: (MuFCRefValue) -> None803 _apilog.logcall('close_cursor', [self._ctx, cursor], None, self._ctx)804 def cur_func(self, cursor):805 # type: (MuFCRefValue) -> MuID806 res_var = CVar('MuID', 'id')807 _apilog.logcall('cur_func', [self._ctx, cursor], res_var, self._ctx)808 return res_var809 def cur_func_ver(self, cursor):810 # type: (MuFCRefValue) -> MuID811 res_var = CVar('MuID', 'id')812 _apilog.logcall('cur_func_ver', [self._ctx, cursor], res_var, self._ctx)813 return res_var814 def cur_inst(self, cursor):815 # type: (MuFCRefValue) -> MuID816 res_var = CVar('MuID', 'id')817 _apilog.logcall('cur_inst', [self._ctx, cursor], res_var, self._ctx)818 return res_var819 def dump_keepalives(self, cursor, results):820 # type: (MuFCRefValue, MuValuePtr) -> None821 _apilog.logcall('dump_keepalives', [self._ctx, cursor, results], None, self._ctx)822 def pop_frames_to(self, cursor):823 # type: (MuFCRefValue) -> None824 _apilog.logcall('pop_frames_to', [self._ctx, cursor], None, self._ctx)825 def push_frame(self, stack, func):826 # type: (MuStackRefValue, MuFuncRefValue) -> None827 _apilog.logcall('push_frame', [self._ctx, stack, func], None, self._ctx)828 def tr64_is_fp(self, value):829 # type: (MuTagRef64Value) -> bool830 # NOTE: runtime dependent method, the return value should not be examined in Python.831 res_var = CVar('MuBool', 'var')832 _apilog.logcall('tr64_is_fp', [self._ctx, value], res_var, self._ctx)833 return res_var834 def tr64_is_int(self, value):835 # type: (MuTagRef64Value) -> bool836 # NOTE: runtime dependent method, the return value should not be examined in Python.837 res_var = CVar('MuBool', 'var')838 _apilog.logcall('tr64_is_int', [self._ctx, value], res_var, self._ctx)839 return res_var840 def tr64_is_ref(self, value):841 # type: (MuTagRef64Value) -> bool842 # NOTE: runtime dependent method, the return value should not be examined in Python.843 res_var = CVar('MuBool', 'var')844 _apilog.logcall('tr64_is_ref', [self._ctx, value], res_var, self._ctx)845 return res_var846 def tr64_to_fp(self, value):847 # type: (MuTagRef64Value) -> MuDoubleValue848 res_var = CVar('MuDoubleValue', 'hdblval')849 _apilog.logcall('tr64_to_fp', [self._ctx, value], res_var, self._ctx)850 return res_var851 def tr64_to_int(self, value):852 # type: (MuTagRef64Value) -> MuIntValue853 res_var = CVar('MuIntValue', 'hintval')854 _apilog.logcall('tr64_to_int', [self._ctx, value], res_var, self._ctx)855 return res_var856 def tr64_to_ref(self, value):857 # type: (MuTagRef64Value) -> MuRefValue858 res_var = CVar('MuRefValue', 'href')859 _apilog.logcall('tr64_to_ref', [self._ctx, value], res_var, self._ctx)860 return res_var861 def tr64_to_tag(self, value):862 # type: (MuTagRef64Value) -> MuIntValue863 res_var = CVar('MuIntValue', 'hintval')864 _apilog.logcall('tr64_to_tag', [self._ctx, value], res_var, self._ctx)865 return res_var866 def tr64_from_fp(self, value):867 # type: (MuDoubleValue) -> MuTagRef64Value868 res_var = CVar('MuTagRef64Value', 'htag')869 _apilog.logcall('tr64_from_fp', [self._ctx, value], res_var, self._ctx)870 return res_var871 def tr64_from_int(self, value):872 # type: (MuIntValue) -> MuTagRef64Value873 res_var = CVar('MuTagRef64Value', 'htag')874 _apilog.logcall('tr64_from_int', [self._ctx, value], res_var, self._ctx)875 return res_var876 def tr64_from_ref(self, ref, tag):877 # type: (MuRefValue, MuIntValue) -> MuTagRef64Value878 res_var = CVar('MuTagRef64Value', 'htag')879 _apilog.logcall('tr64_from_ref', [self._ctx, ref, tag], res_var, self._ctx)880 return res_var881 def enable_watchpoint(self, wpid):882 # type: (MuWPID) -> None883 _apilog.logcall('enable_watchpoint', [self._ctx, wpid], None, self._ctx)884 def disable_watchpoint(self, wpid):885 # type: (MuWPID) -> None886 _apilog.logcall('disable_watchpoint', [self._ctx, wpid], None, self._ctx)887 def pin(self, loc):888 # type: (MuValue) -> MuUPtrValue889 res_var = CVar('MuUPtrValue', 'huptrval')890 _apilog.logcall('pin', [self._ctx, loc], res_var, self._ctx)891 return res_var892 def unpin(self, loc):893 # type: (MuValue) -> None894 _apilog.logcall('unpin', [self._ctx, loc], None, self._ctx)895 def get_addr(self, loc):896 # type: (MuValue) -> MuUPtrValue897 res_var = CVar('MuUPtrValue', 'huptrval')898 _apilog.logcall('get_addr', [self._ctx, loc], res_var, self._ctx)899 return res_var900 def expose(self, func, call_conv, cookie):901 # type: (MuFuncRefValue, MuFlag, MuIntValue) -> MuValue902 res_var = CVar('MuValue', 'hdl')903 _apilog.logcall('expose', [self._ctx, func, call_conv, cookie], res_var, self._ctx)904 return res_var905 def unexpose(self, call_conv, value):906 # type: (MuFlag, MuValue) -> None907 _apilog.logcall('unexpose', [self._ctx, call_conv, value], None, self._ctx)908 def new_ir_builder(self):909 # type: () -> MuIRBuilder910 res_var = CVar('MuIRBuilder*', 'bldr')911 _apilog.logcall('new_ir_builder', [self._ctx], res_var, self._ctx)912 return MuIRBuilder(res_var)913 def make_boot_image(self, whitelist, primordial_func, primordial_stack, primordial_threadlocal, sym_fields, sym_strings, reloc_fields, reloc_strings, output_file):914 # type: ([MuID], MuFuncRefValue, MuStackRefValue, MuRefValue, [MuIRefValue], [MuCString], [MuIRefValue], [MuCString], str) -> None915 whitelist_arr, whitelist_sz = lst2arr('MuID', whitelist)916 sym_fields_arr, sym_fields_sz = lst2arr('MuIRefValue', sym_fields)917 sym_strings_arr, sym_strings_sz = lst2arr('MuCString', sym_strings)918 reloc_fields_arr, reloc_fields_sz = lst2arr('MuIRefValue', reloc_fields)919 reloc_strings_arr, reloc_strings_sz = lst2arr('MuCString', reloc_strings)920 output_file_cstr = CStr(output_file) if output_file else NULL921 _apilog.logcall('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_cstr], None, self._ctx)922class MuIRBuilder:923 def __init__(self, bldr_var):924 self._bldr = bldr_var925 def load(self):926 # type: () -> None927 _apilog.logcall('load', [self._bldr], None, self._bldr)928 def abort(self):929 # type: () -> None930 _apilog.logcall('abort', [self._bldr], None, self._bldr)931 def gen_sym(self, name=None):932 # type: (str) -> MuID933 name_cstr = CStr(name) if name else NULL934 res_var = CVar('MuID', 'id')935 _apilog.logcall('gen_sym', [self._bldr, name_cstr], res_var, self._bldr)936 return res_var937 def new_type_int(self, id, len):938 # type: (MuID, int) -> None939 _apilog.logcall('new_type_int', [self._bldr, id, len], None, self._bldr)940 def new_type_float(self, id):941 # type: (MuID) -> None942 _apilog.logcall('new_type_float', [self._bldr, id], None, self._bldr)943 def new_type_double(self, id):944 # type: (MuID) -> None945 _apilog.logcall('new_type_double', [self._bldr, id], None, self._bldr)946 def new_type_uptr(self, id, ty):947 # type: (MuID, MuTypeNode) -> None948 _apilog.logcall('new_type_uptr', [self._bldr, id, ty], None, self._bldr)949 def new_type_ufuncptr(self, id, sig):950 # type: (MuID, MuFuncSigNode) -> None951 _apilog.logcall('new_type_ufuncptr', [self._bldr, id, sig], None, self._bldr)952 def new_type_struct(self, id, fieldtys):953 # type: (MuID, [MuTypeNode]) -> None954 fieldtys_arr, fieldtys_sz = lst2arr('MuTypeNode', fieldtys)955 _apilog.logcall('new_type_struct', [self._bldr, id, fieldtys_arr, fieldtys_sz], None, self._bldr)956 def new_type_hybrid(self, id, fixedtys, varty):957 # type: (MuID, [MuTypeNode], MuTypeNode) -> None958 fixedtys_arr, fixedtys_sz = lst2arr('MuTypeNode', fixedtys)959 _apilog.logcall('new_type_hybrid', [self._bldr, id, fixedtys_arr, fixedtys_sz, varty], None, self._bldr)960 def new_type_array(self, id, elemty, len):961 # type: (MuID, MuTypeNode, int) -> None962 _apilog.logcall('new_type_array', [self._bldr, id, elemty, len], None, self._bldr)963 def new_type_vector(self, id, elemty, len):964 # type: (MuID, MuTypeNode, int) -> None965 _apilog.logcall('new_type_vector', [self._bldr, id, elemty, len], None, self._bldr)966 def new_type_void(self, id):967 # type: (MuID) -> None968 _apilog.logcall('new_type_void', [self._bldr, id], None, self._bldr)969 def new_type_ref(self, id, ty):970 # type: (MuID, MuTypeNode) -> None971 _apilog.logcall('new_type_ref', [self._bldr, id, ty], None, self._bldr)972 def new_type_iref(self, id, ty):973 # type: (MuID, MuTypeNode) -> None974 _apilog.logcall('new_type_iref', [self._bldr, id, ty], None, self._bldr)975 def new_type_weakref(self, id, ty):976 # type: (MuID, MuTypeNode) -> None977 _apilog.logcall('new_type_weakref', [self._bldr, id, ty], None, self._bldr)978 def new_type_funcref(self, id, sig):979 # type: (MuID, MuFuncSigNode) -> None980 _apilog.logcall('new_type_funcref', [self._bldr, id, sig], None, self._bldr)981 def new_type_tagref64(self, id):982 # type: (MuID) -> None983 _apilog.logcall('new_type_tagref64', [self._bldr, id], None, self._bldr)984 def new_type_threadref(self, id):985 # type: (MuID) -> None986 _apilog.logcall('new_type_threadref', [self._bldr, id], None, self._bldr)987 def new_type_stackref(self, id):988 # type: (MuID) -> None989 _apilog.logcall('new_type_stackref', [self._bldr, id], None, self._bldr)990 def new_type_framecursorref(self, id):991 # type: (MuID) -> None992 _apilog.logcall('new_type_framecursorref', [self._bldr, id], None, self._bldr)993 def new_type_irbuilderref(self, id):994 # type: (MuID) -> None995 _apilog.logcall('new_type_irbuilderref', [self._bldr, id], None, self._bldr)996 def new_funcsig(self, id, paramtys, rettys):997 # type: (MuID, [MuTypeNode], [MuTypeNode]) -> None998 paramtys_arr, paramtys_sz = lst2arr('MuTypeNode', paramtys)999 rettys_arr, rettys_sz = lst2arr('MuTypeNode', rettys)1000 _apilog.logcall('new_funcsig', [self._bldr, id, paramtys_arr, paramtys_sz, rettys_arr, rettys_sz], None, self._bldr)1001 def new_const_int(self, id, ty, value):1002 # type: (MuID, MuTypeNode, int) -> None1003 _apilog.logcall('new_const_int', [self._bldr, id, ty, value], None, self._bldr)1004 def new_const_int_ex(self, id, ty, values):1005 # type: (MuID, MuTypeNode, [rffi.ULONG]) -> None1006 values_arr, values_sz = lst2arr('uint64_t', values)1007 _apilog.logcall('new_const_int_ex', [self._bldr, id, ty, values_arr, values_sz], None, self._bldr)1008 def new_const_float(self, id, ty, value):1009 # type: (MuID, MuTypeNode, float) -> None1010 value_fltstr = '%.20f' % value1011 _apilog.logcall('new_const_float', [self._bldr, id, ty, value_fltstr], None, self._bldr)1012 def new_const_double(self, id, ty, value):1013 # type: (MuID, MuTypeNode, float) -> None1014 value_fltstr = '%.20f' % value1015 _apilog.logcall('new_const_double', [self._bldr, id, ty, value_fltstr], None, self._bldr)1016 def new_const_null(self, id, ty):1017 # type: (MuID, MuTypeNode) -> None1018 _apilog.logcall('new_const_null', [self._bldr, id, ty], None, self._bldr)1019 def new_const_seq(self, id, ty, elems):1020 # type: (MuID, MuTypeNode, [MuGlobalVarNode]) -> None1021 elems_arr, elems_sz = lst2arr('MuGlobalVarNode', elems)1022 _apilog.logcall('new_const_seq', [self._bldr, id, ty, elems_arr, elems_sz], None, self._bldr)1023 def new_const_extern(self, id, ty, symbol):1024 # type: (MuID, MuTypeNode, str) -> None1025 symbol_cstr = CStr(symbol) if symbol else NULL1026 _apilog.logcall('new_const_extern', [self._bldr, id, ty, symbol_cstr], None, self._bldr)1027 def new_global_cell(self, id, ty):1028 # type: (MuID, MuTypeNode) -> None1029 _apilog.logcall('new_global_cell', [self._bldr, id, ty], None, self._bldr)1030 def new_func(self, id, sig):1031 # type: (MuID, MuFuncSigNode) -> None1032 _apilog.logcall('new_func', [self._bldr, id, sig], None, self._bldr)1033 def new_exp_func(self, id, func, callconv, cookie):1034 # type: (MuID, MuFuncNode, MuFlag, MuConstNode) -> None1035 _apilog.logcall('new_exp_func', [self._bldr, id, func, callconv, cookie], None, self._bldr)1036 def new_func_ver(self, id, func, bbs):1037 # type: (MuID, MuFuncNode, [MuBBNode]) -> None1038 bbs_arr, bbs_sz = lst2arr('MuBBNode', bbs)1039 _apilog.logcall('new_func_ver', [self._bldr, id, func, bbs_arr, bbs_sz], None, self._bldr)1040 def new_bb(self, id, nor_param_ids, nor_param_types, exc_param_id, insts):1041 # type: (MuID, [MuID], [MuTypeNode], MuID, [MuInstNode]) -> None1042 nor_param_ids_arr, nor_param_ids_sz = lst2arr('MuID', nor_param_ids)1043 nor_param_types_arr, nor_param_types_sz = lst2arr('MuTypeNode', nor_param_types)1044 insts_arr, insts_sz = lst2arr('MuInstNode', insts)1045 _apilog.logcall('new_bb', [self._bldr, id, nor_param_ids_arr, nor_param_types_arr, nor_param_types_sz, exc_param_id, insts_arr, insts_sz], None, self._bldr)1046 def new_dest_clause(self, id, dest, vars):1047 # type: (MuID, MuBBNode, [MuVarNode]) -> None1048 vars_arr, vars_sz = lst2arr('MuVarNode', vars)1049 _apilog.logcall('new_dest_clause', [self._bldr, id, dest, vars_arr, vars_sz], None, self._bldr)1050 def new_exc_clause(self, id, nor, exc):1051 # type: (MuID, MuDestClause, MuDestClause) -> None1052 _apilog.logcall('new_exc_clause', [self._bldr, id, nor, exc], None, self._bldr)1053 def new_keepalive_clause(self, id, vars):1054 # type: (MuID, [MuLocalVarNode]) -> None1055 vars_arr, vars_sz = lst2arr('MuLocalVarNode', vars)1056 _apilog.logcall('new_keepalive_clause', [self._bldr, id, vars_arr, vars_sz], None, self._bldr)1057 def new_csc_ret_with(self, id, rettys):1058 # type: (MuID, [MuTypeNode]) -> None1059 rettys_arr, rettys_sz = lst2arr('MuTypeNode', rettys)1060 _apilog.logcall('new_csc_ret_with', [self._bldr, id, rettys_arr, rettys_sz], None, self._bldr)1061 def new_csc_kill_old(self, id):1062 # type: (MuID) -> None1063 _apilog.logcall('new_csc_kill_old', [self._bldr, id], None, self._bldr)1064 def new_nsc_pass_values(self, id, tys, vars):1065 # type: (MuID, [MuTypeNode], [MuVarNode]) -> None1066 tys_arr, tys_sz = lst2arr('MuTypeNode', tys)1067 vars_arr, vars_sz = lst2arr('MuVarNode', vars)1068 _apilog.logcall('new_nsc_pass_values', [self._bldr, id, tys_arr, vars_arr, vars_sz], None, self._bldr)1069 def new_nsc_throw_exc(self, id, exc):1070 # type: (MuID, MuVarNode) -> None1071 _apilog.logcall('new_nsc_throw_exc', [self._bldr, id, exc], None, self._bldr)1072 def new_binop(self, id, result_id, optr, ty, opnd1, opnd2, exc_clause=MU_NO_ID):1073 # type: (MuID, MuID, MuFlag, MuTypeNode, MuVarNode, MuVarNode, MuExcClause) -> None1074 _apilog.logcall('new_binop', [self._bldr, id, result_id, optr, ty, opnd1, opnd2, exc_clause], None, self._bldr)1075 def new_binop_with_status(self, id, result_id, status_result_ids, optr, status_flags, ty, opnd1, opnd2, exc_clause=MU_NO_ID):1076 # type: (MuID, MuID, [MuID], MuFlag, MuBinOpStatus, MuTypeNode, MuVarNode, MuVarNode, MuExcClause) -> None1077 status_result_ids_arr, status_result_ids_sz = lst2arr('MuID', status_result_ids)1078 _apilog.logcall('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], None, self._bldr)1079 def new_cmp(self, id, result_id, optr, ty, opnd1, opnd2):1080 # type: (MuID, MuID, MuFlag, MuTypeNode, MuVarNode, MuVarNode) -> None1081 _apilog.logcall('new_cmp', [self._bldr, id, result_id, optr, ty, opnd1, opnd2], None, self._bldr)1082 def new_conv(self, id, result_id, optr, from_ty, to_ty, opnd):1083 # type: (MuID, MuID, MuFlag, MuTypeNode, MuTypeNode, MuVarNode) -> None1084 _apilog.logcall('new_conv', [self._bldr, id, result_id, optr, from_ty, to_ty, opnd], None, self._bldr)1085 def new_select(self, id, result_id, cond_ty, opnd_ty, cond, if_true, if_false):1086 # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode, MuVarNode) -> None1087 _apilog.logcall('new_select', [self._bldr, id, result_id, cond_ty, opnd_ty, cond, if_true, if_false], None, self._bldr)1088 def new_branch(self, id, dest):1089 # type: (MuID, MuDestClause) -> None1090 _apilog.logcall('new_branch', [self._bldr, id, dest], None, self._bldr)1091 def new_branch2(self, id, cond, if_true, if_false):1092 # type: (MuID, MuVarNode, MuDestClause, MuDestClause) -> None1093 _apilog.logcall('new_branch2', [self._bldr, id, cond, if_true, if_false], None, self._bldr)1094 def new_switch(self, id, opnd_ty, opnd, default_dest, cases, dests):1095 # type: (MuID, MuTypeNode, MuVarNode, MuDestClause, [MuConstNode], [MuDestClause]) -> None1096 cases_arr, cases_sz = lst2arr('MuConstNode', cases)1097 dests_arr, dests_sz = lst2arr('MuDestClause', dests)1098 _apilog.logcall('new_switch', [self._bldr, id, opnd_ty, opnd, default_dest, cases_arr, dests_arr, dests_sz], None, self._bldr)1099 def new_call(self, id, result_ids, sig, callee, args, exc_clause=MU_NO_ID, keepalive_clause=MU_NO_ID):1100 # type: (MuID, [MuID], MuFuncSigNode, MuVarNode, [MuVarNode], MuExcClause, MuKeepaliveClause) -> None1101 result_ids_arr, result_ids_sz = lst2arr('MuID', result_ids)1102 args_arr, args_sz = lst2arr('MuVarNode', args)1103 _apilog.logcall('new_call', [self._bldr, id, result_ids_arr, result_ids_sz, sig, callee, args_arr, args_sz, exc_clause, keepalive_clause], None, self._bldr)1104 def new_tailcall(self, id, sig, callee, args):1105 # type: (MuID, MuFuncSigNode, MuVarNode, [MuVarNode]) -> None1106 args_arr, args_sz = lst2arr('MuVarNode', args)1107 _apilog.logcall('new_tailcall', [self._bldr, id, sig, callee, args_arr, args_sz], None, self._bldr)1108 def new_ret(self, id, rvs):1109 # type: (MuID, [MuVarNode]) -> None1110 rvs_arr, rvs_sz = lst2arr('MuVarNode', rvs)1111 _apilog.logcall('new_ret', [self._bldr, id, rvs_arr, rvs_sz], None, self._bldr)1112 def new_throw(self, id, exc):1113 # type: (MuID, MuVarNode) -> None1114 _apilog.logcall('new_throw', [self._bldr, id, exc], None, self._bldr)1115 def new_extractvalue(self, id, result_id, strty, index, opnd):1116 # type: (MuID, MuID, MuTypeNode, int, MuVarNode) -> None1117 _apilog.logcall('new_extractvalue', [self._bldr, id, result_id, strty, index, opnd], None, self._bldr)1118 def new_insertvalue(self, id, result_id, strty, index, opnd, newval):1119 # type: (MuID, MuID, MuTypeNode, int, MuVarNode, MuVarNode) -> None1120 _apilog.logcall('new_insertvalue', [self._bldr, id, result_id, strty, index, opnd, newval], None, self._bldr)1121 def new_extractelement(self, id, result_id, seqty, indty, opnd, index):1122 # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode) -> None1123 _apilog.logcall('new_extractelement', [self._bldr, id, result_id, seqty, indty, opnd, index], None, self._bldr)1124 def new_insertelement(self, id, result_id, seqty, indty, opnd, index, newval):1125 # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode, MuVarNode) -> None1126 _apilog.logcall('new_insertelement', [self._bldr, id, result_id, seqty, indty, opnd, index, newval], None, self._bldr)1127 def new_shufflevector(self, id, result_id, vecty, maskty, vec1, vec2, mask):1128 # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode, MuVarNode) -> None1129 _apilog.logcall('new_shufflevector', [self._bldr, id, result_id, vecty, maskty, vec1, vec2, mask], None, self._bldr)1130 def new_new(self, id, result_id, allocty, exc_clause=MU_NO_ID):1131 # type: (MuID, MuID, MuTypeNode, MuExcClause) -> None1132 _apilog.logcall('new_new', [self._bldr, id, result_id, allocty, exc_clause], None, self._bldr)1133 def new_newhybrid(self, id, result_id, allocty, lenty, length, exc_clause=MU_NO_ID):1134 # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuExcClause) -> None1135 _apilog.logcall('new_newhybrid', [self._bldr, id, result_id, allocty, lenty, length, exc_clause], None, self._bldr)1136 def new_alloca(self, id, result_id, allocty, exc_clause=MU_NO_ID):1137 # type: (MuID, MuID, MuTypeNode, MuExcClause) -> None1138 _apilog.logcall('new_alloca', [self._bldr, id, result_id, allocty, exc_clause], None, self._bldr)1139 def new_allocahybrid(self, id, result_id, allocty, lenty, length, exc_clause=MU_NO_ID):1140 # type: (MuID, MuID, MuTypeNode, MuTypeNode, MuVarNode, MuExcClause) -> None1141 _apilog.logcall('new_allocahybrid', [self._bldr, id, result_id, allocty, lenty, length, exc_clause], None, self._bldr)1142 def new_getiref(self, id, result_id, refty, opnd):1143 # type: (MuID, MuID, MuTypeNode, MuVarNode) -> None1144 _apilog.logcall('new_getiref', [self._bldr, id, result_id, refty, opnd], None, self._bldr)1145 def new_getfieldiref(self, id, result_id, is_ptr, refty, index, opnd):1146 # type: (MuID, MuID, bool, MuTypeNode, int, MuVarNode) -> None1147 is_ptr_bool = 'true' if is_ptr else 'false'1148 _apilog.logcall('new_getfieldiref', [self._bldr, id, result_id, is_ptr_bool, refty, index, opnd], None, self._bldr)1149 def new_getelemiref(self, id, result_id, is_ptr, refty, indty, opnd, index):1150 # type: (MuID, MuID, bool, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode) -> None1151 is_ptr_bool = 'true' if is_ptr else 'false'1152 _apilog.logcall('new_getelemiref', [self._bldr, id, result_id, is_ptr_bool, refty, indty, opnd, index], None, self._bldr)1153 def new_shiftiref(self, id, result_id, is_ptr, refty, offty, opnd, offset):1154 # type: (MuID, MuID, bool, MuTypeNode, MuTypeNode, MuVarNode, MuVarNode) -> None1155 is_ptr_bool = 'true' if is_ptr else 'false'1156 _apilog.logcall('new_shiftiref', [self._bldr, id, result_id, is_ptr_bool, refty, offty, opnd, offset], None, self._bldr)1157 def new_getvarpartiref(self, id, result_id, is_ptr, refty, opnd):1158 # type: (MuID, MuID, bool, MuTypeNode, MuVarNode) -> None1159 is_ptr_bool = 'true' if is_ptr else 'false'1160 _apilog.logcall('new_getvarpartiref', [self._bldr, id, result_id, is_ptr_bool, refty, opnd], None, self._bldr)1161 def new_load(self, id, result_id, is_ptr, ord, refty, loc, exc_clause=MU_NO_ID):1162 # type: (MuID, MuID, bool, MuFlag, MuTypeNode, MuVarNode, MuExcClause) -> None1163 is_ptr_bool = 'true' if is_ptr else 'false'1164 _apilog.logcall('new_load', [self._bldr, id, result_id, is_ptr_bool, ord, refty, loc, exc_clause], None, self._bldr)1165 def new_store(self, id, is_ptr, ord, refty, loc, newval, exc_clause=MU_NO_ID):1166 # type: (MuID, bool, MuFlag, MuTypeNode, MuVarNode, MuVarNode, MuExcClause) -> None1167 is_ptr_bool = 'true' if is_ptr else 'false'1168 _apilog.logcall('new_store', [self._bldr, id, is_ptr_bool, ord, refty, loc, newval, exc_clause], None, self._bldr)1169 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):1170 # type: (MuID, MuID, MuID, bool, bool, MuFlag, MuFlag, MuTypeNode, MuVarNode, MuVarNode, MuVarNode, MuExcClause) -> None1171 is_ptr_bool = 'true' if is_ptr else 'false'1172 is_weak_bool = 'true' if is_weak else 'false'1173 _apilog.logcall('new_cmpxchg', [self._bldr, id, value_result_id, succ_result_id, is_ptr_bool, is_weak_bool, ord_succ, ord_fail, refty, loc, expected, desired, exc_clause], None, self._bldr)1174 def new_atomicrmw(self, id, result_id, is_ptr, ord, optr, ref_ty, loc, opnd, exc_clause=MU_NO_ID):1175 # type: (MuID, MuID, bool, MuFlag, MuFlag, MuTypeNode, MuVarNode, MuVarNode, MuExcClause) -> None1176 is_ptr_bool = 'true' if is_ptr else 'false'1177 _apilog.logcall('new_atomicrmw', [self._bldr, id, result_id, is_ptr_bool, ord, optr, ref_ty, loc, opnd, exc_clause], None, self._bldr)1178 def new_fence(self, id, ord):1179 # type: (MuID, MuFlag) -> None1180 _apilog.logcall('new_fence', [self._bldr, id, ord], None, self._bldr)1181 def new_trap(self, id, result_ids, rettys, exc_clause=MU_NO_ID, keepalive_clause=MU_NO_ID):1182 # type: (MuID, [MuID], [MuTypeNode], MuExcClause, MuKeepaliveClause) -> None1183 result_ids_arr, result_ids_sz = lst2arr('MuID', result_ids)1184 rettys_arr, rettys_sz = lst2arr('MuTypeNode', rettys)1185 _apilog.logcall('new_trap', [self._bldr, id, result_ids_arr, rettys_arr, rettys_sz, exc_clause, keepalive_clause], None, self._bldr)1186 def new_watchpoint(self, id, wpid, result_ids, rettys, dis, ena, exc=MU_NO_ID, keepalive_clause=MU_NO_ID):1187 # type: (MuID, MuWPID, [MuID], [MuTypeNode], MuDestClause, MuDestClause, MuDestClause, MuKeepaliveClause) -> None1188 result_ids_arr, result_ids_sz = lst2arr('MuID', result_ids)1189 rettys_arr, rettys_sz = lst2arr('MuTypeNode', rettys)1190 _apilog.logcall('new_watchpoint', [self._bldr, id, wpid, result_ids_arr, rettys_arr, rettys_sz, dis, ena, exc, keepalive_clause], None, self._bldr)1191 def new_wpbranch(self, id, wpid, dis, ena):1192 # type: (MuID, MuWPID, MuDestClause, MuDestClause) -> None1193 _apilog.logcall('new_wpbranch', [self._bldr, id, wpid, dis, ena], None, self._bldr)1194 def new_ccall(self, id, result_ids, callconv, callee_ty, sig, callee, args, exc_clause=MU_NO_ID, keepalive_clause=MU_NO_ID):1195 # type: (MuID, [MuID], MuFlag, MuTypeNode, MuFuncSigNode, MuVarNode, [MuVarNode], MuExcClause, MuKeepaliveClause) -> None1196 result_ids_arr, result_ids_sz = lst2arr('MuID', result_ids)1197 args_arr, args_sz = lst2arr('MuVarNode', args)1198 _apilog.logcall('new_ccall', [self._bldr, id, result_ids_arr, result_ids_sz, callconv, callee_ty, sig, callee, args_arr, args_sz, exc_clause, keepalive_clause], None, self._bldr)1199 def new_newthread(self, id, result_id, stack, threadlocal, new_stack_clause, exc_clause=MU_NO_ID):1200 # type: (MuID, MuID, MuVarNode, MuVarNode, MuNewStackClause, MuExcClause) -> None1201 _apilog.logcall('new_newthread', [self._bldr, id, result_id, stack, threadlocal, new_stack_clause, exc_clause], None, self._bldr)1202 def new_swapstack(self, id, result_ids, swappee, cur_stack_clause, new_stack_clause, exc_clause=MU_NO_ID, keepalive_clause=MU_NO_ID):1203 # type: (MuID, [MuID], MuVarNode, MuCurStackClause, MuNewStackClause, MuExcClause, MuKeepaliveClause) -> None1204 result_ids_arr, result_ids_sz = lst2arr('MuID', result_ids)1205 _apilog.logcall('new_swapstack', [self._bldr, id, result_ids_arr, result_ids_sz, swappee, cur_stack_clause, new_stack_clause, exc_clause, keepalive_clause], None, self._bldr)1206 def new_comminst(self, id, result_ids, opcode, flags, tys, sigs, args, exc_clause=MU_NO_ID, keepalive_clause=MU_NO_ID):1207 # type: (MuID, [MuID], MuFlag, [MuFlag], [MuTypeNode], [MuFuncSigNode], [MuVarNode], MuExcClause, MuKeepaliveClause) -> None1208 result_ids_arr, result_ids_sz = lst2arr('MuID', result_ids)1209 flags_arr, flags_sz = lst2arr('MuFlag', flags)1210 tys_arr, tys_sz = lst2arr('MuTypeNode', tys)1211 sigs_arr, sigs_sz = lst2arr('MuFuncSigNode', sigs)1212 args_arr, args_sz = lst2arr('MuVarNode', args)1213 _apilog.logcall('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], None, self._bldr)1214# -------------------------------------------------------------------------------------------------------1215# Helpers1216def null(rmu_t):1217 return NULL1218def lst2arr(c_elm_t, lst):1219 sz = len(lst)1220 if len(lst) > 0:1221 arr = CArrayConst(c_elm_t, lst)1222 else:1223 arr = NULL...
docker.py
Source:docker.py
1import docker2import typing3import os4from django.conf import settings5from . import log as logging6from .lock import LockHandler7PREFIX = settings.DOCKER_PREFIX8DOCKER_NETWORK = settings.DOCKER_NETWORK9DOCKER_ENABLED = settings.DOCKER_ENABLED10LockHandler.register("docker")11ContainerType = docker.models.containers.Container12ImageType = docker.models.images.Image13class _Docker:14 client = docker.from_env() if DOCKER_ENABLED else None15 @classmethod16 def get(cls):17 if cls.client:18 return cls.client19 raise Exception("docker is disabled")20class _Container:21 @classmethod22 def get(cls, name: str) -> ContainerType:23 return _Docker.get().containers.get(name)24 @classmethod25 def create(cls, image: str, name: str, network: str) -> ContainerType:26 return _Docker.get().containers.create(image, name=name, network=network)27 @classmethod28 def ls(cls, filter=None) -> typing.List[ContainerType]:29 return _Docker.get().containers.list(30 all=True, filters={"name": f"{PREFIX}_{filter or '*'}"}31 )32 @classmethod33 def by_image(cls, filter: str) -> typing.List[ContainerType]:34 res = _Docker.get().containers.list(all=True, filters={"ancestor": filter})35 res = tuple(x for x in res if x.attrs["Config"]["Image"] == filter)36 return res37 @classmethod38 def start(cls, name: str) -> ContainerType:39 cnt = cls.get(name)40 networks = cnt.attrs.get("NetworkSettings", {}).get("Networks", {})41 for network in networks:42 n = _Docker.get().networks.get(network)43 n.disconnect(cnt)44 cnt.start() 45 for network in networks:46 n = _Docker.get().networks.get(network)47 n.connect(cnt)48 return cnt49 @classmethod50 def stop(cls, name: str) -> ContainerType:51 cnt = cls.get(name)52 cnt.stop()53 return cnt54 @classmethod55 def delete(cls, name: str):56 cnt = cls.get(name)57 cnt.remove()58class _Image:59 @classmethod60 def get(cls, name: str) -> ImageType:61 return _Docker.get().images.get(name)62 @classmethod63 def ls(cls, filter=None) -> typing.List[ImageType]:64 return _Docker.get().images.list(f"{PREFIX}_{filter or '*'}")65 @classmethod66 def delete(cls, tag):67 _Docker.get().images.remove(image=tag)68 @classmethod69 def create(cls, tag, path) -> ImageType:70 return _Docker.get().images.build(path=path, tag=tag, rm=True)71def add_prefix(name: str) -> str:72 if name.startswith(PREFIX):73 return name74 return f"{PREFIX}_{name}"75def remove_prefix(name: str) -> str:76 if name.startswith(PREFIX):77 return name[len(PREFIX) + 1 :]78 return name79class Image:80 def __init__(self, name: str = None, tag: str = None, ident: str = None):81 with logging.LogCall(__file__, "__init__", self.__class__):82 if ident:83 (name, tag) = ident.split(":")84 name = remove_prefix(name)85 if not (name and tag):86 raise ValueError("name and tag need to be specified")87 self.tag = tag88 self.name = name89 self.image_name = add_prefix(name)90 def get_ident(self) -> str:91 with logging.LogCall(__file__, "get_ident", self.__class__):92 return f"{self.image_name}:{self.tag}"93 @classmethod94 def ls(cls, filter=None) -> ImageType:95 with logging.LogCall(__file__, "ls", cls):96 return _Image.ls()97 def get_container(self) -> typing.List[ContainerType]:98 with logging.LogCall(__file__, "get_container", self.__class__):99 return Container.get_by_image(self)100 def exists(self) -> typing.Union[ImageType, None]:101 with logging.LogCall(__file__, "exists", self.__class__):102 try:103 return _Image.get(self.get_ident())104 except:105 return None106 def delete(self) -> bool:107 with logging.LogCall(__file__, "delete", self.__class__):108 with LockHandler.get("docker"):109 if not self.exists():110 return False111 for c in self.get_container():112 c.remove()113 _Image.delete(self.get_ident())114 return True115 def stop(self):116 with logging.LogCall(__file__, "stop", self.__class__):117 for c in self.get_container():118 c.stop()119 def start(self):120 with logging.LogCall(__file__, "start", self.__class__):121 for c in self.get_container():122 c.start()123 def create(self, directory: str) -> bool:124 with logging.LogCall(__file__, "create", self.__class__):125 with LockHandler.get("docker"):126 if self.exists():127 return False128 _plugindir = os.path.join(directory, "container")129 _Image.create(self.get_ident(), _plugindir)130 return True131class Container:132 class State:133 EXITED = "exited"134 RUNNING = "running"135 RESTARTING = "restarting"136 PAUSED = "paused"137 def __init__(self, name: str = None, ident: str = None):138 with logging.LogCall(__file__, "__init__", self.__class__):139 if ident:140 name = remove_prefix(ident)141 if not name:142 raise ValueError("name needs to be specified")143 self.name = name144 self.container_name = self._get_name(name)145 def get_ident(self) -> str:146 return self.container_name147 @classmethod148 def get_by_image(cls, image: Image):149 with logging.LogCall(__file__, "get_by_image", cls):150 return _Container.by_image(image.get_ident())151 @classmethod152 def _get_name(cls, plugin_name: str) -> str:153 with logging.LogCall(__file__, "_get_name", cls):154 return f"{PREFIX}_{plugin_name}"155 @classmethod156 def ls(cls, filter: str = None):157 with logging.LogCall(__file__, "ls", cls):158 return _Container.ls(filter)159 def exists(self) -> typing.Union[ContainerType, None]:160 with logging.LogCall(__file__, "exists", self.__class__):161 try:162 return _Container.get(self.get_ident())163 except:164 return None165 def delete(self) -> bool:166 with logging.LogCall(__file__, "delete", self.__class__):167 with LockHandler.get("docker"):168 _Container.delete(self.get_ident())169 def create(self, image: Image) -> bool:170 with logging.LogCall(__file__, "create", self.__class__):171 with LockHandler.get("docker"):172 if self.exists():173 return False174 _Container.create(175 image.get_ident(), self.get_ident(), DOCKER_NETWORK,176 )177 return True178 def start(self) -> bool:179 with logging.LogCall(__file__, "start", self.__class__):180 with LockHandler.get("docker"):181 cnt = self.exists()182 if not cnt:183 return False184 if cnt.status in (self.State.RUNNING, self.State.RESTARTING):185 return False186 _Container.start(self.get_ident())187 return True188 def stop(self) -> bool:189 with logging.LogCall(__file__, "stop", self.__class__):190 with LockHandler.get("docker"):191 cnt = self.exists()192 if cnt.status == self.State.EXITED:193 return False194 _Container.stop(self.get_ident())195 return True196 def is_running(self) -> bool:197 with logging.LogCall(__file__, "is_running", self.__class__):198 data = self.exists()199 if data:200 return data.status == self.State.RUNNING201 return False202 def logs(self) -> str:203 with logging.LogCall(__file__, "logs", self.__class__):204 container = self.exists()205 if not container:206 return None...
LoggerFence.py
Source:LoggerFence.py
1#!/usr/bin/env python32# coding: utf-83import os, sys, time4import traceback5from contextlib import contextmanager6class LoggerFence:7 def __init__(self, logcall):8 self.__logcall = logcall9 10 self.nested = 0 # not private, can improve?11 self.excpt_count = 012 def set_logcall(self, logcall):13 self.__logcall = logcall14 def mark_api(func):15 # func is an unbound function16 def wrapper(self, *args, **kwargs):17 self.nested += 118 try:19 ret = func(self, *args, **kwargs)20 except:21 # We log the exception for current-module and let the exception propagate.22 if self.nested == 1:23 self.excpt_count += 124 excpt_text = traceback.format_exc()25 self.__logcall(excpt_text)26 raise27 finally:28 self.nested -= 129 return ret30 return wrapper31@contextmanager32def LiveFence(logcall):33 try:34 yield35 except:36 # We log the exception for current-module and let the exception propagate.37 excpt_text = traceback.format_exc()38 logcall(excpt_text)39 raise40def test1():41 fh = open("mylog.txt", "a", encoding="utf8")42 fh.write( time.strftime('%Y-%m-%d %H:%M:%S\n', time.localtime()) )43 with LiveFence(fh.write) as sth:44 result = DoDiv(6, 2)45 fh.write("DoDiv returns: %d\n"%(result))46 with LiveFence(fh.write) as sth:47 result = DoDiv(6, 0) # this will cause exception...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!