22
22
23
23
RE_IS_TEST = re .compile (r'^(.+)\/.*TESTS\/.+\.map$' )
24
24
25
+ RE_CMDLINE_FILE_IAR = re .compile (r'^#\s+(.+\.o)' )
25
26
RE_LIBRARY_IAR = re .compile (r'^(.+\.a)\:.+$' )
26
27
RE_OBJECT_LIBRARY_IAR = re .compile (r'^\s+(.+\.o)\s.*' )
27
28
@@ -72,6 +73,10 @@ def __init__(self):
72
73
73
74
self .misc_flash_mem = 0
74
75
76
+ # Modules passed to the linker on the command line
77
+ # this is a dict because modules are looked up by their basename
78
+ self .cmd_modules = {}
79
+
75
80
76
81
def module_add (self , object_name , size , section ):
77
82
""" Adds a module / section to the list
@@ -286,18 +291,19 @@ def parse_section_armcc(self, line):
286
291
else :
287
292
return ["" , 0 , "" ]
288
293
289
- def parse_object_name_iar (self , line ):
294
+ def parse_object_name_iar (self , object_name ):
290
295
""" Parse object file
291
296
292
297
Positional arguments:
293
298
line - the line containing the object or library
294
299
"""
295
300
296
301
# simple object (not library)
297
- if line .endswith (".o" ):
298
- object_name = line
299
- return object_name
300
-
302
+ if object_name .endswith (".o" ):
303
+ try :
304
+ return self .cmd_modules [object_name ]
305
+ except KeyError :
306
+ return object_name
301
307
else :
302
308
return '[misc]'
303
309
@@ -344,8 +350,7 @@ def parse_section_iar(self, line):
344
350
print "Malformed input found when parsing IAR map: %s" % line
345
351
346
352
# lookup object in dictionary and return module name
347
- temp = test_re_iar .group (5 )
348
- object_name = self .parse_object_name_iar (temp )
353
+ object_name = self .parse_object_name_iar (test_re_iar .group (5 ))
349
354
350
355
return [object_name , size , section ]
351
356
@@ -409,34 +414,47 @@ def check_new_object_lib_iar(self, line):
409
414
else :
410
415
return ""
411
416
417
+ def parse_iar_command_line (self , lines ):
418
+ """Parse the files passed on the command line to the iar linker
419
+
420
+ Positional arguments:
421
+ lines -- an iterator over the lines within a file
422
+ """
423
+ for line in lines :
424
+ if line .startswith ("*" ):
425
+ break
426
+ is_cmdline_file = RE_CMDLINE_FILE_IAR .match (line )
427
+ if is_cmdline_file :
428
+ full_path = is_cmdline_file .group (1 )
429
+ self .cmd_modules [os .path .basename (full_path )] = full_path
430
+
431
+ common_prefix = os .path .dirname (os .path .commonprefix (self .cmd_modules .values ()))
432
+ self .cmd_modules = {s : os .path .relpath (f , common_prefix )
433
+ for s , f in self .cmd_modules .items ()}
434
+
435
+
412
436
def parse_map_file_iar (self , file_desc ):
413
437
""" Main logic to decode IAR map files
414
438
415
439
Positional arguments:
416
440
file_desc - a file like object to parse as an IAR map file
417
441
"""
418
442
419
- # first round, search for objects
420
443
with file_desc as infile :
421
- # Search area to parse
444
+ self .parse_iar_command_line (infile )
445
+
422
446
for line in infile :
423
447
if line .startswith (' Section ' ):
424
448
break
425
449
426
- # Start decoding the map file
427
450
for line in infile :
428
-
429
- [name , size , section ] = self .parse_section_iar (line )
430
-
431
- if size == 0 or name == "" or section == "" :
432
- pass
433
- else :
451
+ name , size , section = self .parse_section_iar (line )
452
+ if size and name and section :
434
453
self .module_add (name , size , section )
435
454
436
455
if line .startswith ('*** MODULE SUMMARY' ): # finish section
437
456
break
438
457
439
- # Start decoding the map file
440
458
current_library = ""
441
459
for line in infile :
442
460
@@ -450,7 +468,6 @@ def parse_map_file_iar(self, file_desc):
450
468
if object_name and current_library :
451
469
temp = '[lib]' + '/' + current_library + '/' + object_name
452
470
self .module_replace (object_name , temp )
453
- self .rename_modules_from_fs (infile .name )
454
471
455
472
def _rename_from_path (self , path , to_find , to_update , skip ):
456
473
for root , subdirs , obj_files in os .walk (path ):
0 commit comments