retdec
labels_handler.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LABELS_HANDLER_H
8 #define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LABELS_HANDLER_H
9 
10 #include <string>
11 
15 
16 namespace llvm {
17 
18 class BasicBlock;
19 
20 } // namespace llvm
21 
22 namespace retdec {
23 namespace llvmir2hll {
24 
25 class Statement;
26 
31 public:
32  LabelsHandler() = default;
33  ~LabelsHandler() = default;
34 
35  std::string getLabel(const llvm::BasicBlock *bb) const;
36  std::string getLabel(ShPtr<Statement> stmt) const;
37  void removeLabel(const std::string &label);
39  const llvm::BasicBlock *targetBB);
40 
41 private:
42  std::string createLabelFor(
43  const llvm::BasicBlock *bb,
44  ShPtr<Statement> stmt) const;
45  std::string ensureLabelIsValid(const std::string &label) const;
46  std::string ensureLabelIsUnique(const std::string &label) const;
47  bool labelIsUsed(const std::string &label) const;
48  std::string generateNewLabel(const std::string &origLabel,
49  std::size_t i);
50  void markLabelAsUsed(const std::string &label);
51 
52 private:
53  // Note: We could have used a mapping of llvm::Function to a set of used
54  // labels, but creating globally unique labels is simpler and sufficient
55  // (we use instruction addresses in basic block names, so the labels should
56  // be pretty unique across all functions).
58 };
59 
60 } // namespace llvmir2hll
61 } // namespace retdec
62 
63 #endif
Handler of labels during conversion of LLVM IR to BIR.
Definition: labels_handler.h:30
void markLabelAsUsed(const std::string &label)
Definition: labels_handler.cpp:91
bool labelIsUsed(const std::string &label) const
Definition: labels_handler.cpp:87
void setGotoTargetLabel(ShPtr< Statement > target, const llvm::BasicBlock *targetBB)
Sets a proper label of a goto target that is in the given basic block.
Definition: labels_handler.cpp:50
void removeLabel(const std::string &label)
Removes the given label from the set of used labels.
Definition: labels_handler.cpp:43
StringSet usedLabels
Definition: labels_handler.h:57
std::string generateNewLabel(const std::string &origLabel, std::size_t i)
std::string createLabelFor(const llvm::BasicBlock *bb, ShPtr< Statement > stmt) const
Definition: labels_handler.cpp:58
std::string getLabel(const llvm::BasicBlock *bb) const
Returns the label of the given basic block.
Definition: labels_handler.cpp:26
std::string ensureLabelIsValid(const std::string &label) const
Definition: labels_handler.cpp:73
std::string ensureLabelIsUnique(const std::string &label) const
Definition: labels_handler.cpp:77
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::set< std::string > StringSet
Set of strings.
Definition: types.h:51
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.