From: Sam Clegg Date: Thu, 1 Mar 2018 00:42:57 +0000 (+0000) Subject: [WebAssembly] Use Twine rather than StringRef for logging messages X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ea397f67e32de01c4bf749cf2880d3c1343275d4;p=platform%2Fupstream%2Fllvm.git [WebAssembly] Use Twine rather than StringRef for logging messages Also add missing tracing to writeU8. Differential Revision: https://reviews.llvm.org/D43919 llvm-svn: 326398 --- diff --git a/lld/wasm/WriterUtils.cpp b/lld/wasm/WriterUtils.cpp index a5d8417..f77127b 100644 --- a/lld/wasm/WriterUtils.cpp +++ b/lld/wasm/WriterUtils.cpp @@ -40,37 +40,40 @@ void wasm::debugWrite(uint64_t Offset, const Twine &Msg) { DEBUG(dbgs() << format(" | %08lld: ", Offset) << Msg << "\n"); } -void wasm::writeUleb128(raw_ostream &OS, uint32_t Number, StringRef Msg) { +void wasm::writeUleb128(raw_ostream &OS, uint32_t Number, const Twine &Msg) { debugWrite(OS.tell(), Msg + "[" + utohexstr(Number) + "]"); encodeULEB128(Number, OS); } -void wasm::writeSleb128(raw_ostream &OS, int32_t Number, StringRef Msg) { +void wasm::writeSleb128(raw_ostream &OS, int32_t Number, const Twine &Msg) { debugWrite(OS.tell(), Msg + "[" + utohexstr(Number) + "]"); encodeSLEB128(Number, OS); } void wasm::writeBytes(raw_ostream &OS, const char *Bytes, size_t Count, - StringRef Msg) { + const Twine &Msg) { debugWrite(OS.tell(), Msg + " [data[" + Twine(Count) + "]]"); OS.write(Bytes, Count); } -void wasm::writeStr(raw_ostream &OS, StringRef String, StringRef Msg) { +void wasm::writeStr(raw_ostream &OS, StringRef String, const Twine &Msg) { debugWrite(OS.tell(), Msg + " [str[" + Twine(String.size()) + "]: " + String + "]"); encodeULEB128(String.size(), OS); OS.write(String.data(), String.size()); } -void wasm::writeU8(raw_ostream &OS, uint8_t Byte, StringRef Msg) { OS << Byte; } +void wasm::writeU8(raw_ostream &OS, uint8_t Byte, const Twine &Msg) { + debugWrite(OS.tell(), Msg + " [0x" + utohexstr(Byte) + "]"); + OS << Byte; +} -void wasm::writeU32(raw_ostream &OS, uint32_t Number, StringRef Msg) { - debugWrite(OS.tell(), Msg + "[" + utohexstr(Number) + "]"); +void wasm::writeU32(raw_ostream &OS, uint32_t Number, const Twine &Msg) { + debugWrite(OS.tell(), Msg + "[0x" + utohexstr(Number) + "]"); support::endian::Writer(OS).write(Number); } -void wasm::writeValueType(raw_ostream &OS, int32_t Type, StringRef Msg) { +void wasm::writeValueType(raw_ostream &OS, int32_t Type, const Twine &Msg) { debugWrite(OS.tell(), Msg + "[type: " + valueTypeToString(Type) + "]"); encodeSLEB128(Type, OS); } diff --git a/lld/wasm/WriterUtils.h b/lld/wasm/WriterUtils.h index 87696b5..c471856 100644 --- a/lld/wasm/WriterUtils.h +++ b/lld/wasm/WriterUtils.h @@ -44,19 +44,20 @@ namespace wasm { void debugWrite(uint64_t Offset, const Twine &Msg); -void writeUleb128(raw_ostream &OS, uint32_t Number, StringRef Msg); +void writeUleb128(raw_ostream &OS, uint32_t Number, const Twine &Msg); -void writeSleb128(raw_ostream &OS, int32_t Number, StringRef Msg); +void writeSleb128(raw_ostream &OS, int32_t Number, const Twine &Msg); -void writeBytes(raw_ostream &OS, const char *Bytes, size_t count, StringRef Msg); +void writeBytes(raw_ostream &OS, const char *Bytes, size_t count, + const Twine &Msg); -void writeStr(raw_ostream &OS, StringRef String, StringRef Msg); +void writeStr(raw_ostream &OS, StringRef String, const Twine &Msg); -void writeU8(raw_ostream &OS, uint8_t byte, StringRef Msg); +void writeU8(raw_ostream &OS, uint8_t byte, const Twine &Msg); -void writeU32(raw_ostream &OS, uint32_t Number, StringRef Msg); +void writeU32(raw_ostream &OS, uint32_t Number, const Twine &Msg); -void writeValueType(raw_ostream &OS, int32_t Type, StringRef Msg); +void writeValueType(raw_ostream &OS, int32_t Type, const Twine &Msg); void writeSig(raw_ostream &OS, const llvm::wasm::WasmSignature &Sig);