SVF
SaberAnnotator.cpp
Go to the documentation of this file.
1 //===- SaberAnnotator.cpp -- Annotation---------------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2017> <Yulei Sui>
6 //
7 
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * SaberAnnotator.cpp
25  *
26  * Created on: May 4, 2014
27  * Author: Yulei Sui
28  */
29 
30 #include "SABER/SaberAnnotator.h"
31 #include "SABER/ProgSlice.h"
32 
33 using namespace SVF;
34 
39 {
40  std::string str;
41  raw_string_ostream rawstr(str);
42  rawstr << SB_SLICESOURCE ; //<< _curSlice->getSource()->getId();
43  if(const Instruction* sourceinst = SVFUtil::dyn_cast<Instruction>(_curSlice->getLLVMValue(_curSlice->getSource())))
44  {
45  addMDTag(const_cast<Instruction*>(sourceinst),rawstr.str());
46  }
47  else
48  assert(false && "instruction of source node not found");
49 
50 }
51 
56 {
57  for(ProgSlice::SVFGNodeSet::const_iterator it = _curSlice->getSinks().begin(),
58  eit = _curSlice->getSinks().end(); it!=eit; ++it)
59  {
60  if(const ActualParmSVFGNode* ap = SVFUtil::dyn_cast<ActualParmSVFGNode>(*it))
61  {
62  const Instruction* sinkinst = ap->getCallSite()->getCallSite();
63  assert(SVFUtil::isa<CallInst>(sinkinst) && "not a call instruction?");
64  const CallInst* sink = SVFUtil::cast<CallInst>(sinkinst);
65  std::string str;
66  raw_string_ostream rawstr(str);
67  rawstr << SB_SLICESINK << _curSlice->getSource()->getId();
68  addMDTag(const_cast<CallInst*>(sink),sink->getArgOperand(0),rawstr.str());
69  }
70  else
71  assert(false && "sink node is not a actual parameter?");
72  }
73 }
74 
79 {
80 
81  assert((succPos == 0 || succPos == 1) && "branch instruction should only have two successors");
82 
83  std::string str;
84  raw_string_ostream rawstr(str);
85  rawstr << SB_FESIBLE << _curSlice->getSource()->getId();
86  BranchInst* br = const_cast<BranchInst*>(brInst);
87  addMDTag(br,br->getCondition(),rawstr.str());
88 }
89 
94 {
95 
96  assert((succPos == 0 || succPos == 1) && "branch instruction should only have two successors");
97 
98  std::string str;
99  raw_string_ostream rawstr(str);
100  rawstr << SB_INFESIBLE << _curSlice->getSource()->getId();
101  BranchInst* br = const_cast<BranchInst*>(brInst);
102  addMDTag(br,br->getCondition(),rawstr.str());
103 }
104 
105 
110 {
111  assert(succPos < switchInst->getNumSuccessors() && "successor position not correct!");
112 }
113 
114 
115 
116 
const SVFGNode * getSource() const
root and sink operations
Definition: ProgSlice.h:112
llvm::BranchInst BranchInst
Definition: BasicTypes.h:157
const char * SB_FESIBLE
Definition: Annotator.h:176
#define assert(ex)
Definition: util.h:141
void annotateSource()
Annotation.
llvm::CallInst CallInst
Definition: BasicTypes.h:143
const char * SB_SLICESOURCE
Saber annotations.
Definition: Annotator.h:174
unsigned u32_t
Definition: SVFBasicTypes.h:75
const Value * getLLVMValue(const SVFGNode *node) const
Get llvm value from a SVFGNode.
Definition: ProgSlice.cpp:154
llvm::Instruction Instruction
Definition: BasicTypes.h:79
llvm::raw_string_ostream raw_string_ostream
Definition: BasicTypes.h:100
const char * SB_INFESIBLE
Definition: Annotator.h:177
const ProgSlice * _curSlice
llvm::SwitchInst SwitchInst
Definition: BasicTypes.h:158
void annotateFeasibleBranch(const BranchInst *brInst, u32_t succPos)
for isBitcode
Definition: ContextDDA.h:15
void annotateInfeasibleBranch(const BranchInst *brInst, u32_t succPos)
void addMDTag(Instruction *inst, std::string str)
Simple add/remove meta data information.
Definition: Annotator.h:99
NodeID getId() const
Get ID.
Definition: GenericGraph.h:164
const char * SB_SLICESINK
Definition: Annotator.h:175
const SVFGNodeSet & getSinks() const
Definition: ProgSlice.h:120
void annotateSwitch(SwitchInst *brInst, u32_t succPos)