Update copyright to LGPL on all files
[dyninst.git] / dyninstAPI / src / BPatch_dependenceGraphNode.C
1 /*
2  * Copyright (c) 1996-2009 Barton P. Miller
3  * 
4  * We provide the Paradyn Parallel Performance Tools (below
5  * described as "Paradyn") on an AS IS basis, and do not warrant its
6  * validity or performance.  We reserve the right to update, modify,
7  * or discontinue this software at any time.  We shall have no
8  * obligation to supply such updates or modifications or any other
9  * form of support to you.
10  * 
11  * By your use of Paradyn, you understand and agree that we (or any
12  * other person or entity with proprietary rights in Paradyn) are
13  * under no obligation to provide either maintenance services,
14  * update services, notices of latent defects, or correction of
15  * defects for Paradyn.
16  * 
17  * This library is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2.1 of the License, or (at your option) any later version.
21  * 
22  * This library is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * Lesser General Public License for more details.
26  * 
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31
32 #include "BPatch_dependenceGraphNode.h"
33 #include "BPatch_dependenceGraphEdge.h"
34
35 void BPatch_dependenceGraphNode::BPatch_dependenceGraphNodeInt(BPatch_instruction* inst) {
36   BPatch_dependenceGraphNodeInt(inst,new BPatch_Vector<BPatch_dependenceGraphEdge*>(),new BPatch_Vector<BPatch_dependenceGraphEdge*>());
37   /*
38     bpinst=inst;
39   incoming=
40   outgoing=new BPatch_Vector<BPatch_dependenceGraphEdge*>();
41   */
42 }
43
44 void BPatch_dependenceGraphNode::BPatch_dependenceGraphNodeInt(BPatch_instruction* inst,BPatch_Vector<BPatch_dependenceGraphEdge*>* inc,BPatch_Vector<BPatch_dependenceGraphEdge*>* out) {
45   bpinst=inst;
46   incoming=inc;
47   outgoing = out;
48   
49   inter = new BPatch_Vector<BPatch_dependenceGraphEdge*>();
50 }
51
52 BPatch_instruction* BPatch_dependenceGraphNode::getBPInstructionInt() {
53   return bpinst;
54 }
55
56 void BPatch_dependenceGraphNode::getOutgoingEdgesInt(BPatch_Vector <BPatch_dependenceGraphEdge *>& out) {
57   unsigned i;
58   for(i=0; i<outgoing->size(); i++)
59     out.push_back((*outgoing)[i]);
60 }
61
62 void BPatch_dependenceGraphNode::getIncomingEdgesInt(BPatch_Vector <BPatch_dependenceGraphEdge *>& inc) {
63   unsigned i;  
64   for(i=0; i<incoming->size(); i++)
65     inc.push_back((*incoming)[i]);
66 }
67
68 bool BPatch_dependenceGraphNode::isImmediateSuccessorInt(BPatch_instruction* other_instruction) {
69   unsigned int i;
70   unsigned int size=outgoing->size();
71   void* address = other_instruction->getAddress();
72   for(i=0; i<size; i++) {
73     if(bpinst != NULL && address == (*outgoing)[i]->getTarget()->bpinst->getAddress())
74       return true;
75   }
76   return false;
77 }
78
79 bool BPatch_dependenceGraphNode::isImmediatePredecessorInt(BPatch_instruction* other_instruction) {
80   unsigned int i;
81   unsigned int size=incoming->size();
82   void* address = other_instruction->getAddress();
83   for(i=0; i<size; i++) {
84     if(bpinst != NULL && address == (*incoming)[i]->getSource()->bpinst->getAddress())
85       return true;
86   }
87   return false;
88 }
89
90 bool BPatch_dependenceGraphNode::addToOutgoing(BPatch_dependenceGraphNode* other_node) {
91   BPatch_instruction* bp = other_node->getBPInstruction();
92   if(bp!=NULL && isImmediateSuccessor(bp))
93     return false;
94   else {
95     outgoing->push_back(new BPatch_dependenceGraphEdge(this,other_node));
96     return true;
97   }
98 }
99
100 bool BPatch_dependenceGraphNode::addToIncoming(BPatch_dependenceGraphNode* other_node) {
101   BPatch_instruction* bp = other_node->getBPInstruction();
102   if(bp != NULL && isImmediatePredecessor(bp))
103     return false;
104   else {
105     incoming->push_back(new BPatch_dependenceGraphEdge(other_node,this));
106     return true;
107   }
108 }