summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/CMakeLists.txt1
-rw-r--r--lib/Support/StringRefMemoryObject.cpp34
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt
index fbc38183bc..6cc8ab236a 100644
--- a/lib/Support/CMakeLists.txt
+++ b/lib/Support/CMakeLists.txt
@@ -48,6 +48,7 @@ add_llvm_library(LLVMSupport
StringMap.cpp
StringPool.cpp
StringRef.cpp
+ StringRefMemoryObject.cpp
SystemUtils.cpp
Timer.cpp
ToolOutputFile.cpp
diff --git a/lib/Support/StringRefMemoryObject.cpp b/lib/Support/StringRefMemoryObject.cpp
new file mode 100644
index 0000000000..5db11e918c
--- /dev/null
+++ b/lib/Support/StringRefMemoryObject.cpp
@@ -0,0 +1,34 @@
+//===- lib/Support/StringRefMemoryObject.cpp --------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/StringRefMemoryObject.h"
+
+using namespace llvm;
+
+int StringRefMemoryObject::readByte(uint64_t Addr, uint8_t *Byte) const {
+ if (Addr >= Base + getExtent() || Addr < Base)
+ return -1;
+ *Byte = Bytes[Addr - Base];
+ return 0;
+}
+
+int StringRefMemoryObject::readBytes(uint64_t Addr,
+ uint64_t Size,
+ uint8_t *Buf,
+ uint64_t *Copied) const {
+ if (Addr >= Base + getExtent() || Addr < Base)
+ return -1;
+ uint64_t Offset = Addr - Base;
+ if (Size > getExtent() - Offset)
+ Size = getExtent() - Offset;
+ memcpy(Buf, Bytes.data() + Offset, Size);
+ if (Copied)
+ *Copied = Size;
+ return 0;
+}