|
9 | 9 | #include "nlohmann/json.hpp" |
10 | 10 | #include "nonstd/optional.hpp" |
11 | 11 |
|
| 12 | +#include "klee/Config/config.h" |
| 13 | + |
| 14 | +#include "llvm/IR/Module.h" |
| 15 | + |
12 | 16 | using nonstd::nullopt; |
13 | 17 | using nonstd::optional; |
14 | 18 | using json = nlohmann::json; |
15 | 19 |
|
16 | 20 | namespace klee { |
17 | 21 |
|
18 | | -// Annotation format: https://github.com/UnitTestBot/klee/discussions/92 |
19 | | -struct Annotation { |
20 | | - enum class StatementKind { |
21 | | - Unknown, |
| 22 | +namespace Statement { |
| 23 | +enum class Kind { |
| 24 | + Unknown, |
22 | 25 |
|
23 | | - Deref, |
24 | | - InitNull, |
25 | | - }; |
| 26 | + Deref, |
| 27 | + InitNull, |
| 28 | + AllocSource, |
| 29 | +}; |
26 | 30 |
|
27 | | - enum class Property { |
28 | | - Unknown, |
| 31 | +enum class Property { |
| 32 | + Unknown, |
29 | 33 |
|
30 | | - Determ, |
31 | | - Noreturn, |
32 | | - }; |
| 34 | + Deterministic, |
| 35 | + Noreturn, |
| 36 | +}; |
33 | 37 |
|
34 | | - struct StatementUnknown { |
35 | | - explicit StatementUnknown(const std::string &str); |
36 | | - virtual ~StatementUnknown(); |
| 38 | +struct Unknown { |
| 39 | +protected: |
| 40 | + std::string rawAnnotation; |
| 41 | + std::string rawOffset; |
| 42 | + std::string rawValue; |
37 | 43 |
|
38 | | - virtual Annotation::StatementKind getStatementName() const; |
39 | | - virtual bool operator==(const StatementUnknown &other) const; |
| 44 | +public: |
| 45 | + std::vector<std::string> offset; |
40 | 46 |
|
41 | | - std::string statementStr; |
42 | | - std::vector<std::string> offset; |
| 47 | + explicit Unknown(const std::string &str = "Unknown"); |
| 48 | + virtual ~Unknown(); |
43 | 49 |
|
44 | | - protected: |
45 | | - void parseOffset(const std::string &offsetStr); |
46 | | - void parseOnlyOffset(const std::string &str); |
47 | | - }; |
| 50 | + virtual bool operator==(const Unknown &other) const; |
| 51 | + [[nodiscard]] virtual Kind getKind() const; |
48 | 52 |
|
49 | | - struct StatementDeref final : public StatementUnknown { |
50 | | - explicit StatementDeref(const std::string &str); |
| 53 | + [[nodiscard]] const std::vector<std::string> &getOffset() const; |
| 54 | + [[nodiscard]] std::string toString() const; |
| 55 | +}; |
51 | 56 |
|
52 | | - Annotation::StatementKind getStatementName() const override; |
53 | | - }; |
| 57 | +struct Deref final : public Unknown { |
| 58 | + explicit Deref(const std::string &str = "Deref"); |
54 | 59 |
|
55 | | - struct StatementInitNull final : public StatementUnknown { |
56 | | - explicit StatementInitNull(const std::string &str); |
| 60 | + [[nodiscard]] Kind getKind() const override; |
| 61 | +}; |
57 | 62 |
|
58 | | - Annotation::StatementKind getStatementName() const override; |
| 63 | +struct InitNull final : public Unknown { |
| 64 | + explicit InitNull(const std::string &str = "InitNull"); |
| 65 | + |
| 66 | + [[nodiscard]] Kind getKind() const override; |
| 67 | +}; |
| 68 | + |
| 69 | +struct AllocSource final : public Unknown { |
| 70 | +public: |
| 71 | + enum Type { |
| 72 | + Alloc = 1, // malloc, calloc, realloc |
| 73 | + New = 2, // operator new |
| 74 | + NewBrackets = 3, // operator new[] |
| 75 | + OpenFile = 4, // open file (fopen, open) |
| 76 | + MutexLock = 5 // mutex lock (pthread_mutex_lock) |
59 | 77 | }; |
60 | 78 |
|
61 | | - using StatementPtr = std::shared_ptr<StatementUnknown>; |
62 | | - using StatementPtrs = std::vector<StatementPtr>; |
| 79 | + Type value; |
63 | 80 |
|
64 | | - bool operator==(const Annotation &other) const; |
| 81 | + explicit AllocSource(const std::string &str = "AllocSource::1"); |
65 | 82 |
|
66 | | - std::string functionName; |
67 | | - std::vector<StatementPtrs> statements; |
68 | | - std::set<Property> properties; |
| 83 | + [[nodiscard]] Kind getKind() const override; |
69 | 84 | }; |
70 | 85 |
|
71 | | -using Annotations = std::map<std::string, Annotation>; |
| 86 | +using Ptr = std::shared_ptr<Unknown>; |
| 87 | +bool operator==(const Ptr &first, const Ptr &second); |
| 88 | +} // namespace Statement |
72 | 89 |
|
73 | | -const std::map<std::string, Annotation::Property> toProperties{ |
74 | | - {"determ", Annotation::Property::Determ}, |
75 | | - {"noreturn", Annotation::Property::Noreturn}, |
76 | | -}; |
| 90 | +// Annotation format: https://github.com/UnitTestBot/klee/discussions/92 |
| 91 | +struct Annotation { |
| 92 | + std::string functionName; |
| 93 | + std::vector<Statement::Ptr> returnStatements; |
| 94 | + std::vector<std::vector<Statement::Ptr>> argsStatements; |
| 95 | + std::set<Statement::Property> properties; |
77 | 96 |
|
78 | | -Annotations parseAnnotationsFile(const json &annotationsJson); |
79 | | -Annotations parseAnnotationsFile(const std::string &path); |
| 97 | + bool operator==(const Annotation &other) const; |
| 98 | +}; |
80 | 99 |
|
81 | | -bool operator==(const Annotation::StatementPtr &first, |
82 | | - const Annotation::StatementPtr &second); |
| 100 | +using AnnotationsMap = std::map<std::string, Annotation>; |
83 | 101 |
|
| 102 | +AnnotationsMap parseAnnotationsJson(const json &annotationsJson); |
| 103 | +AnnotationsMap parseAnnotations(const std::string &path, const llvm::Module *m); |
84 | 104 | } // namespace klee |
85 | 105 |
|
86 | 106 | #endif // KLEE_ANNOTATION_H |
0 commit comments