Skip to content

Commit fdd4ae3

Browse files
committed
Parse full paths from ARM map file
Now we don't have to scan! This is a 20% speed improvement
1 parent 8c54c4e commit fdd4ae3

File tree

1 file changed

+18
-48
lines changed

1 file changed

+18
-48
lines changed

tools/memap.py

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,9 @@ def parse_object_name_armcc(self, line):
240240
return line
241241

242242
else:
243-
244-
test_re_obj_name = re.match(RE_OBJECT_ARMCC, line)
245-
246-
if test_re_obj_name:
247-
object_name = test_re_obj_name.group(1) + '/' + \
248-
test_re_obj_name.group(2)
249-
243+
is_obj = re.match(RE_OBJECT_ARMCC, line)
244+
if is_obj:
245+
object_name = os.path.basename(is_obj.group(1)) + '/' + is_obj.group(3)
250246
return '[lib]/' + object_name
251247
else:
252248
print "Malformed input found when parsing ARMCC map: %s" % line
@@ -374,11 +370,20 @@ def parse_map_file_armcc(self, file_desc):
374370

375371
# Start decoding the map file
376372
for line in infile:
377-
object_name, object_size, section = self.parse_section_armcc(line)
378-
if object_name is not "" and section is not "":
379-
self.module_add(object_name, object_size, section)
373+
self.module_add(*self.parse_section_armcc(line))
374+
375+
common_prefix = os.path.dirname(os.path.commonprefix([
376+
o for o in self.modules.keys() if (o.endswith(".o") and o != "anon$$obj.o" and not o.startswith("[lib]"))]))
377+
new_modules = {}
378+
for name, stats in self.modules.items():
379+
if name == "anon$$obj.o" or name.startswith("[lib]"):
380+
new_modules[name] = stats
381+
elif name.endswith(".o"):
382+
new_modules[os.path.relpath(name, common_prefix)] = stats
383+
else:
384+
new_modules[name] = stats
385+
self.modules = new_modules
380386

381-
self.rename_modules_from_fs(infile.name)
382387

383388

384389
def check_new_library_iar(self, line):
@@ -449,9 +454,7 @@ def parse_map_file_iar(self, file_desc):
449454
break
450455

451456
for line in infile:
452-
name, size, section = self.parse_section_iar(line)
453-
if size and name and section:
454-
self.module_add(name, size, section)
457+
self.module_add(*self.parse_section_iar(line))
455458

456459
if line.startswith('*** MODULE SUMMARY'): # finish section
457460
break
@@ -467,43 +470,10 @@ def parse_map_file_iar(self, file_desc):
467470
object_name = self.check_new_object_lib_iar(line)
468471

469472
if object_name and current_library:
473+
print("Replacing module", object_name, current_library)
470474
temp = '[lib]' + '/'+ current_library + '/'+ object_name
471475
self.module_replace(object_name, temp)
472476

473-
def _rename_from_path(self, path, to_find, to_update, skip):
474-
for root, subdirs, obj_files in os.walk(path):
475-
if os.path.basename(root) in skip:
476-
subdirs[:] = []
477-
continue
478-
basename = os.path.relpath(root, path)
479-
for filename in (to_find.intersection(set(obj_files))):
480-
to_find.remove(filename)
481-
to_update[os.path.join(basename, filename)] = self.modules[filename]
482-
483-
def rename_modules_from_fs(self, path):
484-
""" Converts the current module list to use the path to a module instead
485-
of the name in the map file
486-
487-
Positional arguments:
488-
path - the path to a map file
489-
"""
490-
new_modules = dict()
491-
to_match = set(k for k in self.modules.keys() if not k.startswith("[lib]"))
492-
for module, v in self.modules.items():
493-
if module.startswith("[lib]"):
494-
new_modules[module] = v
495-
is_test = re.match(RE_IS_TEST, path)
496-
if is_test:
497-
self._rename_from_path(is_test.group(1), to_match, new_modules, set(["TESTS"]))
498-
self._rename_from_path(os.path.dirname(path), to_match, new_modules, set())
499-
else:
500-
self._rename_from_path(os.path.dirname(path), to_match, new_modules, [])
501-
502-
for module in to_match:
503-
new_modules[module] = self.modules[module]
504-
505-
self.modules = new_modules
506-
507477

508478
def reduce_depth(self, depth):
509479
"""

0 commit comments

Comments
 (0)