Class: Udb::InstructionSubtype

Inherits:
DatabaseObject show all
Defined in:
lib/udb/obj/instruction.rb

Defined Under Namespace

Classes: Opcode

Instance Method Summary collapse

Constructor Details

#initialize(data, data_path, arch, name: nil)

Parameters:

  • data (Hash{String => T.untyped})
  • data_path (String, Pathname)
  • arch (ConfiguredArchitecture)
  • name (String, nil) (defaults to: nil)


67
68
69
# File 'lib/udb/obj/instruction.rb', line 67

def initialize(data, data_path, arch, name: nil)
  super(data, data_path, arch, DatabaseObject::Kind::InstructionSubtype, name:)
end

Instance Method Details

#opcodesArray<Instruction::Encoding::Field>

Returns:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/udb/obj/instruction.rb', line 87

def opcodes
  @opcodes ||=
    @data["data"]["opcodes"].map do |opcode_name, opcode_data|
      next if opcode_name[0] == "$"

      raise "unexpected: opcode field is not contiguous" if opcode_data["location"].include?("|")

      loc = opcode_data["location"]
      range =
        if loc =~ /^([0-9]+)$/
          bit = ::Regexp.last_match(1)
          bit.to_i..bit.to_i
        elsif loc =~ /^([0-9]+)-([0-9]+)$/
          msb = ::Regexp.last_match(1)
          lsb = ::Regexp.last_match(2)
          raise "range must be specified 'msb-lsb'" unless msb.to_i >= lsb.to_i

          lsb.to_i..msb.to_i
        else
          raise "location format error"
        end
      Instruction::Encoding::Field.new(opcode_name, range)
    end.reject(&:nil?)
end

#typeInstructionType

Returns:



72
73
74
# File 'lib/udb/obj/instruction.rb', line 72

def type
  @type ||= @arch.ref(@data["data"]["type"]["$ref"])
end

#variablesArray<Instruction::DecodeVariable>

Returns:



77
78
79
80
81
82
83
84
# File 'lib/udb/obj/instruction.rb', line 77

def variables
  @variables ||=
    if @data["data"].key?("variables")
      @data["data"]["variables"].map { |var_name, var_data| Instruction::DecodeVariable.new(var_name, var_data) }
    else
      []
    end
end