retdec
llvmir2bir_converter.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_H
8 #define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_H
9 
10 #include <string>
11 
16 
17 namespace llvm {
18 
19 class Function;
20 class GlobalVariable;
21 class Module;
22 class Pass;
23 
24 } // namespace llvm
25 
26 namespace retdec {
27 namespace llvmir2hll {
28 
29 class Config;
30 class Expression;
31 class Function;
32 class LLVMValueConverter;
33 class Module;
34 class Semantics;
35 class StructureConverter;
36 class Variable;
37 class VariablesManager;
38 
45 public:
46  static ShPtr<LLVMIR2BIRConverter> create(llvm::Pass *basePass);
47 
48  ShPtr<Module> convert(llvm::Module *llvmModule,
49  const std::string &moduleName, ShPtr<Semantics> semantics,
50  ShPtr<Config> config, bool enableDebug = false);
51 
54  void setOptionStrictFPUSemantics(bool strict = true);
56 
57 private:
58  LLVMIR2BIRConverter(llvm::Pass *basePass);
59 
62  bool isExternal(const llvm::GlobalVariable &var) const;
63  bool shouldBeConvertedAndAdded(const llvm::GlobalVariable &globVar) const;
64  ShPtr<Variable> convertGlobalVariable(llvm::GlobalVariable &globVar) const;
66  llvm::GlobalVariable &globVar) const;
69 
72  VarVector convertFuncParams(llvm::Function &func);
73  ShPtr<Function> convertFuncDeclaration(llvm::Function &func);
74  void updateFuncToDefinition(llvm::Function &func);
75  VarVector sortLocalVars(const VarSet &vars) const;
76  void generateVarDefinitions(ShPtr<Function> func) const;
77  bool shouldBeConvertedAndAdded(const llvm::Function &func) const;
79  void convertFuncsBodies();
81 
84  void makeIdentifiersValid();
88  void makeFuncVariablesValid(ShPtr<Function> func) const;
90 
91 private:
93  llvm::Pass *basePass;
94 
97 
100 
103 
105  llvm::Module *llvmModule;
106 
109 
112 
115 };
116 
117 } // namespace llvmir2hll
118 } // namespace retdec
119 
120 #endif
A converter of LLVM IR to BIR.
Definition: llvmir2bir_converter.h:44
VarVector sortLocalVars(const VarSet &vars) const
Sorts local variables set vars alphabetically by name.
Definition: llvmir2bir_converter.cpp:220
ShPtr< Variable > convertGlobalVariable(llvm::GlobalVariable &globVar) const
Converts the given LLVM global variable globVar into a variable in BIR.
Definition: llvmir2bir_converter.cpp:118
void generateVarDefinitions(ShPtr< Function > func) const
Generates variable definition statements at the beginning of func.
Definition: llvmir2bir_converter.cpp:229
void updateFuncToDefinition(llvm::Function &func)
Updates the given LLVM function func from declaration to definition.
Definition: llvmir2bir_converter.cpp:198
ShPtr< VariablesManager > variablesManager
Variables manager.
Definition: llvmir2bir_converter.h:114
void makeIdentifiersValid()
Makes all identifiers valid by replacing invalid characters with valid characters.
Definition: llvmir2bir_converter.cpp:278
bool shouldBeConvertedAndAdded(const llvm::GlobalVariable &globVar) const
Determines whether the given LLVM global variable globVar should be converted and added into the resu...
Definition: llvmir2bir_converter.cpp:110
ShPtr< Function > convertFuncDeclaration(llvm::Function &func)
Converts a declaration of the given LLVM function func into a function declaration in BIR.
Definition: llvmir2bir_converter.cpp:181
void setOptionStrictFPUSemantics(bool strict=true)
Enables/disables the use of strict FPU semantics.
Definition: llvmir2bir_converter.cpp:57
LLVMIR2BIRConverter(llvm::Pass *basePass)
Constructs a new converter.
Definition: llvmir2bir_converter.cpp:34
VarVector convertFuncParams(llvm::Function &func)
Converts parameters of the given LLVM function func into a list of function parameters in BIR.
Definition: llvmir2bir_converter.cpp:168
void convertFuncsBodies()
Goes through all functions definitions of the input LLVM module and converts their bodies and stores ...
Definition: llvmir2bir_converter.cpp:266
void convertAndAddFuncsDeclarations()
Converts all functions declarations of the input LLVM module and stores them into the resulting modul...
Definition: llvmir2bir_converter.cpp:254
void makeFuncVariablesValid(ShPtr< Function > func) const
Makes all identifiers of the local variables and parameters in the given function func valid.
Definition: llvmir2bir_converter.cpp:315
UPtr< StructureConverter > structConverter
A converter of the LLVM function structure.
Definition: llvmir2bir_converter.h:111
ShPtr< LLVMValueConverter > converter
A converter from LLVM values to values in BIR.
Definition: llvmir2bir_converter.h:102
llvm::Pass * basePass
Pass that have instantiated the converter.
Definition: llvmir2bir_converter.h:93
static ShPtr< LLVMIR2BIRConverter > create(llvm::Pass *basePass)
Creates a new converter.
Definition: llvmir2bir_converter.cpp:47
ShPtr< Expression > convertGlobalVariableInitializer(llvm::GlobalVariable &globVar) const
Converts initializer of the given LLVM global variable globVar into an expression in BIR.
Definition: llvmir2bir_converter.cpp:135
void makeGlobVarsIdentifiersValid()
Makes all identifiers of the global variables valid.
Definition: llvmir2bir_converter.cpp:286
void makeFuncsIdentifiersValid()
Makes all identifiers of the functions valid (function names, parameters and local variables).
Definition: llvmir2bir_converter.cpp:296
void makeFuncIdentifiersValid(ShPtr< Function > func) const
Makes all identifiers of the given function func valid (function name, parameters and local variables...
Definition: llvmir2bir_converter.cpp:306
ShPtr< Module > convert(llvm::Module *llvmModule, const std::string &moduleName, ShPtr< Semantics > semantics, ShPtr< Config > config, bool enableDebug=false)
Converts the given LLVM module into a module in BIR.
Definition: llvmir2bir_converter.cpp:73
bool isExternal(const llvm::GlobalVariable &var) const
Determines if given LLVM global variable var is external.
Definition: llvmir2bir_converter.cpp:100
ShPtr< Module > resModule
The resulting module in BIR.
Definition: llvmir2bir_converter.h:108
void convertAndAddGlobalVariables()
Converts all global variables of the input LLVM module and stores them into the resulting module.
Definition: llvmir2bir_converter.cpp:149
llvm::Module * llvmModule
The input LLVM module.
Definition: llvmir2bir_converter.h:105
bool enableDebug
Should debugging messages be enabled?
Definition: llvmir2bir_converter.h:99
bool optionStrictFPUSemantics
Use strict FPU semantics?
Definition: llvmir2bir_converter.h:96
A mixin to make classes non-copyable.
Definition: non_copyable.h:27
A base class for all converters of LLVM IR to BIR.
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
std::set< ShPtr< Variable > > VarSet
Set of variables.
Definition: types.h:57
std::vector< ShPtr< Variable > > VarVector
Vector of variables.
Definition: types.h:93
Definition: archive_wrapper.h:19
A mixin to make classes non-copyable.
Declarations, aliases, macros, etc. for the use of smart pointers.
Aliases for several useful types.