diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2015-10-29 09:33:14 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2015-10-29 13:37:03 +0100 |
| commit | e37d545e07a22b0ea9a5ce21b975c73927dd4d50 (patch) | |
| tree | 566485a13749bad8e4b8aaaf653dad20137a76e3 | |
| parent | 89b7cc0b3bdcff8ef57dba232c9aae544c3ded35 (diff) | |
| download | miasm-e37d545e07a22b0ea9a5ce21b975c73927dd4d50.tar.gz miasm-e37d545e07a22b0ea9a5ce21b975c73927dd4d50.zip | |
Expression: normalize ExprInt api
| -rw-r--r-- | miasm2/expression/expression.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py index 5ceb17d6..bd8c0c58 100644 --- a/miasm2/expression/expression.py +++ b/miasm2/expression/expression.py @@ -344,15 +344,21 @@ class ExprInt(Expr): - Constant 0x12345678 on 32bits """ - def __init__(self, arg): - """Create an ExprInt from a numpy int - @arg: numpy int""" - - if not is_modint(arg): - raise ValueError('arg must by numpy int! %s' % arg) - - self._arg = arg - self._size = self.arg.size + def __init__(self, num, size=None): + """Create an ExprInt from a modint or num/size + @arg: modint or num + @size: (optionnal) int size""" + + if is_modint(num): + self._arg = num + self._size = self.arg.size + if size is not None and num.size != size: + raise RuntimeError("size must match modint size") + elif size is not None: + self._arg = mod_size2uint[size](num) + self._size = self.arg.size + else: + raise ValueError('arg must by modint or (int,size)! %s' % num) arg = property(lambda self: self._arg) |