Esempio n. 1
0
    def implementation(self, module, lfunc):
        def _py_c_string_slice_len(in_string, in_str_len, lower, upper):
            zero = lc_size_t(0)
            if lower < zero:
                lower += in_str_len
            if upper < zero:
                upper += in_str_len
            elif upper > in_str_len:
                upper = in_str_len
            temp_len = upper - lower
            if temp_len < zero:
                temp_len = zero
            return temp_len + lc_size_t(1)

        LLVMTranslator(module).translate(_py_c_string_slice_len,
                                         llvm_function=lfunc)
        return lfunc
Esempio n. 2
0
    def implementation(self, module, lfunc):
        # logger.debug((module, str(lfunc)))
        def _py_c_string_slice(out_string, in_string, in_str_len, lower,
                               upper):
            zero = lc_size_t(0)
            if lower < zero:
                lower += in_str_len
            if upper < zero:
                upper += in_str_len
            elif upper > in_str_len:
                upper = in_str_len
            temp_len = upper - lower
            if temp_len < zero:
                temp_len = zero
            strncpy(out_string, in_string + lower, temp_len)
            out_string[temp_len] = li8(0)
            return

        LLVMTranslator(module).translate(_py_c_string_slice,
                                         llvm_function=lfunc)
        return lfunc
Esempio n. 3
0
    def implementation(self, module, ret_val):
        _rtype = ret_val.type.pointee.return_type
        _rem = (llvm.core.Builder.srem if _rtype.kind == llvm.core.TYPE_INTEGER
                else llvm.core.Builder.frem)

        def _py_modulo(arg1, arg2):
            ret_val = rem(arg1, arg2)
            if ret_val < rtype(0):
                if arg2 > rtype(0):
                    ret_val += arg2
            elif arg2 < rtype(0):
                ret_val += arg2
            return ret_val

        LLVMTranslator(module).translate(_py_modulo,
                                         llvm_function=ret_val,
                                         env={
                                             'rtype': _rtype,
                                             'rem': _rem
                                         })
        return ret_val