retdec
validator.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_VALIDATOR_VALIDATOR_H
8 #define RETDEC_LLVMIR2HLL_VALIDATOR_VALIDATOR_H
9 
10 #include <string>
11 
14 #include "retdec/utils/io/log.h"
15 
16 using namespace retdec::utils::io;
17 
18 namespace retdec {
19 namespace llvmir2hll {
20 
35 class Validator: protected OrderedAllVisitor {
36 public:
37  virtual std::string getId() const = 0;
38 
39  bool validate(ShPtr<Module> module, bool printMessageOnError = false);
40 
41 protected:
42  Validator();
43 
44  void traverseAllGlobalVariables();
45  void traverseAllFunctions();
46 
50  void validationError(const std::string &warningMessage) {
51  moduleIsCorrect = false;
52  if (printMessageOnError) {
53  Log::error() << Log::Warning << warningMessage << std::endl;
54  }
55  }
56 
57 protected:
60 
63 
64 private:
65  virtual void runValidation();
66 
67 private:
70 
73 };
74 
75 } // namespace llvmir2hll
76 } // namespace retdec
77 
78 #endif
A visitor that visits everything in an ordered way.
Definition: ordered_all_visitor.h:44
A base class for all validators.
Definition: validator.h:35
virtual std::string getId() const =0
ShPtr< Module > module
The validated module.
Definition: validator.h:59
bool printMessageOnError
Should we print a warning message when encountering an error?
Definition: validator.h:69
bool moduleIsCorrect
true if there has not been an error, false otherwise.
Definition: validator.h:72
void validationError(const std::string &warningMessage)
Function to be called when there is a validation error.
Definition: validator.h:50
ShPtr< Function > func
The currently traversed function.
Definition: validator.h:62
static Logger error()
Definition: log.cpp:69
static const Action Warning
Definition: log.h:98
ShPtr< Module > module
The current module.
Definition: hll_writer.cpp:100
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
Definition: log.h:14
Definition: archive_wrapper.h:19
A visitor that visits everything in an ordered way.
Declarations, aliases, macros, etc. for the use of smart pointers.