Ejemplo n.º 1
0
goto_symext::symex_resultt *
reachability_treet::generate_schedule_formula()
{

  int total_states = 0;
  while (has_more_states())
  {
    total_states++;
    while ((!get_cur_state().has_cswitch_point_occured() ||
           get_cur_state().check_if_ileaves_blocked()) &&
           get_cur_state().can_execution_continue())
    {
      get_cur_state().symex_step(*this);
    }

    if (state_hashing) {
      if (check_for_hash_collision()) {
        post_hash_collision_cleanup();
        go_next_state();
        continue;
      } else {
        update_hash_collision_set();
      }
    }

    next_thread_id = decide_ileave_direction(get_cur_state());

    create_next_state();

    go_next_state();
  }

  return new goto_symext::symex_resultt(schedule_target, schedule_total_claims,
                                        schedule_remaining_claims);
}
Ejemplo n.º 2
0
// 骨架树变到下一骨架。所有骨架树的总数应该是catalan数C(2n,n)/(n+1)
// 对传统24点,n=3,骨架树共有C(6,3)/4 = 5种
bool go_next_state(node* p)
{
	if (!p) return false;
	// r_child^
	if (go_next_state(p->r_child)) return true;
	// l_child^, r_child=0
	if (go_next_state(p->l_child))
	{
		node* r_child_new = initial_state(get_op_count(p->r_child));
		delete (p->r_child);
		p->r_child = r_child_new;
		return true;
	}
	// l_child--=0 r_child++=0
	int lcount = get_op_count(p->l_child);
	int rcount = get_op_count(p->r_child);
	if (lcount > 0)
	{
		node* l_child_new = initial_state(lcount-1);
		node* r_child_new = initial_state(rcount+1);
		delete (p->l_child);
		delete (p->r_child);
		p->l_child = l_child_new;
		p->r_child = r_child_new;
		return true;
	}

	return false;
}
Ejemplo n.º 3
0
int wmain(int argc, wchar_t* argv[])
{
	std::wstring op_set = L"+-*/";
	std::wstring all_bop = L"+-*/^_";
	std::wstring all_uop = L"!";
	bool show_help = false;
	int rr_level = 1;

	tp::cmdline_parser parser;
	parser.add_option(L'p', L"opset", &op_set, true, &tp::cmdline_parser::cf_string);
	parser.add_option(L'h', L"help", &show_help, false, &tp::cmdline_parser::cf_bool);
	parser.add_option(L'r', L"rrlvl", &rr_level, true, &tp::cmdline_parser::cf_int);
	parser.add_option(0, L"debug", &g_debug, false, &tp::cmdline_parser::cf_bool);
	if (!parser.parse(argc, argv))
	{
		usage();
		return 1;
	}
	if (show_help)
	{
		usage();
		return 0;
	}
	if (op_set == L"all") op_set = all_bop + all_uop;

	size_t c = parser.get_target_connt();
	if (c < 3)
	{
		usage();
		return 1;
	}

	// op_set -> bop+uop
	std::wstring bop;
	uti_list_t uop;
	for (size_t i = 0; i < op_set.size(); i++)
	{
		if (all_bop.find(op_set[i]) != std::wstring::npos )
		{
			bop += op_set[i];
		}
		else if (all_uop.find(op_set[i]) != std::wstring::npos)
		{
			uti u = {op_set[i], 0};
			for (i++; op_set[i] >= '0' && op_set[i] <= '9'; i++)
			{
				u.at_ub = u.at_ub * 10 + op_set[i] - '0';
			}
			if (u.at_ub == 0) u.at_ub = 1;
			uop.push_back(u);
		}
		else
		{
			std::wcout << op_set[i] << L" is not a valid operator, run 'cal24 --help' to see valid operators" << std::endl;
			return -2;
		}
	}

	double d = _wtof(parser.get_target(c-1).c_str());
	size_t num_count = c-1;
	double* nums = new double[num_count];
	for (size_t i = 0; i < num_count; i++)
	{
		nums[i] = _wtof(parser.get_target(i).c_str());
	}

	node* p = initial_state(num_count-1);
	do
	{
		calc_on_exptree(p, bop.c_str(), uop, nums, num_count, d, rr_level);
	}while (go_next_state(p));

	delete p;
	delete [] nums;
	return 0;
}