예제 #1
0
int doNlinIR (WF3Info *wf3, MultiNicmosGroup *input,
	      SingleNicmosGroup *zsig) {

/* Arguments:
**	wf3	 i: WFC3 info structure
**	input	io: input image to be corrected
**	zsig	 i: MULTIACCUM zero-read signal image
*/

	/* Local variables */
	NlinData nlin;

	/* Function definitions */
	int getNlinData (WF3Info *, NlinData *);
	void freeNlinData (NlinData *);
	void satcheck (SingleNicmosGroup *, SingleNicmosGroup *);
	void PrSwitch (char *, int);

	/* Do the non-linearity correction for each group */
	if (wf3->nlincorr == PERFORM) {

	    /* Load the nlin reference file data */
	    if (getNlinData (wf3, &nlin))
		return (status);

	    /* Loop over MultiAccum groups */
	    for (wf3->group=wf3->ngroups; wf3->group >= 1; wf3->group--) {

		 if (nlincorr (wf3, &(input->group[wf3->group-1]), &nlin,
			       zsig))
		     return (status);

		 /* Flag pixels in the next group as saturated if they're
		 ** flagged as saturated in the current group */
		 if (wf3->group-1 > 0)
		     satcheck (&(input->group[wf3->group-1]),
			       &(input->group[wf3->group-2]));
	    }

	    freeNlinData (&nlin);

	    PrSwitch ("nlincorr", COMPLETE);
	}

	/* Successful return */
	return (status = 0);
}
예제 #2
0
bool simulator_symext::check_full_trace(
    const abstract_counterexamplet &abstract_counterexample,
    prefixt &prefix,
    goto_symex_statet &state,
    concrete_counterexamplet &concrete_counterexample,
    fail_infot &fail_info)
{
  assert(!prefix.equation.SSA_steps.empty());  
  assert(prefix.equation.SSA_steps.back().is_assert());

  status("Prefix of size "+i2string(prefix.equation.SSA_steps.size()));

  symex_target_equationt::SSA_stepst::const_iterator c_it=
    --prefix.equation.SSA_steps.end();

  simulator_sat_dect satcheck(concrete_model.ns);
  prefix.equation.convert(satcheck);

  if(is_satisfiable(satcheck))
  {
    // grab counterexample!
    build_goto_trace(
        prefix.equation,
        satcheck,
        concrete_model.ns,
        concrete_counterexample.goto_trace);

    return false;
  }

  get_fail_info(
      abstract_counterexample,
      satcheck,
      prefix,
      c_it,
      fail_info);

  // cannot be simulated, its spurious
  status("Spurious counterexample.");

  return true;
}
예제 #3
0
bool simulator_loop_detectiont::check_phase_I_equation(
    symex_target_equationt &equation,
    goto_symex_statet &state,
    const abstract_counterexamplet &abstract_counterexample,
    concrete_counterexamplet &phase_I_counterexample,
    prefixt::step_mapt &step_map,
    fail_infot &fail_info
    )
{
  minimization_listt symbols;

  // run SAT
  symex_target_equationt::SSA_stepst::iterator c_it;

  for(c_it=equation.SSA_steps.begin();
      c_it!=equation.SSA_steps.end();
      c_it++)
  {
    if(c_it->is_assignment())
    {
      const exprt &rhs=c_it->ssa_rhs;
      recurrence_solver::referenced_parameters(state, rhs, symbols);
      continue;
    }

    if(c_it->is_location() ||
        (c_it->is_assume() && c_it->cond_expr.is_true()))
      continue;

    bv_minimizing_dect satcheck(concrete_model.ns);

    symex_target_equationt::SSA_stepst SSA_steps;
    SSA_steps.splice(SSA_steps.end(),
        equation.SSA_steps, equation.SSA_steps.begin(), ++c_it);
    equation.SSA_steps.swap(SSA_steps);
    equation.convert(satcheck);
    equation.SSA_steps.splice(equation.SSA_steps.end(),
        SSA_steps, SSA_steps.begin(), SSA_steps.end());
    --c_it;

    // solve it
    if(!is_satisfiable(satcheck))
      break; // spurious!

    if(c_it->is_assert()) // we reached the assertion
    {
      for (minimization_listt::const_iterator m_it = symbols.begin();
          m_it!=symbols.end(); m_it++)
        std::cout << from_expr (concrete_model.ns, "", *m_it) << ", ";
      std::cout << std::endl;

      satcheck.minimize(symbols);

      build_goto_trace(
          equation,
          satcheck,
          concrete_model.ns,
          phase_I_counterexample.goto_trace);

      return false;
    }
  }

  assert(c_it !=equation.SSA_steps.end());

  // cannot be simulated, its spurious
  status("Phase I Counterexample is spurious");

  // fill fail_info
  fail_info.all_steps = abstract_counterexample.steps;

  assert(c_it->source.pc->is_assert() ||
      c_it->source.pc->is_assume() ||
      c_it->source.pc->is_goto());

  // get the corresponding abstract step
  prefixt::step_mapt::const_iterator s_it=step_map.find(c_it);
  assert (s_it!=step_map.end());
  abstract_counterexamplet::stepst::const_iterator a_it = s_it->second;

  // and fill the steps
  fail_info.steps.clear();

  for(abstract_counterexamplet::stepst::const_iterator
      it=abstract_counterexample.steps.begin();
      it!=abstract_counterexample.steps.end();
      it++)
  {
    fail_info.steps.push_back(*it);
    if(it==a_it) 
      break;
  }

  fail_info.guard=c_it->source.pc->guard;

  // we might need to negate it
  if (c_it->source.pc->is_goto())
    if (c_it->guard_expr.is_false())
      fail_info.guard.make_not();

  return true;
}
예제 #4
0
bool simulator_symext::check_prefix_equation(
    const abstract_counterexamplet &abstract_counterexample,
    prefixt &prefix,
    goto_symex_statet &state,
    concrete_counterexamplet &concrete_counterexample,
    fail_infot &fail_info)
{
  unsigned int left = 0;     /* leftmost index of search interval  */
  unsigned int right = 0;    /* rightmost index of search interval */
  unsigned int step = 1;     /* the current step size              */
  unsigned int index = 0;    /* the current index into the array   */

  // first of all, that should end with an assertion
  // if not, it's spurious for sure

  assert(!prefix.equation.SSA_steps.empty());  
  assert(prefix.equation.SSA_steps.back().is_assert());

  status("Unprocessed prefix of size "+ i2string (prefix.equation.SSA_steps.size ()));

  symex_target_equationt::SSA_stepst::iterator c_it;

  /* construct an array of iterators (for binary search) */
  std::vector<symex_target_equationt::SSA_stepst::iterator> state_array;

  for(c_it=prefix.equation.SSA_steps.begin();
      c_it!=prefix.equation.SSA_steps.end(); 
      c_it++)
  {
    /* assignments and locations don't make a path infeasible */
    if(!(c_it->is_assignment() ||
          c_it->is_location()))
    {
      if(!(c_it->is_assume() && c_it->cond_expr.is_true()))
      {
        state_array.push_back(c_it);

        // this must be an assumption, an assertion or a goto
        assert(c_it->source.pc->is_assert() ||
            c_it->source.pc->is_assume() ||
            c_it->source.pc->is_goto());
      }
    }
  }

  assert(!state_array.empty()); // we expect at least one element!

  status("Processed prefix of size "+ i2string (state_array.size ()));

  right=state_array.size();

  do
  {
    assert(index<state_array.size());
    assert(index>=left);
    assert(index<right);

    status("Simulating prefix of size "+i2string(index+1));

    c_it=state_array[index];

    simulator_sat_dect satcheck(concrete_model.ns);
    symex_target_equationt::SSA_stepst SSA_steps;
    SSA_steps.splice(SSA_steps.end(),
        prefix.equation.SSA_steps, prefix.equation.SSA_steps.begin(), ++c_it);
    prefix.equation.SSA_steps.swap(SSA_steps);
    prefix.equation.convert(satcheck);
    prefix.equation.SSA_steps.splice(prefix.equation.SSA_steps.end(),
        SSA_steps, SSA_steps.begin(), SSA_steps.end());
    --c_it;

    if(is_satisfiable(satcheck))
    {
      // it's the assertion? grab counterexample!
      if(c_it->is_assert())
      {
        build_goto_trace(
            prefix.equation,
            satcheck,
            concrete_model.ns,
            concrete_counterexample.goto_trace);

        return false;
      }

      // otherwise decrease the search interval size
      left=index;       /* feasible element      */
    }
    else // unsatisfiable
    {
      right = index;      /* infeasible element    */
      step  = 1;          /* reset the step size   */
      index = left;       /* and restart from left */

      get_fail_info(
          abstract_counterexample,
          satcheck,
          prefix,
          c_it,
          fail_info);
    }

    /* now increase the index and the step interval */
    index = 
      (left + step < right)? (left + step) : (right - 1); 

    step = 2 * step;
  }
  while(left+1<right);

  // cannot be simulated, its spurious
  status("Spurious counterexample");

  // report the location
  status("Simulation failed at "+
      fail_info.last_step().pc->location.as_string());

  return true;
}