Class: ElfUtils::Section::DebugLine::LineNumberProgram::StateMachine::StateRegisters

Inherits:
Struct
  • Object
show all
Defined in:
lib/elf_utils/section/debug_line/line_number_program/state_machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ StateRegisters

Returns a new instance of StateRegisters.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 13

def initialize(args)
  # save off values we need for `#advance`
  @maximum_operations_per_instruction =
    args.delete(:maximum_operations_per_instruction)
  @minimum_instruction_length = args.delete(:minimum_instruction_length)

  # add the hard-coded defaults
  args.merge!(
    address: 0,
    op_index: 0,
    file: 1,
    line: 1,
    column: 0,
    basic_block: false,
    end_sequence: false,
    prologue_end: false,
    epilogue_begin: false,
    isa: 0,
    discriminator: 0
  )

  # save off the initial values to support `#reset`
  @initial_values = args
  super
end

Instance Attribute Details

#addressObject

Returns the value of attribute address

Returns:

  • (Object)

    the current value of address



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def address
  @address
end

#basic_blockObject

Returns the value of attribute basic_block

Returns:

  • (Object)

    the current value of basic_block



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def basic_block
  @basic_block
end

#columnObject

Returns the value of attribute column

Returns:

  • (Object)

    the current value of column



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def column
  @column
end

#discriminatorObject

Returns the value of attribute discriminator

Returns:

  • (Object)

    the current value of discriminator



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def discriminator
  @discriminator
end

#end_sequenceObject

Returns the value of attribute end_sequence

Returns:

  • (Object)

    the current value of end_sequence



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def end_sequence
  @end_sequence
end

#epilogue_beginObject

Returns the value of attribute epilogue_begin

Returns:

  • (Object)

    the current value of epilogue_begin



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def epilogue_begin
  @epilogue_begin
end

#fileObject

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def file
  @file
end

#is_stmtObject

Returns the value of attribute is_stmt

Returns:

  • (Object)

    the current value of is_stmt



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def is_stmt
  @is_stmt
end

#isaObject

Returns the value of attribute isa

Returns:

  • (Object)

    the current value of isa



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def isa
  @isa
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def line
  @line
end

#op_indexObject

Returns the value of attribute op_index

Returns:

  • (Object)

    the current value of op_index



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def op_index
  @op_index
end

#prologue_endObject

Returns the value of attribute prologue_end

Returns:

  • (Object)

    the current value of prologue_end



10
11
12
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 10

def prologue_end
  @prologue_end
end

Instance Method Details

#advance(operation_advance) ⇒ Object

advance ‘address` & `op_index` by the provided `operation_advance`



40
41
42
43
44
45
46
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 40

def advance(operation_advance)
  self.address += @minimum_instruction_length *
    ((op_index + operation_advance) /
      @maximum_operations_per_instruction)
  self.op_index = (op_index + operation_advance) %
    @maximum_operations_per_instruction
end

#flagsObject



53
54
55
56
57
58
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 53

def flags
  flags = []
  %i[is_stmt basic_block end_sequence prologue_end epilogue_begin]
    .each { |f| flags << f if send(f) }
  flags
end

#resetObject

reset the registers to their initial values



49
50
51
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 49

def reset
  @initial_values.each { |k, v| self[k] = v }
end

#to_sObject



60
61
62
63
64
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 60

def to_s
  "0x%016x %6d %6d %6d %3d %13d  %s" % [
    address, line, column, file, isa, discriminator, flags.join(" ")
  ]
end