using namespace llvm;
using namespace llvm::wasm;
-using namespace lld;
-using namespace lld::wasm;
+namespace lld {
+std::string toString(const wasm::Symbol &sym) {
+ return maybeDemangleSymbol(sym.getName());
+}
+
+std::string maybeDemangleSymbol(StringRef name) {
+ if (wasm::config->demangle)
+ return demangleItanium(name);
+ return name;
+}
+
+std::string toString(wasm::Symbol::Kind kind) {
+ switch (kind) {
+ case wasm::Symbol::DefinedFunctionKind:
+ return "DefinedFunction";
+ case wasm::Symbol::DefinedDataKind:
+ return "DefinedData";
+ case wasm::Symbol::DefinedGlobalKind:
+ return "DefinedGlobal";
+ case wasm::Symbol::DefinedEventKind:
+ return "DefinedEvent";
+ case wasm::Symbol::UndefinedFunctionKind:
+ return "UndefinedFunction";
+ case wasm::Symbol::UndefinedDataKind:
+ return "UndefinedData";
+ case wasm::Symbol::UndefinedGlobalKind:
+ return "UndefinedGlobal";
+ case wasm::Symbol::LazyKind:
+ return "LazyKind";
+ case wasm::Symbol::SectionKind:
+ return "SectionKind";
+ case wasm::Symbol::OutputSectionKind:
+ return "OutputSectionKind";
+ }
+ llvm_unreachable("invalid symbol kind");
+}
+
+namespace wasm {
DefinedFunction *WasmSym::callCtors;
DefinedFunction *WasmSym::initMemory;
DefinedFunction *WasmSym::applyRelocs;
void LazySymbol::fetch() { cast<ArchiveFile>(file)->addMember(&archiveSymbol); }
-std::string lld::toString(const wasm::Symbol &sym) {
- return lld::maybeDemangleSymbol(sym.getName());
-}
-
-std::string lld::maybeDemangleSymbol(StringRef name) {
- if (config->demangle)
- return demangleItanium(name);
- return name;
-}
-
-std::string lld::toString(wasm::Symbol::Kind kind) {
- switch (kind) {
- case wasm::Symbol::DefinedFunctionKind:
- return "DefinedFunction";
- case wasm::Symbol::DefinedDataKind:
- return "DefinedData";
- case wasm::Symbol::DefinedGlobalKind:
- return "DefinedGlobal";
- case wasm::Symbol::DefinedEventKind:
- return "DefinedEvent";
- case wasm::Symbol::UndefinedFunctionKind:
- return "UndefinedFunction";
- case wasm::Symbol::UndefinedDataKind:
- return "UndefinedData";
- case wasm::Symbol::UndefinedGlobalKind:
- return "UndefinedGlobal";
- case wasm::Symbol::LazyKind:
- return "LazyKind";
- case wasm::Symbol::SectionKind:
- return "SectionKind";
- case wasm::Symbol::OutputSectionKind:
- return "OutputSectionKind";
- }
- llvm_unreachable("invalid symbol kind");
-}
-
-
-void lld::wasm::printTraceSymbolUndefined(StringRef name, const InputFile* file) {
+void printTraceSymbolUndefined(StringRef name, const InputFile* file) {
message(toString(file) + ": reference to " + name);
}
// Print out a log message for --trace-symbol.
-void lld::wasm::printTraceSymbol(Symbol *sym) {
+void printTraceSymbol(Symbol *sym) {
// Undefined symbols are traced via printTraceSymbolUndefined
if (sym->isUndefined())
return;
message(toString(sym->getFile()) + s + sym->getName());
}
-const char *lld::wasm::defaultModule = "env";
-const char *lld::wasm::functionTableName = "__indirect_function_table";
+const char *defaultModule = "env";
+const char *functionTableName = "__indirect_function_table";
+
+} // namespace wasm
+} // namespace lld
using namespace llvm::wasm;
namespace lld {
+std::string toString(ValType type) {
+ switch (type) {
+ case ValType::I32:
+ return "i32";
+ case ValType::I64:
+ return "i64";
+ case ValType::F32:
+ return "f32";
+ case ValType::F64:
+ return "f64";
+ case ValType::V128:
+ return "v128";
+ case ValType::EXNREF:
+ return "exnref";
+ }
+ llvm_unreachable("Invalid wasm::ValType");
+}
+
+std::string toString(const WasmSignature &sig) {
+ SmallString<128> s("(");
+ for (ValType type : sig.Params) {
+ if (s.size() != 1)
+ s += ", ";
+ s += toString(type);
+ }
+ s += ") -> ";
+ if (sig.Returns.empty())
+ s += "void";
+ else
+ s += toString(sig.Returns[0]);
+ return s.str();
+}
-void wasm::debugWrite(uint64_t offset, const Twine &msg) {
+std::string toString(const WasmGlobalType &type) {
+ return (type.Mutable ? "var " : "const ") +
+ toString(static_cast<ValType>(type.Type));
+}
+
+std::string toString(const WasmEventType &type) {
+ if (type.Attribute == WASM_EVENT_ATTRIBUTE_EXCEPTION)
+ return "exception";
+ return "unknown";
+}
+
+namespace wasm {
+void debugWrite(uint64_t offset, const Twine &msg) {
LLVM_DEBUG(dbgs() << format(" | %08lld: ", offset) << msg << "\n");
}
-void wasm::writeUleb128(raw_ostream &os, uint32_t number, const Twine &msg) {
+void 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, const Twine &msg) {
+void 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,
+void writeBytes(raw_ostream &os, const char *bytes, size_t count,
const Twine &msg) {
debugWrite(os.tell(), msg + " [data[" + Twine(count) + "]]");
os.write(bytes, count);
}
-void wasm::writeStr(raw_ostream &os, StringRef string, const Twine &msg) {
+void 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, const Twine &msg) {
+void 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, const Twine &msg) {
+void writeU32(raw_ostream &os, uint32_t number, const Twine &msg) {
debugWrite(os.tell(), msg + "[0x" + utohexstr(number) + "]");
support::endian::write(os, number, support::little);
}
-void wasm::writeValueType(raw_ostream &os, ValType type, const Twine &msg) {
+void writeValueType(raw_ostream &os, ValType type, const Twine &msg) {
writeU8(os, static_cast<uint8_t>(type),
msg + "[type: " + toString(type) + "]");
}
-void wasm::writeSig(raw_ostream &os, const WasmSignature &sig) {
+void writeSig(raw_ostream &os, const WasmSignature &sig) {
writeU8(os, WASM_TYPE_FUNC, "signature type");
writeUleb128(os, sig.Params.size(), "param Count");
for (ValType paramType : sig.Params) {
}
}
-void wasm::writeI32Const(raw_ostream &os, int32_t number, const Twine &msg) {
+void writeI32Const(raw_ostream &os, int32_t number, const Twine &msg) {
writeU8(os, WASM_OPCODE_I32_CONST, "i32.const");
writeSleb128(os, number, msg);
}
-void wasm::writeI64Const(raw_ostream &os, int32_t number, const Twine &msg) {
+void writeI64Const(raw_ostream &os, int32_t number, const Twine &msg) {
writeU8(os, WASM_OPCODE_I64_CONST, "i64.const");
writeSleb128(os, number, msg);
}
-void wasm::writeMemArg(raw_ostream &os, uint32_t alignment, uint32_t offset) {
+void writeMemArg(raw_ostream &os, uint32_t alignment, uint32_t offset) {
writeUleb128(os, alignment, "alignment");
writeUleb128(os, offset, "offset");
}
-void wasm::writeInitExpr(raw_ostream &os, const WasmInitExpr &initExpr) {
+void writeInitExpr(raw_ostream &os, const WasmInitExpr &initExpr) {
writeU8(os, initExpr.Opcode, "opcode");
switch (initExpr.Opcode) {
case WASM_OPCODE_I32_CONST:
writeU8(os, WASM_OPCODE_END, "opcode:end");
}
-void wasm::writeLimits(raw_ostream &os, const WasmLimits &limits) {
+void writeLimits(raw_ostream &os, const WasmLimits &limits) {
writeU8(os, limits.Flags, "limits flags");
writeUleb128(os, limits.Initial, "limits initial");
if (limits.Flags & WASM_LIMITS_FLAG_HAS_MAX)
writeUleb128(os, limits.Maximum, "limits max");
}
-void wasm::writeGlobalType(raw_ostream &os, const WasmGlobalType &type) {
+void writeGlobalType(raw_ostream &os, const WasmGlobalType &type) {
// TODO: Update WasmGlobalType to use ValType and remove this cast.
writeValueType(os, ValType(type.Type), "global type");
writeU8(os, type.Mutable, "global mutable");
}
-void wasm::writeGlobal(raw_ostream &os, const WasmGlobal &global) {
+void writeGlobal(raw_ostream &os, const WasmGlobal &global) {
writeGlobalType(os, global.Type);
writeInitExpr(os, global.InitExpr);
}
-void wasm::writeEventType(raw_ostream &os, const WasmEventType &type) {
+void writeEventType(raw_ostream &os, const WasmEventType &type) {
writeUleb128(os, type.Attribute, "event attribute");
writeUleb128(os, type.SigIndex, "sig index");
}
-void wasm::writeEvent(raw_ostream &os, const WasmEvent &event) {
+void writeEvent(raw_ostream &os, const WasmEvent &event) {
writeEventType(os, event.Type);
}
-void wasm::writeTableType(raw_ostream &os, const llvm::wasm::WasmTable &type) {
+void writeTableType(raw_ostream &os, const llvm::wasm::WasmTable &type) {
writeU8(os, WASM_TYPE_FUNCREF, "table type");
writeLimits(os, type.Limits);
}
-void wasm::writeImport(raw_ostream &os, const WasmImport &import) {
+void writeImport(raw_ostream &os, const WasmImport &import) {
writeStr(os, import.Module, "import module name");
writeStr(os, import.Field, "import field name");
writeU8(os, import.Kind, "import kind");
}
}
-void wasm::writeExport(raw_ostream &os, const WasmExport &export_) {
+void writeExport(raw_ostream &os, const WasmExport &export_) {
writeStr(os, export_.Name, "export name");
writeU8(os, export_.Kind, "export kind");
switch (export_.Kind) {
fatal("unsupported export type: " + Twine(export_.Kind));
}
}
-} // namespace lld
-
-std::string lld::toString(ValType type) {
- switch (type) {
- case ValType::I32:
- return "i32";
- case ValType::I64:
- return "i64";
- case ValType::F32:
- return "f32";
- case ValType::F64:
- return "f64";
- case ValType::V128:
- return "v128";
- case ValType::EXNREF:
- return "exnref";
- }
- llvm_unreachable("Invalid wasm::ValType");
-}
-
-std::string lld::toString(const WasmSignature &sig) {
- SmallString<128> s("(");
- for (ValType type : sig.Params) {
- if (s.size() != 1)
- s += ", ";
- s += toString(type);
- }
- s += ") -> ";
- if (sig.Returns.empty())
- s += "void";
- else
- s += toString(sig.Returns[0]);
- return s.str();
-}
-
-std::string lld::toString(const WasmGlobalType &type) {
- return (type.Mutable ? "var " : "const ") +
- toString(static_cast<ValType>(type.Type));
-}
-std::string lld::toString(const WasmEventType &type) {
- if (type.Attribute == WASM_EVENT_ATTRIBUTE_EXCEPTION)
- return "exception";
- return "unknown";
-}
+} // namespace wasm
+} // namespace lld