def get_counter_aig(k):  # -> (int,int,int)
    template = \
        """
        MODULE main  -- count-up till k
          VAR
            state: 0..{k};
          IVAR
            reset: boolean;
            inc: boolean;

          DEFINE
            beep := (state={k});

          ASSIGN
            init(state) := 0;
            next(state) := case
                             reset: 0;
                             inc: state + 1;
                             TRUE:state;
                           esac;

          SPEC
            AG(!beep)  -- then we use the bad signal
        """

    global reset, inc
    counter_smv = cleandoc(template).format(k=str(k))

    ret, out, err = execute_shell(
        'smvflatten | smvtoaig | aigmove | aigtoaig -a',
        input=counter_smv + "\n")
    assert ret == 0, to_str_ret_out_err(ret, out, err)

    out_lines = out.splitlines()
    aag, m, i, l, o, a = out_lines[0].split()
    # assert i == '1' and o == '1'
    assert i == '2' and o == '1'

    for i in filter(lambda l: l.startswith('i'), out_lines):
        i = i.split()
        if i[1] == "reset":
            reset = int(i[0][1:])

        if i[1] == "inc":
            inc = int(i[0][1:])

    reset = (reset + 1) * 2
    inc = (inc + 1) * 2

    ret, out, err = execute_shell('aigstrip | aigtoaig -a', input=out)
    out_lines = out.splitlines()
    aag, m, i, l, o, a = out_lines[0].split()

    out_def_line = out_lines[int(i) + 1 + int(l)]
    assert len(out_def_line.split()) == 1, out_def_line

    out_signal = int(out_def_line)

    return out, out_signal
def get_counter_aig(k):  # -> (int,int,int)
    template = \
        """
        MODULE main  -- count-up till k
          VAR
            state: 0..{k};
          IVAR
            reset: boolean;
            inc: boolean;

          DEFINE
            beep := (state={k});

          ASSIGN
            init(state) := 0;
            next(state) := case
                             reset: 0;
                             inc: state + 1;
                             TRUE:state;
                           esac;

          SPEC
            AG(!beep)  -- then we use the bad signal
        """

    global reset, inc
    counter_smv = cleandoc(template).format(k=str(k))

    ret, out, err = execute_shell('smvflatten | smvtoaig | aigmove | aigtoaig -a', input=counter_smv + "\n")
    assert ret == 0, to_str_ret_out_err(ret, out, err)

    out_lines = out.splitlines()
    aag, m, i, l, o, a = out_lines[0].split()
    # assert i == '1' and o == '1'
    assert i == '2' and o == '1'

    for i in filter(lambda l: l.startswith('i'), out_lines):
        i = i.split()
        if i[1] == "reset":
            reset = int(i[0][1:])

        if i[1] == "inc":
            inc = int(i[0][1:])

    reset = (reset + 1) * 2
    inc = (inc + 1) * 2

    ret, out, err = execute_shell('aigstrip | aigtoaig -a', input=out)
    out_lines = out.splitlines()
    aag, m, i, l, o, a = out_lines[0].split()

    out_def_line = out_lines[int(i) + 1 + int(l)]
    assert len(out_def_line.split()) == 1, out_def_line

    out_signal = int(out_def_line)

    return out, out_signal
示例#3
0
def convert_and_check(test):
    rc, out, err = execute_shell(TOOL + ' ' + test)

    if rc != 0:
        print()
        print(test)
        print('The tool returned a non-zero status: ', to_str_ret_out_err(rc, out, err))
        exit(1)

    return out
示例#4
0
def convert_and_check(test):
    rc, out, err = execute_shell(TOOL + ' ' + test)

    if rc != 0:
        print()
        print(test)
        print('The tool returned a non-zero status: ',
              to_str_ret_out_err(rc, out, err))
        exit(1)

    return out
示例#5
0
def execute_goal_script(script: str) -> str:
    """
    :return: stdout as printed by GOAL
    """

    script_tmp_file_name = get_tmp_file_name("goal_script_")
    with open(script_tmp_file_name, 'w') as f:
        f.write(script)
        logger.debug(script)

    cmd_to_execute = '%s batch %s' % (GOAL, script_tmp_file_name)
    res, out, err = execute_shell(cmd_to_execute)
    assert res == 0 and err == '', 'Shell call failed:\n' + cmd_to_execute + '\nres=%i\n err=%s' % (res, err)

    remove(script_tmp_file_name)
    return out
示例#6
0
def synthesize_spec(aag_spec: str) -> bool:
    tmp_file_name = get_tmp_file_name() + '.aag'
    with open(tmp_file_name, 'w') as f:
        f.write(aag_spec)

    cmd_line = AISY + ' ' + tmp_file_name + ' -q -r'
    print('  synthesizing: \n', cmd_line)
    ret, out, err = execute_shell(cmd_line)

    assert not err.strip(), err
    assert not out.strip(), out

    assert ret in [EXIT_STATUS_REALIZABLE, EXIT_STATUS_UNREALIZABLE], str(ret)

    os.remove(tmp_file_name)   # on fail, keep it

    return ret == EXIT_STATUS_REALIZABLE
示例#7
0
def synthesize_spec(aag_spec: str) -> bool:
    tmp_file_name = get_tmp_file_name() + '.aag'
    with open(tmp_file_name, 'w') as f:
        f.write(aag_spec)

    cmd_line = AISY + ' ' + tmp_file_name + ' -q -r'
    print('  synthesizing: \n', cmd_line)
    ret, out, err = execute_shell(cmd_line)

    assert not err.strip(), err
    assert not out.strip(), out

    assert ret in [EXIT_STATUS_REALIZABLE, EXIT_STATUS_UNREALIZABLE], str(ret)

    os.remove(tmp_file_name)  # on fail, keep it

    return ret == EXIT_STATUS_REALIZABLE
def write_and_die():
    global spec, out, new_format
    (j, f) = aiger_hacky_remove_jf(spec)
    res, string = aiglib.aiger_write_to_string(spec, aiglib.aiger_ascii_mode,
                                               2147483648)
    # maybe useful for gc?
    spec.num_justice = j
    spec.num_fairness = f
    assert res != 0, 'writing failure'

    if not new_format:
        # post-process
        ret, out_string, err = execute_shell(
            'aigmove -i | aigor | aigtoaig -a', input=string)
        assert ret == 0, 'post-processing failure: ' + \
                         to_str_ret_out_err(ret, string, err) + \
                         'input was:\n' + string
        string = out_string

    out.write(string)
    exit(0)
def write_and_die():
    global spec, out, new_format
    (j, f) = aiger_hacky_remove_jf(spec)
    res, string = aiglib.aiger_write_to_string(spec,
                                               aiglib.aiger_ascii_mode,
                                               2147483648)
    # maybe useful for gc?
    spec.num_justice = j
    spec.num_fairness = f
    assert res != 0, 'writing failure'

    if not new_format:
        # post-process
        ret, out_string, err = execute_shell(
            'aigmove -i | aigor | aigtoaig -a',
            input=string)
        assert ret == 0, 'post-processing failure: ' + \
                         to_str_ret_out_err(ret, string, err) + \
                         'input was:\n' + string
        string = out_string

    out.write(string)
    exit(0)