Adding BPatch_dependenceGraphNode and -Edge to represent graphs used in slicing
[dyninst.git] / dyninstAPI / src / BPatch_dependenceGraphNode.C
1 /*
2  * Copyright (c) 1996-2004 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  * This license is for research uses.  For such uses, there is no
12  * charge. We define "research use" to mean you may freely use it
13  * inside your organization for whatever purposes you see fit. But you
14  * may not re-distribute Paradyn or parts of Paradyn, in any form
15  * source or binary (including derivatives), electronic or otherwise,
16  * to any other organization or entity without our permission.
17  * 
18  * (for other uses, please contact us at paradyn@cs.wisc.edu)
19  * 
20  * All warranties, including without limitation, any warranty of
21  * merchantability or fitness for a particular purpose, are hereby
22  * excluded.
23  * 
24  * By your use of Paradyn, you understand and agree that we (or any
25  * other person or entity with proprietary rights in Paradyn) are
26  * under no obligation to provide either maintenance services,
27  * update services, notices of latent defects, or correction of
28  * defects for Paradyn.
29  * 
30  * Even if advised of the possibility of such damages, under no
31  * circumstances shall we (or any other person or entity with
32  * proprietary rights in the software licensed hereunder) be liable
33  * to you or any third party for direct, indirect, or consequential
34  * damages of any character regardless of type of action, including,
35  * without limitation, loss of profits, loss of use, loss of good
36  * will, or computer failure or malfunction.  You agree to indemnify
37  * us (and any other person or entity with proprietary rights in the
38  * software licensed hereunder) for any and all liability it may
39  * incur to third parties resulting from your use of Paradyn.
40  */
41
42 #include "BPatch_dependenceGraphNode.h"
43 #include "BPatch_dependenceGraphEdge.h"
44
45 void BPatch_dependenceGraphNode::BPatch_dependenceGraphNodeInt(BPatch_instruction* inst) {
46   BPatch_dependenceGraphNodeInt(inst,new BPatch_Vector<BPatch_dependenceGraphEdge*>(),new BPatch_Vector<BPatch_dependenceGraphEdge*>());
47   /*
48     bpinst=inst;
49   incoming=
50   outgoing=new BPatch_Vector<BPatch_dependenceGraphEdge*>();
51   */
52 }
53
54 void BPatch_dependenceGraphNode::BPatch_dependenceGraphNodeInt(BPatch_instruction* inst,BPatch_Vector<BPatch_dependenceGraphEdge*>* inc,BPatch_Vector<BPatch_dependenceGraphEdge*>* out) {
55   bpinst=inst;
56   incoming=inc;
57   outgoing = out;
58   
59   inter = new BPatch_Vector<BPatch_dependenceGraphEdge*>();
60 }
61
62 BPatch_instruction* BPatch_dependenceGraphNode::getBPInstructionInt() {
63   return bpinst;
64 }
65
66 void BPatch_dependenceGraphNode::getOutgoingEdgesInt(BPatch_Vector <BPatch_dependenceGraphEdge *>& out) {
67   int i;
68   for(i=0; i<outgoing->size(); i++)
69     out.push_back((*outgoing)[i]);
70 }
71
72 void BPatch_dependenceGraphNode::getIncomingEdgesInt(BPatch_Vector <BPatch_dependenceGraphEdge *>& inc) {
73   int i;  
74   for(i=0; i<incoming->size(); i++)
75     inc.push_back((*incoming)[i]);
76 }
77
78 bool BPatch_dependenceGraphNode::isImmediateSuccessorInt(BPatch_instruction* other_instruction) {
79   unsigned int i;
80   unsigned int size=outgoing->size();
81   void* address = other_instruction->getAddress();
82   for(i=0; i<size; i++) {
83     if(bpinst != NULL && address == (*outgoing)[i]->getTarget()->bpinst->getAddress())
84       return true;
85   }
86   return false;
87 }
88
89 bool BPatch_dependenceGraphNode::isImmediatePredecessorInt(BPatch_instruction* other_instruction) {
90   unsigned int i;
91   unsigned int size=incoming->size();
92   void* address = other_instruction->getAddress();
93   for(i=0; i<size; i++) {
94     if(bpinst != NULL && address == (*incoming)[i]->getSource()->bpinst->getAddress())
95       return true;
96   }
97   return false;
98 }
99
100 bool BPatch_dependenceGraphNode::addToOutgoing(BPatch_dependenceGraphNode* other_node) {
101   BPatch_instruction* bp = other_node->getBPInstruction();
102   if(bp!=NULL && isImmediateSuccessor(bp))
103     return false;
104   else {
105     outgoing->push_back(new BPatch_dependenceGraphEdge(this,other_node));
106     return true;
107   }
108 }
109
110 bool BPatch_dependenceGraphNode::addToIncoming(BPatch_dependenceGraphNode* other_node) {
111   BPatch_instruction* bp = other_node->getBPInstruction();
112   if(bp != NULL && isImmediatePredecessor(bp))
113     return false;
114   else {
115     incoming->push_back(new BPatch_dependenceGraphEdge(other_node,this));
116     return true;
117   }
118 }