about summary refs log tree commit diff stats
path: root/miasm2/core/asmblock.py
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2018-04-11 11:22:13 +0200
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2018-04-19 13:57:25 +0200
commitc8104588e23cfc53f3d3608b743578a51f279ebf (patch)
tree62905efa09c38ab889080a00d73cef45d4ed5066 /miasm2/core/asmblock.py
parente8df24eab8cf24ea7a5a7c5adee0f7462deb7d58 (diff)
downloadmiasm-c8104588e23cfc53f3d3608b743578a51f279ebf.tar.gz
miasm-c8104588e23cfc53f3d3608b743578a51f279ebf.zip
Asmblock: fix AsmSymbolPool API
Diffstat (limited to 'miasm2/core/asmblock.py')
-rw-r--r--miasm2/core/asmblock.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/miasm2/core/asmblock.py b/miasm2/core/asmblock.py
index 7d18c4f5..07b8ceeb 100644
--- a/miasm2/core/asmblock.py
+++ b/miasm2/core/asmblock.py
@@ -334,9 +334,20 @@ class asm_block_bad(AsmBlockBad):
 
 
 class AsmSymbolPool(object):
+    """
+    Store symbols.
+
+    A symbol links a name to an (optional) offset
+
+    Rules and limitations:
+    - two different symbols cannot have the same offset
+    - two different symbols cannot have the same name
+    - symbols manipulation (comparison, creation ...) can only be done on
+      symbols generated by the same symbol pool
+    """
 
     def __init__(self):
-        self._labels = []
+        self._labels = set()
         self._name2label = {}
         self._offset2label = {}
         self._label_num = 0
@@ -359,7 +370,7 @@ class AsmSymbolPool(object):
             raise ValueError('symbol %s has same name as %s' %
                              (label, self._name2label[label.name]))
 
-        self._labels.append(label)
+        self._labels.add(label)
         if label.offset is not None:
             self._offset2label[label.offset] = label
         if label.name != "":
@@ -427,10 +438,17 @@ class AsmSymbolPool(object):
             self._offset2label[label.offset] = label
 
     @property
-    def items(self):
+    def labels(self):
         """Return all labels"""
         return self._labels
 
+    @property
+    def items(self):
+        """Return all labels"""
+        warnings.warn('DEPRECATION WARNING: use "labels" instead of "items"')
+        return list(self._labels)
+
+
     def __str__(self):
         return reduce(lambda x, y: x + str(y) + '\n', self._labels, "")
 
@@ -446,7 +464,7 @@ class AsmSymbolPool(object):
 
     def merge(self, symbol_pool):
         """Merge with another @symbol_pool"""
-        self._labels += symbol_pool._labels
+        self._labels.update(symbol_pool.labels)
         self._name2label.update(symbol_pool._name2label)
         self._offset2label.update(symbol_pool._offset2label)