[WebAssembly] Use Twine rather than StringRef for logging messages
authorSam Clegg <sbc@chromium.org>
Thu, 1 Mar 2018 00:42:57 +0000 (00:42 +0000)
committerSam Clegg <sbc@chromium.org>
Thu, 1 Mar 2018 00:42:57 +0000 (00:42 +0000)
Also add missing tracing to writeU8.

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

llvm-svn: 326398

lld/wasm/WriterUtils.cpp
lld/wasm/WriterUtils.h

index a5d8417..f77127b 100644 (file)
@@ -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<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);
 }
index 87696b5..c471856 100644 (file)
@@ -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);