def clean(self) -> None: """ Clean each address of memory with empty words """ self.mem_blocks[self.TEXT_SECTION_START] = Word() self.mem_blocks[self.DATA_SECTION_START] = Word() self.mem_blocks[self.STACK_POINTER] = Word() self.mem_blocks[self.GLOBAL_POINTER] = Word()
def __init__(self, data, tag, address): self.data = Word(data=data) self.tag = tag self.address = address self.valid = False self.dirty = False self.timestamp = datetime.utcnow().timestamp()
def __load_line(self, line, line_size): line = (line // line_size) * line_size data_line = [] for offset in range(0, line_size, 4): data = self.mem_blocks.get(line + offset, Word()).data data_line.append(data) return data_line
def set_register_value(self, num: int, value): if self.__is_valid_register(num): if num == 0: return self.registers[num].value = Word((value or 0)) else: raise InvalidRegister( "Invalid Register, there only 32 valid registers")
def __call__(self, word: Word) -> None: self.ft = word.get_k_bits_from(1, 16) self.instruction_name = self.instruction_name + 'T' if int( self.ft) == 1 else self.instruction_name + 'F' super().__call__(word) return self
def set_lo_value(self, value): self.registers["LO"].value = Word(value)
def __init__(self, name: str, value: Word = Word()): self.name = name self.value = value
def set_hi_value(self, value): self.registers["HI"].value = Word(value)
def store(self, address, data): block = self.block_index(address) self.cache_control[block].valid_this() self.cache_control[block].clean_this() self.cache_control[block].set_tag(address) self.cache[block] = Word(data)
def test_is_empty(self): empty_word = Word() assert empty_word.is_empty()
def __store(self, address, data): self.mem_blocks[address] = Word(data)
def __load(self, address) -> Word: self.access_count[3] += 1 data = self.mem_blocks.get(address, Word(data=None)) return data
def factory(self, word: Word) -> BaseInstruction: op_code = word.get_opcode() if word.is_empty(): raise Exception("Empty instruction") return self.instructions.get(op_code, self.i_inst)(word)