Class: Instruction::Encoding
- Inherits:
-
Object
- Object
- Instruction::Encoding
- Defined in:
- lib/arch_obj_models/instruction.rb
Overview
represents an instruction encoding
Defined Under Namespace
Classes: Field
Instance Attribute Summary collapse
-
#decode_variables ⇒ Array<DecodeVariable>
readonly
List of decode variables.
-
#format ⇒ String
readonly
Format, as a string of 0,1 and -,.
-
#opcode_fields ⇒ Array<Field>
readonly
List of fields containing opcodes.
Instance Method Summary collapse
-
#initialize(format, decode_vars) ⇒ Encoding
constructor
A new instance of Encoding.
-
#size ⇒ Integer
Size, in bits, of the encoding.
Constructor Details
#initialize(format, decode_vars) ⇒ Encoding
Returns a new instance of Encoding.
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/arch_obj_models/instruction.rb', line 519 def initialize(format, decode_vars) @format = format @opcode_fields = [] field_chars = [] @format.chars.each_with_index do |c, idx| if c == "-" next if field_chars.empty? field_text = field_chars.join("") field_lsb = @format.size - idx field_msb = @format.size - idx - 1 + field_text.size @opcode_fields << Field.new(field_text, field_lsb..field_msb) field_chars.clear next else field_chars << c end end # add the least significant field unless field_chars.empty? field_text = field_chars.join("") @opcode_fields << Field.new(field_text, 0...field_text.size) end @decode_variables = [] decode_vars&.each do |var| @decode_variables << DecodeVariable.new(self, var) end end |
Instance Attribute Details
#decode_variables ⇒ Array<DecodeVariable> (readonly)
Returns List of decode variables.
486 487 488 |
# File 'lib/arch_obj_models/instruction.rb', line 486 def decode_variables @decode_variables end |
#format ⇒ String (readonly)
Returns format, as a string of 0,1 and -,.
478 479 480 |
# File 'lib/arch_obj_models/instruction.rb', line 478 def format @format end |
#opcode_fields ⇒ Array<Field> (readonly)
Returns List of fields containing opcodes.
483 484 485 |
# File 'lib/arch_obj_models/instruction.rb', line 483 def opcode_fields @opcode_fields end |
Instance Method Details
#size ⇒ Integer
Returns Size, in bits, of the encoding.
553 554 555 |
# File 'lib/arch_obj_models/instruction.rb', line 553 def size @format.size end |