forked from OSchip/llvm-project
Implemented __invert__, __and__ and __or__ in the EDSC Python bindings
This allows to use bitwise operators as logical (accounting for differences in precedence). PiperOrigin-RevId: 232489024
This commit is contained in:
parent
3fa22b88de
commit
d8e5ce0107
|
@ -529,6 +529,11 @@ PYBIND11_MODULE(pybind, m) {
|
|||
PythonExpr e2) { return PythonExpr(::EQ(e1, e2)); })
|
||||
.def("__ne__", [](PythonExpr e1,
|
||||
PythonExpr e2) { return PythonExpr(::NE(e1, e2)); })
|
||||
.def("__and__", [](PythonExpr e1,
|
||||
PythonExpr e2) { return PythonExpr(::And(e1, e2)); })
|
||||
.def("__or__", [](PythonExpr e1,
|
||||
PythonExpr e2) { return PythonExpr(::Or(e1, e2)); })
|
||||
.def("__invert__", [](PythonExpr e) { return PythonExpr(::Negate(e)); })
|
||||
.def("__str__", &PythonExpr::str,
|
||||
R"DOC(Returns the string value for the Expr)DOC");
|
||||
|
||||
|
|
|
@ -93,8 +93,8 @@ class EdscTest(unittest.TestCase):
|
|||
def testBoolean(self):
|
||||
with E.ContextManager():
|
||||
i, j, k, l = list(map(E.Expr, [E.Bindable() for _ in range(4)]))
|
||||
stmt1 = E.And(i < j, j >= k)
|
||||
stmt2 = E.Negate(E.Or(stmt1, k == l))
|
||||
stmt1 = (i < j) & (j >= k)
|
||||
stmt2 = ~(stmt1 | (k == l))
|
||||
str = stmt2.__str__()
|
||||
self.assertIn("~((($1 < $2) && ($2 >= $3)) || ($3 == $4))", str)
|
||||
|
||||
|
|
Loading…
Reference in New Issue