Esempio n. 1
0
 def loop(self, n_iter):
     """
     Returns a new tester to record actions inside the loop.  The created
     loop action object maintains a references to the return Tester's
     `actions` list.
     """
     loop_tester = LoopTester(self._circuit, self.clock)
     self.actions.append(
         Loop(n_iter, loop_tester.index, loop_tester.actions))
     return loop_tester
Esempio n. 2
0
    def make_file_write(self, i, action):
        assert file_mode_allows_writing(action.file.mode), \
            f'File mode "{action.file.mode}" is not compatible with writing.'

        idx = '__i'
        fd = self.fd_var(action.file)
        value = self.make_name(action.value)
        byte_expr = f"({value} >> (8 * {idx})) & 8'hFF"

        return self.generate_action_code(i, [
            Loop(loop_var=idx,
                 n_iter=action.file.chunk_size,
                 count='down' if action.file.endianness == 'big' else 'up',
                 actions=[self.write_byte(fd, byte_expr)])
        ])
Esempio n. 3
0
    def make_file_read(self, i, action):
        assert file_mode_allows_reading(action.file.mode), \
            f'File mode "{action.file.mode}" is not compatible with reading.'

        idx = '__i'
        fd = self.fd_var(action.file)
        in_ = self.in_var(action.file)

        return self.generate_action_code(i, [
            f'{in_} = 0;',
            Loop(loop_var=idx,
                 n_iter=action.file.chunk_size,
                 count='down' if action.file.endianness == 'big' else 'up',
                 actions=[f'{in_} |= $fgetc({fd}) << (8 * {idx});'])
        ])
Esempio n. 4
0
def test_action_strs():
    circ = common.TestBasicClkCircuit
    assert str(Poke(circ.I, 1)) == 'Poke(BasicClkCircuit.I, 1)'
    assert str(Expect(circ.O, 1)) == 'Expect(BasicClkCircuit.O, 1)'
    assert str(Eval()) == 'Eval()'
    assert str(Step(circ.CLK, 1)) == 'Step(BasicClkCircuit.CLK, steps=1)'
    assert str(Print(circ.O, "%08x")) == 'Print(BasicClkCircuit.O, "%08x")'
    assert str(Peek(circ.O)) == 'Peek(BasicClkCircuit.O)'
    index = f"__fault_loop_var_action_0"
    assert str(Loop(12, index, [Peek(circ.O), Poke(circ.I, 1)])) == \
        f'Loop(12, {index}, ' \
        f'[Peek(BasicClkCircuit.O), Poke(BasicClkCircuit.I, 1)])'
    file = File("my_file", Tester(circ), "r", 1)
    assert str(FileOpen(file)) == 'FileOpen(File<"my_file">)'
    assert str(FileRead(file)) == 'FileRead(File<"my_file">)'
    assert str(FileWrite(file, 3)) == 'FileWrite(File<"my_file">, 3)'
    assert str(FileClose(file)) == 'FileClose(File<"my_file">)'
Esempio n. 5
0
    def make_file_read(self, i, action):
        assert file_mode_allows_reading(action.file.mode), \
            f'File mode {action.file.mode} is not compatible with reading.'

        idx = 'i'
        fd = self.fd_var(action.file)
        in_ = self.in_var(action.file)
        err_msg = f'Reached end of file {action.file.name_without_ext}'

        return self.generate_action_code(i, [
            Loop(loop_var=idx,
                 n_iter=action.file.chunk_size,
                 count='down' if action.file.endianness == 'big' else 'up',
                 actions=[
                     f'int result = fgetc({fd});',
                     If(f'result == EOF',
                        [f'std::cout << "{err_msg}" << std::endl;', 'break;']),
                     f'{in_}[{idx}] = result;'
                 ])
        ])
Esempio n. 6
0
    def make_file_write(self, i, action):
        assert file_mode_allows_writing(action.file.mode), \
            f'File mode {action.file.mode} is not compatible with writing.'

        idx = 'i'
        fd = self.fd_var(action.file)
        value = f'top->{verilator_name(action.value.name)}'
        byte_expr = f'({value} >> ({idx} * 8)) & 0xFF'
        err_msg = f'Error writing to {action.file.name_without_ext}'

        return self.generate_action_code(i, [
            Loop(loop_var=idx,
                 n_iter=action.file.chunk_size,
                 count='down' if action.file.endianness == 'big' else 'up',
                 actions=[
                     'int result = ' + self.write_byte(fd, byte_expr) + ';',
                     If(f'result == EOF',
                        [f'std::cout << "{err_msg}" << std::endl;', 'break;']),
                 ])
        ])