diff --git a/README.md b/README.md index 05875ba..5cfb3c3 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,4 @@ Awesome stuff! - there is no memory management. VEX is kind of weird with this, so care will have to be taken... - converting from string to tag is currently very slow (a hastily written consecutive bunch of strcmps) - IRCallee assumes that addresses are 64-bytes long, and will corrupt memory otherwise. This can be fixed by writing a getter/setter instead of using the macroed ones. +- deepCopying a binder IRExpr seems to crash VEX diff --git a/pyvex.c b/pyvex.c index add7855..3fe2f36 100644 --- a/pyvex.c +++ b/pyvex.c @@ -54,6 +54,7 @@ initpyvex(void) // expressions PYVEX_INITTYPE(IRExpr); + PYVEX_INITTYPE(IRExprBinder); PYVEX_INITTYPE(IRExprRdTmp); PYVEX_INITTYPE(IRExprGet); PYVEX_INITTYPE(IRExprQop); diff --git a/pyvex_irexpr.c b/pyvex_irexpr.c index cbf590f..d1d04ce 100644 --- a/pyvex_irexpr.c +++ b/pyvex_irexpr.c @@ -56,7 +56,7 @@ PyObject *wrap_IRExpr(IRExpr *i) switch (i->tag) { - //PYVEX_WRAPCASE(IRExpr, Iex_, Binder) + PYVEX_WRAPCASE(IRExpr, Iex_, Binder) PYVEX_WRAPCASE(IRExpr, Iex_, Get) //PYVEX_WRAPCASE(IRExpr, Iex_, GetI) PYVEX_WRAPCASE(IRExpr, Iex_, RdTmp) @@ -80,6 +80,36 @@ PyObject *wrap_IRExpr(IRExpr *i) return (PyObject *)o; } +/////////////////// +// Binder IRExpr // +/////////////////// + +static int +pyIRExprBinder_init(pyIRExpr *self, PyObject *args, PyObject *kwargs) +{ + PYVEX_WRAP_CONSTRUCTOR(IRExpr); + + Int binder; + static char *kwlist[] = {"binder", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &binder)) return -1; + + self->wrapped = IRExpr_Binder(binder); + return 0; +} + +PYVEX_ACCESSOR_BUILDVAL(IRExprBinder, IRExpr, wrapped->Iex.Binder.binder, binder, "i") + +static PyGetSetDef pyIRExprBinder_getseters[] = +{ + PYVEX_ACCESSOR_DEF(IRExprBinder, binder), + {NULL} +}; + +PyObject *pyIRExprBinder_deepCopy(PyObject *self) { PyErr_SetString(VexException, "binder does not support deepCopy()"); return NULL; } + +static PyMethodDef pyIRExprBinder_methods[] = { {"deepCopy", (PyCFunction)pyIRExprBinder_deepCopy, METH_NOARGS, "not supported by binder"}, {NULL} }; +PYVEX_SUBTYPEOBJECT(IRExprBinder, IRExpr); + //////////////// // Get IRExpr // //////////////// @@ -123,7 +153,7 @@ pyIRExprRdTmp_init(pyIRExpr *self, PyObject *args, PyObject *kwargs) { PYVEX_WRAP_CONSTRUCTOR(IRExpr); - UInt tmp; + IRTemp tmp; static char *kwlist[] = {"tmp", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "I", kwlist, &tmp)) return -1; diff --git a/pyvex_types.h b/pyvex_types.h index 6a9f8fd..94a5fa5 100644 --- a/pyvex_types.h +++ b/pyvex_types.h @@ -45,6 +45,7 @@ extern PyTypeObject pyIRStmtExitType; // expressions PYVEX_TYPEHEADER(IRExpr); +extern PyTypeObject pyIRExprBinderType; extern PyTypeObject pyIRExprRdTmpType; extern PyTypeObject pyIRExprGetType; extern PyTypeObject pyIRExprQopType; diff --git a/test.py b/test.py index 2e5bc77..3d79d6d 100644 --- a/test.py +++ b/test.py @@ -269,6 +269,11 @@ class PyVEXTest(unittest.TestCase): ### Expressions ### ################### + def test_irexpr_binder(self): + m = pyvex.IRExprBinder(1534252) + self.assertEqual(m.binder, 1534252) + self.assertRaises(Exception, m.deepCopy, ()) + def test_irexpr_rdtmp(self): irsb = pyvex.IRSB(bytes='\x90\x5d\xc3') self.assertEqual(irsb.next.tmp, irsb.next.deepCopy().tmp)