Beispiel #1
0
void SCCP::analyze() {
    // Queue the first block to start iteration.
    cfgwork.push(ir->begin);
    while (!cfgwork.empty()) {
        while (!cfgwork.empty())
            analyzeBlock(cfgwork.pop());
        while (!ssawork.empty())
            analyzeSSA(ssawork.pop());
    }
    // TODO own cmdline flag? something less intrusive
    // if ((enable_verbose || enable_printir) && ir->size() > 1000)
    //  printCounts(ir, eval_counts);
}
Beispiel #2
0
void BinaryTree<T>::preOrder_0rec()
{
	SeqStack<BinTreeNode<T>*> s;
	BinTreeNode<T> *temp=root;
	s.push(temp);
	while(s.pop(temp))
	{
		cout<<temp->data;
		if(temp->rightChild!=NULL)
			s.push(temp->rightChild);
		if(temp->leftChild!=NULL)
			s.push(temp->leftChild);
	}
}
Beispiel #3
0
main(){
	try{
		while(cin >> input_word)
			if(!CheckWord()){
				Output(false);
				return 0;
			}
		Output(stack.is_empty());
	}
	catch(...){
		Output(false);
	}
	return 0;
}
int main()
{
    SeqStack<int> ss;
    cout << ss.ToString() << endl;

    int e;
    while (cin >> e)
    {
        ss.Push(e);
    }
    cout << ss.ToString() << endl;

    while (!ss.IsEmpty())
    {
        cout << "Top is " << ss.GetTop() << endl;
        ss.Pop();
        cout << ss.ToString() << endl;
    }

    //
    cout << "<End>" << endl;
    return 0;
}
Beispiel #5
0
bool CheckNumber(int this_word){
	if(this_word == word_then){
		if (stack.pop() != word_if)
			return false;
		stack.push(this_word);
	}
	else if(this_word == word_else){
		if (stack.pop() != word_then)
			return false;
	}
	else if(this_word == word_end){
		for (int tmp = stack.pop(); tmp != word_begin; tmp = stack.pop())
			if (tmp != word_then)
				return false;
	}
	else
		stack.push(this_word);
	return(true);
}
Beispiel #6
0
int main()
{
	char e1;
	SeqStack<char> stacks;
	string values="abcd";
	for (int i=0;i<4;i++)
	{
		stacks.push(values[i]);
	}
	
	

	try
	{
		e1=stacks.pop();
		stacks.pop();
		stacks.pop();
		stacks.pop();
	}
	catch(logic_error&exc)
	{
		cerr<<exc.what();
	}
	cout<<e1;
	try
	{
		cout<<stacks.get();
	}
	catch(logic_error&exc)
	{
		cerr<<exc.what();
	}
	
	system("pause");
	return 0;
}
Beispiel #7
0
TEST(SeqStackTest, capacityTest) {
    SeqStack<CarInfo> stk;
    ASSERT_EQ(5, stk.getCapacity());

    CarInfo c1 {"JA87G87", 2014, 12, 9, 19, 0, 0};
    CarInfo c2 {"JA85877", 2014, 12, 9, 19, 10, 6};
    CarInfo c3 {"JB30840", 2014, 12, 9, 19, 12, 30};
    CarInfo c4 {"JB56X56", 2014, 12, 9, 19, 30, 0};
    CarInfo c5 {"JA88888", 2014, 12, 9, 19, 40, 30};
    CarInfo c6 {"JA88S88", 2014, 12, 9, 19, 45, 17};

    stk.push(c1);
    stk.push(c2);
    stk.push(c3);
    stk.push(c4);
    stk.push(c5);
    stk.push(c6);

    ASSERT_EQ(10, stk.getCapacity());

        std::string expectStr(
R"(JA88S88, 2014-12-9, 19-45-17
JA88888, 2014-12-9, 19-40-30
JB56X56, 2014-12-9, 19-30-0
JB30840, 2014-12-9, 19-12-30
JA85877, 2014-12-9, 19-10-6
JA87G87, 2014-12-9, 19-0-0
)");

    std::string actualStr;
    stk.traverse([&actualStr](const CarInfo & car) { actualStr += to_string(car) + '\n'; });
    EXPECT_STREQ(expectStr.c_str(), actualStr.c_str());
}

TEST(SeqStackTest, popTest) {
    SeqStack<CarInfo> stk;

    CarInfo c1 {"JA87G87", 2014, 12, 9, 19, 0, 0};
    CarInfo c2 {"JA85877", 2014, 12, 9, 19, 10, 6};
    CarInfo c3 {"JB30840", 2014, 12, 9, 19, 12, 30};
    CarInfo c4 {"JB56X56", 2014, 12, 9, 19, 30, 0};
    CarInfo c5 {"JA88888", 2014, 12, 9, 19, 40, 30};
    CarInfo c6 {"JA88S88", 2014, 12, 9, 19, 45, 17};

    stk.push(c1);
    stk.push(c2);
    stk.push(c3);
    stk.push(c4);
    stk.push(c5);
    stk.push(c6);

    stk.pop(3);
    stk.pop(2);
    EXPECT_THROW(stk.pop(2), std::out_of_range);
}
Beispiel #8
0
/**
 * Enque the block.  If it is already visited, just enqueu it.
 * Otherwise, mark it reached and enque all the instructions in the block.
 */
void SCCP::addBlock(BlockStartInstr* block) {
    if (!mark.get(block->id))
        cfgwork.push(block);
    else
        ssawork.add(block);
}