Convert a list of instructions into an easm op code string.

    :param instruction_list:
    :return:
516431
def instruction_list_to_easm(instruction_list: list) -> str:
    
    result = ""

    for instruction in instruction_list:
        result += "{} {}".format(instruction["address"], instruction["opcode"])
        if "argument" in instruction:
            result += " " + instruction["argument"]
        result += "\n"

    return result
1251377
def opcode_list(self, script):
        """"""
        opcodes = []
        new_pc = 0
        try:
            for opcode, data, pc, new_pc in self.get_opcodes(script):
                opcodes.append(self.disassemble_for_opcode_data(opcode, data))
        except ScriptError:
            opcodes.append(binascii.hexlify(script[new_pc:]).decode("utf8"))

        return opcodes
1150060
def to_word(stype):
    
    output = []  # List of instructions

    if stype == 'u8':  # Byte to word
        output.append('ld l, a')
        output.append('ld h, 0')

    elif stype == 'i8':  # Signed byte to word
        output.append('ld l, a')
        output.append('add a, a')
        output.append('sbc a, a')
        output.append('ld h, a')

    elif stype == 'f16':  # Must MOVE HL into DE
        output.append('ex de, hl')

    elif stype == 'f':
        output.append('call __FTOU32REG')
        REQUIRES.add('ftou32reg.asm')

    return output
454424
def operands(self):
        
        if not self.is_instruction:
            raise ValueError('expected instruction value, got %s'
                             % (self._kind,))
        it = ffi.lib.LLVMPY_InstructionOperandsIter(self)
        parents = self._parents.copy()
        parents.update(instruction=self)
        return _OperandsIterator(it, parents)
211206
def get_user_instructions(self):
        
        res = []
        # TODO: Check if instructions can be stored in other content_trees
        for e in get_instructions(self.content_trees[0], self.namespaces):
            childs = e.getchildren()
            if childs:
                res.extend([c.text for c in childs])
            else:
                res.append(e.text)
        return res
967529
def merge_specific_instructions(chunks, join_preamble=True, join_raster=True):
    
    new_instructions = []
    last_opcode = None
    instruction_buffer = b''
    for instruction in chunks:
        opcode = match_opcode(instruction)
        if   join_preamble and OPCODES[opcode][0] == 'preamble' and last_opcode == 'preamble':
            instruction_buffer += instruction
        elif join_raster   and 'raster' in OPCODES[opcode][0] and 'raster' in last_opcode:
            instruction_buffer += instruction
        else:
            if instruction_buffer:
                new_instructions.append(instruction_buffer)
            instruction_buffer = instruction
        last_opcode = OPCODES[opcode][0]
    if instruction_buffer:
        new_instructions.append(instruction_buffer)
    return new_instructions
341880
def oper(inst):
    
    i = inst.strip(' \t\n').split(' ')
    I = i[0].lower()  # Instruction
    i = ''.join(i[1:])

    op = i.split(',')
    if I in {'call', 'jp', 'jr'} and len(op) > 1:
        op = op[1:] + ['f']

    elif I == 'djnz':
        op.append('b')

    elif I in {'push', 'pop', 'call'}:
        op.append('sp')  # Sp is also affected by push, pop and call

    elif I in {'or', 'and', 'xor', 'neg', 'cpl', 'rrca', 'rlca'}:
        op.append('a')

    elif I in {'rra', 'rla'}:
        op.extend(['a', 'f'])

    elif I in ('rr', 'rl'):
        op.append('f')

    elif I in {'adc', 'sbc'}:
        if len(op) == 1:
            op = ['a', 'f'] + op

    elif I in {'add', 'sub'}:
        if len(op) == 1:
            op = ['a'] + op

    elif I in {'ldd', 'ldi', 'lddr', 'ldir'}:
        op = ['hl', 'de', 'bc']

    elif I in {'cpd', 'cpi', 'cpdr', 'cpir'}:
        op = ['a', 'hl', 'bc']

    elif I == 'exx':
        op = ['*', 'bc', 'de', 'hl', 'b', 'c', 'd', 'e', 'h', 'l']

    elif I in {'ret', 'reti', 'retn'}:
        op += ['sp']

    elif I == 'out':
        if len(op) and RE_OUTC.match(op[0]):
            op[0] = 'c'
        else:
            op.pop(0)

    elif I == 'in':
        if len(op) > 1 and RE_OUTC.match(op[1]):
            op[1] = 'c'
        else:
            op.pop(1)

    for i in range(len(op)):
        tmp = RE_INDIR16.match(op[i])
        if tmp is not None:
            op[i] = '(' + op[i].strip()[1:-1].strip().lower() + ')'  # '  (  dE )  ' => '(de)'

    return op
