Ejemplo n.º 1
0
 def init_state(self, instructions, **args):
     """Load the program into a memory object.
     This function should ONLY be called by unit tests.
     """
     mem = new_memory()
     written_so_far = 0
     for i, (data, width) in enumerate(instructions):
         num_bytes = width / 8
         mem.write(RESET_ADDR + written_so_far, num_bytes, data)
         written_so_far += num_bytes
     self.state = new_state(mem=mem, debug=self.debug, **args)
     self.max_insts = len(instructions)
Ejemplo n.º 2
0
def new_state(mem=None, debug=Debug(), **args):
    if mem is None:
        mem = new_memory()
    state = State(mem, debug)
    for attr in possible_attributes:
        if attr in args:
            setattr(state, attr, args[attr])
    for arg, value in args.items():
        if arg in possible_attributes:
            continue
        elif arg.startswith("rf") and arg[2].isdigit():
            index = int(arg[2:])
            if index >= 107:
                raise ValueError("The Epiphany only has 107 registers cannot set rf[%d]." %
                                 index)
            state.set_register(index, value)
        elif arg.startswith("rf") and arg[2:] in reg_map:
            state.set_register(reg_map[arg[2:]], value)
        else:
            raise KeyError('No such register: {0}'.format(arg[2:]))
    return state