My Project
cover.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 #ifndef __CPUI_COVER__
19 #define __CPUI_COVER__
20 
21 #include "type.hh"
22 
23 class PcodeOp;
24 class FlowBlock;
25 class Varnode;
26 
35 class CoverBlock {
36  const PcodeOp *start;
37  const PcodeOp *stop;
38 public:
39  CoverBlock(void) { start = (const PcodeOp *)0; stop = (const PcodeOp *)0; }
40  static uintm getUIndex(const PcodeOp *op);
41  const PcodeOp *getStart(void) const { return start; }
42  const PcodeOp *getStop(void) const { return stop; }
43  void clear(void) { start = (const PcodeOp *)0; stop = (const PcodeOp *)0; }
44  void setAll(void) {
45  start = (const PcodeOp *)0; stop = (const PcodeOp *)1; }
46  void setBegin(const PcodeOp *begin) {
47  start = begin; if (stop==(const PcodeOp *)0) stop = (const PcodeOp *)1; }
48  void setEnd(const PcodeOp *end) { stop = end; }
49  int4 intersect(const CoverBlock &op2) const;
50  bool empty(void) const {
51  return ((start==(const PcodeOp *)0)&&(stop==(const PcodeOp *)0)); }
52  bool contain(const PcodeOp *point) const;
53  int4 boundary(const PcodeOp *point) const;
54  void merge(const CoverBlock &op2);
55  void print(ostream &s) const;
56 };
57 
68 class Cover {
69  map<int4,CoverBlock> cover;
70  static const CoverBlock emptyBlock;
71  void addRefRecurse(const FlowBlock *bl);
72 public:
73  void clear(void) { cover.clear(); }
74  int4 compareTo(const Cover &op2) const;
75  const CoverBlock &getCoverBlock(int4 i) const;
76  int4 intersect(const Cover &op2) const;
77  int4 intersectByBlock(int4 blk,const Cover &op2) const;
78  void intersectList(vector<int4> &listout,const Cover &op2,int4 level) const;
79  bool contain(const PcodeOp *op,int4 max) const;
80  int4 containVarnodeDef(const Varnode *vn) const;
81  void merge(const Cover &op2);
82  void rebuild(const Varnode *vn);
83  void addDefPoint(const Varnode *vn);
84  void addRefPoint(const PcodeOp *ref,const Varnode *vn);
85  // void remove_refpoint(const PcodeOp *ref,const Varnode *vn) {
86  // rebuild(vn); } // Cheap but inefficient
87  void print(ostream &s) const;
88  map<int4,CoverBlock>::const_iterator begin(void) const { return cover.begin(); }
89  map<int4,CoverBlock>::const_iterator end(void) const { return cover.end(); }
90 };
91 
92 #endif
const PcodeOp * getStart(void) const
Get the start of the range.
Definition: cover.hh:41
Description of a control-flow block containing PcodeOps.
Definition: block.hh:60
map< int4, CoverBlock >::const_iterator end(void) const
Get end of CoverBlocks.
Definition: cover.hh:89
static uintm getUIndex(const PcodeOp *op)
Get the comparison index for a PcodeOp.
Definition: cover.cc:27
void setEnd(const PcodeOp *end)
Reset end of range.
Definition: cover.hh:48
The topological scope of a variable within a basic block.
Definition: cover.hh:35
void setAll(void)
Mark whole block as covered.
Definition: cover.hh:44
Lowest level operation of the p-code language.
Definition: op.hh:58
const PcodeOp * getStop(void) const
Get the end of the range.
Definition: cover.hh:42
bool empty(void) const
Return true if this is empty/uncovered.
Definition: cover.hh:50
int4 boundary(const PcodeOp *point) const
Characterize given point as boundary.
Definition: cover.cc:127
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
Classes for describing and printing data-types.
A description of the topological scope of a single variable object.
Definition: cover.hh:68
void clear(void)
Clear this to an empty Cover.
Definition: cover.hh:73
bool contain(const PcodeOp *point) const
Check containment of given point.
Definition: cover.cc:105
void clear(void)
Clear this block to empty/uncovered.
Definition: cover.hh:43
map< int4, CoverBlock >::const_iterator begin(void) const
Get beginning of CoverBlocks.
Definition: cover.hh:88
void merge(const CoverBlock &op2)
Merge another CoverBlock into this.
Definition: cover.cc:145
void setBegin(const PcodeOp *begin)
Reset start of range.
Definition: cover.hh:46
void print(ostream &s) const
Dump a description to stream.
Definition: cover.cc:186
int4 intersect(const CoverBlock &op2) const
Compute intersection with another CoverBlock.
Definition: cover.cc:57
CoverBlock(void)
Construct empty/uncovered block.
Definition: cover.hh:39