618342
def execute_lite(self, instructions, context=None):
        
        if context:
            self.__cpu.registers = dict(context)

        for instr in instructions:
            self.__execute_one(instr)

        return dict(self.__cpu.registers), self.__mem
1008717
def get_instructions(self):
        
        # it is possible to a cache for instructions (avoid a new disasm)
        if self.cached_instructions is None:
            lsa = LinearSweepAlgorithm()
            ins = lsa.get_instructions(self.CM, self.size, self.insn,
                                          self.idx)
            self.cached_instructions = list(ins)

        for i in self.cached_instructions:
            yield i
212966
def build_instructions(self, co):
        
        # FIXME: remove this when all subsidiary functions have been removed.
        # We should be able to get everything from the self.insts list.
        self.code = array('B', co.co_code)

        bytecode = Bytecode(co, self.opc)
        self.build_prev_op()
        self.insts = self.remove_extended_args(list(bytecode))
        self.lines = self.build_lines_data(co)
        self.offset2inst_index = {}
        for i, inst in enumerate(self.insts):
            self.offset2inst_index[inst.offset] = i

        return bytecode
1335832
def get_ir(cfg_func):
    
    ir_func = ir.Function()
    ir_var_list = []
    cfg_var_list = []
    ir_bb_label_list = []
    for cfg_var in cfg_func.variable_list:
        ir_var = ir.Variable(cfg_var.name)
        ir_var_list.append(ir_var)
        cfg_var_list.append(cfg_var)
    label = 0
    for cfg_bb in cfg_func.basic_block_list:
        ir_bb_label_list.append(label)
        for cfg_instr in cfg_bb.instruction_list:
            if isinstance(cfg_instr, cfg.ArithInstruction):
                ir_instr = ir.ArithInstruction(ir_func)
                ir_lhs = get_ir_numeric(cfg_instr.lhs, cfg_var_list, ir_var_list)
                ir_rhs_1 = get_ir_numeric(cfg_instr.rhs_1, cfg_var_list, ir_var_list)
                ir_rhs_2 = get_ir_numeric(cfg_instr.rhs_2, cfg_var_list, ir_var_list)
                ir_op = ir.Operation(cfg_instr.op.name)
                ir_instr.update(ir_lhs, ir_rhs_1, ir_rhs_2, ir_op)
            elif isinstance(cfg_instr, cfg.CmpInstruction):
                ir_instr = ir.CmpInstruction(ir_func)
                ir_lhs = get_ir_numeric(cfg_instr.lhs, cfg_var_list, ir_var_list)
                ir_rhs_1 = get_ir_numeric(cfg_instr.rhs_1, cfg_var_list, ir_var_list)
                ir_rhs_2 = get_ir_numeric(cfg_instr.rhs_2, cfg_var_list, ir_var_list)
                ir_op = ir.Operation(cfg_instr.op.name)
                ir_instr.update(ir_lhs, ir_rhs_1, ir_rhs_2, ir_op)
            elif isinstance(cfg_instr, cfg.EqInstruction):
                ir_instr = ir.EqInstruction(ir_func)
                ir_lhs = get_ir_numeric(cfg_instr.lhs, cfg_var_list, ir_var_list)
                ir_rhs = get_ir_numeric(cfg_instr.rhs, cfg_var_list, ir_var_list)
                ir_instr.update(ir_lhs, ir_rhs)
            ir_func.add_instruction_by_label(label, ir_instr)
            label += 1
        #at end of BB, add branch statements
        if cfg_bb.number_of_children is 1:
            ir_instr = ir.UncondnJumpInstruction(ir_func)
            ir_func.add_instruction_by_label(label, ir_instr)
        elif cfg_bb.number_of_children is 2:
            if isinstance(cfg_bb.condition_instr, cfg.CmpInstruction):
                ir_instr = ir.CmpInstruction(ir_func)
                ir_lhs = get_ir_numeric(cfg_bb.condition_instr.lhs, cfg_var_list, ir_var_list)
                ir_rhs_1 = get_ir_numeric(cfg_bb.condition_instr.rhs_1, cfg_var_list, ir_var_list)
                ir_rhs_2 = get_ir_numeric(cfg_bb.condition_instr.rhs_2, cfg_var_list, ir_var_list)
                ir_op = ir.Operation(cfg_bb.condition_instr.op.name)
                ir_instr.update(ir_lhs, ir_rhs_1, ir_rhs_2, ir_op)
                ir_func.add_instruction_by_label(label, ir_instr)
                label += 1
            ir_instr = ir.CondnJumpInstruction(ir_func)
            ir_condn_var = get_ir_numeric(cfg_bb.condition, cfg_var_list, ir_var_list)
            ir_instr.update(ir_condn_var, 0, 0)
            ir_func.add_instruction_by_label(label, ir_instr)
        else:
            ir_instr = ir.ReturnInstruction(ir_func)
            ir_func.add_instruction_by_label(label, ir_instr)
        label += 1

    k = 0
    for cfg_bb in cfg_func.basic_block_list:
        if cfg_bb.number_of_children is 1:
            this_label = ir_bb_label_list[k] + len(cfg_bb.instruction_list)
            assert(isinstance(ir_func.instr_list[this_label], ir.UncondnJumpInstruction))
            next_label = ir_bb_label_list[cfg_bb.child.identity]
            ir_func.instr_list[this_label].next_instr_label = next_label
        elif cfg_bb.number_of_children is 2:
            this_label = ir_bb_label_list[k] + len(cfg_bb.instruction_list) 
            if isinstance(cfg_bb.condition_instr, cfg.CmpInstruction):
                this_label += 1
            assert(isinstance(ir_func.instr_list[this_label], ir.CondnJumpInstruction))
            next_true_label = ir_bb_label_list[cfg_bb.child_true.identity]
            next_false_label = ir_bb_label_list[cfg_bb.child_false.identity]
            ir_func.instr_list[this_label].instr_true_label = next_true_label
            ir_func.instr_list[this_label].instr_false_label = next_false_label
        k += 1
    ir_input_variables = []
    for cfg_var in cfg_func.input_variable_list:
        ir_var = get_ir_numeric(cfg_var, cfg_var_list, ir_var_list)
        ir_input_variables.append(ir_var)

    ir_output_variables = []
    for cfg_var in cfg_func.output_variable_list:
        ir_var = get_ir_numeric(cfg_var, cfg_var_list, ir_var_list)
        ir_output_variables.append(ir_var)
    ir_func.set_input_variables(ir_input_variables)
    ir_func.set_output_variables(ir_output_variables)
    ir_func.add_summary(cfg_func.summary)
    return ir_func
