Skip to content

Commit faac445

Browse files
committed
feat: add support for .obj files in memap
1 parent e03b3b6 commit faac445

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

tools/memap.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ def parse_mapfile(self, mapfile):
104104

105105

106106
class _GccParser(_Parser):
107-
RE_OBJECT_FILE = re.compile(r'^(.+\/.+\.o)$')
108-
RE_LIBRARY_OBJECT = re.compile(r'^.+' + r''.format(sep) + r'lib((.+\.a)\((.+\.o)\))$')
107+
RE_OBJECT_FILE = re.compile(r'^(.+\/.+\.o(bj)?)$')
108+
RE_LIBRARY_OBJECT = re.compile(r'^.+' + r''.format(sep) + r'lib((.+\.a)\((.+\.o(bj)?)\))$')
109109
RE_STD_SECTION = re.compile(r'^\s+.*0x(\w{8,16})\s+0x(\w+)\s(.+)$')
110110
RE_FILL_SECTION = re.compile(r'^\s*\*fill\*\s+0x(\w{8,16})\s+0x(\w+).*$')
111+
OBJECT_EXTENSIONS = (".o", ".obj")
111112

112113
ALL_SECTIONS = _Parser.SECTIONS + _Parser.OTHER_SECTIONS + \
113114
_Parser.MISC_FLASH_SECTIONS + ('unknown', 'OUTPUT')
@@ -214,12 +215,12 @@ def parse_mapfile(self, file_desc):
214215
self.module_add(object_name, object_size, current_section)
215216

216217
common_prefix = dirname(commonprefix([
217-
o for o in self.modules.keys() if (o.endswith(".o") and not o.startswith("[lib]"))]))
218+
o for o in self.modules.keys() if (o.endswith(self.OBJECT_EXTENSIONS) and not o.startswith("[lib]"))]))
218219
new_modules = {}
219220
for name, stats in self.modules.items():
220221
if name.startswith("[lib]"):
221222
new_modules[name] = stats
222-
elif name.endswith(".o"):
223+
elif name.endswith(self.OBJECT_EXTENSIONS):
223224
new_modules[relpath(name, common_prefix)] = stats
224225
else:
225226
new_modules[name] = stats
@@ -229,15 +230,16 @@ def parse_mapfile(self, file_desc):
229230
class _ArmccParser(_Parser):
230231
RE = re.compile(
231232
r'^\s+0x(\w{8})\s+0x(\w{8})\s+(\w+)\s+(\w+)\s+(\d+)\s+[*]?.+\s+(.+)$')
232-
RE_OBJECT = re.compile(r'(.+\.(l|ar))\((.+\.o)\)')
233+
RE_OBJECT = re.compile(r'(.+\.(l|ar))\((.+\.o(bj)?)\)')
234+
OBJECT_EXTENSIONS = (".o", ".obj")
233235

234236
def parse_object_name(self, line):
235237
""" Parse object file
236238
237239
Positional arguments:
238240
line - the line containing the object or library
239241
"""
240-
if line.endswith(".o"):
242+
if line.endswith(self.OBJECT_EXTENSIONS):
241243
return line
242244

243245
else:
@@ -305,12 +307,12 @@ def parse_mapfile(self, file_desc):
305307
self.module_add(*self.parse_section(line))
306308

307309
common_prefix = dirname(commonprefix([
308-
o for o in self.modules.keys() if (o.endswith(".o") and o != "anon$$obj.o" and not o.startswith("[lib]"))]))
310+
o for o in self.modules.keys() if (o.endswith(self.OBJECT_EXTENSIONS) and o != "anon$$obj.o" and o != "anon$$obj.obj" and not o.startswith("[lib]"))]))
309311
new_modules = {}
310312
for name, stats in self.modules.items():
311-
if name == "anon$$obj.o" or name.startswith("[lib]"):
313+
if name == "anon$$obj.o" or name == "anon$$obj.obj" or name.startswith("[lib]"):
312314
new_modules[name] = stats
313-
elif name.endswith(".o"):
315+
elif name.endswith(self.OBJECT_EXTENSIONS):
314316
new_modules[relpath(name, common_prefix)] = stats
315317
else:
316318
new_modules[name] = stats
@@ -322,9 +324,10 @@ class _IarParser(_Parser):
322324
r'^\s+(.+)\s+(zero|const|ro code|inited|uninit)\s'
323325
r'+0x([\'\w]+)\s+0x(\w+)\s+(.+)\s.+$')
324326

325-
RE_CMDLINE_FILE = re.compile(r'^#\s+(.+\.o)')
327+
RE_CMDLINE_FILE = re.compile(r'^#\s+(.+\.o(bj)?)')
326328
RE_LIBRARY = re.compile(r'^(.+\.a)\:.+$')
327-
RE_OBJECT_LIBRARY = re.compile(r'^\s+(.+\.o)\s.*')
329+
RE_OBJECT_LIBRARY = re.compile(r'^\s+(.+\.o(bj)?)\s.*')
330+
OBJECT_EXTENSIONS = (".o", ".obj")
328331

329332
def __init__(self):
330333
_Parser.__init__(self)
@@ -338,7 +341,7 @@ def parse_object_name(self, object_name):
338341
Positional arguments:
339342
line - the line containing the object or library
340343
"""
341-
if object_name.endswith(".o"):
344+
if object_name.endswith(self.OBJECT_EXTENSIONS):
342345
try:
343346
return self.cmd_modules[object_name]
344347
except KeyError:
@@ -432,7 +435,7 @@ def parse_command_line(self, lines):
432435
break
433436
for arg in line.split(" "):
434437
arg = arg.rstrip(" \n")
435-
if (not arg.startswith("-")) and arg.endswith(".o"):
438+
if (not arg.startswith("-")) and arg.endswith(self.OBJECT_EXTENSIONS):
436439
self.cmd_modules[basename(arg)] = arg
437440

438441
common_prefix = dirname(commonprefix(list(self.cmd_modules.values())))

0 commit comments

Comments
 (0)