(
self: IRBuilder, e: Expression, true: BasicBlock, false: BasicBlock
)
| 27 | |
| 28 | |
| 29 | def process_conditional( |
| 30 | self: IRBuilder, e: Expression, true: BasicBlock, false: BasicBlock |
| 31 | ) -> None: |
| 32 | if isinstance(e, OpExpr) and e.op in ["and", "or"]: |
| 33 | if e.op == "and": |
| 34 | # Short circuit 'and' in a conditional context. |
| 35 | new = BasicBlock() |
| 36 | process_conditional(self, e.left, new, false) |
| 37 | self.activate_block(new) |
| 38 | process_conditional(self, e.right, true, false) |
| 39 | else: |
| 40 | # Short circuit 'or' in a conditional context. |
| 41 | new = BasicBlock() |
| 42 | process_conditional(self, e.left, true, new) |
| 43 | self.activate_block(new) |
| 44 | process_conditional(self, e.right, true, false) |
| 45 | elif isinstance(e, UnaryExpr) and e.op == "not": |
| 46 | process_conditional(self, e.expr, false, true) |
| 47 | else: |
| 48 | res = maybe_process_conditional_comparison(self, e, true, false) |
| 49 | if res: |
| 50 | return |
| 51 | # Catch-all for arbitrary expressions. |
| 52 | reg = self.accept(e) |
| 53 | self.add_bool_branch(reg, true, false) |
| 54 | |
| 55 | |
| 56 | def maybe_process_conditional_comparison( |
no test coverage detected
searching dependent graphs…