class AVR::OpcodeDecoder

Attributes

opcode_definitions[R]
opcode_match_masks[R]
operand_parsers[R]
cache[R]

Public Class Methods

add_opcode_definition(opcode_definition) click to toggle source
# File lib/avr/opcode_decoder.rb, line 152
def self.add_opcode_definition(opcode_definition)
  opcode_definitions << opcode_definition
  opcode_match_masks[opcode_definition.match_mask] ||= {}
  opcode_match_masks.fetch(opcode_definition.match_mask)[opcode_definition.match_value] = opcode_definition
end
add_operand_parser(operand_parser) click to toggle source
# File lib/avr/opcode_decoder.rb, line 159
def self.add_operand_parser(operand_parser)
  operand_parsers[operand_parser.pattern] = operand_parser
end
new() click to toggle source
# File lib/avr/opcode_decoder.rb, line 167
def initialize
  @cache = T.let({}, T::Hash[Integer, DecodedOpcode])
end

Public Instance Methods

decode(word) click to toggle source
# File lib/avr/opcode_decoder.rb, line 172
def decode(word)
  cached_decoded_opcode = cache[word]
  return cached_decoded_opcode if cached_decoded_opcode

  OpcodeDecoder.opcode_match_masks.each do |mask, values|
    opcode_definition = values[word & mask]
    next unless opcode_definition

    operands = opcode_definition.extract_operands(word)
    decoded_opcode = DecodedOpcode.new(opcode_definition, operands)
    cache[word] = decoded_opcode
    return decoded_opcode
  end
  nil
end
print_cache() click to toggle source