Class: Udb::InstructionSubtype

Inherits:
TopLevelDatabaseObject 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)

Parameters:



65
66
67
# File 'lib/udb/obj/instruction.rb', line 65

def initialize(data, data_path, arch)
  super(data, data_path, arch)
end

Instance Method Details

#opcodesArray<Instruction::Encoding::Field>

Returns:



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

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:



70
71
72
# File 'lib/udb/obj/instruction.rb', line 70

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

#variablesArray<Instruction::DecodeVariable>

Returns:



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

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