Class: Zemu::Debug::Symbol

Inherits:
Object
  • Object
show all
Defined in:
lib/zemu/debug.rb

Overview

Represents a symbol definition, of the form ‘label = address`.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, address) ⇒ Symbol

Returns a new instance of Symbol.



95
96
97
98
# File 'lib/zemu/debug.rb', line 95

def initialize(label, address)
    @label = label
    @address = address
end

Instance Attribute Details

#addressObject (readonly)

Address of this symbol in the binary.



93
94
95
# File 'lib/zemu/debug.rb', line 93

def address
  @address
end

#labelObject (readonly)

Textual label for this symbol.



90
91
92
# File 'lib/zemu/debug.rb', line 90

def label
  @label
end

Class Method Details

.parse(s) ⇒ Object

Parse a symbol definition, returning a Symbol instance.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/zemu/debug.rb', line 62

def self.parse(s)
    # Split on whitespace.
    tokens = s.to_s.split(' ')

    if tokens.size < 3
        raise ArgumentError, "Invalid symbol definition: '#{s}'"
    end

    label = tokens[0]

    address = nil

    if /0x[0-9a-fA-F]+/ =~ tokens[2]
        address = tokens[2][2..-1].to_i(16)
    elsif /\$[0-9a-fA-F]+/ =~ tokens[2]
        address = tokens[2][1..-1].to_i(16)
    elsif /\d+/ =~ tokens[2]
        address = tokens[2].to_i
    end

    if address.nil?
        raise ArgumentError, "Invalid symbol address: '#{tokens[2]}'"
    end

    return self.new(label, address)
end