Beispiel #1
0
void EventEntry::print(ostream& out, int indent) const{
	if(name()!="any"){
		for(int i=0;i<indent;++i){
			out << "\t";
		}
		out << "event "<< name() << "(";
		const SymTab* st = this->symTab();
		if(st!=NULL){
			for(SymTab::const_iterator i = st->begin(); i != st->end();){
				if((*i)->kind()==SymTabEntry::Kind::VARIABLE_KIND){
					VariableEntry* ve = (VariableEntry*) (*i);
					if(ve->varKind()==VariableEntry::VarKind::PARAM_VAR){
						out << ve->type()->fullName()<<" "<<ve->name();
						out << "(offset = " << ve->offSet() << ")";
					}
				}
				++i;
				if(i != st->end()){
					out << ", ";
				}
			}
		}
		out << ");"<<endl;
	}
}
Beispiel #2
0
void EventEntry::memAlloc(MemoryMgr &mm){
	memory_mgr_ = MemoryMgr();
	//cout << "Event memAlloc" << endl;
	SymTab* st = this->symTab();
	if(st!=NULL){
		for(SymTab::iterator i = st->begin(); i != st->end();++i){
			if((*i)->kind()==SymTabEntry::Kind::VARIABLE_KIND){
				VariableEntry* ve = (VariableEntry*) (*i);
				if(ve->varKind()==VariableEntry::VarKind::PARAM_VAR){
					ve->offSet(memory_mgr_.getNextAddress());
				}
			}
		}
	}
}
Beispiel #3
0
Type* EventEntry::typeCheck(){
	vector<Type*>* arg_types = new vector<Type*>();

	SymTab* st = this->symTab();
	if(st!=NULL){
		for(SymTab::iterator i = st->begin(); i != st->end();++i){
			if((*i)->kind()==SymTabEntry::Kind::VARIABLE_KIND){
				VariableEntry* ve = (VariableEntry*) (*i);
				if(ve->varKind()==VariableEntry::VarKind::PARAM_VAR){
					arg_types->push_back(ve->type());
				}
			}
		}
	}
	type()->argTypes(arg_types);
	return NULL;
}
void FunctionEntry::print(ostream& out, int indent) const
{

    out << type()->fullName() << " " << name();
    out << "(";


    int i = 0;
    const SymTab *st = symTab();
    if(st!=NULL)
    {

        SymTab::const_iterator it = st->begin();
        for (i=0; (it != st->end()); i++, ++it)
        {
            SymTabEntry *ste = (SymTabEntry *)(*it);
            if(ste->kind() == SymTabEntry::Kind::VARIABLE_KIND)
            {
                VariableEntry *ve = (VariableEntry *)ste;
                if(ve->varKind() != VariableEntry::VarKind::PARAM_VAR)
                {
                    break;
                }
            }
        }
    }
    if(i!=0)
    {
        printST(out, indent,'\0', '\0', false, 0, i);
    }
    out << ")";

    if((st != NULL && i < st->size()) || body())
    {
        out << " {";
        if(st != NULL && i < st->size())
            printST(out, indent,'\0', ';',true, i, st->size());
        if(body())
            body()->printWithoutBraces(out, indent);
        out << "}";
    }

}
Beispiel #5
0
void FunctionEntry::memAlloc(MemoryMgr &mm){
	memory_mgr_ = MemoryMgr();

	const SymTab* st = this->symTab();
	bool p_var = true;
	if(st!=NULL){
		for(SymTab::const_iterator i = st->begin(); i != st->end(); ++i){
			if((*i)->kind()==SymTabEntry::Kind::VARIABLE_KIND){
				VariableEntry* ve = (VariableEntry*) (*i);
				if(ve->varKind()==VariableEntry::VarKind::PARAM_VAR && p_var){
					//Parameters
					ve->offSet(memory_mgr_.getNextAddress());
				} else {
					if(p_var){
						//Set control_link_ and return_address_
						returnLabel(memory_mgr_.getNextAddress());
						returnOffset(memory_mgr_.getNextAddress());
						controlLink(memory_mgr_.getNextAddress());
						p_var = false;
					}
					//Local variables declared in function
					ve->memAlloc(memory_mgr_);
				}
			}
		}
		if(p_var){
			returnLabel(memory_mgr_.getNextAddress());
			returnOffset(memory_mgr_.getNextAddress());
			controlLink(memory_mgr_.getNextAddress());
		}
	}
	if(body()!=NULL){
		body()->memAlloc(memory_mgr_);

		//Used for returning in case function reaches the end of its body without a return statement
		mem_reg_ = memory_mgr_.getNextRegister(true);
		memory_mgr_.addRegister(mem_reg_);
		label_reg_ = memory_mgr_.getNextRegister(true);
		memory_mgr_.addRegister(label_reg_);
		memory_mgr_.freeRegister(mem_reg_);
		memory_mgr_.freeRegister(label_reg_);
	}
}
Beispiel #6
0
void FunctionEntry::print(ostream& out, int indent) const{
	for(int i=0;i<indent;++i){
		out << "\t";
	}
	out << type()->retType()->name() << " " << name() << "(";
	const SymTab* st = this->symTab();
	bool p_var = true;
	if(st!=NULL){
		for(SymTab::const_iterator i = st->begin(); i != st->end(); ++i){
			if((*i)->kind()==SymTabEntry::Kind::VARIABLE_KIND){
				VariableEntry* ve = (VariableEntry*) (*i);
				if(ve->varKind()==VariableEntry::VarKind::PARAM_VAR && p_var){
					if(i != st->begin()){
						out << ", ";
					}
					out << ve->type()->fullName()<<" "<<ve->name();
					out << "(offset = " << ve->offSet() << ")";
				} else {
					if(p_var){
						out << ")(return_label = " << returnLabel() << ", return_address = " << returnOffset() << ", control_link = " << controlLink() << ") {" << endl;
						p_var = false;
					}
					ve->print(out,indent+1);
				}
			}
		}
	}
	if(p_var){
		out << ")(return_address = " << returnOffset() << ", control_link = " << controlLink() << ")";
	}
	if(body()!=NULL){
		if(p_var){
			out<<" {" << endl;
		}
		body()->printWithoutBraces(out,indent);
		for(int i=0;i<indent-1;++i){
			out << "\t";
		}
		out << "}";
	}
	out<< ";" << endl;
}
Beispiel #7
0
CodeBlock* FunctionEntry::codeGen() {
	if(body()!=NULL){

		CodeBlock* func_block = new CodeBlock();
		func_block->setStartLabel(func_start_);
		func_block->append(body()->codeGen());

		const SymTab* st = this->symTab();
		if(st!=NULL){
			for(SymTab::const_iterator i = st->begin(); i != st->end(); ++i){
				if((*i)->kind()==SymTabEntry::Kind::VARIABLE_KIND){
					VariableEntry* ve = (VariableEntry*) (*i);
					if(ve->varKind()!=VariableEntry::VarKind::PARAM_VAR){
						func_block->append(ve->codeGen());
					}
				}
			}
		}

		CodeBlock* func_end = new CodeBlock();

		//Loads label from memory
		ICode lab_addr(ICode::ICodeType::ADD,&MemoryMgr::basePointerRegister(),new Value(returnLabel(),Type::TypeTag::UINT),&mem_reg_);
		ICode load_lab(ICode::ICodeType::LDI,&mem_reg_,&label_reg_);
		ICode ret_jmp(ICode::ICodeType::JMPI,&label_reg_);

		func_end->append(lab_addr);
		func_end->append(load_lab);
		func_end->append(ret_jmp);

		func_block->append(func_end);

		return func_block;
	}
	return NULL;
}