• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14def check_N_v8_format(insn)
15  insn.operands.each do |op|
16    raise "Instruction " + insn.mnemonic + " has unexpected format " + insn.format.pretty if ! op.reg? || op.width != 8
17  end
18end
19
20def get_format_for(insn)
21  fmt = insn.format.pretty
22  if fmt == "imm4_v4_v4_v4_v4_v4"
23    # Merge imm4_v4_v4_v4_v4_v4 and imm4_v4_v4_v4 since they haave the same handling code
24    fmt = "imm4_v4_v4_v4"
25  end
26
27  if insn.prefix
28    if fmt == "pref_imm16_v8"
29      # This format requires specific handler for each call instruction
30      fmt = insn.opcode
31    else
32      # All other instructions accept N v8
33      check_N_v8_format(insn)
34      prefix_name = insn.prefix.name
35      fmt = prefix_name + "_N_v8"
36    end
37  end
38  return "call_#{fmt}"
39end
40
41def get_call_insns
42  Panda.instructions.select { |insn| insn.properties.include?('call') && insn.properties.include?('dynamic') }
43end
44