2
0

ObjectBuffer.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===--- ObjectBuffer.h - Utility class to wrap object memory ---*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file declares a wrapper class to hold the memory into which an
  11. // object will be generated.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_EXECUTIONENGINE_OBJECTBUFFER_H
  15. #define LLVM_EXECUTIONENGINE_OBJECTBUFFER_H
  16. #include "llvm/ADT/SmallVector.h"
  17. #include "llvm/Support/MemoryBuffer.h"
  18. #include "llvm/Support/raw_ostream.h"
  19. namespace llvm {
  20. class ObjectMemoryBuffer : public MemoryBuffer {
  21. public:
  22. template <unsigned N>
  23. ObjectMemoryBuffer(SmallVector<char, N> SV)
  24. : SV(SV), BufferName("<in-memory object>") {
  25. init(this->SV.begin(), this->SV.end(), false);
  26. }
  27. template <unsigned N>
  28. ObjectMemoryBuffer(SmallVector<char, N> SV, StringRef Name)
  29. : SV(SV), BufferName(Name) {
  30. init(this->SV.begin(), this->SV.end(), false);
  31. }
  32. const char* getBufferIdentifier() const override { return BufferName.c_str(); }
  33. BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; }
  34. private:
  35. SmallVector<char, 4096> SV;
  36. std::string BufferName;
  37. };
  38. } // namespace llvm
  39. #endif