Predator  [unstable] git snapshot
adt_op_meta.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_ADT_OP_META_H
21 #define H_GUARD_ADT_OP_META_H
22 
23 #include "util.hh" // for RETURN_IF_COMPARED
24 #include "symheap.hh"
25 
26 namespace AdtOp {
27 
28 //// enumeration of supported meta-operations (only pointer operations for now)
31  MO_ALLOC, /// a new object is introduced
32  MO_FREE, /// an existing object disappears
33  MO_SET, /// a value is written to a field
34  MO_UNSET /// a tracked field is invalidated
35 };
36 
37 //// description of a meta-operation (only pointer operations for now)
38 struct MetaOperation {
39  EMetaOperation code; /// kind of meta-operation
40  TObjId obj; /// object ID we operate on
41  TOffset off; /// offset we write at (set/unset)
42  TObjId tgtObj; /// object we take address of (set)
43  TOffset tgtOff; /// tgt offset of the address (set)
44  ETargetSpecifier tgtTs; /// tgt specifier of the addr (set)
45 
47  const EMetaOperation code_ = MO_INVALID,
48  const TObjId obj_ = OBJ_INVALID,
49  const TOffset off_ = 0,
50  const TObjId tgtObj_ = OBJ_INVALID,
51  const TOffset tgtOff_ = 0,
52  const ETargetSpecifier tgtTs_ = TS_INVALID):
53  code (code_),
54  obj (obj_),
55  off (off_),
56  tgtObj (tgtObj_),
57  tgtOff (tgtOff_),
58  tgtTs (tgtTs_)
59  {
60  }
61 };
62 
63 /// required to be defined by the implementation of std::set
64 inline bool operator<(const MetaOperation &a, const MetaOperation &b)
65 {
66  // compare lexicographically
67  RETURN_IF_COMPARED(a, b, code);
68  RETURN_IF_COMPARED(a, b, obj);
69  RETURN_IF_COMPARED(a, b, off);
70  RETURN_IF_COMPARED(a, b, tgtObj);
71  RETURN_IF_COMPARED(a, b, tgtOff);
72  RETURN_IF_COMPARED(a, b, tgtTs);
73 
74  // the items are incomparable
75  return false;
76 }
77 
78 /// set of meta-operations (which should be independent on each other)
79 typedef std::set<MetaOperation> TMetaOpSet;
80 
81 bool diffHeaps(TMetaOpSet *pDst, const SymHeap &sh1, const SymHeap &sh2);
82 
83 } // namespace AdtOp
84 
85 #endif /* H_GUARD_ADT_OP_META_H */