def update_from_chunk(self): chunk = self.chunk[8:] pos = 0 rifx = self.config.rifx parents = [self] while pos < len(chunk): size = utils.word2py_int(chunk[pos:pos + 2], rifx) instr_id = chunk[pos + 2:pos + 4] instr_id = abs(utils.signed_word2py_int(instr_id, rifx)) instr = chunk[pos:pos + size] offset = self.offset + 8 + pos obj = cmx_instr.make_instruction(self.config, instr, offset) name = cmx_const.INSTR_CODES.get(instr_id, '') if name.startswith('Begin'): parents[-1].add(obj) parents.append(obj) elif name.startswith('End'): parents[-1].add(obj) parents = parents[:-1] elif instr_id == cmx_const.JUMP_ABSOLUTE: parents[-1].add(obj) sz = obj.get('jump') - offset - 8 obj.chunk += chunk[pos + 8:pos + 8 + sz] size += sz else: parents[-1].add(obj) pos += size self.chunk = self.chunk[:8]
def make_instruction(config, chunk=None, offset=0, identifier=None, **kwargs): instructions = INSTR_16bit if config.v16bit else INSTR_32bit if chunk is not None: identifier = abs(utils.signed_word2py_int(chunk[2:4], config.rifx)) cls = instructions.get(identifier, CmxInstruction) kwargs['code'] = identifier return cls(config, chunk, offset, **kwargs)
def update_from_chunk(self): chunk = self.chunk[8:] pos = 0 rifx = self.config.rifx parents = [self] while pos < len(chunk): size = utils.word2py_int(chunk[pos:pos + 2], rifx) instr_id = utils.signed_word2py_int(chunk[pos + 2:pos + 4], rifx) instr = chunk[pos:pos + size] obj = cmx_instr.make_instruction(self.config, instr) name = cmx_const.INSTR_CODES.get(instr_id, '') if name.startswith('Begin'): parents[-1].add(obj) parents.append(obj) elif name.startswith('End'): parents = parents[:-1] parents[-1].add(obj) else: parents[-1].add(obj) pos += size self.chunk = self.chunk[:8]
def _get_code(self, code_str): return abs(utils.signed_word2py_int(code_str, self.config.rifx))