retdec
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
retdec::bin2llvmir::AsmInstruction Class Reference

#include <asm_instruction.h>

Collaboration diagram for retdec::bin2llvmir::AsmInstruction:
Collaboration graph
[legend]

Classes

class  iterator_impl
 

Public Types

using iterator = iterator_impl< std::bidirectional_iterator_tag, llvm::Instruction >
 
using const_iterator = iterator_impl< std::bidirectional_iterator_tag, const llvm::Instruction >
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

 AsmInstruction ()
 
 AsmInstruction (llvm::Instruction *inst)
 
 AsmInstruction (llvm::BasicBlock *bb)
 
 AsmInstruction (llvm::Function *f)
 
 AsmInstruction (llvm::Module *m, retdec::common::Address addr)
 
bool operator< (const AsmInstruction &o) const
 
bool operator== (const AsmInstruction &o) const
 
bool operator!= (const AsmInstruction &o) const
 
 operator bool () const
 
iterator begin ()
 
iterator end ()
 
reverse_iterator rbegin ()
 
reverse_iterator rend ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 
bool isValid () const
 
bool isInvalid () const
 
cs_insn * getCapstoneInsn () const
 
std::string getDsm () const
 
retdec::common::Address getAddress () const
 
retdec::common::Address getEndAddress () const
 
std::size_t getByteSize () const
 
std::size_t getBitSize () const
 
bool contains (retdec::common::Address addr) const
 
AsmInstruction getNext () const
 
AsmInstruction getPrev () const
 
bool instructionsCanBeErased ()
 
bool eraseInstructions ()
 
llvm::Instruction * makeTerminal ()
 
llvm::BasicBlock * makeStart (const std::string &name="")
 
llvm::BasicBlock * getBasicBlock () const
 
llvm::Function * getFunction () const
 
llvm::Module * getModule () const
 
llvm::LLVMContext & getContext () const
 
std::vector< llvm::Instruction * > getInstructions ()
 
std::vector< llvm::BasicBlock * > getBasicBlocks ()
 
bool empty ()
 
llvm::Instruction * front ()
 
llvm::Instruction * back ()
 
llvm::StoreInst * getLlvmToAsmInstruction () const
 
llvm::Instruction * insertBack (llvm::Instruction *i)
 
llvm::Instruction * insertBackSafe (llvm::Instruction *i)
 
bool storesValue (llvm::Value *val) const
 
std::string dump () const
 
template<typename T >
bool containsInstruction ()
 
template<typename T >
T * getInstructionFirst ()
 

Static Public Member Functions

static Llvm2CapstoneInsnMapgetLlvmToCapstoneInsnMap (const llvm::Module *m)
 
static llvm::GlobalVariable * getLlvmToAsmGlobalVariable (const llvm::Module *m)
 
static void setLlvmToAsmGlobalVariable (const llvm::Module *m, llvm::GlobalVariable *gv)
 
static retdec::common::Address getInstructionAddress (llvm::Instruction *inst)
 
static retdec::common::Address getInstructionEndAddress (llvm::Instruction *inst)
 
static retdec::common::Address getBasicBlockAddress (llvm::BasicBlock *bb)
 
static retdec::common::Address getTrueBasicBlockAddress (llvm::BasicBlock *bb)
 
static retdec::common::Address getBasicBlockEndAddress (llvm::BasicBlock *bb)
 
static retdec::common::Address getFunctionAddress (llvm::Function *f)
 
static retdec::common::Address getFunctionEndAddress (llvm::Function *f)
 
static bool isLlvmToAsmInstruction (const llvm::Value *inst)
 
static void clear ()
 

Private Types

using ModuleGlobalPair = std::pair< const llvm::Module *, llvm::GlobalVariable * >
 
using ModuleInstructionMap = std::pair< const llvm::Module *, std::map< llvm::StoreInst *, cs_insn * > >
 

Private Member Functions

const llvm::GlobalVariable * getLlvmToAsmGlobalVariablePrivate (llvm::Module *m) const
 
bool isLlvmToAsmInstructionPrivate (llvm::Value *inst) const
 

Private Attributes

llvm::StoreInst * _llvmToAsmInstr = nullptr
 

Static Private Attributes

static std::vector< ModuleGlobalPair_module2global
 
