about summary refs log tree commit diff homepage
path: root/lib
diff options
context:
space:
mode:
authorMartin Nowack <m.nowack@imperial.ac.uk>2018-07-29 15:49:59 +0100
committerCristian Cadar <c.cadar@imperial.ac.uk>2018-10-24 14:15:25 +0300
commit56e4c597a8d7e641604aea1ecfff4600fbf8dea9 (patch)
tree9f075e02d74aed8da313ea53904c42bf7140e768 /lib
parent7120c775037c911848fa634ae6398baf577d5650 (diff)
downloadklee-56e4c597a8d7e641604aea1ecfff4600fbf8dea9.tar.gz
Introduce KLEEIRMetaData to manipulate LLVM-IR metadata
Simplify the handling of metadata attached to LLVM IR that is specific
to KLEE.
Diffstat (limited to 'lib')
-rw-r--r--lib/Module/KLEEIRMetaData.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/Module/KLEEIRMetaData.h b/lib/Module/KLEEIRMetaData.h
new file mode 100644
index 00000000..86c24d05
--- /dev/null
+++ b/lib/Module/KLEEIRMetaData.h
@@ -0,0 +1,51 @@
+//===-- KLEEIRMetaData.h ----------------------------------------*- C++ -*-===//
+//
+//                     The KLEE Symbolic Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LIB_MODULE_KLEEIRMETADATA_H_
+#define LIB_MODULE_KLEEIRMETADATA_H_
+
+#include "llvm/IR/MDBuilder.h"
+
+namespace klee {
+
+/// Handles KLEE-specific LLVM IR meta-data.
+class KleeIRMetaData : public llvm::MDBuilder {
+
+  llvm::LLVMContext &Context;
+
+public:
+  KleeIRMetaData(llvm::LLVMContext &context)
+      : llvm::MDBuilder(context), Context(context) {}
+
+  /// \brief Return a string node reflecting the value
+  llvm::MDNode *createStringNode(llvm::StringRef value) {
+    return llvm::MDNode::get(Context, createString(value));
+  }
+
+  void addAnnotation(llvm::Instruction &inst, llvm::StringRef key,
+                           llvm::StringRef value) {
+    inst.setMetadata(key, createStringNode(value));
+  }
+
+  /// \brief Check if the instruction has the key/value meta data
+  static bool hasAnnotation(const llvm::Instruction &inst, llvm::StringRef key,
+                             llvm::StringRef value) {
+    auto v = inst.getMetadata(key);
+    if (!v)
+      return false;
+    auto sv = llvm::dyn_cast<llvm::MDString>(v->getOperand(0));
+    if (!sv)
+      return false;
+
+    return sv->getString().equals(value);
+  }
+};
+}
+
+#endif /* LIB_MODULE_KLEEIRMETADATA_H_ */