diff options
Diffstat (limited to 'include/klee/Module/KCallable.h')
-rw-r--r-- | include/klee/Module/KCallable.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/include/klee/Module/KCallable.h b/include/klee/Module/KCallable.h new file mode 100644 index 00000000..bf8b17ea --- /dev/null +++ b/include/klee/Module/KCallable.h @@ -0,0 +1,71 @@ +//===-- KCallable.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_KCALLABLE_H +#define KLEE_KCALLABLE_H + +#include <string> + +#include "llvm/ADT/Twine.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/InlineAsm.h" +#include "llvm/IR/LLVMContext.h" + +namespace klee { +/// Wrapper for callable objects passed in callExternalFunction +class KCallable { +public: + enum CallableKind { CK_Function, CK_InlineAsm }; + +private: + const CallableKind Kind; + +public: + KCallable(CallableKind Kind) : Kind(Kind) {} + + CallableKind getKind() const { return Kind; } + + virtual llvm::StringRef getName() const = 0; + virtual llvm::PointerType *getType() const = 0; + virtual llvm::Value *getValue() = 0; + + virtual ~KCallable() = default; +}; + +class KInlineAsm : public KCallable { +private: + static unsigned getFreshAsmId() { + static unsigned globalId = 0; + return globalId++; + } + + llvm::InlineAsm *value; + std::string name; + +public: + KInlineAsm(llvm::InlineAsm *value) + : KCallable(CK_InlineAsm), value(value), + name("__asm__" + llvm::Twine(getFreshAsmId()).str()) {} + + llvm::StringRef getName() const override { return name; } + + llvm::PointerType *getType() const override { return value->getType(); } + + llvm::Value *getValue() override { return value; } + + static bool classof(const KCallable *callable) { + return callable->getKind() == CK_InlineAsm; + } + + llvm::InlineAsm *getInlineAsm() { return value; } +}; + +} // namespace klee + +#endif /* KLEE_KCALLABLE_H */ |