1255563
def tokenize_ofp_instruction_arg(arg):
    
    arg_re = re.compile("[^,()]*")
    try:
        rest = arg
        result = []
        while len(rest):
            m = arg_re.match(rest)
            if m.end(0) == len(rest):
                result.append(rest)
                return result
            if rest[m.end(0)] == '(':
                this_block, rest = _tokenize_paren_block(
                    rest, m.end(0) + 1)
                result.append(this_block)
            elif rest[m.end(0)] == ',':
                result.append(m.group(0))
                rest = rest[m.end(0):]
            else:  # is ')'
                raise Exception
            if len(rest):
                assert rest[0] == ','
                rest = rest[1:]
        return result
    except Exception:
        raise ryu.exception.OFPInvalidActionString(action_str=arg)
706527
def execute(self, asm_instr):
        
        # Update the instruction pointer.
        self.ir_emulator.registers[self.ip] = asm_instr.address + asm_instr.size

        # Process syscall.
        if self.arch_info.instr_is_syscall(asm_instr):
            raise Syscall()

        # Process instruction and return next address instruction to execute.
        return self.__execute(asm_instr)
289695
def assemble(self, code):
        
        with io.BytesIO() as code_out:
            for ins in code:
                write_instruction(code_out, code_out.tell(), ins)
            self._code = code_out.getvalue()
758685
def show(self):
        
        off = 0
        for n, i in enumerate(self.get_instructions()):
            print("{:8d} (0x{:08x}) {:04x} {:30} {}".format(n, off, i.get_op_value(), i.get_name(), i.get_output(self.idx)))
            off += i.get_length()
67448
def parse_instruction(string, location, tokens):
    
    mnemonic_str = tokens.get("mnemonic")
    operands = [op for op in tokens.get("operands", [])]

    instr = ArmInstruction(
        string,
        mnemonic_str["ins"],
        operands,
        arch_info.architecture_mode
    )

    if "cc" in mnemonic_str:
        instr.condition_code = cc_mapper[mnemonic_str["cc"]]

    if "uf" in mnemonic_str:
        instr.update_flags = True

    if "ldm_stm_addr_mode" in mnemonic_str:
        instr.ldm_stm_addr_mode = ldm_stm_am_mapper[mnemonic_str["ldm_stm_addr_mode"]]

    return instr
486885
def instructions(self):
        

        if self._instructions is None:
            # Compile the rule into an Instructions instance; we do
            # this lazily to amortize the cost of the compilation,
            # then cache that result for efficiency...
            self._instructions = parser.parse_rule(self.name, self.text)

        return self._instructions