mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-28 23:17:10 +00:00
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
This commit is contained in:
@@ -270,8 +270,7 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes,
|
||||
const MCDisassembler *DisAsm = DC->getDisAsm();
|
||||
MCInstPrinter *IP = DC->getIP();
|
||||
MCDisassembler::DecodeStatus S;
|
||||
SmallVector<char, 64> InsnStr;
|
||||
raw_svector_ostream Annotations(InsnStr);
|
||||
small_string_ostream<64> Annotations;
|
||||
S = DisAsm->getInstruction(Inst, Size, MemoryObject, PC,
|
||||
/*REMOVE*/ nulls(), Annotations);
|
||||
switch (S) {
|
||||
@@ -281,13 +280,10 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes,
|
||||
return 0;
|
||||
|
||||
case MCDisassembler::Success: {
|
||||
Annotations.flush();
|
||||
StringRef AnnotationsStr = Annotations.str();
|
||||
|
||||
SmallVector<char, 64> InsnStr;
|
||||
raw_svector_ostream OS(InsnStr);
|
||||
formatted_raw_ostream FormattedOS(OS);
|
||||
IP->printInst(&Inst, FormattedOS, AnnotationsStr);
|
||||
IP->printInst(&Inst, FormattedOS, Annotations.str());
|
||||
|
||||
if (DC->getOptions() & LLVMDisassembler_Option_PrintLatency)
|
||||
emitLatency(DC, Inst);
|
||||
|
Reference in New Issue
Block a user