Predator  [unstable] git snapshot
shape.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Kamil Dudka <kdudka@redhat.com>
3  *
4  * This file is part of predator.
5  *
6  * predator is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * any later version.
10  *
11  * predator is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with predator. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef H_GUARD_SHAPE_H
21 #define H_GUARD_SHAPE_H
22 
23 #include "symheap.hh"
24 #include "util.hh" // for RETURN_IF_COMPARED
25 
26 /// describe how the shape looks like
27 struct ShapeProps {
31 
33  kind(/* just for tracking uses of uninitialized values */ OK_REGION),
34  size(0)
35  {
36  }
37 
38  /// if the size_ argument is zero, it means unknown size
39  ShapeProps(EObjKind kind_, BindingOff bOff_, TSizeOf size_ = 0):
40  kind(kind_),
41  bOff(bOff_),
42  size(size_)
43  {
44  }
45 };
46 
47 inline bool operator<(const ShapeProps &a, const ShapeProps &b)
48 {
49  // compare kind of shape
50  RETURN_IF_COMPARED(a, b, kind);
51 
52  // compare size of nodes
53  RETURN_IF_COMPARED(a, b, size);
54 
55  // compare the offsets
56  return a.bOff < b.bOff;
57 }
58 
59 inline bool operator==(const ShapeProps &a, const ShapeProps &b)
60 {
61  return a.kind == b.kind
62  && a.size == b.size
63  && a.bOff == b.bOff;
64 }
65 
66 inline bool operator!=(const ShapeProps &a, const ShapeProps &b)
67 {
68  return !operator==(a, b);
69 }
70 
71 /// inductive definition of a container shape
72 struct Shape {
75  unsigned length; ///< count of objects (both regions or abstract)
76 
77  /// just to track uses of uninitialized values
78  Shape():
80  length(0)
81  {
82  }
83 
84  Shape(TObjId entry_, const ShapeProps &props_, unsigned length_):
85  entry(entry_),
86  props(props_),
87  length(length_)
88  {
89  }
90 };
91 
92 inline bool operator<(const Shape &a, const Shape &b)
93 {
94  RETURN_IF_COMPARED(a, b, entry);
95  RETURN_IF_COMPARED(a, b, props);
96  return a.length < b.length;
97 }
98 
99 inline bool operator==(const Shape &a, const Shape &b)
100 {
101  return a.entry == b.entry
102  && a.props == b.props
103  && a.length == b.length;
104 }
105 
106 inline bool operator!=(const Shape &a, const Shape &b)
107 {
108  return !operator==(a, b);
109 }
110 
111 /// list of shape properties (kind, binding offsets) candidates
112 typedef std::vector<ShapeProps> TShapePropsList;
113 
114 /// set of shapes given by their inductive definition
115 typedef std::set<Shape> TShapeSet;
116 
117 /// list of shapes given by their inductive definition
118 typedef std::vector<Shape> TShapeList;
119 
120 /// list of shapes grouped by heap index they occur in
121 typedef std::vector<TShapeList> TShapeListByHeapIdx;
122 
123 /// return the list of objects that the given shape consists of
124 void objListByShape(TObjList *pDst, const SymHeap &sh, const Shape &shape);
125 
126 /// return the set of objects that the given shape consists of
127 void objSetByShape(TObjSet *pDst, const SymHeap &sh, const Shape &shape);
128 
129 /// return the last object (the opposite of entry) of the given shape
130 TObjId lastObjOfShape(const SymHeap &sh, const Shape &shape);
131 
132 #endif /* H_GUARD_SHAPE_H */