# Path: voidwalker/framework/target/inferior.py
# class Inferior(object):
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, cpu):
#         self._cpu = cpu
#         self._threads = {}
# 
#     @abc.abstractmethod
#     def id(self):
#         raise NotImplementedError
# 
#     def cpu(self):
#         return self._cpu
# 
#     def has_thread(self, thread_id):
#         return thread_id in self._threads
# 
#     def add_thread(self, thread):
#         self._threads[thread.id()] = thread
# 
#     def thread(self, thread_id):
#         assert self.has_thread(thread_id)
#         return self._threads[thread_id]
# 
#     @abc.abstractmethod
#     def disassemble(self, address, length):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def read_memory(self, address, length):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def write_memory(self, buf, address):
#         raise NotImplementedError
# 
# Path: voidwalker/framework/target/inferior.py
# class InferiorFactory(object):
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, cpu_factory):
#         self._cpu_factory = cpu_factory
# 
#     @abc.abstractmethod
#     def create_inferior(self, inferior_id):
#         raise NotImplementedError
# 
# Path: voidwalker/framework/target/thread.py
# class Thread(object):
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, inferior):
#         self._inferior = inferior
#         self._contexts = deque()
# 
#     def get_inferior(self):
#         return self._inferior
# 
#     def contexts(self):
#         return self._contexts
# 
#     @abc.abstractmethod
#     def name(self):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def id(self):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def is_valid(self):
#         raise NotImplementedError
# 
# Path: voidwalker/framework/target/thread.py
# class ThreadFactory(object):
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def create_thread(self, inferior, thread_id):
#         raise NotImplementedError
# 
# Path: voidwalker/backends/test/platform.py
# class TestCpu(Cpu):
#     register_dict = OrderedDict([('gp', ('r0 r1').split()),
#                                  ('sp', ('pc sp flags').split())])
# 
#     def __init__(self, cpu_factory):
#         registers = OrderedDict()
#         for group, register_list in self.register_dict.items():
#             registers[group] = [Register(x) for x in register_list]
#         super(TestCpu, self).__init__(cpu_factory, registers)
# 
#     @classmethod
#     def architecture(cls):
#         return Architecture.Test
# 
#     def stack_pointer(self):
#         return self.register('sp')
# 
#     def program_counter(self):
#         return self.register('pc')
# 
# Path: voidwalker/backends/test/platform.py
# class TestCpuFactory(CpuFactory):
#     def __init__(self):
#         self._registers = None
# 
#     def create_cpu(self, architecture):
#         return TestCpu(self)
# 
#     def create_register(self, cpu, register):
#         class TestRegister(type(register), object):
#             def __init__(self, name):
#                 super(TestRegister, self).__init__(name)
#                 self._size = 8
#                 self._value = 0
# 
#             def size(self):
#                 return self._size
# 
#             def value(self):
#                 return self._value
# 
#         return TestRegister(register.name())


from ...framework.target import Inferior
from ...framework.target import InferiorFactory
from ...framework.target import Thread
from ...framework.target import ThreadFactory
from .platform import TestCpu
from .platform import TestCpuFactory


class TestInferiorFactory(InferiorFactory):
    def __init__(self):
        super(TestInferiorFactory, self).__init__(TestCpuFactory())

    def create_inferior(self, cpu, inferior_id):
        return TestInferior(cpu, inferior_id)

    def create_thread(self, inferior, thread_id):
        thread = TestThread(inferior.id(), thread_id)
        inferior.add_thread(thread)
        return thread


class TestThread(Thread):
    def __init__(self, inferior, thread_id):
        super(TestThread, self).__init__(inferior)
        self._thread_id = thread_id

    def name(self):
        return ('thread %d' % self._thread_id)

    def id(self):
        return self._thread_id

    def is_valid(self):
        return True



# Path: voidwalker/framework/target/inferior.py
# class Inferior(object):
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, cpu):
#         self._cpu = cpu
#         self._threads = {}
# 
#     @abc.abstractmethod
#     def id(self):
#         raise NotImplementedError
# 
#     def cpu(self):
#         return self._cpu
# 
#     def has_thread(self, thread_id):
#         return thread_id in self._threads
# 
#     def add_thread(self, thread):
#         self._threads[thread.id()] = thread
# 
#     def thread(self, thread_id):
#         assert self.has_thread(thread_id)
#         return self._threads[thread_id]
# 
#     @abc.abstractmethod
#     def disassemble(self, address, length):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def read_memory(self, address, length):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def write_memory(self, buf, address):
#         raise NotImplementedError
# 
# Path: voidwalker/framework/target/inferior.py
# class InferiorFactory(object):
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, cpu_factory):
#         self._cpu_factory = cpu_factory
# 
#     @abc.abstractmethod
#     def create_inferior(self, inferior_id):
#         raise NotImplementedError
# 
# Path: voidwalker/framework/target/thread.py
# class Thread(object):
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, inferior):
#         self._inferior = inferior
#         self._contexts = deque()
# 
#     def get_inferior(self):
#         return self._inferior
# 
#     def contexts(self):
#         return self._contexts
# 
#     @abc.abstractmethod
#     def name(self):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def id(self):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def is_valid(self):
#         raise NotImplementedError
# 
# Path: voidwalker/framework/target/thread.py
# class ThreadFactory(object):
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def create_thread(self, inferior, thread_id):
#         raise NotImplementedError
# 
# Path: voidwalker/backends/test/platform.py
# class TestCpu(Cpu):
#     register_dict = OrderedDict([('gp', ('r0 r1').split()),
#                                  ('sp', ('pc sp flags').split())])
# 
#     def __init__(self, cpu_factory):
#         registers = OrderedDict()
#         for group, register_list in self.register_dict.items():
#             registers[group] = [Register(x) for x in register_list]
#         super(TestCpu, self).__init__(cpu_factory, registers)
# 
#     @classmethod
#     def architecture(cls):
#         return Architecture.Test
# 
#     def stack_pointer(self):
#         return self.register('sp')
# 
#     def program_counter(self):
#         return self.register('pc')
# 
# Path: voidwalker/backends/test/platform.py
# class TestCpuFactory(CpuFactory):
#     def __init__(self):
#         self._registers = None
# 
#     def create_cpu(self, architecture):
#         return TestCpu(self)
# 
#     def create_register(self, cpu, register):
#         class TestRegister(type(register), object):
#             def __init__(self, name):
#                 super(TestRegister, self).__init__(name)
#                 self._size = 8
#                 self._value = 0
# 
#             def size(self):
#                 return self._size
# 
#             def value(self):
#                 return self._value
# 
#         return TestRegister(register.name())


# Path: voidwalker/backends/test/target.py
from ...framework.target import Inferior
from ...framework.target import InferiorFactory
from ...framework.target import Thread
from ...framework.target import ThreadFactory
from .platform import TestCpu
from .platform import TestCpuFactory



class TestInferiorFactory(InferiorFactory):
    def __init__(self):
        super(TestInferiorFactory, self).__init__(TestCpuFactory())

    def create_inferior(self, cpu, inferior_id):
        return TestInferior(cpu, inferior_id)

    def create_thread(self, inferior, thread_id):
        thread = TestThread(inferior.id(), thread_id)
        inferior.add_thread(thread)
        return thread


class TestThread(Thread):
    def __init__(self, inferior, thread_id):
        super(TestThread, self).__init__(inferior)
        self._thread_id = thread_id

    def name(self):
        return ('thread %d' % self._thread_id)

    def id(self):
        return self._thread_id

    def is_valid(self):
        return True



class TestThreadFactory(ThreadFactory):