static std::vector< ModuleInstructionMap_module2instMap
 

Friends

std::ostream & operator<< (std::ostream &out, const AsmInstruction &a)
 

Detailed Description

Assembly instruction representation.

This is a lightway class that contains only one llvm::StoreInst pointer. I.e. this class can be passed by value instead of by reference or pointer.

Member Typedef Documentation

◆ const_iterator

using retdec::bin2llvmir::AsmInstruction::const_iterator = iterator_impl< std::bidirectional_iterator_tag, const llvm::Instruction>

◆ const_reverse_iterator

◆ iterator

using retdec::bin2llvmir::AsmInstruction::iterator = iterator_impl< std::bidirectional_iterator_tag, llvm::Instruction>

◆ ModuleGlobalPair

using retdec::bin2llvmir::AsmInstruction::ModuleGlobalPair = std::pair< const llvm::Module*, llvm::GlobalVariable*>
private

◆ ModuleInstructionMap

using retdec::bin2llvmir::AsmInstruction::ModuleInstructionMap = std::pair< const llvm::Module*, std::map<llvm::StoreInst*, cs_insn*> >
private

◆ reverse_iterator

Constructor & Destructor Documentation

◆ AsmInstruction() [1/5]

retdec::bin2llvmir::AsmInstruction::AsmInstruction ( )

◆ AsmInstruction() [2/5]

retdec::bin2llvmir::AsmInstruction::AsmInstruction ( llvm::Instruction *  inst)

◆ AsmInstruction() [3/5]

retdec::bin2llvmir::AsmInstruction::AsmInstruction ( llvm::BasicBlock *  bb)

◆ AsmInstruction() [4/5]

retdec::bin2llvmir::AsmInstruction::AsmInstruction ( llvm::Function *  f)

◆ AsmInstruction() [5/5]

retdec::bin2llvmir::AsmInstruction::AsmInstruction ( llvm::Module *  m,
retdec::common::Address  addr 
)

Member Function Documentation

◆ back()

llvm::Instruction * retdec::bin2llvmir::AsmInstruction::back ( )
Returns
Last LLVM instruction in this ASM instruction, or nullptr if ASM instruction is empty.
Note
Special LLVM to ASM mapping instruction is ignored, use dedicated method to get it.

◆ begin() [1/2]

AsmInstruction::iterator retdec::bin2llvmir::AsmInstruction::begin ( )

◆ begin() [2/2]

AsmInstruction::const_iterator retdec::bin2llvmir::AsmInstruction::begin ( ) const

◆ clear()

void retdec::bin2llvmir::AsmInstruction::clear ( )
static

◆ contains()

bool retdec::bin2llvmir::AsmInstruction::contains ( retdec::common::Address  addr) const

◆ containsInstruction()

template<typename T >
bool retdec::bin2llvmir::AsmInstruction::containsInstruction ( )
inline

◆ dump()

std::string retdec::bin2llvmir::AsmInstruction::dump ( ) const

◆ empty()

bool retdec::bin2llvmir::AsmInstruction::empty ( )

◆ end() [1/2]

AsmInstruction::iterator retdec::bin2llvmir::AsmInstruction::end ( )

◆ end() [2/2]

AsmInstruction::const_iterator retdec::bin2llvmir::AsmInstruction::end ( ) const

◆ eraseInstructions()

bool retdec::bin2llvmir::AsmInstruction::eraseInstructions ( )

If possible (see instructionsCanBeErased()), erase LLVM instructions belonging to this ASM instruction. If instructions can not be erased, they are not changed at all.

Returns
True if all instructions were successfully erased, false otherwise.

◆ front()

llvm::Instruction * retdec::bin2llvmir::AsmInstruction::front ( )
Returns
First LLVM instruction in this ASM instruction, or nullptr if ASM instruction is empty.
Note
Special LLVM to ASM mapping instruction is ignored, use dedicated method to get it.

◆ getAddress()

retdec::common::Address retdec::bin2llvmir::AsmInstruction::getAddress ( ) const

◆ getBasicBlock()

llvm::BasicBlock * retdec::bin2llvmir::AsmInstruction::getBasicBlock ( ) const
Returns
Basic block where LLVM to ASM instruction belongs, or nullptr if ASM instruction not valid.

