about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/arch/aarch64/arch.py1
-rw-r--r--miasm2/arch/arm/arch.py3
-rw-r--r--miasm2/arch/mips32/arch.py1
-rw-r--r--miasm2/arch/msp430/arch.py1
-rw-r--r--miasm2/arch/sh4/arch.py1
-rw-r--r--miasm2/arch/x86/arch.py1
-rw-r--r--miasm2/core/cpu.py3
-rw-r--r--miasm2/expression/expression.py62
-rw-r--r--miasm2/expression/expression_helper.py5
9 files changed, 58 insertions, 20 deletions
diff --git a/miasm2/arch/aarch64/arch.py b/miasm2/arch/aarch64/arch.py
index 3545e4c5..00f3509d 100644
--- a/miasm2/arch/aarch64/arch.py
+++ b/miasm2/arch/aarch64/arch.py
@@ -325,6 +325,7 @@ conds_inv_expr, _, conds_inv_info = gen_regs(CONDS_INV, {})
 
 
 class instruction_aarch64(instruction):
+    __slots__ = []
     delayslot = 0
 
     def __init__(self, *args, **kargs):
diff --git a/miasm2/arch/arm/arch.py b/miasm2/arch/arm/arch.py
index 23ce170c..23935dd4 100644
--- a/miasm2/arch/arm/arch.py
+++ b/miasm2/arch/arm/arch.py
@@ -278,6 +278,7 @@ class additional_info:
 
 
 class instruction_arm(instruction):
+    __slots__ = []
     delayslot = 0
 
     def __init__(self, *args, **kargs):
@@ -420,6 +421,8 @@ class instruction_arm(instruction):
         return ExprInt_from(expr, self.offset+8)
 
 class instruction_armt(instruction_arm):
+    __slots__ = []
+    delayslot = 0
 
     def __init__(self, *args, **kargs):
         super(instruction_armt, self).__init__(*args, **kargs)
diff --git a/miasm2/arch/mips32/arch.py b/miasm2/arch/mips32/arch.py
index f64e09e5..04ce6bdd 100644
--- a/miasm2/arch/mips32/arch.py
+++ b/miasm2/arch/mips32/arch.py
@@ -78,6 +78,7 @@ br_2 = ['BEQ', 'BEQL', 'BNE']
 
 
 class instruction_mips32(cpu.instruction):
+    __slots__ = []
     delayslot = 1
 
     def __init__(self, *args, **kargs):
diff --git a/miasm2/arch/msp430/arch.py b/miasm2/arch/msp430/arch.py
index cda49608..56793a11 100644
--- a/miasm2/arch/msp430/arch.py
+++ b/miasm2/arch/msp430/arch.py
@@ -107,6 +107,7 @@ class additional_info:
 
 
 class instruction_msp430(instruction):
+    __slots__ = []
     delayslot = 0
 
     def dstflow(self):
diff --git a/miasm2/arch/sh4/arch.py b/miasm2/arch/sh4/arch.py
index 7039016c..d9ac2c9f 100644
--- a/miasm2/arch/sh4/arch.py
+++ b/miasm2/arch/sh4/arch.py
@@ -386,6 +386,7 @@ class additional_info:
 
 
 class instruction_sh4(instruction):
+    __slots__ = []
     delayslot = 0
 
     def __init__(self, *args, **kargs):
diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py
index 36e2e3b7..a10e1038 100644
--- a/miasm2/arch/x86/arch.py
+++ b/miasm2/arch/x86/arch.py
@@ -465,6 +465,7 @@ class additional_info:
 
 
 class instruction_x86(instruction):
+    __slots__ = []
     delayslot = 0
 
     def __init__(self, *args, **kargs):
diff --git a/miasm2/core/cpu.py b/miasm2/core/cpu.py
index 48f7e26e..d304108d 100644
--- a/miasm2/core/cpu.py
+++ b/miasm2/core/cpu.py
@@ -910,6 +910,9 @@ class metamn(type):
 
 
 class instruction(object):
+    __slots__ = ["name", "mode", "args",
+                 "l", "b", "offset", "data",
+                 "additional_info", "delayslot"]
 
     def __init__(self, name, mode, args, additional_info=None):
         self.name = name
diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py
index 341b90fd..229f8a21 100644
--- a/miasm2/expression/expression.py
+++ b/miasm2/expression/expression.py
@@ -114,27 +114,28 @@ class Expr(object):
 
     "Parent class for Miasm Expressions"
 
-    is_term = False   # Terminal expression
-    is_simp = False   # Expression already simplified
-    is_canon = False  # Expression already canonised
-    is_eval = False   # Expression already evalued
+    __slots__ = ["is_term", "is_simp", "is_canon",
+                 "is_eval", "_hash", "_repr", "_size",
+                 "is_var_ident"]
 
-    _hash = None
-    _repr = None
 
     def set_size(self, value):
         raise ValueError('size is not mutable')
 
-    def __init__(self, arg):
-        self.arg = arg
+    def __init__(self):
+        self.is_term = False   # Terminal expression
+        self.is_simp = False   # Expression already simplified
+        self.is_canon = False  # Expression already canonised
+        self.is_eval = False   # Expression already evalued
+        self.is_var_ident = False # Expression not identifier
+
+        self._hash = None
+        self._repr = None
 
     size = property(lambda self: self._size)
 
     # Common operations
 
