5656#include < optional>
5757#include < tuple>
5858
59+ using namespace lld ;
60+ using namespace lld ::coff;
5961using namespace llvm ;
6062using namespace llvm ::object;
6163using namespace llvm ::COFF;
6264using namespace llvm ::sys;
6365
66+ COFFSyncStream::COFFSyncStream (COFFLinkerContext &ctx, DiagLevel level)
67+ : SyncStream(ctx.e, level), ctx(ctx) {}
68+
69+ COFFSyncStream coff::Log (COFFLinkerContext &ctx) {
70+ return {ctx, DiagLevel::Log};
71+ }
72+ COFFSyncStream coff::Msg (COFFLinkerContext &ctx) {
73+ return {ctx, DiagLevel::Msg};
74+ }
75+ COFFSyncStream coff::Warn (COFFLinkerContext &ctx) {
76+ return {ctx, DiagLevel::Warn};
77+ }
78+ COFFSyncStream coff::Err (COFFLinkerContext &ctx) {
79+ return {ctx, DiagLevel::Err};
80+ }
81+ COFFSyncStream coff::Fatal (COFFLinkerContext &ctx) {
82+ return {ctx, DiagLevel::Fatal};
83+ }
84+ uint64_t coff::errCount (COFFLinkerContext &ctx) { return ctx.e .errorCount ; }
85+
6486namespace lld ::coff {
6587
6688bool link (ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
@@ -75,7 +97,7 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
7597
7698 ctx->driver .linkerMain (args);
7799
78- return errorCount ( ) == 0 ;
100+ return errCount (*ctx ) == 0 ;
79101}
80102
81103// Parse options of the form "old;new".
@@ -212,7 +234,8 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
212234 ctx.symtab .addFile (make<PDBInputFile>(ctx, mbref));
213235 break ;
214236 case file_magic::coff_cl_gl_object:
215- error (filename + " : is not a native COFF file. Recompile without /GL" );
237+ Err (ctx) << filename
238+ << " : is not a native COFF file. Recompile without /GL" ;
216239 break ;
217240 case file_magic::pecoff_executable:
218241 if (ctx.config .mingw ) {
@@ -302,17 +325,17 @@ void LinkerDriver::addArchiveBuffer(MemoryBufferRef mb, StringRef symName,
302325
303326 obj->parentName = parentName;
304327 ctx.symtab .addFile (obj);
305- log ( " Loaded " + toString ( obj) + " for " + symName) ;
328+ Log (ctx) << " Loaded " << obj << " for " << symName;
306329}
307330
308331void LinkerDriver::enqueueArchiveMember (const Archive::Child &c,
309332 const Archive::Symbol &sym,
310333 StringRef parentName) {
311334
312335 auto reportBufferError = [=](Error &&e, StringRef childName) {
313- fatal ( " could not get the buffer for the member defining symbol " +
314- toCOFFString (ctx, sym) + " : " + parentName + " (" + childName +
315- " ): " + toString ( std::move (e)) );
336+ Fatal (ctx) << " could not get the buffer for the member defining symbol "
337+ << & sym << " : " << parentName << " (" << childName
338+ << " ): " << std::move (e);
316339 };
317340
318341 if (!c.getParent ()->isThin ()) {
@@ -361,7 +384,7 @@ void LinkerDriver::parseDirectives(InputFile *file) {
361384 if (s.empty ())
362385 return ;
363386
364- log ( " Directives: " + toString ( file) + " : " + s) ;
387+ Log (ctx) << " Directives: " << file << " : " << s ;
365388
366389 ArgParser parser (ctx);
367390 // .drectve is always tokenized using Windows shell rules.
@@ -414,7 +437,7 @@ void LinkerDriver::parseDirectives(InputFile *file) {
414437 break ;
415438 case OPT_entry:
416439 if (!arg->getValue ()[0 ])
417- fatal ( " missing entry point symbol name" ) ;
440+ Fatal (ctx) << " missing entry point symbol name" ;
418441 ctx.config .entry = addUndefined (mangle (arg->getValue ()), true );
419442 break ;
420443 case OPT_failifmismatch:
@@ -779,7 +802,7 @@ StringRef LinkerDriver::findDefaultEntry() {
779802 if (findUnderscoreMangle (" wWinMain" )) {
780803 if (!findUnderscoreMangle (" WinMain" ))
781804 return mangle (" wWinMainCRTStartup" );
782- warn ( " found both wWinMain and WinMain; using latter" ) ;
805+ Warn (ctx) << " found both wWinMain and WinMain; using latter" ;
783806 }
784807 return mangle (" WinMainCRTStartup" );
785808 }
@@ -2200,7 +2223,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22002223 config->incremental = false ;
22012224 }
22022225
2203- if (errorCount ( ))
2226+ if (errCount (ctx ))
22042227 return ;
22052228
22062229 std::set<sys::fs::UniqueID> wholeArchives;
@@ -2279,7 +2302,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22792302 stream << " " << path << " \n " ;
22802303 }
22812304
2282- message (buffer) ;
2305+ Msg (ctx) << buffer ;
22832306 }
22842307
22852308 // Process files specified as /defaultlib. These must be processed after
0 commit comments