Ejemplo n.º 1
0
Archivo: crest.py Proyecto: edmcman/tbf
    def _create_nondet_method(self, method_name, method_type, param_types):
        if not (method_type == 'void' or self.is_supported_type(method_type)):
            logging.warning('Crest can\'t handle symbolic values of type %s',
                            method_type)
            internal_type = 'unsigned long long'
            logging.warning('Continuing with type %s for method %s',
                            internal_type, method_name)
        elif method_type == '_Bool':
            internal_type = 'char'
        else:
            internal_type = method_type
        var_name = utils.get_sym_var_name(method_name)
        marker_method_call = 'CREST_' + '_'.join(internal_type.split())
        method_head = utils.get_method_head(method_name, method_type,
                                            param_types)
        method_body = ['{']
        if method_type != 'void':
            method_body += [
                '{0} {1};'.format(internal_type, var_name), '{0}({1});'.format(
                    marker_method_call, var_name)
            ]

            if method_type == internal_type:
                method_body.append('return {0};'.format(var_name))
            else:
                method_body.append('return ({0}) {1};'.format(
                    method_type, var_name))

        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body
Ejemplo n.º 2
0
    def _get_nondet_method_definition(method_name, method_type, param_types):
        var_name = utils.get_sym_var_name(method_name)
        method_head = utils.get_method_head(method_name, method_type,
                                            param_types)
        method_body = ['{']
        if method_type != 'void':
            method_body += [
                '{0} {1};'.format(method_type, var_name),
                'input(&{0}, sizeof({0}), \"{0}\");'.format(var_name),
                'return {0};'.format(var_name)
            ]
        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body
Ejemplo n.º 3
0
Archivo: klee.py Proyecto: edmcman/tbf
    def _create_nondet_method(self, method_name, method_type, param_types):
        var_name = utils.get_sym_var_name(method_name)
        method_head = utils.get_method_head(method_name, method_type,
                                            param_types)
        method_body = ['{']
        if method_type != 'void':
            method_body += [
                '{0} {1};'.format(method_type, var_name),
                'klee_make_symbolic(&{0}, sizeof({0}), \"{0}\");'.format(
                    var_name), 'return {0};'.format(var_name)
            ]
        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body
Ejemplo n.º 4
0
    def _create_nondet_method(self, method_name, method_type, param_types):
        var_name = utils.get_sym_var_name(method_name)
        method_head = utils.get_method_head(method_name, method_type,
                                            param_types)
        method_body = ['{']
        if method_type != 'void':
            if 'float' in method_type or 'double' in method_type:
                conversion_cmd = 'strtold({0}, 0);'.format(var_name)
            elif 'unsigned' in method_type and 'long long' in method_type:
                conversion_cmd = 'strtoull({0}, 0, 10);'.format(var_name)
            else:
                conversion_cmd = 'strtoll({0}, 0, 10);'.format(var_name)
            return_statement = 'return ({0}) {1}'.format(
                method_type, conversion_cmd)
            method_body += [
                'char * {0} = malloc(1000);'.format(var_name),
                'fgets({0}, 1000, stdin);'.format(var_name), return_statement
            ]
        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body