klee
KLEEIRMetaData.h
Go to the documentation of this file.
1//===-- KLEEIRMetaData.h ----------------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_KLEEIRMETADATA_H
11#define KLEE_KLEEIRMETADATA_H
12
13#include "llvm/IR/MDBuilder.h"
14
15namespace klee {
16
18class KleeIRMetaData : public llvm::MDBuilder {
19
20 llvm::LLVMContext &Context;
21
22public:
23 KleeIRMetaData(llvm::LLVMContext &context)
24 : llvm::MDBuilder(context), Context(context) {}
25
27 llvm::MDNode *createStringNode(llvm::StringRef value) {
28 return llvm::MDNode::get(Context, createString(value));
29 }
30
31 void addAnnotation(llvm::Instruction &inst, llvm::StringRef key,
32 llvm::StringRef value) {
33 inst.setMetadata(key, createStringNode(value));
34 }
35
37 static bool hasAnnotation(const llvm::Instruction &inst, llvm::StringRef key,
38 llvm::StringRef value) {
39 auto v = inst.getMetadata(key);
40 if (!v)
41 return false;
42 auto sv = llvm::dyn_cast<llvm::MDString>(v->getOperand(0));
43 if (!sv)
44 return false;
45
46 return sv->getString().equals(value);
47 }
48};
49}
50
51#endif /* KLEE_KLEEIRMETADATA_H */
Context - Helper class for storing global information about a KLEE run.
Definition: Context.h:18
Handles KLEE-specific LLVM IR meta-data.
static bool hasAnnotation(const llvm::Instruction &inst, llvm::StringRef key, llvm::StringRef value)
Check if the instruction has the key/value meta data.
llvm::LLVMContext & Context
KleeIRMetaData(llvm::LLVMContext &context)
llvm::MDNode * createStringNode(llvm::StringRef value)
Return a string node reflecting the value.
void addAnnotation(llvm::Instruction &inst, llvm::StringRef key, llvm::StringRef value)
Definition: main.cpp:291