Skip to content

Commit 7af4423

Browse files
author
Edras Pacola
committed
refactoring, attention:
removed from variable_factory.py the condition below because this is done now on the device_info at mchplnet: if ( self.device_info.processor_id == "__GENERIC_MICROCHIP_DSPIC__" ): # TODO implement it better for future cores. self.device_info.uc_width = 2
1 parent ff41129 commit 7af4423

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

pyx2cscope/parser/elf16_parser.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ class Elf16Parser(ElfParser):
3535
xc16_read_elf_path (str): Path to the XC16 `readelf` executable.
3636
"""
3737

38-
def _load_symbol_table(self):
39-
"""Load symbol tables.
40-
41-
This method exists at this class only for compatibility.
42-
This class is deprecated and not maintained on current version.
43-
"""
44-
pass
4538

4639
def __init__(self, elf_path):
4740
"""Initialize the Elf16Parser instance.
@@ -77,6 +70,17 @@ def __init__(self, elf_path):
7770
self.tree_string = None
7871
self.next_line = None
7972

73+
def _load_symbol_table(self):
74+
"""Load symbol tables.
75+
76+
This method exists at this class only for compatibility.
77+
This class is deprecated and not maintained on current version.
78+
"""
79+
pass
80+
81+
def _close_elf_file(self):
82+
pass
83+
8084
def _parse_cu_attributes(self):
8185
"""Parse the attributes of a compilation unit from the ELF file.
8286

pyx2cscope/parser/elf_parser.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ def __init__(self, elf_path: str):
6262
self.elf_file = None
6363
self.variable_map = {}
6464
self.symbol_table = {}
65-
self.array_size = 0
65+
6666
self._load_elf_file()
67+
self._map_variables()
6768
self._load_symbol_table()
68-
69+
self._close_elf_file()
6970

7071
def get_var_info(self, name: str) -> Optional[VariableInfo]:
7172
"""Return the VariableInfo associated with a given variable name, or None if not found.
@@ -76,8 +77,6 @@ def get_var_info(self, name: str) -> Optional[VariableInfo]:
7677
Returns:
7778
Optional[VariableInfo]: The information of the variable, if available.
7879
"""
79-
if not self.variable_map:
80-
self.map_variables()
8180
return self.variable_map.get(name)
8281

8382
def get_var_list(self) -> List[str]:
@@ -86,20 +85,8 @@ def get_var_list(self) -> List[str]:
8685
Returns:
8786
List[str]: A sorted list of variable names.
8887
"""
89-
if not self.variable_map:
90-
self._map_variables()
9188
return sorted(self.variable_map.keys(), key=lambda x: x.lower())
9289

93-
def map_variables(self) -> Dict[str, VariableInfo]:
94-
"""Map variables from the parsed DWARF information and return them.
95-
96-
Returns:
97-
Dict[str, VariableInfo]: A dictionary of variable names to VariableInfo objects.
98-
"""
99-
if not self.variable_map:
100-
self._map_variables()
101-
return self.variable_map
102-
10390
@abstractmethod
10491
def _load_elf_file(self):
10592
"""Load the ELF file according to the specific hardware architecture.
@@ -124,19 +111,32 @@ def _map_variables(self) -> Dict[str, VariableInfo]:
124111
Dict[str, VariableInfo]: A dictionary of variable names to VariableInfo objects.
125112
"""
126113

114+
@abstractmethod
115+
def _close_elf_file(self):
116+
"""Abstract method to close any open file connection after parsing is done."""
117+
118+
127119
class DummyParser(ElfParser):
128120
"""Dummy implementation of ElfParser class.
129121
130122
This class provides basic functionality of a parser in case an elf_file is
131123
not supplied. It is a pure implementation of class ElfParser.
132124
"""
133125

126+
134127
def __init__(self, elf_path = ""):
135128
"""DummyParser constructor takes no argument."""
136129
super().__init__(elf_path = elf_path)
137130

138131
def _load_elf_file(self):
139132
pass
140133

134+
def _load_symbol_table(self):
135+
pass
136+
141137
def _map_variables(self) -> Dict[str, VariableInfo]:
142-
return {}
138+
return {}
139+
140+
def _close_elf_file(self):
141+
pass
142+

pyx2cscope/parser/generic_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _load_elf_file(self):
3434
except IOError:
3535
raise Exception(f"Error loading ELF file: {self.elf_path}")
3636

37-
def close_elf_file(self):
37+
def _close_elf_file(self):
3838
"""Closes the ELF file stream."""
3939
if self.stream:
4040
self.stream.close()

pyx2cscope/variable/variable_factory.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,8 @@ def __init__(self, l_net: LNet, elf_path=None):
4545
"""
4646
self.l_net = l_net
4747
self.device_info = self.l_net.get_device_info()
48-
if (
49-
self.device_info.processor_id == "__GENERIC_MICROCHIP_DSPIC__"
50-
): # TODO implement it better for future cores.
51-
self.device_info.uc_width = 2
5248

53-
# we should be able to initialize without using and elf file
49+
# we should be able to initialize without using and elf file.
5450
if elf_path is None:
5551
self.parser = DummyParser()
5652
else:

0 commit comments

Comments
 (0)