Skip to content

Commit 33c59ab

Browse files
committed
[WebAssembly] Wrap definitions in namespace lld { namespace wasm {. NFC
Similar to D68323, but for wasm. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D68759 llvm-svn: 374279
1 parent c05a875 commit 33c59ab

11 files changed

+187
-158
lines changed

lld/wasm/Driver.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ using namespace llvm::object;
3737
using namespace llvm::sys;
3838
using namespace llvm::wasm;
3939

40-
using namespace lld;
41-
using namespace lld::wasm;
42-
43-
Configuration *lld::wasm::config;
40+
namespace lld {
41+
namespace wasm {
42+
Configuration *config;
4443

4544
namespace {
4645

@@ -79,8 +78,7 @@ class LinkerDriver {
7978
};
8079
} // anonymous namespace
8180

82-
bool lld::wasm::link(ArrayRef<const char *> args, bool canExitEarly,
83-
raw_ostream &error) {
81+
bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &error) {
8482
errorHandler().logName = args::getFilenameWithoutExe(args[0]);
8583
errorHandler().errorOS = &error;
8684
errorHandler().errorLimitExceededMsg =
@@ -787,3 +785,6 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
787785
// Write the result to the file.
788786
writeResult();
789787
}
788+
789+
} // namespace wasm
790+
} // namespace lld

lld/wasm/InputChunks.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
using namespace llvm;
2020
using namespace llvm::wasm;
2121
using namespace llvm::support::endian;
22-
using namespace lld;
23-
using namespace lld::wasm;
2422

25-
StringRef lld::relocTypeToString(uint8_t relocType) {
23+
namespace lld {
24+
StringRef relocTypeToString(uint8_t relocType) {
2625
switch (relocType) {
2726
#define WASM_RELOC(NAME, REL) \
2827
case REL: \
@@ -33,10 +32,11 @@ StringRef lld::relocTypeToString(uint8_t relocType) {
3332
llvm_unreachable("unknown reloc type");
3433
}
3534

36-
std::string lld::toString(const InputChunk *c) {
35+
std::string toString(const wasm::InputChunk *c) {
3736
return (toString(c->file) + ":(" + c->getName() + ")").str();
3837
}
3938

39+
namespace wasm {
4040
StringRef InputChunk::getComdatName() const {
4141
uint32_t index = getComdat();
4242
if (index == UINT32_MAX)
@@ -346,3 +346,6 @@ void InputSegment::generateRelocationCode(raw_ostream &os) const {
346346
writeUleb128(os, 0, "offset");
347347
}
348348
}
349+
350+
} // namespace wasm
351+
} // namespace lld

lld/wasm/InputFiles.cpp

+19-16
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,27 @@
2222

2323
#define DEBUG_TYPE "lld"
2424

25-
using namespace lld;
26-
using namespace lld::wasm;
27-
2825
using namespace llvm;
2926
using namespace llvm::object;
3027
using namespace llvm::wasm;
3128

32-
std::unique_ptr<llvm::TarWriter> lld::wasm::tar;
29+
namespace lld {
30+
31+
// Returns a string in the format of "foo.o" or "foo.a(bar.o)".
32+
std::string toString(const wasm::InputFile *file) {
33+
if (!file)
34+
return "<internal>";
35+
36+
if (file->archiveName.empty())
37+
return file->getName();
38+
39+
return (file->archiveName + "(" + file->getName() + ")").str();
40+
}
3341

34-
Optional<MemoryBufferRef> lld::wasm::readFile(StringRef path) {
42+
namespace wasm {
43+
std::unique_ptr<llvm::TarWriter> tar;
44+
45+
Optional<MemoryBufferRef> readFile(StringRef path) {
3546
log("Loading: " + path);
3647

3748
auto mbOrErr = MemoryBuffer::getFile(path);
@@ -48,7 +59,7 @@ Optional<MemoryBufferRef> lld::wasm::readFile(StringRef path) {
4859
return mbref;
4960
}
5061

51-
InputFile *lld::wasm::createObjectFile(MemoryBufferRef mb,
62+
InputFile *createObjectFile(MemoryBufferRef mb,
5263
StringRef archiveName) {
5364
file_magic magic = identify_magic(mb.getBuffer());
5465
if (magic == file_magic::wasm_object) {
@@ -542,13 +553,5 @@ void BitcodeFile::parse() {
542553
symbols.push_back(createBitcodeSymbol(keptComdats, objSym, *this));
543554
}
544555

545-
// Returns a string in the format of "foo.o" or "foo.a(bar.o)".
546-
std::string lld::toString(const wasm::InputFile *file) {
547-
if (!file)
548-
return "<internal>";
549-
550-
if (file->archiveName.empty())
551-
return file->getName();
552-
553-
return (file->archiveName + "(" + file->getName() + ")").str();
554-
}
556+
} // namespace wasm
557+
} // namespace lld

lld/wasm/LTO.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
#include <vector>
3737

3838
using namespace llvm;
39-
using namespace lld;
40-
using namespace lld::wasm;
4139

40+
namespace lld {
41+
namespace wasm {
4242
static std::unique_ptr<lto::LTO> createLTO() {
4343
lto::Config c;
4444
c.Options = initTargetOptionsFromCodeGenFlags();
@@ -165,3 +165,6 @@ std::vector<StringRef> BitcodeCompiler::compile() {
165165

166166
return ret;
167167
}
168+
169+
} // namespace wasm
170+
} // namespace lld

lld/wasm/OutputSections.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@
2020

2121
using namespace llvm;
2222
using namespace llvm::wasm;
23-
using namespace lld;
24-
using namespace lld::wasm;
2523

24+
namespace lld {
25+
26+
// Returns a string, e.g. "FUNCTION(.text)".
27+
std::string toString(const wasm::OutputSection &sec) {
28+
if (!sec.name.empty())
29+
return (sec.getSectionName() + "(" + sec.name + ")").str();
30+
return sec.getSectionName();
31+
}
32+
33+
namespace wasm {
2634
static StringRef sectionTypeToString(uint32_t sectionType) {
2735
switch (sectionType) {
2836
case WASM_SEC_CUSTOM:
@@ -58,13 +66,6 @@ static StringRef sectionTypeToString(uint32_t sectionType) {
5866
}
5967
}
6068

61-
// Returns a string, e.g. "FUNCTION(.text)".
62-
std::string lld::toString(const OutputSection &sec) {
63-
if (!sec.name.empty())
64-
return (sec.getSectionName() + "(" + sec.name + ")").str();
65-
return sec.getSectionName();
66-
}
67-
6869
StringRef OutputSection::getSectionName() const {
6970
return sectionTypeToString(type);
7071
}
@@ -248,3 +249,6 @@ void CustomSection::writeRelocations(raw_ostream &os) const {
248249
for (const InputSection *s : inputSections)
249250
s->writeRelocations(os);
250251
}
252+
253+
} // namespace wasm
254+
} // namespace lld

lld/wasm/Relocations.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
using namespace llvm;
1515
using namespace llvm::wasm;
1616

17-
using namespace lld;
18-
using namespace lld::wasm;
19-
17+
namespace lld {
18+
namespace wasm {
2019
static bool requiresGOTAccess(const Symbol *sym) {
2120
return config->isPic && !sym->isHidden() && !sym->isLocal();
2221
}
@@ -54,7 +53,7 @@ static void addGOTEntry(Symbol *sym) {
5453
out.globalSec->addStaticGOTEntry(sym);
5554
}
5655

57-
void lld::wasm::scanRelocations(InputChunk *chunk) {
56+
void scanRelocations(InputChunk *chunk) {
5857
if (!chunk->live)
5958
return;
6059
ObjFile *file = chunk->file;
@@ -113,3 +112,6 @@ void lld::wasm::scanRelocations(InputChunk *chunk) {
113112

114113
}
115114
}
115+
116+
} // namespace wasm
117+
} // namespace lld

lld/wasm/SymbolTable.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
using namespace llvm;
2222
using namespace llvm::wasm;
2323
using namespace llvm::object;
24-
using namespace lld;
25-
using namespace lld::wasm;
2624

27-
SymbolTable *lld::wasm::symtab;
25+
namespace lld {
26+
namespace wasm {
27+
SymbolTable *symtab;
2828

2929
void SymbolTable::addFile(InputFile *file) {
3030
log("Processing: " + toString(file));
@@ -692,3 +692,6 @@ void SymbolTable::handleSymbolVariants() {
692692
}
693693
}
694694
}
695+
696+
} // namespace wasm
697+
} // namespace lld

lld/wasm/Symbols.cpp

+45-43
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,45 @@
2121

2222
using namespace llvm;
2323
using namespace llvm::wasm;
24-
using namespace lld;
25-
using namespace lld::wasm;
2624

25+
namespace lld {
26+
std::string toString(const wasm::Symbol &sym) {
27+
return maybeDemangleSymbol(sym.getName());
28+
}
29+
30+
std::string maybeDemangleSymbol(StringRef name) {
31+
if (wasm::config->demangle)
32+
return demangleItanium(name);
33+
return name;
34+
}
35+
36+
std::string toString(wasm::Symbol::Kind kind) {
37+
switch (kind) {
38+
case wasm::Symbol::DefinedFunctionKind:
39+
return "DefinedFunction";
40+
case wasm::Symbol::DefinedDataKind:
41+
return "DefinedData";
42+
case wasm::Symbol::DefinedGlobalKind:
43+
return "DefinedGlobal";
44+
case wasm::Symbol::DefinedEventKind:
45+
return "DefinedEvent";
46+
case wasm::Symbol::UndefinedFunctionKind:
47+
return "UndefinedFunction";
48+
case wasm::Symbol::UndefinedDataKind:
49+
return "UndefinedData";
50+
case wasm::Symbol::UndefinedGlobalKind:
51+
return "UndefinedGlobal";
52+
case wasm::Symbol::LazyKind:
53+
return "LazyKind";
54+
case wasm::Symbol::SectionKind:
55+
return "SectionKind";
56+
case wasm::Symbol::OutputSectionKind:
57+
return "OutputSectionKind";
58+
}
59+
llvm_unreachable("invalid symbol kind");
60+
}
61+
62+
namespace wasm {
2763
DefinedFunction *WasmSym::callCtors;
2864
DefinedFunction *WasmSym::initMemory;
2965
DefinedFunction *WasmSym::applyRelocs;
@@ -298,49 +334,12 @@ const OutputSectionSymbol *SectionSymbol::getOutputSectionSymbol() const {
298334

299335
void LazySymbol::fetch() { cast<ArchiveFile>(file)->addMember(&archiveSymbol); }
300336

301-
std::string lld::toString(const wasm::Symbol &sym) {
302-
return lld::maybeDemangleSymbol(sym.getName());
303-
}
304-
305-
std::string lld::maybeDemangleSymbol(StringRef name) {
306-
if (config->demangle)
307-
return demangleItanium(name);
308-
return name;
309-
}
310-
311-
std::string lld::toString(wasm::Symbol::Kind kind) {
312-
switch (kind) {
313-
case wasm::Symbol::DefinedFunctionKind:
314-
return "DefinedFunction";
315-
case wasm::Symbol::DefinedDataKind:
316-
return "DefinedData";
317-
case wasm::Symbol::DefinedGlobalKind:
318-
return "DefinedGlobal";
319-
case wasm::Symbol::DefinedEventKind:
320-
return "DefinedEvent";
321-
case wasm::Symbol::UndefinedFunctionKind:
322-
return "UndefinedFunction";
323-
case wasm::Symbol::UndefinedDataKind:
324-
return "UndefinedData";
325-
case wasm::Symbol::UndefinedGlobalKind:
326-
return "UndefinedGlobal";
327-
case wasm::Symbol::LazyKind:
328-
return "LazyKind";
329-
case wasm::Symbol::SectionKind:
330-
return "SectionKind";
331-
case wasm::Symbol::OutputSectionKind:
332-
return "OutputSectionKind";
333-
}
334-
llvm_unreachable("invalid symbol kind");
335-
}
336-
337-
338-
void lld::wasm::printTraceSymbolUndefined(StringRef name, const InputFile* file) {
337+
void printTraceSymbolUndefined(StringRef name, const InputFile* file) {
339338
message(toString(file) + ": reference to " + name);
340339
}
341340

342341
// Print out a log message for --trace-symbol.
343-
void lld::wasm::printTraceSymbol(Symbol *sym) {
342+
void printTraceSymbol(Symbol *sym) {
344343
// Undefined symbols are traced via printTraceSymbolUndefined
345344
if (sym->isUndefined())
346345
return;
@@ -354,5 +353,8 @@ void lld::wasm::printTraceSymbol(Symbol *sym) {
354353
message(toString(sym->getFile()) + s + sym->getName());
355354
}
356355

357-
const char *lld::wasm::defaultModule = "env";
358-
const char *lld::wasm::functionTableName = "__indirect_function_table";
356+
const char *defaultModule = "env";
357+
const char *functionTableName = "__indirect_function_table";
358+
359+
} // namespace wasm
360+
} // namespace lld

lld/wasm/SyntheticSections.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
using namespace llvm;
2323
using namespace llvm::wasm;
2424

25-
using namespace lld;
26-
using namespace lld::wasm;
25+
namespace lld {
26+
namespace wasm {
2727

28-
OutStruct lld::wasm::out;
28+
OutStruct out;
2929

3030
namespace {
3131

@@ -567,3 +567,6 @@ void RelocSection::writeBody() {
567567
writeUleb128(bodyOutputStream, count, "reloc count");
568568
sec->writeRelocations(bodyOutputStream);
569569
}
570+
571+
} // namespace wasm
572+
} // namespace lld

lld/wasm/Writer.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939

4040
using namespace llvm;
4141
using namespace llvm::wasm;
42-
using namespace lld;
43-
using namespace lld::wasm;
4442

43+
namespace lld {
44+
namespace wasm {
4545
static constexpr int stackAlignment = 16;
4646

4747
namespace {
@@ -1088,4 +1088,7 @@ void Writer::createHeader() {
10881088
fileSize += header.size();
10891089
}
10901090

1091-
void lld::wasm::writeResult() { Writer().run(); }
1091+
void writeResult() { Writer().run(); }
1092+
1093+
} // namespace wasm
1094+
} // namespace lld

0 commit comments

Comments
 (0)