Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "llvm/Pass.h"
- #include "llvm/IR/Module.h"
- #include "llvm/IR/Function.h"
- #include "llvm/Support/raw_ostream.h"
- #include "llvm/IR/Type.h"
- #include "llvm/IR/DerivedTypes.h"
- #include "llvm/IR/Instructions.h"
- #include "llvm/IR/Instruction.h"
- #include "llvm/IR/IRBuilder.h"
- #include "llvm/IR/User.h"
- #include "llvm/IR/Value.h"
- #include "llvm/IR/Constant.h"
- #include "llvm/IR/Constants.h"
- #include "llvm/Support/InstIterator.h"
- #include "sstream"
- #include "string"
- #include "list"
- #include "vector"
- using namespace llvm;
- using namespace std;
- namespace
- {
- struct testing : public ModulePass
- {
- static char ID;
- Function *hook;
- LLVMContext* Context;
- int rtrn;
- string expr,lhsvar;
- list<string> oprnd;
- list<string>::iterator oprnditer;
- testing() : ModulePass(ID) {}
- int abc(Instruction *vi)
- {
- stringstream opcode,operands;
- if(isa<LoadInst>(*vi) || isa<AllocaInst>(*vi))
- {
- if(isa<LoadInst>(*vi))
- {
- operands << vi->getOperand(0);
- expr+=operands.str()+"_";
- oprnd.push_back(operands.str());
- }
- errs() << "\t\t" << *vi << "\n";
- return 0;
- }
- opcode << vi->getOpcode();
- expr+=opcode.str()+"_";
- errs() << "\t\t" << *vi << "\n";
- for(User::op_iterator i = vi->op_begin(); i != vi->op_end(); ++i)
- {
- if(Instruction *ti = dyn_cast<Instruction>(*i))
- rtrn=testing::abc(ti);
- }
- return 1;
- }
- virtual bool runOnModule(Module &M)
- {
- for(Module::iterator F = M.begin(); F != M.end(); ++F)
- {
- for(Function::iterator BB = F->begin(); BB != F->end(); ++BB)
- {
- vector<Instruction*> worklist;
- vector<Instruction*>::iterator worklistiter;
- for(inst_iterator I = inst_begin(F); I != inst_end(F); ++I)
- {
- worklist.push_back(&*I);
- }
- for(worklistiter = worklist.begin(); worklistiter != worklist.end(); ++worklistiter)
- {
- Instruction* instr = *worklistiter;
- expr="";
- oprnd.clear();
- errs() << "use: " <<*instr << "\n";
- for (User::op_iterator i = instr->op_begin(); i != instr->op_end(); ++i)
- {
- if(Instruction *vi = dyn_cast<Instruction>(*i))
- {
- //errs() << "\t\t" << *vi << "\n"; //<< "\t\t" << instr->getOpcode()
- if(isa<StoreInst>(*instr))
- {
- if(!isa<AllocaInst>(*vi))
- {
- rtrn=testing::abc(vi);
- errs() << "expr: " << expr << "\n";
- errs() << "operands: ";
- for(oprnditer=oprnd.begin();oprnditer!=oprnd.end();++oprnditer)
- errs() << *oprnditer << " ";
- }
- else
- {
- stringstream lhs;
- lhs << instr->getOperand(1);
- lhsvar=lhs.str();
- errs() << "\n\t\t" << *vi << "\n";
- errs() << "LHS variable: " << lhsvar << "\n\n";
- }
- }
- }
- }
- if(isa<StoreInst>(*instr))
- {
- //need to call a external function named //hashtable(string), which will take "expr" which has been computed above as an arument.
- }
- }
- }
- }
- return false;
- }
- };
- }
- char testing::ID = 0;
- static RegisterPass<testing> X("testing", "test function exist", false, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement