Example #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;
	}
}
Example #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());
				}
			}
		}
	}
}
Example #3
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_);
	}
}
Example #4
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;
}