-    def __str__(self):
-        return str(self.arg)
-
     def __getitem__(self, i):
         if not isinstance(i, slice):
             raise TypeError("Expression: Bad slice: %s" % i)
@@ -146,12 +147,6 @@ class Expr(object):
     def get_size(self):
         raise DeprecationWarning("use X.size instead of X.get_size()")
 
-    def get_r(self, mem_read=False, cst_read=False):
-        return self.arg.get_r(mem_read, cst_read)
-
-    def get_w(self):
-        return self.arg.get_w()
-
     def is_function_call(self):
         """Returns true if the considered Expr is a function call
         """
@@ -343,11 +338,15 @@ class ExprInt(Expr):
      - Constant 0x12345678 on 32bits
      """
 
+    __slots__ = ["_arg"]
+
     def __init__(self, num, size=None):
         """Create an ExprInt from a modint or num/size
         @arg: modint or num
         @size: (optionnal) int size"""
 
+        super(ExprInt, self).__init__()
+
         if is_modint(num):
             self._arg = num
             self._size = self.arg.size
@@ -420,11 +419,14 @@ class ExprId(Expr):
      - variable v1
      """
 
+    __slots__ = ["_name"]
+
     def __init__(self, name, size=32):
         """Create an identifier
         @name: str, identifier's name
         @size: int, identifier's size
         """
+        super(ExprId, self).__init__()
 
         self._name, self._size = name, size
 
@@ -478,11 +480,16 @@ class ExprAff(Expr):
      - var1 <- 2
     """
 
+    __slots__ = ["_src", "_dst"]
+
     def __init__(self, dst, src):
         """Create an ExprAff for dst <- src
         @dst: Expr, affectation destination
         @src: Expr, affectation source
         """
+
+        super(ExprAff, self).__init__()
+
         if dst.size != src.size:
             raise ValueError(
                 "sanitycheck: ExprAff args must have same size! %s" %
@@ -578,6 +585,8 @@ class ExprCond(Expr):
      - if (cond) then ... else ...
     """
 
+    __slots__ = ["_cond", "_src1", "_src2"]
+
     def __init__(self, cond, src1, src2):
         """Create an ExprCond
         @cond: Expr, condition
@@ -585,6 +594,8 @@ class ExprCond(Expr):
         @src2: Expr, value if condition is evaled zero
         """
 
+        super(ExprCond, self).__init__()
+
         assert(src1.size == src2.size)
 
         self._cond, self._src1, self._src2 = cond, src1, src2
@@ -657,11 +668,16 @@ class ExprMem(Expr):
      - Memory write
     """
 
+    __slots__ = ["_arg", "_size"]
+
     def __init__(self, arg, size=32):
         """Create an ExprMem
         @arg: Expr, memory access address
         @size: int, memory access size
         """
+
+        super(ExprMem, self).__init__()
+
         if not isinstance(arg, Expr):
             raise ValueError(
                 'ExprMem: arg must be an Expr (not %s)' % type(arg))
@@ -725,12 +741,16 @@ class ExprOp(Expr):
      - parity bit(var1)
     """
 
+    __slots__ = ["_op", "_args"]
+
     def __init__(self, op, *args):
         """Create an ExprOp
         @op: str, operation
         @*args: Expr, operand list
         """
 
+        super(ExprOp, self).__init__()
+
         sizes = set([arg.size for arg in args])
 
         if len(sizes) != 1:
@@ -868,7 +888,11 @@ class ExprOp(Expr):
 
 class ExprSlice(Expr):
 
+    __slots__ = ["_arg", "_start", "_stop"]
+
     def __init__(self, arg, start, stop):
+        super(ExprSlice, self).__init__()
+
         assert(start < stop)
 
         self._arg, self._start, self._stop = arg, start, stop
@@ -948,12 +972,16 @@ class ExprCompose(Expr):
     In the example, salad.size == 3.
     """
 
+    __slots__ = ["_args"]
+
     def __init__(self, args):
         """Create an ExprCompose
         The ExprCompose is contiguous and starts at 0
         @args: tuple(Expr, int, int)
         """
 
+        super(ExprCompose, self).__init__()
+
         last_stop = 0
         args = sorted(args, key=itemgetter(1))
         for e, start, stop in args:
diff --git a/miasm2/expression/expression_helper.py b/miasm2/expression/expression_helper.py
index ece720e0..7c398105 100644
--- a/miasm2/expression/expression_helper.py
+++ b/miasm2/expression/expression_helper.py
@@ -293,8 +293,7 @@ class Variables_Identifier(object):
         if not isinstance(expr, m2_expr.ExprId):
             return False
 
-        return hasattr(expr, cls.is_var_ident) and \
-            getattr(expr, cls.is_var_ident) == True
+        return expr.is_var_ident
 
     def find_variables_rec(self, expr):
         """Recursive method called by find_variable to expand @expr.
@@ -311,7 +310,7 @@ class Variables_Identifier(object):
                 identifier = m2_expr.ExprId("%s%s" % (self.var_prefix,
                                                       self.var_indice.next()),
                                             size = expr.size)
-                setattr(identifier, self.__class__.is_var_ident, True)
+                identifier.is_var_ident = True
                 self._vars[identifier] = expr
 
             # Recursion stop case