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 {
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());
}
};
#include "llvm/Support/Debug.h"
#include "llvm/Support/EndianStream.h"
-#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/LEB128.h"
#define DEBUG_TYPE "lld"
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<support::little>(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) {
#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"
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);