添加AI生成函数, 准备制作map文件解析功能;
This commit is contained in:
65
source/func_upgrade_1727523631782.py
Normal file
65
source/func_upgrade_1727523631782.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
def parse_map_file(map_file_path):
|
||||
# 定义正则表达式模式
|
||||
section_pattern = re.compile(r'^\s*(\w+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+(.*)$')
|
||||
symbol_pattern = re.compile(r'^\s*([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+(\w+)\s+(.*)$')
|
||||
|
||||
sections = {}
|
||||
symbols = {}
|
||||
|
||||
with open(map_file_path, 'r') as file:
|
||||
for line in file:
|
||||
# 匹配section行
|
||||
match = section_pattern.match(line)
|
||||
if match:
|
||||
section_name = match.group(1)
|
||||
start_address = int(match.group(2), 16)
|
||||
end_address = int(match.group(3), 16)
|
||||
size = int(match.group(4), 16)
|
||||
sections[section_name] = {
|
||||
'start_address': start_address,
|
||||
'end_address': end_address,
|
||||
'size': size
|
||||
}
|
||||
continue
|
||||
|
||||
# 匹配symbol行
|
||||
match = symbol_pattern.match(line)
|
||||
if match:
|
||||
address = int(match.group(1), 16)
|
||||
size = int(match.group(2), 16)
|
||||
type_ = match.group(3)
|
||||
name = match.group(4)
|
||||
definition = match.group(5)
|
||||
symbols[name] = {
|
||||
'address': address,
|
||||
'size': size,
|
||||
'type': type_,
|
||||
'definition': definition
|
||||
}
|
||||
|
||||
return sections, symbols
|
||||
|
||||
# 使用示例
|
||||
map_file_path = 'D:\WorkingProject\LightStackOptimizer\software\lamina_controller_dsp\lamina_controller_dsp\DEBUG\lamina_controller_dsp.map'
|
||||
path_map = Path(map_file_path)
|
||||
sections, symbols = parse_map_file(map_file_path)
|
||||
|
||||
print("Sections:")
|
||||
for section_name, section_info in sections.items():
|
||||
print(f"Section: {section_name}")
|
||||
print(f" Start Address: {section_info['start_address']:X}")
|
||||
print(f" End Address: {section_info['end_address']:X}")
|
||||
print(f" Size: {section_info['size']:X}")
|
||||
print()
|
||||
|
||||
print("Symbols:")
|
||||
for symbol_name, symbol_info in symbols.items():
|
||||
print(f"Symbol: {symbol_name}")
|
||||
print(f" Address: {symbol_info['address']:X}")
|
||||
print(f" Size: {symbol_info['size']:X}")
|
||||
print(f" Type: {symbol_info['type']}")
|
||||
print(f" Definition: {symbol_info['definition']}")
|
||||
print()
|
||||
Reference in New Issue
Block a user