void dDAGFunctionStatementFlow::CompileCIL(dCIL& cil)
{
	//	m_backPatchStart = cil.GetLast();
	//	m_currentBreakLabel = cil.NewLabel();
	//	m_currentContinueLabel = "";
	
	dString loopBeginLabel (cil.NewLabel());
	dCILInstrLabel* const entryLabel = new dCILInstrLabel(cil, loopBeginLabel);
	entryLabel->Trace();

	if (m_loopBodyStmt) {
		m_loopBodyStmt->CompileCIL(cil);
	}

	dDAGFunctionStatement* const posFixStmt = GetPostFixStatement();
	if (posFixStmt) {
		dAssert(0);
		posFixStmt->CompileCIL(cil);
	}

	if (m_testExpression) {
		m_testExpression->CompileCIL(cil);

		dCILInstrConditional* const conditional = new dCILInstrConditional(cil, dCILInstrConditional::m_if, m_testExpression->m_result.m_label, m_testExpression->m_result.GetType(), entryLabel->GetArg0().m_label, cil.NewLabel());
		conditional->Trace();

		dCILInstrLabel* const exitLabel = new dCILInstrLabel(cil, conditional->GetArg2().m_label);
		exitLabel->Trace();
		conditional->SetTargets (entryLabel, exitLabel);

	} else {
		dAssert (0);
	}

}
Exemplo n.º 2
0
void dDAGFunctionNode::CompileCIL(dCIL& cil)  
{
	dAssert (m_body);
	dDAGClassNode* const myClass = GetClass();

	cil.ResetTemporaries();
	dString returnVariable (cil.NewTemp());

	dString functionName (myClass->GetFunctionName (m_name, m_parameters));
	dCILInstrFunction* const function = new dCILInstrFunction (cil, functionName, m_returnType->GetArgType());
	m_functionStart = function->GetNode();

	if (!m_isStatic) {
		dAssert (0);
//		dList<dDAGParameterNode*>::dListNode* const argNode = m_parameters.GetFirst();
//		dDAGParameterNode* const arg = argNode->GetInfo();
//		m_opertatorThis = arg->m_result.m_label;
	}

	// emit the function arguments
	for (dList<dDAGParameterNode*>::dListNode* argNode = m_parameters.GetFirst(); argNode; argNode = argNode->GetNext()) {
		dDAGParameterNode* const arg = argNode->GetInfo();
		arg->m_result = function->AddParameter (arg->m_name, arg->m_type->GetArgType())->GetInfo();
	}
	function->Trace();

	dCILInstrLabel* const entryPoint = new dCILInstrLabel(cil, cil.NewLabel());
	entryPoint->Trace();

	for (dList<dDAGParameterNode*>::dListNode* argNode = m_parameters.GetFirst(); argNode; argNode = argNode->GetNext()) {
		dDAGParameterNode* const arg = argNode->GetInfo();

		dTree<dCILInstr::dArg, dString>::dTreeNode* const varNameNode = m_body->FindVariable(arg->m_name);
		dAssert (varNameNode);
		dCILInstrArgument* const localVariable = new dCILInstrArgument(cil, varNameNode->GetInfo().m_label, varNameNode->GetInfo().GetType());
		localVariable->Trace();
	}


	for (dList<dDAGParameterNode*>::dListNode* argNode = m_parameters.GetFirst(); argNode; argNode = argNode->GetNext()) {
		dDAGParameterNode* const arg = argNode->GetInfo();
		dTree<dCILInstr::dArg, dString>::dTreeNode* const varNameNode = m_body->FindVariable(arg->m_name);
		dAssert (varNameNode);
		//dCILInstrStore* const store = new dCILInstrStore(cil, varNameNode->GetInfo().m_label, varNameNode->GetInfo().GetType(), arg->m_name, arg->GetType()->GetArgType());
		dString localVariableAliasName(cil.NewTemp());
		dCILInstrMove* const store = new dCILInstrMove(cil, localVariableAliasName, arg->GetType()->GetArgType(), varNameNode->GetInfo().m_label, varNameNode->GetInfo().GetType());
		//arg->m_result =  store->GetArg0();
		varNameNode->GetInfo().m_label = localVariableAliasName;
		store->Trace();
	}


	m_body->CompileCIL(cil);
	if (!m_returnType->GetArgType().m_isPointer && (m_returnType->GetArgType().m_intrinsicType == dCILInstr::m_void)) {
		 if (!cil.GetLast()->GetInfo()->GetAsReturn()) {
			dCILInstrReturn* const ret = new dCILInstrReturn(cil, "", dCILInstr::dArgType (dCILInstr::m_void));
			ret->Trace();
		}
	}

	new dCILInstrFunctionEnd(function);
//	cil.Trace();
}