diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f296f7..b9ebaad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to * `hide-name`, `hide-address` and `hide-size` style properties to hide specific visual elements * `flags` can be specified at map file as well * `size` property at root level to modify the document size +* Friendly name field (`name`) for sections at the yaml map file to be used instead of ID ## [0.2.0] - 2023-12-14 diff --git a/README.md b/README.md index 7fa5d9e..8e1bf4a 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ an `id`, an `address` and a `size`. While these three are needed, there are other possible attributes that are optional: - `name`: Friendly text name that would be used instead of the `id` -- `type`: Section type, which can be used for different purposes. Possibilities are `section` (default) and `area`. +- `type`: Section type, which can be used for different purposes. Current possibilities are `section` (default) and `area`. The input file should contain the `map` keyword whose value is an array of sections. Below an example of how an input file should look like: @@ -67,7 +67,7 @@ of how an input file should look like: - ... ``` -In order to use this file, invoke Linkerscope and specify the yaml map file as input: +In order to use this file, invoke LinkerScope and specify the yaml map file as input: ```bash ./linkerscope.py -i memory_map.yaml -o memory_map.svg -c config.yaml @@ -78,7 +78,7 @@ In order to use this file, invoke Linkerscope and specify the yaml map file as i For a complex diagram that fully represents the memory map of a given program, handcrafting the memory map can be time-consuming. In the case that the intended diagram is related to a program, the necessary information is already available at the generated GNU Linker map files. -Linkerscope conveniently provides the possibility to parse these files and generate diagram from those. For that, simply +LinkerScope conveniently provides the possibility to parse these files and generate diagram from those. For that, simply specify the `.map` file as an input. ```bash @@ -306,13 +306,13 @@ At the folder examples, there are a series of configurations and map `.yaml` fil - [x] Labels at specific memory addresses - [x] Area titles -- [ ] Links across specific areas +- [x] Links across specific areas - [ ] Choose side of the labels - [x] Memory direction - [x] Hide specific elements - [ ] Memory size in bytes - [ ] Section links across breaks -- [ ] Friendly name and identifier +- [x] Friendly name and identifier - [ ] Legend - [ ] Area representation different from section - [ ] Make `type` default to `section` diff --git a/map_drawer.py b/map_drawer.py index 2671d0e..f8edb3c 100755 --- a/map_drawer.py +++ b/map_drawer.py @@ -426,7 +426,8 @@ def _make_text(self, ) def _make_name(self, section): - return self._make_text(section.id, + name = section.name if section.name is not None else section.id + return self._make_text(name, (section.name_label_pos_x,section.name_label_pos_y), style=section.style, anchor='middle', diff --git a/map_file_loader.py b/map_file_loader.py index d0988c8..fe5ccf2 100644 --- a/map_file_loader.py +++ b/map_file_loader.py @@ -37,9 +37,11 @@ def parse_yaml(filename): y = yaml.safe_load(file) for element in y['map']: + print(element) sections.append(Section(address=element['address'], size=element['size'], id=element['id'], + name=element.get('name'), parent=element.get('parent', 'none'), _type=element.get('type', 'area'), flags=element.get('flags', '') diff --git a/map_parser.py b/map_parser.py index 0750835..162325c 100644 --- a/map_parser.py +++ b/map_parser.py @@ -9,8 +9,8 @@ class MapParser: Parse a linker map file and convert it to a yaml file for further processing """ def __init__(self, input_filename, output_filename): - self.areas = [] self.sections = [] + self.subsections = [] self.input_filename = input_filename self.output_filename = output_filename @@ -26,22 +26,23 @@ def parse(self): prev_line = line my_dict = {'map': []} - for area in self.areas: + for section in self.sections: my_dict['map'].append({ 'type': 'area', - 'address': area.address, - 'size': area.size, - 'name': area.name, + 'address': section.address, + 'size': section.size, + 'id': section.id, + 'flags': section.flags }) - for section in self.sections: + for subsection in self.subsections: my_dict['map'].append({ 'type': 'section', - 'parent': section.filter_parent, - 'address': section.address, - 'size': section.size, - 'name': section.id, - 'flags': section.flags + 'parent': subsection.parent, + 'address': subsection.address, + 'size': subsection.size, + 'id': subsection.id, + 'flags': subsection.flags }) with open(self.output_filename, 'w', encoding='utf8') as file: @@ -55,13 +56,13 @@ def process_areas(self, line): result = p.search(line) if result is not None: - self.areas.append(Section(parent=None, - id=result.group(1), - address=int(result.group(2), 0), - size=int(result.group(3), 0), - _type='area' - ) - ) + self.sections.append(Section(parent=None, + id=result.group(1), + address=int(result.group(2), 0), + size=int(result.group(3), 0), + _type='area' + ) + ) def process_sections(self, line): pattern = r'\s(.[^.]+).([^. \n]+)[\n\r]\s+(0x[0-9a-fA-F]{16})\s+' \ @@ -71,10 +72,10 @@ def process_sections(self, line): result = p.search(line) if result is not None: - self.sections.append(Section(parent=result.group(1), - id=result.group(2), - address=int(result.group(3), 0), - size=int(result.group(4), 0), - _type='section' - ) - ) + self.subsections.append(Section(parent=result.group(1), + id=result.group(2), + address=int(result.group(3), 0), + size=int(result.group(4), 0), + _type='section' + ) + ) diff --git a/section.py b/section.py index 74c60be..14061ec 100755 --- a/section.py +++ b/section.py @@ -16,12 +16,13 @@ class Section: label_offset: int = 10 style: Style - def __init__(self, size, address, id, _type, parent, flags=[]): + def __init__(self, size, address, id, _type, parent, flags=[], name=None): self.type = _type self.parent = parent self.size = size self.address = address self.id = id + self.name = name self.size_y = 0 self.size_x = 0 self.style = Style() diff --git a/style.py b/style.py index 32c685e..f596297 100644 --- a/style.py +++ b/style.py @@ -33,7 +33,7 @@ class Style: def __init__(self, style=None): if style is not None: for key, value in style.items(): - setattr(self, key.replace('-','_'), style.get(key, value)) + setattr(self, key.replace('-', '_'), style.get(key, value)) def override_properties_from(self, style): """