Index: lld/trunk/wasm/OutputSections.h =================================================================== --- lld/trunk/wasm/OutputSections.h +++ lld/trunk/wasm/OutputSections.h @@ -60,7 +60,7 @@ SyntheticSection(uint32_t Type, std::string Name = "") : OutputSection(Type, Name), BodyOutputStream(Body) { if (!Name.empty()) - writeStr(BodyOutputStream, Name); + writeStr(BodyOutputStream, Name, "section name"); } void writeTo(uint8_t *Buf) override { @@ -96,8 +96,8 @@ std::string getSectionName() const; void writeToStream(raw_ostream &OS) { - writeBytes(OS, Header.data(), Header.size()); - writeBytes(OS, Body.data(), Body.size()); + OS.write(Header.data(), Header.size()); + OS.write(Body.data(), Body.size()); } }; Index: lld/trunk/wasm/OutputSections.cpp =================================================================== --- lld/trunk/wasm/OutputSections.cpp +++ lld/trunk/wasm/OutputSections.cpp @@ -15,6 +15,7 @@ #include "lld/Common/ErrorHandler.h" #include "lld/Common/Threads.h" #include "llvm/ADT/Twine.h" +#include "llvm/Support/LEB128.h" #define DEBUG_TYPE "lld" @@ -72,7 +73,7 @@ void OutputSection::createHeader(size_t BodySize) { raw_string_ostream OS(Header); debugWrite(OS.tell(), "section type [" + Twine(getSectionName()) + "]"); - writeUleb128(OS, Type, nullptr); + encodeULEB128(Type, OS); writeUleb128(OS, BodySize, "section size"); OS.flush(); log("createHeader: " + toString(*this) + " body=" + Twine(BodySize) + Index: lld/trunk/wasm/WriterUtils.h =================================================================== --- lld/trunk/wasm/WriterUtils.h +++ lld/trunk/wasm/WriterUtils.h @@ -10,6 +10,7 @@ #ifndef LLD_WASM_WRITERUTILS_H #define LLD_WASM_WRITERUTILS_H +#include "lld/Common/LLVM.h" #include "llvm/ADT/Twine.h" #include "llvm/Object/Wasm.h" #include "llvm/Support/raw_ostream.h" @@ -36,23 +37,21 @@ uint32_t Value; }; -void debugWrite(uint64_t Offset, llvm::Twine Msg); +void debugWrite(uint64_t Offset, const Twine &Msg); -void writeUleb128(raw_ostream &OS, uint32_t Number, const char *Msg); +void writeUleb128(raw_ostream &OS, uint32_t Number, StringRef Msg); -void writeSleb128(raw_ostream &OS, int32_t Number, const char *Msg); +void writeSleb128(raw_ostream &OS, int32_t Number, StringRef Msg); -void writeBytes(raw_ostream &OS, const char *Bytes, size_t count, - const char *Msg = nullptr); +void writeBytes(raw_ostream &OS, const char *Bytes, size_t count, StringRef Msg); -void writeStr(raw_ostream &OS, const llvm::StringRef String, - const char *Msg = nullptr); +void writeStr(raw_ostream &OS, StringRef String, StringRef Msg); -void writeU8(raw_ostream &OS, uint8_t byte, const char *Msg); +void writeU8(raw_ostream &OS, uint8_t byte, StringRef Msg); -void writeU32(raw_ostream &OS, uint32_t Number, const char *Msg); +void writeU32(raw_ostream &OS, uint32_t Number, StringRef Msg); -void writeValueType(raw_ostream &OS, int32_t Type, const char *Msg); +void writeValueType(raw_ostream &OS, int32_t Type, StringRef Msg); void writeSig(raw_ostream &OS, const llvm::wasm::WasmSignature &Sig); Index: lld/trunk/wasm/WriterUtils.cpp =================================================================== --- lld/trunk/wasm/WriterUtils.cpp +++ lld/trunk/wasm/WriterUtils.cpp @@ -13,7 +13,6 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/EndianStream.h" -#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/LEB128.h" #define DEBUG_TYPE "lld" @@ -39,49 +38,43 @@ namespace lld { -void wasm::debugWrite(uint64_t Offset, Twine Msg) { - DEBUG(dbgs() << format(" | %08" PRIx64 ": ", Offset) << Msg << "\n"); +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, const char *Msg) { - if (Msg) - debugWrite(OS.tell(), Msg + formatv(" [{0:x}]", Number)); +void wasm::writeUleb128(raw_ostream &OS, uint32_t Number, StringRef Msg) { + debugWrite(OS.tell(), Msg + "[" + utohexstr(Number) + "]"); encodeULEB128(Number, OS); } -void wasm::writeSleb128(raw_ostream &OS, int32_t Number, const char *Msg) { - if (Msg) - debugWrite(OS.tell(), Msg + formatv(" [{0:x}]", Number)); +void wasm::writeSleb128(raw_ostream &OS, int32_t Number, StringRef Msg) { + debugWrite(OS.tell(), Msg + "[" + utohexstr(Number) + "]"); encodeSLEB128(Number, OS); } void wasm::writeBytes(raw_ostream &OS, const char *Bytes, size_t Count, - const char *Msg) { - if (Msg) - debugWrite(OS.tell(), Msg + formatv(" [data[{0}]]", Count)); + StringRef Msg) { + debugWrite(OS.tell(), Msg + " [data[" + Twine(Count) + "]]"); OS.write(Bytes, Count); } -void wasm::writeStr(raw_ostream &OS, const StringRef String, const char *Msg) { - if (Msg) - debugWrite(OS.tell(), - Msg + formatv(" [str[{0}]: {1}]", String.size(), String)); - writeUleb128(OS, String.size(), nullptr); - writeBytes(OS, String.data(), String.size()); +void wasm::writeStr(raw_ostream &OS, StringRef String, StringRef 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, const char *Msg) { - OS << byte; -} +void wasm::writeU8(raw_ostream &OS, uint8_t byte, StringRef Msg) { OS << byte; } -void wasm::writeU32(raw_ostream &OS, uint32_t Number, const char *Msg) { - debugWrite(OS.tell(), Msg + formatv("[{0:x}]", Number)); +void wasm::writeU32(raw_ostream &OS, uint32_t Number, StringRef Msg) { + debugWrite(OS.tell(), Msg + "[" + utohexstr(Number) + "]"); support::endian::Writer(OS).write(Number); } -void wasm::writeValueType(raw_ostream &OS, int32_t Type, const char *Msg) { - debugWrite(OS.tell(), Msg + formatv("[type: {0}]", valueTypeToString(Type))); - writeSleb128(OS, Type, nullptr); +void wasm::writeValueType(raw_ostream &OS, int32_t Type, StringRef Msg) { + debugWrite(OS.tell(), Msg + "[type: " + valueTypeToString(Type) + "]"); + encodeSLEB128(Type, OS); } void wasm::writeSig(raw_ostream &OS, const WasmSignature &Sig) {