Exemplo n.º 1
0
 def generate_CALL(self, op):
     calldescr = op.descr
     assert isinstance(calldescr, CallDescr)
     ty_function_ptr = self.cpu.get_calldescr_ty_function_ptr(calldescr)
     v = op.args[0]
     if isinstance(v, Const):
         func = self.cpu._make_const(v.getint(), ty_function_ptr)
     else:
         func = self.getintarg(v)
         func = llvm_rffi.LLVMBuildIntToPtr(self.builder,
                                            func,
                                            ty_function_ptr, "")
     nb_args = len(op.args) - 1
     arglist = lltype.malloc(rffi.CArray(llvm_rffi.LLVMValueRef), nb_args,
                             flavor='raw')
     for i in range(nb_args):
         v = op.args[1 + i]
         index = calldescr.args_indices[i]
         getarg = self.cpu.getarg_by_index[index]
         value_ref = getarg(self, v)
         arglist[i] = value_ref
     res = llvm_rffi.LLVMBuildCall(self.builder,
                                   func, arglist, nb_args, "")
     lltype.free(arglist, flavor='raw')
     if op.result is not None:
         assert calldescr.res_index >= 0
         self.vars[op.result] = res
Exemplo n.º 2
0
 def getptrarg(self, v):
     try:
         value_ref = self.vars[v]
     except KeyError:
         return self.cpu._make_const(v.getaddr(self.cpu),
                                     self.cpu.ty_char_ptr)
     else:
         ty = llvm_rffi.LLVMTypeOf(value_ref)
         if ty == self.cpu.ty_int:
             value_ref = llvm_rffi.LLVMBuildIntToPtr(
                 self.builder, value_ref, self.cpu.ty_char_ptr, "")
         else:
             assert (ty != self.cpu.ty_bit and ty != self.cpu.ty_char
                     and ty != self.cpu.ty_unichar)
         return value_ref
Exemplo n.º 3
0
 def generate_CAST_INT_TO_PTR(self, op):
     res = llvm_rffi.LLVMBuildIntToPtr(self.builder,
                                       self.getintarg(op.args[0]),
                                       self.cpu.ty_char_ptr, "")
     self.vars[op.result] = res