Fix parse map info error bug.
import sys
import re
-map_file = sys.argv[1]
-
+def get_mem_info(map_file):
total_ram = 0
total_rom = 0
map_lines = []
@@ -12,7 +11,12 @@ with open(map_file, 'r') as f:
s = f.read()
# find the memory configuration
- mem_config_text = re.findall('Memory Configuration\n\nName Origin Length Attributes\n([\s\S]+)\nLinker script and memory map', s)[0]
+ mem_config_list = re.findall('Memory Configuration\n\nName Origin Length Attributes\n([\s\S]+)\nLinker script and memory map', s)
+ mem_config_text = '' if not mem_config_list else mem_config_list[0]
+ if not mem_config_text:
+ print 'Can\'t parse memory info, memory info get fail!'
+ return
+
# find the ROM configuration
rom_config_text = re.findall('\w+\s+(0x\w+)\s+(0x\w+)\s+xr\n',mem_config_text)
# get every ROM configuration's start - end address
@@ -31,7 +35,11 @@ with open(map_file, 'r') as f:
ram_config += [{'start':int(ram[0], 16), 'end':int(ram[0], 16) + int(ram[1], 16)}]
# find memory map (without discard and debug sections)
- mem_map = re.findall('Linker script and memory map([\s\S]+?)OUTPUT\('+map_file.replace('.map','.elf'), s)[0]
+ mem_map_list = re.findall('Linker script and memory map([\s\S]+?)OUTPUT\('+map_file.replace('.map','.elf'), s)
+ mem_map = '' if not mem_map_list else mem_map_list[0]
+ if not mem_map:
+ print 'Can\'t parse memory info, memory info get fail!'
+ return
# find sections address - length in memory map
modules = list(set(item[0] for item in re.findall('0x\w+\s+0x\w+\s+.+?([^/\\\]+\.[ao])(\(.+\.o\))?\n', mem_map)))
@@ -80,3 +88,8 @@ print '|=================================================================|'
print '| %-40s | %-8d | %-8d |'%('TOTAL (bytes)', total_rom, total_ram)
print '|=================================================================|'
+def main():
+ get_mem_info(sys.argv[1])
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file
