diff options
author | Alp Toker <alp@nuanti.com> | 2014-06-26 00:00:48 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-06-26 00:00:48 +0000 |
commit | 255907042245b77779e3e38c5ce66901866cabe5 (patch) | |
tree | 92db65aa99c37ab5f68cd6adaae1d8cf6d629b8f /lib/Target/X86 | |
parent | ce6e7c7a59e8595ea3f30d87cbad4af278cb5ef3 (diff) | |
download | llvm-255907042245b77779e3e38c5ce66901866cabe5.tar.gz llvm-255907042245b77779e3e38c5ce66901866cabe5.tar.bz2 llvm-255907042245b77779e3e38c5ce66901866cabe5.tar.xz |
Introduce a string_ostream string builder facilty
string_ostream is a safe and efficient string builder that combines opaque
stack storage with a built-in ostream interface.
small_string_ostream<bytes> additionally permits an explicit stack storage size
other than the default 128 bytes to be provided. Beyond that, storage is
transferred to the heap.
This convenient class can be used in most places an
std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair
would previously have been used, in order to guarantee consistent access
without byte truncation.
The patch also converts much of LLVM to use the new facility. These changes
include several probable bug fixes for truncated output, a programming error
that's no longer possible with the new interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211749 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86')
-rw-r--r-- | lib/Target/X86/AsmParser/X86AsmParser.cpp | 3 | ||||
-rw-r--r-- | lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp | 3 | ||||
-rw-r--r-- | lib/Target/X86/X86AsmPrinter.cpp | 6 |
3 files changed, 4 insertions, 8 deletions
diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp index 3e57914f9e..7e04608d99 100644 --- a/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -2412,8 +2412,7 @@ bool X86AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2]; if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3]; - SmallString<126> Msg; - raw_svector_ostream OS(Msg); + small_string_ostream<128> OS; OS << "ambiguous instructions require an explicit suffix (could be "; for (unsigned i = 0; i != NumMatches; ++i) { if (i != 0) diff --git a/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp index 78403424da..3f9eb07d83 100644 --- a/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp +++ b/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp @@ -281,8 +281,7 @@ void X86AsmBackend::relaxInstruction(const MCInst &Inst, MCInst &Res) const { unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode()); if (RelaxedOp == Inst.getOpcode()) { - SmallString<256> Tmp; - raw_svector_ostream OS(Tmp); + small_string_ostream<256> OS; Inst.dump_pretty(OS); OS << "\n"; report_fatal_error("unexpected instruction to relax: " + OS.str()); diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 1dca5689ad..cdfff82143 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -550,8 +550,7 @@ emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel, } void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) { - SmallString<128> Directive; - raw_svector_ostream OS(Directive); + small_string_ostream<128> OS; StringRef Name = Sym->getName(); if (Subtarget->isTargetKnownWindowsMSVC()) @@ -572,8 +571,7 @@ void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) { OS << ",data"; } - OS.flush(); - OutStreamer.EmitBytes(Directive); + OutStreamer.EmitBytes(OS.str()); } void X86AsmPrinter::EmitEndOfAsmFile(Module &M) { |