retdec
demangler.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_BIN2LLVMIR_PROVIDERS_DEMANGLER_H
8 #define RETDEC_BIN2LLVMIR_PROVIDERS_DEMANGLER_H
9 
10 #include <map>
11 
12 #include <llvm/IR/Module.h>
13 
18 
19 namespace retdec {
20 
21 namespace loader {
22 class Image;
23 }
24 namespace ctypes {
25 class Type;
26 }
27 
28 namespace bin2llvmir {
29 
30 /*
31  * @brief Combined interface for Demangler library and ctypes2llvmir translator.
32  */
33 class Demangler
34 {
35 public:
36  using FunctionPair = std::pair<
37  llvm::Function *,
38  std::shared_ptr<retdec::ctypes::Function>>;
39 
40 public:
41  Demangler(
42  llvm::Module *llvmModule,
43  Config *config,
44  const std::shared_ptr<ctypesparser::TypeConfig> &typeConfig,
45  std::unique_ptr<retdec::demangler::Demangler> demangler);
46 
47  std::string demangleToString(const std::string &mangled);
48 
49  FunctionPair getPairFunction(const std::string &mangled);
50 
52 
53 private:
54  llvm::Type *getLlvmType(std::shared_ptr<retdec::ctypes::Type> type);
55 
56 private:
57  llvm::Module *_llvmModule = nullptr;
58  Config *_config = nullptr;
59  std::unique_ptr<retdec::ctypes::Module> _ctypesModule;
60  std::shared_ptr<ctypesparser::TypeConfig> _typeConfig;
61  std::unique_ptr<demangler::Demangler> _demangler;
62 };
63 
68 {
69 public:
70  static std::unique_ptr<Demangler> getItaniumDemangler(
71  llvm::Module *m,
72  Config *config,
73  const std::shared_ptr<ctypesparser::TypeConfig> &typeConfig);
74 
75  static std::unique_ptr<Demangler> getMicrosoftDemangler(
76  llvm::Module *m,
77  Config *config,
78  const std::shared_ptr<ctypesparser::TypeConfig> &typeConfig);
79 
80  static std::unique_ptr<Demangler> getBorlandDemangler(
81  llvm::Module *m,
82  Config *config,
83  const std::shared_ptr<ctypesparser::TypeConfig> &typeConfig);
84 };
85 
97 {
98 public:
99  static Demangler *addDemangler(
100  llvm::Module *llvmModule,
101  Config *config,
102  const std::shared_ptr<ctypesparser::TypeConfig> &typeConfig);
103 
104  static Demangler *getDemangler(llvm::Module *m);
105  static bool getDemangler(
106  llvm::Module *m,
107  Demangler *&d);
108 
109  static void clear();
110 
111 private:
113  static std::map<llvm::Module *, std::unique_ptr<Demangler>> _module2demangler;
114 };
115 
116 } // namespace bin2llvmir
117 } // namespace retdec
118 
119 #endif
Config DB provider for bin2llvmirl.
Definition: config.h:24
Class for creating demanglers.
Definition: demangler.h:68
static std::unique_ptr< Demangler > getMicrosoftDemangler(llvm::Module *m, Config *config, const std::shared_ptr< ctypesparser::TypeConfig > &typeConfig)
Crates new instance of MicrosoftDemangler.
Definition: demangler.cpp:96
static std::unique_ptr< Demangler > getBorlandDemangler(llvm::Module *m, Config *config, const std::shared_ptr< ctypesparser::TypeConfig > &typeConfig)
Crates new instance of BorlandDemangler.
Definition: demangler.cpp:109
static std::unique_ptr< Demangler > getItaniumDemangler(llvm::Module *m, Config *config, const std::shared_ptr< ctypesparser::TypeConfig > &typeConfig)
Crates new instance of ItaniumDemangler.
Definition: demangler.cpp:83
Definition: demangler.h:97
static std::map< llvm::Module *, std::unique_ptr< Demangler > > _module2demangler
Mapping of modules to demanglers associated with them.
Definition: demangler.h:113
static Demangler * getDemangler(llvm::Module *m)
Definition: demangler.cpp:156
static void clear()
Definition: demangler.cpp:181
static Demangler * addDemangler(llvm::Module *llvmModule, Config *config, const std::shared_ptr< ctypesparser::TypeConfig > &typeConfig)
Definition: demangler.cpp:129
Definition: demangler.h:34
Config * _config
Definition: demangler.h:58
std::pair< llvm::Function *, std::shared_ptr< retdec::ctypes::Function > > FunctionPair
Definition: demangler.h:38
llvm::Type * getLlvmType(std::shared_ptr< retdec::ctypes::Type > type)
Definition: demangler.cpp:63
Demangler(llvm::Module *llvmModule, Config *config, const std::shared_ptr< ctypesparser::TypeConfig > &typeConfig, std::unique_ptr< retdec::demangler::Demangler > demangler)
Definition: demangler.cpp:26
std::string demangleToString(const std::string &mangled)
Definition: demangler.cpp:37
std::shared_ptr< ctypesparser::TypeConfig > _typeConfig
Definition: demangler.h:60
demangler::Demangler * getDemangler()
Definition: demangler.cpp:70
llvm::Module * _llvmModule
Definition: demangler.h:57
std::unique_ptr< demangler::Demangler > _demangler
Definition: demangler.h:61
std::unique_ptr< retdec::ctypes::Module > _ctypesModule
Definition: demangler.h:59
FunctionPair getPairFunction(const std::string &mangled)
Definition: demangler.cpp:42
A base class of all C types.
Definition: type.h:22
Definition: demangler_base.h:31
Definition: image.h:22
Common tool information representation.
File to include for demangling work.
The frontend-end part of the decompiler.
Generic loader.
Definition: archive_wrapper.h:19
Defines type widths and singnedness for types that are implementation specific.