◆ getBasicBlockAddress()

retdec::common::Address retdec::bin2llvmir::AsmInstruction::getBasicBlockAddress ( llvm::BasicBlock *  bb)
static

◆ getBasicBlockEndAddress()

retdec::common::Address retdec::bin2llvmir::AsmInstruction::getBasicBlockEndAddress ( llvm::BasicBlock *  bb)
static

◆ getBasicBlocks()

std::vector< llvm::BasicBlock * > retdec::bin2llvmir::AsmInstruction::getBasicBlocks ( )

◆ getBitSize()

std::size_t retdec::bin2llvmir::AsmInstruction::getBitSize ( ) const

◆ getByteSize()

std::size_t retdec::bin2llvmir::AsmInstruction::getByteSize ( ) const

◆ getCapstoneInsn()

cs_insn * retdec::bin2llvmir::AsmInstruction::getCapstoneInsn ( ) const

◆ getContext()

llvm::LLVMContext & retdec::bin2llvmir::AsmInstruction::getContext ( ) const
Returns
Context where LLVM to ASM instruction belongs Use only on valid assembly instructions.

◆ getDsm()

std::string retdec::bin2llvmir::AsmInstruction::getDsm ( ) const

◆ getEndAddress()

retdec::common::Address retdec::bin2llvmir::AsmInstruction::getEndAddress ( ) const

◆ getFunction()

llvm::Function * retdec::bin2llvmir::AsmInstruction::getFunction ( ) const
Returns
Function where LLVM to ASM instruction belongs, or nullptr if ASM instruction not valid.

◆ getFunctionAddress()

retdec::common::Address retdec::bin2llvmir::AsmInstruction::getFunctionAddress ( llvm::Function *  f)
static

◆ getFunctionEndAddress()

retdec::common::Address retdec::bin2llvmir::AsmInstruction::getFunctionEndAddress ( llvm::Function *  f)
static

◆ getInstructionAddress()

retdec::common::Address retdec::bin2llvmir::AsmInstruction::getInstructionAddress ( llvm::Instruction *  inst)
static

◆ getInstructionEndAddress()

retdec::common::Address retdec::bin2llvmir::AsmInstruction::getInstructionEndAddress ( llvm::Instruction *  inst)
static

◆ getInstructionFirst()

template<typename T >
T* retdec::bin2llvmir::AsmInstruction::getInstructionFirst ( )
inline

◆ getInstructions()

std::vector< llvm::Instruction * > retdec::bin2llvmir::AsmInstruction::getInstructions ( )

◆ getLlvmToAsmGlobalVariable()

llvm::GlobalVariable * retdec::bin2llvmir::AsmInstruction::getLlvmToAsmGlobalVariable ( const llvm::Module *  m)
static

◆ getLlvmToAsmGlobalVariablePrivate()

const llvm::GlobalVariable * retdec::bin2llvmir::AsmInstruction::getLlvmToAsmGlobalVariablePrivate ( llvm::Module *  m) const
private

◆ getLlvmToAsmInstruction()

llvm::StoreInst * retdec::bin2llvmir::AsmInstruction::getLlvmToAsmInstruction ( ) const

◆ getLlvmToCapstoneInsnMap()

Llvm2CapstoneInsnMap & retdec::bin2llvmir::AsmInstruction::getLlvmToCapstoneInsnMap ( const llvm::Module *  m)
static

◆ getModule()

llvm::Module * retdec::bin2llvmir::AsmInstruction::getModule ( ) const
Returns
Module where LLVM to ASM instruction belongs, or nullptr if ASM instruction not valid.

◆ getNext()

AsmInstruction retdec::bin2llvmir::AsmInstruction::getNext ( ) const
Returns
Next ASM instruction after this ASM instrution. If there is none, returned ASM instruction is invalid.

◆ getPrev()

AsmInstruction retdec::bin2llvmir::AsmInstruction::getPrev ( ) const
Returns
Previous ASM instruction before this ASM instrution. If there is none, returned ASM instruction is invalid.

◆ getTrueBasicBlockAddress()

retdec::common::Address retdec::bin2llvmir::AsmInstruction::getTrueBasicBlockAddress ( llvm::BasicBlock *  bb)
static

◆ insertBack()

