def from_opaque_string(s): if isinstance(s, str): return s elif isinstance(s, ootype._string): return OOSupport.from_rstr(s) else: return LLSupport.from_rstr(s)
def newgraph(gv_FUNCTYPE, name): FUNCTYPE = from_opaque_object(gv_FUNCTYPE).value # 'name' is just a way to track things if not isinstance(name, str): name = LLSupport.from_rstr(name) inputargs = [] erasedinputargs = [] for ARG in FUNCTYPE.ARGS: v = flowmodel.Variable() v.concretetype = ARG inputargs.append(v) v = flowmodel.Variable() v.concretetype = lltype.erasedType(ARG) erasedinputargs.append(v) startblock = flowmodel.Block(inputargs) # insert an exploding operation here which is removed by # builder.end() to ensure that builder.end() is actually called. startblock.operations.append( flowmodel.SpaceOperation("debug_assert", [flowmodel.Constant(False, lltype.Bool), flowmodel.Constant("you didn't call builder.end()?", lltype.Void)], varoftype(lltype.Void))) return_var = flowmodel.Variable() return_var.concretetype = FUNCTYPE.RESULT graph = flowmodel.FunctionGraph(name, startblock, return_var) v1 = flowmodel.Variable() v1.concretetype = lltype.erasedType(FUNCTYPE.RESULT) graph.prereturnblock = flowmodel.Block([v1]) casting_link(graph.prereturnblock, [v1], graph.returnblock) substartblock = flowmodel.Block(erasedinputargs) casting_link(graph.startblock, inputargs, substartblock) fptr = lltype.functionptr(FUNCTYPE, name, graph=graph) return genconst(fptr)
def genop(block, opname, vars_gv, gv_RESULT_TYPE): # 'opname' is a constant string # gv_RESULT_TYPE comes from constTYPE if not isinstance(opname, str): opname = LLSupport.from_rstr(opname) block = from_opaque_object(block) assert block.exits == [], "block already closed" opvars = _inputvars(vars_gv) if gv_RESULT_TYPE is guess: RESULT_TYPE = guess_result_type(opname, opvars) elif isinstance(gv_RESULT_TYPE, lltype.LowLevelType): RESULT_TYPE = gv_RESULT_TYPE else: RESULT_TYPE = from_opaque_object(gv_RESULT_TYPE).value v = flowmodel.Variable() v.concretetype = RESULT_TYPE op = flowmodel.SpaceOperation(opname, opvars, v) block.operations.append(op) return to_opaque_object(erasedvar(v, block))
def ll_strtod_formatd(fmt, x): return LLSupport.to_rstr(rarithmetic.formatd(LLSupport.from_rstr(fmt), x))
def ll_strtod_parts_to_float(sign, beforept, afterpt, exponent): return rarithmetic.parts_to_float(LLSupport.from_rstr(sign), LLSupport.from_rstr(beforept), LLSupport.from_rstr(afterpt), LLSupport.from_rstr(exponent))
def unicode_to_ll(self, s): from pypy.rpython.module.support import LLSupport return LLSupport.to_runicode(s)
def string_to_ll(self, s): from pypy.rpython.module.support import LLSupport return LLSupport.to_rstr(s)
def _get_cspecnode(s): from pypy.rpython.module.support import LLSupport llstr = lltype.cast_opaque_ptr(llmemory.GCREF, LLSupport.to_rstr(s)) box = ConstPtr(llstr) return ConstantSpecNode(box)
def build_bytecode(s): result = ''.join([chr(int(t)) for t in s.split(',')]) return LLSupport.to_rstr(result)
def revealconstrepr(gv_value): c = _from_opaque(gv_value) # XXX: what to do with ootype? #import pdb;pdb.set_trace() return LLSupport.to_rstr(repr(c.value))
def revealconstrepr(gv_value): c = from_opaque_object(gv_value) return LLSupport.to_rstr(repr(c.value))
def revealconstrepr(self): return LLSupport.from_rstr(llimpl.revealconstrepr(self.v))