Exemple #1
0
 def test(self):
     # Test that we split both sides and that everything gets passed through
     # correctly.  Don't worry about special cases within _restrict_condition
     # since those are tested separately.
     self.new_binding()
     var = self._program.NewVariable()
     var.AddBinding(ONLY_TRUE)
     var.AddBinding(ONLY_FALSE)
     var.AddBinding(AMBIGUOUS)
     true_cond, false_cond = state.split_conditions(self._node, var)
     self.check_binding("v=? | v=T", true_cond.binding, v=var.bindings[0])
     self.check_binding("v=? | v=F", false_cond.binding, v=var.bindings[0])
Exemple #2
0
 def test(self):
     # Test that we split both sides and that everything gets passed through
     # correctly.  Don't worry about special cases within _restrict_condition
     # since those are tested separately.
     p = self.new_binding("x")
     parent = state.Condition(self._node, None, [[p]])
     var = self._program.NewVariable("v")
     var.AddBinding(ONLY_TRUE)
     var.AddBinding(ONLY_FALSE)
     var.AddBinding(AMBIGUOUS)
     true_cond, false_cond = state.split_conditions(self._node, parent, var)
     self.assertIs(parent, true_cond.parent)
     self.check_binding("__split=None v=? | __split=None v=T",
                        true_cond.binding)
     self.assertIs(parent, false_cond.parent)
     self.check_binding("__split=None v=? | __split=None v=F",
                        false_cond.binding)
Exemple #3
0
def jump_if(state, op, ctx, pop=False, jump_if_val=False, or_pop=False):
  """Implementation of various _JUMP_IF bytecodes.

  Args:
    state: Initial FrameState.
    op: An opcode.
    ctx: The current context.
    pop: True if a value is popped off the stack regardless.
    jump_if_val: True or False (indicates which value will lead to a jump).
    or_pop: True if a value is popped off the stack only when the jump is
        not taken.
  Returns:
    The new FrameState.
  """
  assert not (pop and or_pop)
  # Determine the conditions.  Assume jump-if-true, then swap conditions
  # if necessary.
  if pop:
    state, value = state.pop()
  else:
    value = state.top()
  jump, normal = frame_state.split_conditions(state.node, value)
  if not jump_if_val:
    jump, normal = normal, jump
  # Jump.
  if jump is not frame_state.UNSATISFIABLE:
    if jump:
      assert jump.binding
      else_state = state.forward_cfg_node(jump.binding).forward_cfg_node()
    else:
      else_state = state.forward_cfg_node()
    ctx.vm.store_jump(op.target, else_state)
  else:
    else_state = None
  # Don't jump.
  if or_pop:
    state = state.pop_and_discard()
  if normal is frame_state.UNSATISFIABLE:
    return state.set_why("unsatisfiable")
  elif not else_state and not normal:
    return state  # We didn't actually branch.
  else:
    return state.forward_cfg_node(normal.binding if normal else None)