llvm::Instruction * retdec::bin2llvmir::AsmInstruction::insertBack ( llvm::Instruction *  i)

Insert instruction i at the end of LLVM instructions associated with this ASM instruction.

Note
Be careful, this does not take care of potential terminators. If the last LLVM instruction is a terminator and you insert something after it, you will probably create an invalid module.
Returns
Inserted instruction.

◆ insertBackSafe()

llvm::Instruction * retdec::bin2llvmir::AsmInstruction::insertBackSafe ( llvm::Instruction *  i)

Same as insertBack() but if asm instruction ends with terminator, the new instruction is inserted before it.

◆ instructionsCanBeErased()

bool retdec::bin2llvmir::AsmInstruction::instructionsCanBeErased ( )

It is possible to erase LLVM instructions, if none of them is used outside of this ASM instruction – when erased, there will not be any users left.

Returns
True if instruction can be erase, false otherwise.

◆ isInvalid()

bool retdec::bin2llvmir::AsmInstruction::isInvalid ( ) const

◆ isLlvmToAsmInstruction()

bool retdec::bin2llvmir::AsmInstruction::isLlvmToAsmInstruction ( const llvm::Value *  inst)
static

◆ isLlvmToAsmInstructionPrivate()

bool retdec::bin2llvmir::AsmInstruction::isLlvmToAsmInstructionPrivate ( llvm::Value *  inst) const
private

◆ isValid()

bool retdec::bin2llvmir::AsmInstruction::isValid ( ) const

◆ makeStart()

llvm::BasicBlock * retdec::bin2llvmir::AsmInstruction::makeStart ( const std::string &  name = "")

Make this ASM instruction start in basic block – first in BB. If it already is first, nothing is modified and an existing BB is returned. If it is not first yet, split BB on it to create a new BB

◆ makeTerminal()

llvm::Instruction * retdec::bin2llvmir::AsmInstruction::makeTerminal ( )

Make this ASM instruction terminal – last in BB, ending with terminator Instruction. If it already is terminal, nothing is modified and an existing terminator is returned. If it is not terminal yet, BB is split on the next ASM instruction, this instruction ends with an unconditional branch to the new BB, and this branch is returned.

◆ operator bool()

retdec::bin2llvmir::AsmInstruction::operator bool ( ) const
explicit
Returns
True it AsmInstruction is valid, false otherwise.

◆ operator!=()

bool retdec::bin2llvmir::AsmInstruction::operator!= ( const AsmInstruction o) const

◆ operator<()

bool retdec::bin2llvmir::AsmInstruction::operator< ( const AsmInstruction o) const

◆ operator==()

bool retdec::bin2llvmir::AsmInstruction::operator== ( const AsmInstruction o) const

◆ rbegin() [1/2]

AsmInstruction::reverse_iterator retdec::bin2llvmir::AsmInstruction::rbegin ( )

◆ rbegin() [2/2]

AsmInstruction::const_reverse_iterator retdec::bin2llvmir::AsmInstruction::rbegin ( ) const

◆ rend() [1/2]

AsmInstruction::reverse_iterator retdec::bin2llvmir::AsmInstruction::rend ( )

◆ rend() [2/2]

AsmInstruction::const_reverse_iterator retdec::bin2llvmir::AsmInstruction::rend ( ) const

◆ setLlvmToAsmGlobalVariable()

void retdec::bin2llvmir::AsmInstruction::setLlvmToAsmGlobalVariable ( const llvm::Module *  m,
llvm::GlobalVariable *  gv 
)
static

◆ storesValue()

bool retdec::bin2llvmir::AsmInstruction::storesValue ( llvm::Value *  val) const

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const AsmInstruction a 
)
friend

Member Data Documentation

◆ _llvmToAsmInstr

llvm::StoreInst* retdec::bin2llvmir::AsmInstruction::_llvmToAsmInstr = nullptr
private

◆ _module2global

std::vector< AsmInstruction::ModuleGlobalPair > retdec::bin2llvmir::AsmInstruction::_module2global
staticprivate

◆ _module2instMap

std::vector< AsmInstruction::ModuleInstructionMap > retdec::bin2llvmir::AsmInstruction::_module2instMap
staticprivate

The documentation for this class was generated from the following files: