ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sageInterfaceAsm.h
Go to the documentation of this file.
1 #ifndef ROSE_SAGE_INTERFACE_ASM
2 #define ROSE_SAGE_INTERFACE_ASM
3 
4 // These functions in this file are expected to become a part of the
5 // Binary Analysis and Transformation interfaces in the new ROSE API.
6 
7 namespace SageInterface
8  {
9  // DQ (4/26/2010): Added this file of functions to support binary analysis work.
10 
11  void addComment(SgAsmStatement* stmt, const std::string & input_string );
12 
13  SgAsmElfSection* getSection ( SgProject* project, const std::string & name );
14 
15  // Simple way to get the section that that a pointer points into (if any).
16  SgAsmElfSection* getSection ( SgProject* project, size_t ptr );
17 
19  SgAsmFunction* getAsmFunction ( SgAsmInstruction* asmInstruction );
20 
22  SgAsmBlock* getAsmBlock ( SgAsmInstruction* asmInstruction );
23 
26 
27  std::string generateUniqueName ( size_t value, std::map<size_t,int> & usedOffsets, size_t & counter );
28 
29  size_t get_value ( SgAsmValueExpression* asmValueExpression );
30  std::string get_valueString( SgAsmValueExpression* asmValueExpression );
31 
32  bool isMovInstruction ( SgAsmInstruction* asmInstruction );
33 
34  bool isInstructionKind ( SgAsmInstruction* asmInstruction, X86InstructionKind instuctionKind );
35 
36  typedef bool (*EquivalenceTestFunctionType) (SgNode* x, SgNode* y);
37 
38  // Definition of object equivalence for purposes of the AST matching using for instruction recognition.
39  bool equivalenceTest(SgNode* x, SgNode* y);
40 
41  // These functions are used internally within the find function.
42  std::vector<SgNode*> flattenAST ( SgNode* node );
43  std::vector<SgNode*> matchAST ( SgNode* node, std::vector<SgNode*> & listOfNodes, EquivalenceTestFunctionType equivalenceTest );
44 
45  // General function to find matching target AST in larger AST.
46  // SgNode* find ( SgNode* astNode, SgNode* target, EquivalenceTestFunctionType equivalenceTest );
47  std::vector<SgNode*> find ( SgNode* astNode, SgNode* target, EquivalenceTestFunctionType equivalenceTest );
48 
49  // DQ (4/28/2010): Added support for interface to detect NOP's in all their glory.
51  // bool isNOP ( const SgAsmInstruction* asmInstruction );
52  bool isNOP ( SgAsmInstruction* asmInstruction );
54  bool isNOP ( const std::vector<SgAsmInstruction*> & asmInstructionList );
56  std::vector<std::vector<SgAsmInstruction*> > find_NOP_sequences ( SgAsmBlock* asmBlock );
57 
58  // DQ (5/1/2010): We need a whole set of interface functions similar to this.
60  void insertInstruction(SgAsmInstruction* targetInstruction, SgAsmInstruction* newInstruction, bool insertBefore);
61 
63  void insertInstructionBefore(SgAsmInstruction* targetInstruction, SgAsmInstruction* newInstruction);
64 
66  void removeInstruction(SgAsmStatement* instruction);
67 
68  }
69 
70 // endif for ROSE_SAGE_INTERFACE_ASM
71 #endif