Exemplo n.º 1
0
bool dDataFlowGraph::ApplyCopyPropagation()
{
	bool ret = false;
	UpdateReachingDefinitions();
//m_cil->Trace();

	for (dCIL::dListNode* node = m_basicBlocks.m_begin; node != m_basicBlocks.m_end; node = node->GetNext()) {
		dCILInstrMove* const moveInst = node->GetInfo()->GetAsMove();
		if (moveInst) {
moveInst->Trace();
			dInstructionVariableDictionary::dTreeNode* const usedVariableNode = m_variableUsed.Find (moveInst->GetArg0().m_label);
			if (usedVariableNode) {
				const dList<dCIL::dListNode*>& usedVariableList = usedVariableNode->GetInfo();
				for (const dList<dCIL::dListNode*>::dListNode* useVariableNode = usedVariableList.GetFirst() ; useVariableNode; useVariableNode = useVariableNode->GetNext()) {
					dCIL::dListNode* const node1 = useVariableNode->GetInfo();
					dCILInstr* const inst = node1->GetInfo();
					dTrace (("\t\t"));
					inst->Trace();
					//TraceReachIn (node1);

					if (DoMoveReachInstruction(node1, moveInst)) {
						ret |= inst->ApplyCopyPropagation(moveInst);
					}
				}
			}

m_cil->Trace();
		}
	}

	return ret;
}
	void RayCastCompoundsAllSubShapes(const dVector& origin, const dVector& end)
	{
		m_param = 1.0f;
		m_body = NULL;
		NewtonWorld* const world = GetWorld();
		NewtonWorldRayCast(world, &origin[0], &end[0], PickCompound, this, NULL, 0);
		if (m_body) {
			// we found a compound, find all sub shape on teh path of the ray
			dMatrix matrix;
			NewtonBodyGetMatrix(m_body, &matrix[0][0]);
			dVector localP0(matrix.UntransformVector(origin));
			dVector localP1(matrix.UntransformVector(end));

			NewtonCollision* const compoundCollision = NewtonBodyGetCollision(m_body);
			dAssert(NewtonCollisionGetType(compoundCollision) == SERIALIZE_ID_COMPOUND);
			for (void* node = NewtonCompoundCollisionGetFirstNode(compoundCollision); node; node = NewtonCompoundCollisionGetNextNode(compoundCollision, node)) {
				dVector normal;
				dLong attribute;
				NewtonCollision* const subShape = NewtonCompoundCollisionGetCollisionFromNode(compoundCollision, node);
				dFloat xxx = NewtonCollisionRayCast(subShape, &localP0[0], &localP1[0], &normal[0], &attribute);
				if (xxx < 1.0f) {
					dTrace (("sub shape hit\n"))
				}
			}
		}
	}
Exemplo n.º 3
0
void dDataFlowGraph::TraceReachOutput(dCIL::dListNode* const node) const
{
	dCILInstr* const stmt = node->GetInfo();
	stmt->Trace();
	const dDataFlowPoint& point = m_dataFlowGraph.Find(node)->GetInfo();
	if (point.m_reachStmtInputSet.GetCount()) {
		dTrace(("\t\t\treach to:\n"));

		dDataFlowPoint::dVariableSet<dCIL::dListNode*>::Iterator iter(point.m_reachStmtOutputSet);
		for (iter.Begin(); iter; iter++) {
			dCIL::dListNode* const reachedNode = iter.GetKey();
			dCILInstr* const reachedInstr = reachedNode->GetInfo();
			dTrace(("\t\t\t"));
			reachedInstr->Trace();
		}
		dTrace(("\n"));
	}
}
Exemplo n.º 4
0
void dDataFlowGraph::dBasicBlock::Trace() const
{
	#ifdef TRACE_INTERMEDIATE_CODE
		int test = 1;
		for (dCIL::dListNode* stmtNode = m_begin; test; stmtNode = stmtNode->GetNext()) {
			test = (stmtNode != m_end);
			const dThreeAdressStmt& stmt = stmtNode->GetInfo();
			DTRACE_INTRUCTION(&stmt);
		}
		dTrace(("\n"));
	#endif
}
Exemplo n.º 5
0
void dBasicBlock::Trace() const
{
	bool terminate = false;
	for (dCIL::dListNode* node = m_begin; !terminate; node = node->GetNext()) {
		terminate = (node == m_end);
		node->GetInfo()->Trace();
	}

/*
	dCILInstrLabel* const label = m_begin->GetInfo()->GetAsLabel();
	dTrace ((" block-> %s\n", label->GetArg0().m_label.GetStr()));

	if (m_idom) {
		dTrace(("   immediateDominator-> %s\n", m_idom->m_begin->GetInfo()->GetAsLabel()->GetArg0().m_label.GetStr()));
	} else {
		dTrace(("   immediateDominator->\n"));
	}

	dTrace(("   dominatorTreeChildren-> "));
	for (dList<const dBasicBlock*>::dListNode* childNode = m_children.GetFirst(); childNode; childNode = childNode->GetNext()) {
		const dBasicBlock* const childBlock = childNode->GetInfo();
		dCILInstrLabel* const label = childBlock->m_begin->GetInfo()->GetAsLabel();
		dTrace(("%s ", label->GetArg0().m_label.GetStr()));
	}
	dTrace(("\n"));


	dTrace (("   dominators-> "));
	dTree<int, const dBasicBlock*>::Iterator iter (m_dominators);
	for (iter.Begin(); iter; iter ++) {
		const dBasicBlock& domBlock = *iter.GetKey();
		dCILInstrLabel* const label = domBlock.m_begin->GetInfo()->GetAsLabel();
		dTrace (("%s ", label->GetArg0().m_label.GetStr()));
	}
	dTrace (("\n"));
*/
/*
	dTrace(("   dominanceFrontier-> "));
	for (dList<const dBasicBlock*>::dListNode* childFrontierNode = m_dominanceFrontier.GetFirst(); childFrontierNode; childFrontierNode = childFrontierNode->GetNext()) {
		const dBasicBlock* const childBlock = childFrontierNode->GetInfo();
		dCILInstrLabel* const label = childBlock->m_begin->GetInfo()->GetAsLabel();
		dTrace(("%s ", label->GetArg0().m_label.GetStr()));
	}
	dTrace (("\n"));
*/
	dTrace (("\n"));
}
Exemplo n.º 6
0
void AnimatedPlayerController(DemoEntityManager* const scene)
{
	// load the sky box
	scene->CreateSkyBox();
	dTrace(("sorry demo %s temporarilly disabled\n", __FUNCTION__));
	return;

#if 0
	CreateLevelMesh(scene, "flatPlane.ngd", true);

	dMatrix origin (dGetIdentityMatrix());
	origin.m_posit.m_y = -0.0f;

	dMatrix origin1 (origin);
	InverseKinematicAnimationManager* const animationManager = new InverseKinematicAnimationManager(scene);

	dPointer<DemoEntity> humanModel (DemoEntity::LoadNGD_mesh("whiteman.ngd", scene->GetNewton(), scene->GetShaderCache()));

	//dAnimIKController* const human = animationManager->CreateHuman("whiteman.ngd", origin1);
	dAnimIKController* const human = animationManager->CreateHuman(&(*humanModel), origin1);
	//dAnimIKController* const human = animationManager->CreateHuman("skintest.ngd", origin1);
	

DemoEntity* const referenceModel = DemoEntity::LoadNGD_mesh("viper.ngd", scene->GetNewton(), scene->GetShaderCache());
origin1.m_posit.m_z = 2.0f;
referenceModel->ResetMatrix(*scene, referenceModel->GetCurrentMatrix() * origin1);
scene->Append(referenceModel);

dMatrix xxxx(origin1);
for (int i = 0; i < 10; i ++) {
	xxxx.m_posit.m_x += 2;
	dMatrix xxxx1(xxxx);
	for (int j = 0; j < 10; j ++) {
		xxxx1.m_posit.m_z -= 2;
		animationManager->CreateHuman(&(*humanModel), xxxx1);
	}
}
	
	origin.m_posit = dVector(-4.0f, 1.0f, 0.0f, 1.0f);
	scene->SetCameraMatrix(dGetIdentityMatrix(), origin.m_posit);
#endif
}
Exemplo n.º 7
0
// generates the canonical Items set for a LR(1) grammar
void dParserCompiler::CanonicalItemSets (
	dTree<dState*, dCRCTYPE>& stateMap, 
	const dProductionRule& ruleList, 
	const dTree<dTokenInfo, dCRCTYPE>& symbolList, 
	const dOperatorsPrecedence& operatorPrecedence,
	FILE* const debugFile)
{
	dList<dItem> itemSet;
	dList<dState*> stateList;

	// start by building an item set with only the first rule
	dItem& item = itemSet.Append()->GetInfo();
	item.m_indexMarker = 0;
	item.m_lookAheadSymbolCRC = dCRC64 (DACCEPT_SYMBOL);
	item.m_lookAheadSymbolName = DACCEPT_SYMBOL;
	item.m_ruleNode = ruleList.GetFirst();

	// build a rule info map
	dTree<dList<void*>, dCRCTYPE> ruleMap;
	for (dProductionRule::dListNode* ruleNode = ruleList.GetFirst(); ruleNode; ruleNode = ruleNode->GetNext()) {
		dRuleInfo& info = ruleNode->GetInfo();

		dTree<dList<void*>, dCRCTYPE>::dTreeNode* node = ruleMap.Find(info.m_nameCRC);
		if (!node) {
			node = ruleMap.Insert(info.m_nameCRC);
		}
		dList<void*>& entry = node->GetInfo();
		entry.Append(ruleNode);
	}


	// find the closure for the first this item set with only the first rule
	dState* const state = Closure (itemSet, symbolList, ruleMap);
	operatorPrecedence.SaveLastOperationSymbol (state);

	stateMap.Insert(state, state->GetKey());
	stateList.Append(state);

	state->Trace(debugFile);

	// now for each state found 
	int stateNumber = 1;
	for (dList<dState*>::dListNode* node = stateList.GetFirst(); node; node = node->GetNext()) {
		dState* const state = node->GetInfo();

		dTree<dTokenInfo, dCRCTYPE>::Iterator iter (symbolList);
		for (iter.Begin(); iter; iter ++) {

			dCRCTYPE symbol = iter.GetKey();
			dState* const newState = Goto (state, symbol, symbolList, ruleMap);

			if (newState->GetCount()) {
				const dTokenInfo& tokenInfo = iter.GetNode()->GetInfo();
				dTransition& transition = state->m_transitions.Append()->GetInfo();
				transition.m_symbol = symbol;
				transition.m_name = tokenInfo.m_name; 
				transition.m_type = tokenInfo.m_type;
				dAssert (transition.m_symbol == dCRC64(transition.m_name.GetStr()));
				transition.m_targetState = newState;

				dTree<dState*, dCRCTYPE>::dTreeNode* const targetStateNode = stateMap.Find(newState->GetKey());
				if (!targetStateNode) {
					newState->m_number = stateNumber;

					stateNumber ++;
					stateMap.Insert(newState, newState->GetKey());
					newState->Trace(debugFile);
					stateList.Append(newState);

					operatorPrecedence.SaveLastOperationSymbol (newState);

				} else {
					transition.m_targetState = targetStateNode->GetInfo();
					delete newState;
				}
			} else {
				delete newState;
			}
		}

		dTrace (("state#:%d   items: %d   transitions: %d\n", state->m_number, state->GetCount(), state->m_transitions.GetCount()));
	}
}
Exemplo n.º 8
0
void dParserCompiler::BuildParsingTable (
	const dTree<dState*, dCRCTYPE>& stateList, 
	dCRCTYPE startSymbol, 
	const dOperatorsPrecedence& operatorPrecedence) const
{
	dTree<dState*, dCRCTYPE>::Iterator stateIter (stateList);

	unsigned emptySymbol = 0;

	const dCRCTYPE acceptingSymbol = dCRC64 (DACCEPT_SYMBOL);
	// create Shift Reduce action table
	for (stateIter.Begin(); stateIter; stateIter ++) {
		dState* const state = stateIter.GetNode()->GetInfo();

		// add all shift actions first
		for (dList<dTransition>::dListNode* node = state->m_transitions.GetFirst(); node; node = node->GetNext()) {
			dTransition& transition = node->GetInfo();
			if (transition.m_type == TERMINAL) {

				// find item generating this shift action and mark it as used.
				const dState* const targetState = transition.m_targetState;
				dAssert (!state->m_actions.Find (transition.m_symbol));
				dTree<dAction, dCRCTYPE>::dTreeNode* const actionNode = state->m_actions.Insert (transition.m_symbol); 
				dAction& action = actionNode->GetInfo();
				action.m_type = dSHIFT;
				action.m_myItem = NULL;
				action.m_nextState = targetState->m_number;
				action.m_reduceRuleNode = NULL;
			}
		}

		// add all reduce actions
		dList<dAction*> potencialConflictinActions;
		for (dState::dListNode* itemNode = state->GetFirst(); itemNode; itemNode = itemNode->GetNext()) {
			dItem& item = itemNode->GetInfo();
			const dRuleInfo& ruleInfo = item.m_ruleNode->GetInfo();
			if ((ruleInfo.m_ruleNumber == 0) && (item.m_indexMarker == 1)) {
				dTree<dAction, dCRCTYPE>::dTreeNode* const actionNode = state->m_actions.Insert (acceptingSymbol); 
				dAssert (actionNode);
				dAction& action = actionNode->GetInfo();
				action.m_type = dACCEPT;
				action.m_myItem = &item;
				action.m_reduceRuleNode = NULL;
			} else if ((item.m_indexMarker == ruleInfo.GetCount()) && (ruleInfo.m_nameCRC != startSymbol)) {
				dTree<dAction, dCRCTYPE>::dTreeNode* actionNode = state->m_actions.Find (item.m_lookAheadSymbolCRC); 
				if (!actionNode) {
					actionNode = state->m_actions.Insert (item.m_lookAheadSymbolCRC); 
					dAction& action = actionNode->GetInfo();
					action.m_type = dREDUCE;
					action.m_myItem = &item;
					action.m_nextState = 0;
					action.m_reduceRuleNode = item.m_ruleNode;
				} else {
					dAction& action = actionNode->GetInfo();
					action.m_myItem = &item;
					action.m_reduceRuleNode = item.m_ruleNode;
					potencialConflictinActions.Append (&actionNode->GetInfo());
				}
			}
		}

		// now resolve all conflicting actions
		if (potencialConflictinActions.GetCount()) {

			// resolve conflicting actions
			dList<dAction*>::dListNode* nextActionNode = NULL;
			for (dList<dAction*>::dListNode* actionNode = potencialConflictinActions.GetFirst(); actionNode; actionNode = nextActionNode) {
				dAction* const action = actionNode->GetInfo();

				if (action->m_type == dREDUCE) {
					// this is a reduce reduce conflict
					dAssert (0);
					dTrace (("This is a reduce Reduce conflict, resolve in favor of of first production rule\n")); 
				}
				nextActionNode = actionNode->GetNext();

				const dItem& item = *action->m_myItem;
				if (item.m_lastOperatorSymbolCRC != emptySymbol) {
					const dOperatorsAssociation* const operatorAssosiation = operatorPrecedence.FindAssociation (item.m_lastOperatorSymbolCRC);
					dAssert (operatorAssosiation);
					if (operatorAssosiation->m_associativity == dOperatorsAssociation::m_left) {

						const dOperatorsAssociation* const lookAheadOperatorAssosiation = operatorPrecedence.FindAssociation (item.m_lookAheadSymbolCRC);
						if (!(lookAheadOperatorAssosiation && (lookAheadOperatorAssosiation->m_prioprity > operatorAssosiation->m_prioprity))) {
							action->m_type = dREDUCE;
						}
					}
					potencialConflictinActions.Remove(actionNode);
				}
			}

			// for any conflicting actions left, display warning
			for (dList<dAction*>::dListNode* actionNode = potencialConflictinActions.GetFirst(); actionNode; actionNode = actionNode->GetNext()) {
				dAction* const action = actionNode->GetInfo();

				dRuleInfo& rule = action->m_reduceRuleNode->GetInfo();
				dString sentence;
				sentence += rule.m_name;
				sentence += " : ";
				for (dRuleInfo::dListNode* node = rule.GetFirst(); node; node = node->GetNext()) {
					sentence += node->GetInfo().m_name;
					sentence += " ";
				}

				if (action->m_type == dSHIFT) {
					if (!rule.m_shiftReduceErrorMark) {
						rule.m_shiftReduceErrorMark = true;
						if (m_shiftReduceExpectedWarnings <= 0) {
							DisplayError ("\nstate %d: shift reduce warning resolved in favor of shift. on rule\n", state->m_number);
							DisplayError ("  %s\n", sentence.GetStr());
						}
						m_shiftReduceExpectedWarnings --;
					}
					
				} else {
					dAssert (0);
					DisplayError ("\nstate %d: reduce reduce error resolved in favor of first sentence. on rule\n", state->m_number);
					DisplayError ("  %s\n", sentence.GetStr());
				}
			}
		}
	}


	// create Goto Table
	for (stateIter.Begin(); stateIter; stateIter ++) {
		dState* const state = stateIter.GetNode()->GetInfo();
		for (dList<dTransition>::dListNode* node = state->m_transitions.GetFirst(); node; node = node->GetNext()) {
			dTransition& transition = node->GetInfo();
			if (transition.m_type == NONTERMINAL) {
				state->m_goto.Insert (transition.m_targetState, transition.m_symbol); 
			}
		}
	}
}