void TR::ILValidator::checkSoundness(TR::TreeTop *start, TR::TreeTop *stop) { soundnessRule(start, start != NULL, "Start tree must exist"); soundnessRule(stop, !stop || stop->getNode() != NULL, "Stop tree must have a node"); TR::NodeChecklist treetopNodes(comp()), ancestorNodes(comp()), visitedNodes(comp()); // Can't use iterators here, because those presuppose the IL is sound. Walk trees the old-fashioned way. // for (TR::TreeTop *currentTree = start; currentTree != stop; currentTree = currentTree->getNextTreeTop()) { soundnessRule(currentTree, currentTree->getNode() != NULL, "Tree must have a node"); soundnessRule(currentTree, !treetopNodes.contains(currentTree->getNode()), "Treetop node n%dn encountered twice", currentTree->getNode()->getGlobalIndex()); treetopNodes.add(currentTree->getNode()); TR::TreeTop *next = currentTree->getNextTreeTop(); if (next) { soundnessRule(currentTree, next->getNode() != NULL, "Tree after n%dn must have a node", currentTree->getNode()->getGlobalIndex()); soundnessRule(currentTree, next->getPrevTreeTop() == currentTree, "Doubly-linked treetop list must be consistent: n%dn->n%dn<-n%dn", currentTree->getNode()->getGlobalIndex(), next->getNode()->getGlobalIndex(), next->getPrevTreeTop()->getNode()->getGlobalIndex()); } else { soundnessRule(currentTree, stop == NULL, "Reached the end of the trees after n%dn without encountering the stop tree n%dn", currentTree->getNode()->getGlobalIndex(), stop? stop->getNode()->getGlobalIndex() : 0); checkNodeSoundness(currentTree, currentTree->getNode(), ancestorNodes, visitedNodes); } } }
void TR::SoundnessRule::validate(TR::ResolvedMethodSymbol *methodSymbol) { TR::TreeTop *start = methodSymbol->getFirstTreeTop(); TR::TreeTop *stop = methodSymbol->getLastTreeTop(); checkSoundnessCondition(start, start != NULL, "Start tree must exist"); checkSoundnessCondition(stop, !stop || stop->getNode() != NULL, "Stop tree must have a node"); TR::NodeChecklist treetopNodes(comp()), ancestorNodes(comp()), visitedNodes(comp()); /* NOTE: Can't use iterators here, because iterators presuppose that the IL is sound. */ for (TR::TreeTop *currentTree = start; currentTree != stop; currentTree = currentTree->getNextTreeTop()) { checkSoundnessCondition(currentTree, currentTree->getNode() != NULL, "Tree must have a node"); checkSoundnessCondition(currentTree, !treetopNodes.contains(currentTree->getNode()), "Treetop node n%dn encountered twice", currentTree->getNode()->getGlobalIndex()); treetopNodes.add(currentTree->getNode()); TR::TreeTop *next = currentTree->getNextTreeTop(); if (next) { checkSoundnessCondition(currentTree, next->getNode() != NULL, "Tree after n%dn must have a node", currentTree->getNode()->getGlobalIndex()); checkSoundnessCondition(currentTree, next->getPrevTreeTop() == currentTree, "Doubly-linked treetop list must be consistent: n%dn->n%dn<-n%dn", currentTree->getNode()->getGlobalIndex(), next->getNode()->getGlobalIndex(), next->getPrevTreeTop()->getNode()->getGlobalIndex()); } else { checkSoundnessCondition(currentTree, stop == NULL, "Reached the end of the trees after n%dn without encountering the stop tree n%dn", currentTree->getNode()->getGlobalIndex(), stop? stop->getNode()->getGlobalIndex() : 0); checkNodeSoundness(currentTree, currentTree->getNode(), ancestorNodes, visitedNodes); } } }