class AVR::OpcodeDecoder::OpcodeDefinition

Constants

ProcType

Attributes

mnemonic[R]
parse_proc[R]
pattern[R]

Public Class Methods

new(pattern, mnemonic, parse_proc) click to toggle source
# File lib/avr/opcode_decoder.rb, line 29
def initialize(pattern, mnemonic, parse_proc)
  @pattern = T.let(pattern.gsub(/[^01a-zA-Z]/, ''), String)
  raise "Incorrect pattern length for #{pattern}" unless @pattern.size == 16

  @mnemonic = mnemonic
  @parse_proc = parse_proc

  @operand_pattern = T.let(nil, T.nilable(String))
  @match_value = T.let(nil, T.nilable(Integer))
  @match_mask = T.let(nil, T.nilable(Integer))
end

Public Instance Methods

extract_operands(word) click to toggle source
# File lib/avr/opcode_decoder.rb, line 62
def extract_operands(word)
  operands = Hash.new(0)
  mask = 0x10000
  pattern.split('').each do |operand|
    mask >>= 1
    next if %w[0 1].include?(operand)

    operands[operand.to_sym] <<= 1
    operands[operand.to_sym] |= 1 if (word & mask) != 0
  end
  operands.each_with_object({}) { |(k, v), h| h[k] = Value.new(v) }
end
match?(word) click to toggle source
# File lib/avr/opcode_decoder.rb, line 57
def match?(word)
  word & match_mask == match_value
end
match_mask() click to toggle source
# File lib/avr/opcode_decoder.rb, line 52
def match_mask
  @match_mask ||= pattern.gsub(/[01]/, '1').gsub(/[^01]/, '0').to_i(2)
end
match_value() click to toggle source
# File lib/avr/opcode_decoder.rb, line 47
def match_value
  @match_value ||= pattern.gsub(/[^01]/, '0').to_i(2)
end
operand_pattern() click to toggle source
# File lib/avr/opcode_decoder.rb, line 42
def operand_pattern
  @operand_pattern ||= pattern.gsub(/[01]/, '_')
end
parse(cpu, opcode_definition, operands) click to toggle source
# File lib/avr/opcode_decoder.rb, line 82
def parse(cpu, opcode_definition, operands)
  parse_proc.call(cpu, opcode_definition, operands)
end