retdec
llvm_value_converter.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_VALUE_CONVERTER_H
8 #define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_VALUE_CONVERTER_H
9 
10 #include <llvm/ADT/ArrayRef.h>
11 
14 
15 namespace llvm {
16 
17 class CallInst;
18 class CompositeType;
19 class Constant;
20 class GlobalVariable;
21 class Instruction;
22 class Type;
23 class Value;
24 
25 } // namespace llvm
26 
27 namespace retdec {
28 namespace llvmir2hll {
29 
30 class CallExpr;
31 class Expression;
32 class LLVMConstantConverter;
33 class LLVMInstructionConverter;
34 class LLVMTypeConverter;
35 class Module;
36 class Type;
37 class Variable;
38 class VariablesManager;
39 
44 private:
46 
47 public:
49  ShPtr<VariablesManager> varManager);
50 
54  ShPtr<Expression> convertValueToExpression(llvm::Value *value);
56  ShPtr<Variable> convertValueToVariable(llvm::Value *value);
58 
61  ShPtr<Type> convertType(const llvm::Type *type);
63 
66  bool storesStringLiteral(const llvm::GlobalVariable &globVar) const;
67  ShPtr<Expression> convertConstantToExpression(llvm::Constant *constant);
69 
72  ShPtr<Expression> convertInstructionToExpression(llvm::Instruction *inst);
73  ShPtr<CallExpr> convertCallInstToCallExpr(llvm::CallInst &inst);
75  llvm::CompositeType *type, ShPtr<Expression> base,
76  llvm::ArrayRef<unsigned> indices);
78 
81  void setOptionStrictFPUSemantics(bool strict = true);
83 
84 private:
85  bool isConsideredAsPointer(const llvm::Value *value) const;
86  bool shouldBeConvertedAsConst(const llvm::Constant *constant) const;
87  bool shouldBeConvertedAsInst(const llvm::Instruction *inst) const;
88 
89  ShPtr<Type> determineVariableType(llvm::Value *value);
90 
93 
96 
99 
102 
105 };
106 
107 } // namespace llvmir2hll
108 } // namespace retdec
109 
110 #endif
A converter from LLVM values to values in BIR.
Definition: llvm_value_converter.h:43
ShPtr< Type > convertType(const llvm::Type *type)
Converts the given LLVM type type into a type in BIR.
Definition: llvm_value_converter.cpp:163
ShPtr< Expression > convertConstantToExpression(llvm::Constant *constant)
Converts the given LLVM constant constant into an expression in BIR.
Definition: llvm_value_converter.cpp:185
ShPtr< CallExpr > convertCallInstToCallExpr(llvm::CallInst &inst)
Converts the given LLVM call instruction inst into an expression in BIR.
Definition: llvm_value_converter.cpp:208
void setOptionStrictFPUSemantics(bool strict=true)
Enables/disables the use of strict FPU semantics.
Definition: llvm_value_converter.cpp:232
ShPtr< Expression > convertValueToDerefExpression(llvm::Value *value)
Converts the given LLVM value value into a dereference expression in BIR.
Definition: llvm_value_converter.cpp:82
bool shouldBeConvertedAsInst(const llvm::Instruction *inst) const
Determines whether the given LLVM instruction inst should be converted into BIR as instruction.
Definition: llvm_value_converter.cpp:279
bool storesStringLiteral(const llvm::GlobalVariable &globVar) const
Determines whether the given LLVM global variable globVar stores string literal.
Definition: llvm_value_converter.cpp:173
ShPtr< Expression > convertValueToExpression(llvm::Value *value)
Converts the given LLVM value value into an expression in BIR.
Definition: llvm_value_converter.cpp:106
static ShPtr< LLVMValueConverter > create(ShPtr< Module > resModule, ShPtr< VariablesManager > varManager)
Creates a new converter.
Definition: llvm_value_converter.cpp:60
ShPtr< Expression > convertValueToExpressionDirectly(llvm::Value *value)
Converts the given LLVM value value into an expression in BIR.
Definition: llvm_value_converter.cpp:123
LLVMValueConverter(ShPtr< Module > resModule, ShPtr< VariablesManager > varManager)
Constructs a new converter.
Definition: llvm_value_converter.cpp:44
ShPtr< Module > resModule
The resulting module in BIR.
Definition: llvm_value_converter.h:104
ShPtr< Expression > convertInstructionToExpression(llvm::Instruction *inst)
Converts the given LLVM instruction inst into an expression in BIR.
Definition: llvm_value_converter.cpp:198
ShPtr< LLVMInstructionConverter > instConverter
A converter from LLVM instruction to expression in BIR.
Definition: llvm_value_converter.h:95
UPtr< LLVMConstantConverter > constConverter
A converter from LLVM constant to constant in BIR.
Definition: llvm_value_converter.h:98
ShPtr< Expression > generateAccessToAggregateType(llvm::CompositeType *type, ShPtr< Expression > base, llvm::ArrayRef< unsigned > indices)
Generates access to aggregate type as a part of conversion of LLVM instruction insertvalue or extract...
Definition: llvm_value_converter.cpp:220
ShPtr< Type > determineVariableType(llvm::Value *value)
Determines the correct type of the given LLVM value value.
Definition: llvm_value_converter.cpp:292
ShPtr< LLVMTypeConverter > typeConverter
A converter from LLVM type to type in BIR.
Definition: llvm_value_converter.h:92
ShPtr< Variable > convertValueToVariable(llvm::Value *value)
Converts the given LLVM value value into a variable in BIR.
Definition: llvm_value_converter.cpp:146
bool shouldBeConvertedAsConst(const llvm::Constant *constant) const
Determines whether the given LLVM constant constant should be converted into BIR as constant.
Definition: llvm_value_converter.cpp:257
ShPtr< VariablesManager > variablesManager
Variables manager.
Definition: llvm_value_converter.h:101
bool isConsideredAsPointer(const llvm::Value *value) const
Determines whether the given LLVM value is considered as pointer variable.
Definition: llvm_value_converter.cpp:243
A mixin to make classes non-copyable.
Definition: non_copyable.h:27
Definition: itanium_ast_ctypes_parser.h:12
A library providing API for working with back-end IR.
std::shared_ptr< T > ShPtr
An alias for a shared pointer.
Definition: smart_ptr.h:18
std::unique_ptr< T > UPtr
An alias for a unique pointer.
Definition: smart_ptr.h:26
Definition: archive_wrapper.h:19
A mixin to make classes non-copyable.
Declarations, aliases, macros, etc. for the use of smart pointers.