Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/friendly name instead of ids #14

Merged
merged 3 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion map_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions map_file_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand Down
51 changes: 26 additions & 25 deletions map_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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+' \
Expand All @@ -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'
)
)
3 changes: 2 additions & 1 deletion section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down