Class: RPicSim::Xc8SymFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rpicsim/xc8_sym_file.rb

Overview

This class can be used to load an XC8 sym file and get the information about the symbols in it. This is useful because the COF file produced by XC8 does not have enough information to identify what memory space every symbol is in.

Example usage:

class MySim < RPicSim::Sim
  use_device 'PIC18F25K50'
  use_file DistDir + 'TestXC8.hex'
  import_symbols RPicSim::Xc8SymFile.new(DistDir + 'TestXC8.sym')

  # ...
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, opts = {}) ⇒ Xc8SymFile

Creates a new instance of this class containing information from the specified file.

Parameters:

  • filename (String)
  • opts (Hash) (defaults to: {})

    Specified additional options. The options are:

    • :user_ram_sections: Array of strings of section names that should be considered to be in RAM.

    • :user_program_memory_sections: Array of strings of section names that should be considered to be in program memory.

    • :user_eeprom_sections: Array of strings of section names that should be considered to be in EEPROM.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rpicsim/xc8_sym_file.rb', line 64

def initialize(filename, opts = {})
  @symbols = {}
  @symbols_in_ram = {}
  @symbols_in_eeprom = {}
  @symbols_in_program_memory = {}

  @filename = filename
  @sections_in_ram = %w{ABS BIGRAM COMRAM RAM SFR FARRAM
                        BANK0 BANK1 BANK2 BANK3 BANK4 BANK5 BANK6 BANK7}
  @sections_in_code = %w{CODE CONST IDLOC MEDIUMCONST SMALLCONST}
  @sections_in_eeprom = %w{EEDATA}

  allowed_keys = [:user_ram_sections,
                  :user_program_memory_sections,
                  :user_eeprom_sections,
                  :custom_ram_sections,
                  :custom_code_sections,
                  :custom_eeprom_sections]
  invalid_keys = opts.keys - allowed_keys
  if !invalid_keys.empty?
    raise "Invalid options: #{invalid_keys.inspect}"
  end

  @sections_in_ram += opts.fetch(:user_ram_sections, [])
  @sections_in_code += opts.fetch(:user_program_memory_sections, [])
  @sections_in_eeprom += opts.fetch(:user_eeprom_sections, [])

  # Legacy options introduced in 0.4.0, but deprecated now.
  @sections_in_ram += opts.fetch(:custom_ram_sections, [])
  @sections_in_code += opts.fetch(:custom_code_sections, [])
  @sections_in_eeprom += opts.fetch(:custom_eeprom_sections, [])

  read_data
  sort_data
end

Instance Attribute Details

#symbolsHash (readonly)

Returns all the symbols. The return value is a hash where the keys are the names of the symbols (represented as Ruby symbols) and the values are the addresses of the symbols.

Returns:

  • (Hash)


27
28
29
# File 'lib/rpicsim/xc8_sym_file.rb', line 27

def symbols
  @symbols
end

#symbols_in_eepromHash (readonly)

Returns all the symbols in EEPROM. The return value is a hash where the keys are the names of the symbols (represented as Ruby symbols) and the values are the addresses of the symbols.

Returns:

  • (Hash)


41
42
43
# File 'lib/rpicsim/xc8_sym_file.rb', line 41

def symbols_in_eeprom
  @symbols_in_eeprom
end

#symbols_in_program_memoryHash (readonly)

Returns all the symbols in program memory. The return value is a hash where the keys are the names of the symbols (represented as Ruby symbols) and the values are the addresses of the symbols.

Returns:

  • (Hash)


48
49
50
# File 'lib/rpicsim/xc8_sym_file.rb', line 48

def symbols_in_program_memory
  @symbols_in_program_memory
end

#symbols_in_ramHash (readonly)

Returns all the symbols in RAM. The return value is a hash where the keys are the names of the symbols (represented as Ruby symbols) and the values are the addresses of the symbols.

Returns:

  • (Hash)


34
35
36
# File 'lib/rpicsim/xc8_sym_file.rb', line 34

def symbols_in_ram
  @symbols_in_ram
end