Class: Instruction::EncodingField

Inherits:
Object
  • Object
show all
Defined in:
lib/arch_obj_models/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.



232
233
234
235
236
# File 'lib/arch_obj_models/instruction.rb', line 232

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



227
228
229
# File 'lib/arch_obj_models/instruction.rb', line 227

def name
  @name
end

#rangeObject (readonly)

range in the encoding



230
231
232
# File 'lib/arch_obj_models/instruction.rb', line 230

def range
  @range
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


244
245
246
# File 'lib/arch_obj_models/instruction.rb', line 244

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

#hashObject



248
249
250
# File 'lib/arch_obj_models/instruction.rb', line 248

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

#opcode?Boolean

is this encoding field a fixed opcode?

Returns:

  • (Boolean)


239
240
241
# File 'lib/arch_obj_models/instruction.rb', line 239

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

#pretty_to_sObject



252
253
254
255
256
# File 'lib/arch_obj_models/instruction.rb', line 252

def pretty_to_s
  return @pretty unless @pretty.nil?

  @name
end

#sizeObject



258
259
260
# File 'lib/arch_obj_models/instruction.rb', line 258

def size
  @range.size
end