[lld] r326398 - [WebAssembly] Use Twine rather than StringRef for logging messages

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 16:42:57 PST 2018


Author: sbc
Date: Wed Feb 28 16:42:57 2018
New Revision: 326398

URL: http://llvm.org/viewvc/llvm-project?rev=326398&view=rev
Log:
[WebAssembly] Use Twine rather than StringRef for logging messages

Also add missing tracing to writeU8.

Differential Revision: https://reviews.llvm.org/D43919

Modified:
    lld/trunk/wasm/WriterUtils.cpp
    lld/trunk/wasm/WriterUtils.h

Modified: lld/trunk/wasm/WriterUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/WriterUtils.cpp?rev=326398&r1=326397&r2=326398&view=diff
==============================================================================
--- lld/trunk/wasm/WriterUtils.cpp (original)
+++ lld/trunk/wasm/WriterUtils.cpp Wed Feb 28 16:42:57 2018
@@ -40,37 +40,40 @@ void wasm::debugWrite(uint64_t Offset, c
   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<support::little>(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);
 }

Modified: lld/trunk/wasm/WriterUtils.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/WriterUtils.h?rev=326398&r1=326397&r2=326398&view=diff
==============================================================================
--- lld/trunk/wasm/WriterUtils.h (original)
+++ lld/trunk/wasm/WriterUtils.h Wed Feb 28 16:42:57 2018
@@ -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);
 




More information about the llvm-commits mailing list