about summary refs log tree commit diff stats
path: root/miasm2/expression/modint.py
diff options
context:
space:
mode:
authorserpilliere <serpilliere@users.noreply.github.com>2016-12-16 15:03:53 +0100
committerGitHub <noreply@github.com>2016-12-16 15:03:53 +0100
commit5f8ba4cb1b84d3af4ebed46c6a9b3120eb50233e (patch)
treef5aaffbe8d92b38fa9260599c1bb5d3180356164 /miasm2/expression/modint.py
parent50661f59da48540a6d87ab5f42c41e761a9c11d8 (diff)
parent40fefe35dd4cae1cecd63e3877cb0a91deb26bcc (diff)
downloadmiasm-5f8ba4cb1b84d3af4ebed46c6a9b3120eb50233e.tar.gz
miasm-5f8ba4cb1b84d3af4ebed46c6a9b3120eb50233e.zip
Merge pull request #456 from commial/feature/anyint
Feature/anyint
Diffstat (limited to 'miasm2/expression/modint.py')
-rw-r--r--miasm2/expression/modint.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/miasm2/expression/modint.py b/miasm2/expression/modint.py
index 76896eb9..a801c948 100644
--- a/miasm2/expression/modint.py
+++ b/miasm2/expression/modint.py
@@ -198,25 +198,36 @@ mod_size2int = {}
 mod_uint2size = {}
 mod_int2size = {}
 
+def define_int(size):
+    """Build the 'modint' instance corresponding to size @size"""
+    global mod_size2int, mod_int2size
+
+    name = 'int%d' % size
+    cls = type(name, (modint,), {"size": size, "limit": 1 << size})
+    globals()[name] = cls
+    mod_size2int[size] = cls
+    mod_int2size[cls] = size
+    return cls
+
+def define_uint(size):
+    """Build the 'moduint' instance corresponding to size @size"""
+    global mod_size2uint, mod_uint2size
+
+    name = 'uint%d' % size
+    cls = type(name, (moduint,), {"size": size, "limit": 1 << size})
+    globals()[name] = cls
+    mod_size2uint[size] = cls
+    mod_uint2size[cls] = size
+    return cls
 
 def define_common_int():
     "Define common int: ExprInt1, ExprInt2, .."
-    global mod_size2int, mod_int2size, mod_size2uint, mod_uint2size
-
     common_int = xrange(1, 257)
 
     for i in common_int:
-        name = 'uint%d' % i
-        c = type(name, (moduint,), {"size": i, "limit": 1 << i})
-        globals()[name] = c
-        mod_size2uint[i] = c
-        mod_uint2size[c] = i
+        define_int(i)
 
     for i in common_int:
-        name = 'int%d' % i
-        c = type(name, (modint,), {"size": i, "limit": 1 << i})
-        globals()[name] = c
-        mod_size2int[i] = c
-        mod_int2size[c] = i
+        define_uint(i)
 
 define_common_int()