Class: Udb::Instruction::EncodingField

Inherits:
Object
  • Object
show all
Defined in:
lib/udb/obj/instruction.rb

Overview

represents a single contiguous instruction encoding field Multiple EncodingFields may make up a single DecodeField, e.g., when an immediate is split across multiple locations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, range, pretty = nil) ⇒ EncodingField

Returns a new instance of EncodingField.



556
557
558
559
560
# File 'lib/udb/obj/instruction.rb', line 556

def initialize(name, range, pretty = nil)
  @name = name
  @range = range
  @pretty = pretty
end

Instance Attribute Details

#nameObject (readonly)

name, which corresponds to a name used in riscv_opcodes



551
552
553
# File 'lib/udb/obj/instruction.rb', line 551

def name
  @name
end

#rangeObject (readonly)

range in the encoding



554
555
556
# File 'lib/udb/obj/instruction.rb', line 554

def range
  @range
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


568
569
570
# File 'lib/udb/obj/instruction.rb', line 568

def eql?(other)
  @name == other.name && @range == other.range
end

#hashObject



572
573
574
# File 'lib/udb/obj/instruction.rb', line 572

def hash
  [@name, @range].hash
end

#opcode?Boolean

is this encoding field a fixed opcode?

Returns:

  • (Boolean)


563
564
565
# File 'lib/udb/obj/instruction.rb', line 563

def opcode?
  name.match?(/^[01]+$/)
end

#pretty_to_sObject



576
577
578
579
580
# File 'lib/udb/obj/instruction.rb', line 576

def pretty_to_s
  return @pretty unless @pretty.nil?

  @name
end

#sizeObject



582
583
584
# File 'lib/udb/obj/instruction.rb', line 582

def size
  @range.size
end