Class: Instruction::Encoding::Field

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

Overview

represents an encoding field (contiguous set of bits that form an opcode or decode variable slot)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, range) ⇒ Field

Returns a new instance of Field.

Parameters:

  • name (#to_s)

    Either string of 0’s ans 1’s or a bunch of dashses

  • range (Range)

    Range of the field in the parent CSR



502
503
504
505
# File 'lib/arch_obj_models/instruction.rb', line 502

def initialize(name, range)
  @name = name.to_s
  @range = range
end

Instance Attribute Details

#nameString (readonly)

Returns Either string of 0’s ans 1’s or a bunch of dashses.

Examples:

Field of a decode variable

encoding.opcode_fields[0] #=> '-----' (for imm5)

Field of an opcode

encoding.opcode_fields[1] #=> '0010011' (for funct7)

Returns:

  • (String)

    Either string of 0’s ans 1’s or a bunch of dashses



495
496
497
# File 'lib/arch_obj_models/instruction.rb', line 495

def name
  @name
end

#rangeRange (readonly)

Returns Range of bits in the parent corresponding to this field.

Returns:

  • (Range)

    Range of bits in the parent corresponding to this field



498
499
500
# File 'lib/arch_obj_models/instruction.rb', line 498

def range
  @range
end

Instance Method Details

#opcode?Boolean

Returns whether or not the field represents part of the opcode (i.e., not a decode variable).

Returns:

  • (Boolean)

    whether or not the field represents part of the opcode (i.e., not a decode variable)



508
509
510
# File 'lib/arch_obj_models/instruction.rb', line 508

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

#to_sObject



512
513
514
# File 'lib/arch_obj_models/instruction.rb', line 512

def to_s
  "#{name}[#{range}]"
end