Class: AVR::OpcodeDecoder::OpcodeDefinition
- Inherits:
-
Object
- Object
- AVR::OpcodeDecoder::OpcodeDefinition
- Extended by:
- T::Sig
- Defined in:
- lib/avr/opcode_decoder.rb
Constant Summary collapse
- ProcType =
T.type_alias do T.proc.params( cpu: CPU, opcode_definition: OpcodeDefinition, operands: Opcode::OperandValueHashType ).returns(Instruction) end
Instance Attribute Summary collapse
-
#mnemonic ⇒ Object
readonly
Returns the value of attribute mnemonic.
-
#parse_proc ⇒ Object
readonly
Returns the value of attribute parse_proc.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #extract_operands(word) ⇒ Object
-
#initialize(pattern, mnemonic, parse_proc) ⇒ OpcodeDefinition
constructor
A new instance of OpcodeDefinition.
- #match?(word) ⇒ Boolean
- #match_mask ⇒ Object
- #match_value ⇒ Object
- #operand_pattern ⇒ Object
- #parse(cpu, opcode_definition, operands) ⇒ Object
Constructor Details
#initialize(pattern, mnemonic, parse_proc) ⇒ OpcodeDefinition
Returns a new instance of OpcodeDefinition.
29 30 31 32 33 34 35 36 37 38 39 |
# 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 |
Instance Attribute Details
#mnemonic ⇒ Object (readonly)
Returns the value of attribute mnemonic.
23 24 25 |
# File 'lib/avr/opcode_decoder.rb', line 23 def mnemonic @mnemonic end |
#parse_proc ⇒ Object (readonly)
Returns the value of attribute parse_proc.
26 27 28 |
# File 'lib/avr/opcode_decoder.rb', line 26 def parse_proc @parse_proc end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
20 21 22 |
# File 'lib/avr/opcode_decoder.rb', line 20 def pattern @pattern end |
Instance Method Details
#extract_operands(word) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# 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) ⇒ Boolean
57 58 59 |
# File 'lib/avr/opcode_decoder.rb', line 57 def match?(word) word & match_mask == match_value end |
#match_mask ⇒ Object
52 53 54 |
# 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 ⇒ Object
47 48 49 |
# File 'lib/avr/opcode_decoder.rb', line 47 def match_value @match_value ||= pattern.gsub(/[^01]/, '0').to_i(2) end |
#operand_pattern ⇒ Object
42 43 44 |
# File 'lib/avr/opcode_decoder.rb', line 42 def operand_pattern @operand_pattern ||= pattern.gsub(/[01]/, '_') end |
#parse(cpu, opcode_definition, operands) ⇒ Object
82 83 84 |
# File 'lib/avr/opcode_decoder.rb', line 82 def parse(cpu, opcode_definition, operands) parse_proc.call(cpu, opcode_definition, operands) end |