Maor round of bugfixes and incremental improvements
- fixed errors in TextIO and IOModule - moved to Int32 and UInt32 based arithmetic - added a lot of end-to-end and other testsassembly-parser-rework
parent
cd5795bb74
commit
71093fe72f
@ -1,22 +1,22 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from riscemu.types import MemorySection, MemoryFlags, T_RelativeAddress
|
||||
|
||||
class IOModule(ABC):
|
||||
addr: int
|
||||
size: int
|
||||
|
||||
def __init__(self, addr: int, size: int):
|
||||
self.addr = addr
|
||||
self.size = size
|
||||
class IOModule(MemorySection, ABC):
|
||||
def __init__(self, name: str, flags: MemoryFlags, size: int, owner: str = 'system', base: int = 0):
|
||||
super(IOModule, self).__init__(name, flags, size, base, owner, None)
|
||||
|
||||
@abstractmethod
|
||||
def read(self, addr: int, size: int):
|
||||
pass
|
||||
def contains(self, addr, size: int = 0):
|
||||
return self.base <= addr < self.base + self.size and \
|
||||
self.base <= addr + size <= self.base + self.size
|
||||
|
||||
@abstractmethod
|
||||
def write(self, addr: int, data: bytearray, size: int):
|
||||
pass
|
||||
def dump(self, start: T_RelativeAddress, end: Optional[T_RelativeAddress] = None, fmt: str = 'hex',
|
||||
bytes_per_row: int = 16, rows: int = 10, group: int = 4):
|
||||
print(self)
|
||||
|
||||
def contains(self, addr, size: int = 0):
|
||||
return self.addr <= addr < self.addr + self.size and \
|
||||
self.addr <= addr + size <= self.addr + self.size
|
||||
def __repr__(self):
|
||||
return "{}[{}] at 0x{:0X} (size={}bytes, flags={})".format(
|
||||
self.__class__.__name__, self.name, self.base, self.size, self.flags
|
||||
)
|
@ -1,2 +1,3 @@
|
||||
from .test_tokenizer import *
|
||||
from .test_helpers import *
|
||||
from .test_integers import *
|
@ -0,0 +1,19 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from riscemu.types import Int32, UInt32
|
||||
|
||||
|
||||
class TestTokenizer(TestCase):
|
||||
|
||||
def test_logical_right_shift(self):
|
||||
a = Int32(100)
|
||||
self.assertEqual(a.shift_right_logical(0), a)
|
||||
self.assertEqual(a.shift_right_logical(10), 0)
|
||||
self.assertEqual(a.shift_right_logical(1), 100>>1)
|
||||
|
||||
a = Int32(-100)
|
||||
self.assertEqual(a.shift_right_logical(0), a)
|
||||
self.assertEqual(a.shift_right_logical(1), 2147483598)
|
||||
self.assertEqual(a.shift_right_logical(10), 4194303)
|
||||
self.assertEqual(a.shift_right_logical(31), 1)
|
||||
self.assertEqual(a.shift_right_logical(32), 0)
|
Loading…
Reference in New Issue