aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-04-05 22:42:30 +0000
committerChris Lattner <sabre@nondot.org>2010-04-05 22:42:30 +0000
commit4c842dda3939c6b9f83ba7e8e19e43445cd9a832 (patch)
treed3d4dd38475faa8e3bea9c995f993b662b688df9
parentda72249ecbfcaa6c8d81e9798812283b8a9947ed (diff)
downloadexternal_llvm-4c842dda3939c6b9f83ba7e8e19e43445cd9a832.zip
external_llvm-4c842dda3939c6b9f83ba7e8e19e43445cd9a832.tar.gz
external_llvm-4c842dda3939c6b9f83ba7e8e19e43445cd9a832.tar.bz2
stringref-ize the MemoryBuffer::get apis. This requires
a co-committed clang patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100485 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/MemoryBuffer.h4
-rw-r--r--lib/AsmParser/Parser.cpp2
-rw-r--r--lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp16
-rw-r--r--lib/Support/MemoryBuffer.cpp19
-rw-r--r--tools/lto/LTOModule.cpp14
-rw-r--r--utils/FileCheck/FileCheck.cpp6
6 files changed, 27 insertions, 34 deletions
diff --git a/include/llvm/Support/MemoryBuffer.h b/include/llvm/Support/MemoryBuffer.h
index fcea5d2..ef7af69 100644
--- a/include/llvm/Support/MemoryBuffer.h
+++ b/include/llvm/Support/MemoryBuffer.h
@@ -65,13 +65,13 @@ public:
/// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
/// that EndPtr[0] must be a null byte and be accessible!
- static MemoryBuffer *getMemBuffer(const char *StartPtr, const char *EndPtr,
+ static MemoryBuffer *getMemBuffer(StringRef InputData,
const char *BufferName = "");
/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
/// copying the contents and taking ownership of it. This has no requirements
/// on EndPtr[0].
- static MemoryBuffer *getMemBufferCopy(const char *StartPtr,const char *EndPtr,
+ static MemoryBuffer *getMemBufferCopy(StringRef InputData,
const char *BufferName = "");
/// getNewMemBuffer - Allocate a new MemoryBuffer of the specified size that
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp
index aac4027..1ab3734 100644
--- a/lib/AsmParser/Parser.cpp
+++ b/lib/AsmParser/Parser.cpp
@@ -56,7 +56,7 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
SMDiagnostic &Err, LLVMContext &Context) {
MemoryBuffer *F =
- MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
+ MemoryBuffer::getMemBuffer(StringRef(AsmString, strlen(AsmString)),
"<string>");
return ParseAssembly(F, M, Err, Context);
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index c58f76b..cd8329d 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -61,6 +61,7 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
// If this asmstr is empty, just print the #APP/#NOAPP markers.
// These are useful to see where empty asm's wound up.
if (AsmStr[0] == 0) {
+ // Don't emit the comments if writing to a .o file.
if (!OutStreamer.hasRawTextSupport()) return;
OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
@@ -104,7 +105,7 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
}
case '\n':
++LastEmitted; // Consume newline character.
- OS << '\n'; // Indent code with newline.
+ OS << '\n'; // Indent code with newline.
break;
case '$': {
++LastEmitted; // Consume '$' character.
@@ -183,26 +184,23 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
// supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
if (*LastEmitted == ':') {
++LastEmitted; // Consume ':' character.
- if (*LastEmitted == 0) {
- llvm_report_error("Bad ${:} expression in inline asm string: '"
- + std::string(AsmStr) + "'");
- }
+ if (*LastEmitted == 0)
+ llvm_report_error("Bad ${:} expression in inline asm string: '" +
+ std::string(AsmStr) + "'");
Modifier[0] = *LastEmitted;
++LastEmitted; // Consume modifier character.
}
- if (*LastEmitted != '}') {
+ if (*LastEmitted != '}')
llvm_report_error("Bad ${} expression in inline asm string: '"
+ std::string(AsmStr) + "'");
- }
++LastEmitted; // Consume '}' character.
}
- if (Val >= NumOperands-1) {
+ if (Val >= NumOperands-1)
llvm_report_error("Invalid $ operand number in inline asm string: '"
+ std::string(AsmStr) + "'");
- }
// Okay, we finally have a value number. Ask the target to print this
// operand!
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index 4f135ea..2b95089 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -71,13 +71,12 @@ namespace {
class MemoryBufferMem : public MemoryBuffer {
std::string FileID;
public:
- MemoryBufferMem(const char *Start, const char *End, StringRef FID,
- bool Copy = false)
+ MemoryBufferMem(StringRef InputData, StringRef FID, bool Copy = false)
: FileID(FID) {
if (!Copy)
- init(Start, End);
+ init(InputData.data(), InputData.data()+InputData.size());
else
- initCopyOf(Start, End);
+ initCopyOf(InputData.data(), InputData.data()+InputData.size());
}
virtual const char *getBufferIdentifier() const {
@@ -88,19 +87,17 @@ public:
/// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
/// that EndPtr[0] must be a null byte and be accessible!
-MemoryBuffer *MemoryBuffer::getMemBuffer(const char *StartPtr,
- const char *EndPtr,
+MemoryBuffer *MemoryBuffer::getMemBuffer(StringRef InputData,
const char *BufferName) {
- return new MemoryBufferMem(StartPtr, EndPtr, BufferName);
+ return new MemoryBufferMem(InputData, BufferName);
}
/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
/// copying the contents and taking ownership of it. This has no requirements
/// on EndPtr[0].
-MemoryBuffer *MemoryBuffer::getMemBufferCopy(const char *StartPtr,
- const char *EndPtr,
+MemoryBuffer *MemoryBuffer::getMemBufferCopy(StringRef InputData,
const char *BufferName) {
- return new MemoryBufferMem(StartPtr, EndPtr, BufferName, true);
+ return new MemoryBufferMem(InputData, BufferName, true);
}
/// getNewUninitMemBuffer - Allocate a new MemoryBuffer of the specified size
@@ -112,7 +109,7 @@ MemoryBuffer *MemoryBuffer::getNewUninitMemBuffer(size_t Size,
char *Buf = (char *)malloc(Size+1);
if (!Buf) return 0;
Buf[Size] = 0;
- MemoryBufferMem *SB = new MemoryBufferMem(Buf, Buf+Size, BufferName);
+ MemoryBufferMem *SB = new MemoryBufferMem(StringRef(Buf, Size), BufferName);
// The memory for this buffer is owned by the MemoryBuffer.
SB->MustDeleteBuffer = true;
return SB;
diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp
index 08576ab..b269e78 100644
--- a/tools/lto/LTOModule.cpp
+++ b/tools/lto/LTOModule.cpp
@@ -101,13 +101,13 @@ LTOModule* LTOModule::makeLTOModule(const char* path,
/// Also if next byte is on a different page, don't assume it is readable.
MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
{
- const char* startPtr = (char*)mem;
- const char* endPtr = startPtr+length;
- if ((((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0)
- || (*endPtr != 0))
- return MemoryBuffer::getMemBufferCopy(startPtr, endPtr);
- else
- return MemoryBuffer::getMemBuffer(startPtr, endPtr);
+ const char *startPtr = (char*)mem;
+ const char *endPtr = startPtr+length;
+ if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 ||
+ *endPtr != 0)
+ return MemoryBuffer::getMemBufferCopy(StringRef(startPtr, length));
+
+ return MemoryBuffer::getMemBuffer(StringRef(startPtr, length));
}
diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp
index c6a1392..e7cd713 100644
--- a/utils/FileCheck/FileCheck.cpp
+++ b/utils/FileCheck/FileCheck.cpp
@@ -441,7 +441,7 @@ struct CheckString {
/// CanonicalizeInputFile - Remove duplicate horizontal space from the specified
/// memory buffer, free it, and return a new one.
static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) {
- SmallVector<char, 16> NewFile;
+ SmallString<128> NewFile;
NewFile.reserve(MB->getBufferSize());
for (const char *Ptr = MB->getBufferStart(), *End = MB->getBufferEnd();
@@ -461,9 +461,7 @@ static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) {
// Free the old buffer and return a new one.
MemoryBuffer *MB2 =
- MemoryBuffer::getMemBufferCopy(NewFile.data(),
- NewFile.data() + NewFile.size(),
- MB->getBufferIdentifier());
+ MemoryBuffer::getMemBufferCopy(NewFile.str(), MB->getBufferIdentifier());
delete MB;
return MB2;