blob: 3aeb9902ac3980f527806a70192d8c9891db3ade (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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 KLEE_KLEEIRMETADATA_H
#define KLEE_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 /* KLEE_KLEEIRMETADATA_H */
|