diff --git a/src/dmd/cli.d b/src/dmd/cli.d index 0dfc0ba7abac..bcdfd0807fa8 100644 --- a/src/dmd/cli.d +++ b/src/dmd/cli.d @@ -282,8 +282,8 @@ struct Usage Option("unittest", "compile in unit tests" ), - Option("v", - "verbose" + Option("v[=file]", + "verbose with option to output to a file (defaults to stdout)" ), Option("vcolumns", "print character (column) numbers in diagnostics" diff --git a/src/dmd/dmodule.d b/src/dmd/dmodule.d index dd05e9b04f3b..edd4505204b1 100644 --- a/src/dmd/dmodule.d +++ b/src/dmd/dmodule.d @@ -527,16 +527,16 @@ extern (C++) final class Module : Package return null; if (global.params.verbose) { - fprintf(global.stdmsg, "import "); + fprintf(global.params.verbose, "import "); if (packages) { for (size_t i = 0; i < packages.dim; i++) { Identifier pid = (*packages)[i]; - fprintf(global.stdmsg, "%s.", pid.toChars()); + fprintf(global.params.verbose, "%s.", pid.toChars()); } } - fprintf(global.stdmsg, "%s\t(%s)\n", ident.toChars(), m.srcfile.toChars()); + fprintf(global.params.verbose, "%s\t(%s)\n", ident.toChars(), m.srcfile.toChars()); } m = m.parse(); diff --git a/src/dmd/dmsc.d b/src/dmd/dmsc.d index 6bf3cc4027a3..df55c4c35d41 100644 --- a/src/dmd/dmsc.d +++ b/src/dmd/dmsc.d @@ -111,7 +111,7 @@ void backend_init() exe, false, //params.trace, params.nofloat, - params.verbose, + params.verbose ? true : false, params.optimize, params.symdebug, params.alwaysframe, diff --git a/src/dmd/dsymbolsem.d b/src/dmd/dsymbolsem.d index c3ead1560fb4..261494cafb78 100644 --- a/src/dmd/dsymbolsem.d +++ b/src/dmd/dsymbolsem.d @@ -1358,7 +1358,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor memcpy(name, se.string, se.len); name[se.len] = 0; if (global.params.verbose) - fprintf(global.stdmsg, "library %s\n", name); + fprintf(global.params.verbose, "library %s\n", name); if (global.params.moduleDeps && !global.params.moduleDepsFile) { OutBuffer* ob = global.params.moduleDeps; @@ -1475,7 +1475,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor { /* Print unrecognized pragmas */ - fprintf(global.stdmsg, "pragma %s", pd.ident.toChars()); + fprintf(global.params.verbose, "pragma %s", pd.ident.toChars()); if (pd.args) { for (size_t i = 0; i < pd.args.dim; i++) @@ -1487,15 +1487,15 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor sc = sc.endCTFE(); e = e.ctfeInterpret(); if (i == 0) - fprintf(global.stdmsg, " ("); + fprintf(global.params.verbose, " ("); else - fprintf(global.stdmsg, ","); - fprintf(global.stdmsg, "%s", e.toChars()); + fprintf(global.params.verbose, ","); + fprintf(global.params.verbose, "%s", e.toChars()); } if (pd.args.dim) - fprintf(global.stdmsg, ")"); + fprintf(global.params.verbose, ")"); } - fprintf(global.stdmsg, "\n"); + fprintf(global.params.verbose, "\n"); } goto Lnodecl; } diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index e0aeb9097851..2aaecb86867b 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -4276,7 +4276,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor } if (global.params.verbose) - fprintf(global.stdmsg, "file %.*s\t(%s)\n", cast(int)se.len, se.string, name); + fprintf(global.params.verbose, "file %.*s\t(%s)\n", cast(int)se.len, se.string, name); if (global.params.moduleDeps !is null) { OutBuffer* ob = global.params.moduleDeps; diff --git a/src/dmd/globals.d b/src/dmd/globals.d index 10cc6191701b..334e9cd28ae5 100644 --- a/src/dmd/globals.d +++ b/src/dmd/globals.d @@ -78,7 +78,7 @@ struct Param bool oneobj; // write one object file instead of multiple ones bool trace; // insert profiling hooks bool tracegc; // instrument calls to 'new' - bool verbose; // verbose compile + FILE* verbose; // verbose compile bool vcg_ast; // write-out codegen-ast bool showColumns; // print character (column) numbers in diagnostics bool vtls; // identify thread local variables diff --git a/src/dmd/globals.h b/src/dmd/globals.h index 260de8b24429..539fb62fe9d7 100644 --- a/src/dmd/globals.h +++ b/src/dmd/globals.h @@ -70,7 +70,7 @@ struct Param bool oneobj; // write one object file instead of multiple ones bool trace; // insert profiling hooks bool tracegc; // instrument calls to 'new' - bool verbose; // verbose compile + FILE* verbose; // verbose compile bool vcg_ast; // write-out codegen-ast bool showColumns; // print character (column) numbers in diagnostics bool vtls; // identify thread local variables diff --git a/src/dmd/glue.d b/src/dmd/glue.d index 753048b296cf..7de56e135f25 100644 --- a/src/dmd/glue.d +++ b/src/dmd/glue.d @@ -323,8 +323,8 @@ void genObjFile(Module m, bool multiobj) if (m.ident == Id.entrypoint) { - bool v = global.params.verbose; - global.params.verbose = false; + auto v = global.params.verbose; + global.params.verbose = null; for (size_t i = 0; i < m.members.dim; i++) { @@ -807,7 +807,7 @@ void FuncDeclaration_toObjFile(FuncDeclaration fd, bool multiobj) fd.semanticRun = PASS.obj; if (global.params.verbose) - fprintf(global.stdmsg, "function %s\n", fd.toPrettyChars()); + fprintf(global.params.verbose, "function %s\n", fd.toPrettyChars()); Symbol *s = toSymbol(fd); func_t *f = s.Sfunc; diff --git a/src/dmd/inline.d b/src/dmd/inline.d index 4657695b9735..4a1c4a3b33f4 100644 --- a/src/dmd/inline.d +++ b/src/dmd/inline.d @@ -1276,7 +1276,7 @@ public: return; if (global.params.verbose && (eresult || sresult)) - fprintf(global.stdmsg, "inlined %s =>\n %s\n", fd.toPrettyChars(), parent.toPrettyChars()); + fprintf(global.params.verbose, "inlined %s =>\n %s\n", fd.toPrettyChars(), parent.toPrettyChars()); if (eresult && e.type.ty != Tvoid) { @@ -1706,7 +1706,7 @@ public void inlineScanModule(Module m) { Dsymbol s = (*m.members)[i]; //if (global.params.verbose) - // fprintf(global.stdmsg, "inline scan symbol %s\n", s.toChars()); + // fprintf(global.params.verbose, "inline scan symbol %s\n", s.toChars()); scope InlineScanVisitor v = new InlineScanVisitor(); s.accept(v); } diff --git a/src/dmd/json.d b/src/dmd/json.d index 4efe9f43c443..f6a8ef6ee32e 100644 --- a/src/dmd/json.d +++ b/src/dmd/json.d @@ -797,7 +797,7 @@ extern (C++) void json_generate(OutBuffer* buf, Modules* modules) { Module m = (*modules)[i]; if (global.params.verbose) - fprintf(global.stdmsg, "json gen %s\n", m.toChars()); + fprintf(global.params.verbose, "json gen %s\n", m.toChars()); m.accept(json); } json.arrayEnd(); diff --git a/src/dmd/lib.d b/src/dmd/lib.d index b514af6c3774..c09dca062fcd 100644 --- a/src/dmd/lib.d +++ b/src/dmd/lib.d @@ -103,7 +103,7 @@ class Library final void write() { if (global.params.verbose) - fprintf(global.stdmsg, "library %s\n", loc.filename); + fprintf(global.params.verbose, "library %s\n", loc.filename); OutBuffer libbuf; WriteLibToBuffer(&libbuf); diff --git a/src/dmd/link.d b/src/dmd/link.d index 598b83149704..b5110d524da6 100644 --- a/src/dmd/link.d +++ b/src/dmd/link.d @@ -671,8 +671,8 @@ public int runLINK() { // Print it for (size_t i = 0; i < argv.dim; i++) - fprintf(global.stdmsg, "%s ", argv[i]); - fprintf(global.stdmsg, "\n"); + fprintf(global.params.verbose, "%s ", argv[i]); + fprintf(global.params.verbose, "\n"); } argv.push(null); // set up pipes @@ -745,7 +745,7 @@ version (Windows) int status; size_t len; if (global.params.verbose) - fprintf(global.stdmsg, "%s %s\n", cmd, args); + fprintf(global.params.verbose, "%s %s\n", cmd, args); if (!global.params.mscoff) { if ((len = strlen(args)) > 255) @@ -808,7 +808,7 @@ version (Windows) } } //if (global.params.verbose) - // fprintf(global.stdmsg, "\n"); + // fprintf(global.params.verbose, "\n"); if (status) { if (status == -1) @@ -853,10 +853,10 @@ public int runProgram() //printf("runProgram()\n"); if (global.params.verbose) { - fprintf(global.stdmsg, "%s", global.params.exefile); + fprintf(global.params.verbose, "%s", global.params.exefile); for (size_t i = 0; i < global.params.runargs.dim; ++i) - fprintf(global.stdmsg, " %s", global.params.runargs[i]); - fprintf(global.stdmsg, "\n"); + fprintf(global.params.verbose, " %s", global.params.runargs[i]); + fprintf(global.params.verbose, "\n"); } // Build argv[] Strings argv; diff --git a/src/dmd/mars.d b/src/dmd/mars.d index f0913c7b37a4..7101e1ab4f96 100644 --- a/src/dmd/mars.d +++ b/src/dmd/mars.d @@ -143,8 +143,8 @@ extern (C++) void genCmain(Scope* sc) m.members = p.parseModule(); assert(p.token.value == TOKeof); assert(!p.errors); // shouldn't have failed to parse it - bool v = global.params.verbose; - global.params.verbose = false; + auto v = global.params.verbose; + global.params.verbose = null; m.importedFrom = m; m.importAll(null); m.dsymbolSemantic(null); @@ -474,9 +474,9 @@ private int tryMain(size_t argc, const(char)** argv) if (global.params.verbose) { - fprintf(global.stdmsg, "binary %s\n", global.params.argv0); - fprintf(global.stdmsg, "version %s\n", global._version); - fprintf(global.stdmsg, "config %s\n", global.inifilename ? global.inifilename : "(none)"); + fprintf(global.params.verbose, "binary %s\n", global.params.argv0); + fprintf(global.params.verbose, "version %s\n", global._version); + fprintf(global.params.verbose, "config %s\n", global.inifilename ? global.inifilename : "(none)"); } //printf("%d source files\n",files.dim); @@ -668,7 +668,7 @@ private int tryMain(size_t argc, const(char)** argv) { Module m = modules[modi]; if (global.params.verbose) - fprintf(global.stdmsg, "parse %s\n", m.toChars()); + fprintf(global.params.verbose, "parse %s\n", m.toChars()); if (!Module.rootModule) Module.rootModule = m; m.importedFrom = m; // m.isRoot() == true @@ -725,7 +725,7 @@ private int tryMain(size_t argc, const(char)** argv) foreach (m; modules) { if (global.params.verbose) - fprintf(global.stdmsg, "import %s\n", m.toChars()); + fprintf(global.params.verbose, "import %s\n", m.toChars()); genhdrfile(m); } } @@ -736,7 +736,7 @@ private int tryMain(size_t argc, const(char)** argv) foreach (m; modules) { if (global.params.verbose) - fprintf(global.stdmsg, "importall %s\n", m.toChars()); + fprintf(global.params.verbose, "importall %s\n", m.toChars()); m.importAll(null); } if (global.errors) @@ -748,7 +748,7 @@ private int tryMain(size_t argc, const(char)** argv) foreach (m; modules) { if (global.params.verbose) - fprintf(global.stdmsg, "semantic %s\n", m.toChars()); + fprintf(global.params.verbose, "semantic %s\n", m.toChars()); m.dsymbolSemantic(null); } //if (global.errors) @@ -769,7 +769,7 @@ private int tryMain(size_t argc, const(char)** argv) foreach (m; modules) { if (global.params.verbose) - fprintf(global.stdmsg, "semantic2 %s\n", m.toChars()); + fprintf(global.params.verbose, "semantic2 %s\n", m.toChars()); m.semantic2(null); } Module.runDeferredSemantic2(); @@ -780,19 +780,19 @@ private int tryMain(size_t argc, const(char)** argv) foreach (m; modules) { if (global.params.verbose) - fprintf(global.stdmsg, "semantic3 %s\n", m.toChars()); + fprintf(global.params.verbose, "semantic3 %s\n", m.toChars()); m.semantic3(null); } if (includeImports) { - // Note: DO NOT USE foreach here because Module.amodules.dim can + // Note: DO NOT USE foreach here because compiledImports.dim can // change on each iteration of the loop for (size_t i = 0; i < compiledImports.dim; i++) { auto m = compiledImports[i]; assert(m.isRoot); if (global.params.verbose) - fprintf(global.stdmsg, "semantic3 %s\n", m.toChars()); + fprintf(global.params.verbose, "semantic3 %s\n", m.toChars()); m.semantic3(null); modules.push(m); } @@ -807,7 +807,7 @@ private int tryMain(size_t argc, const(char)** argv) foreach (m; modules) { if (global.params.verbose) - fprintf(global.stdmsg, "inline scan %s\n", m.toChars()); + fprintf(global.params.verbose, "inline scan %s\n", m.toChars()); inlineScanModule(m); } } @@ -926,7 +926,7 @@ private int tryMain(size_t argc, const(char)** argv) foreach (m; modules) { if (global.params.verbose) - fprintf(global.stdmsg, "code %s\n", m.toChars()); + fprintf(global.params.verbose, "code %s\n", m.toChars()); genObjFile(m, false); if (entrypoint && m == rootHasMain) genObjFile(entrypoint, false); @@ -941,7 +941,7 @@ private int tryMain(size_t argc, const(char)** argv) foreach (m; modules) { if (global.params.verbose) - fprintf(global.stdmsg, "code %s\n", m.toChars()); + fprintf(global.params.verbose, "code %s\n", m.toChars()); obj_start(cast(char*)m.srcfile.toChars()); genObjFile(m, global.params.multiobj); if (entrypoint && m == rootHasMain) @@ -1339,11 +1339,11 @@ private void printPredefinedVersions() { if (global.params.verbose && global.versionids) { - fprintf(global.stdmsg, "predefs "); + fprintf(global.params.verbose, "predefs "); foreach (const str; *global.versionids) - fprintf(global.stdmsg, " %s", str.toChars); + fprintf(global.params.verbose, " %s", str.toChars); - fprintf(global.stdmsg, "\n"); + fprintf(global.params.verbose, "\n"); } } @@ -1415,9 +1415,9 @@ private bool parseCommandLine(const ref Strings arguments, const size_t argc, re { bool errors; - void error(const(char)* format, const(char*) arg = null) + void error(T...)(const(char)* format, T args) { - dmd.errors.error(Loc(), format, arg); + dmd.errors.error(Loc(), format, args); errors = true; } @@ -1630,8 +1630,6 @@ private bool parseCommandLine(const ref Strings arguments, const size_t argc, re else params.trace = true; } - else if (arg == "-v") // https://dlang.org/dmd.html#switch-v - params.verbose = true; else if (arg == "-vcg-ast") params.vcg_ast = true; else if (arg == "-vtls") // https://dlang.org/dmd.html#switch-vtls @@ -1640,6 +1638,24 @@ private bool parseCommandLine(const ref Strings arguments, const size_t argc, re params.showColumns = true; else if (arg == "-vgc") // https://dlang.org/dmd.html#switch-vgc params.vgc = true; + else if (p[1] == 'v') // https://dlang.org/dmd.html#switch-v + { + if (p[2] == '\0') + { + params.verbose = stdout; + } + else + { + auto filename = p + 2 + ((p[2] == '=') ? 1 : 0); + params.verbose = fopen(filename, "w"); + if (!params.verbose) + { + import core.stdc.errno : errno; + error("failed to open verbose output file '%s' (errno %d)", filename, errno); + return true; + } + } + } else if (startsWith(p + 1, "verrors")) // https://dlang.org/dmd.html#switch-verrors { if (p[8] == '=' && isdigit(cast(char)p[9])) @@ -2175,7 +2191,7 @@ private extern(C++) bool marsOnImport(Module m) (m.md && m.md.packages) ? m.md.packages : &empty, m.ident, m.isPackageFile))) { if (global.params.verbose) - fprintf(global.stdmsg, "compileimport (%s)\n", m.srcfile.toChars); + fprintf(global.params.verbose, "compileimport (%s)\n", m.srcfile.toChars); compiledImports.push(m); return true; // this import will be compiled } diff --git a/src/dmd/statementsem.d b/src/dmd/statementsem.d index 9eaa42351171..41b4adebf823 100644 --- a/src/dmd/statementsem.d +++ b/src/dmd/statementsem.d @@ -2247,7 +2247,7 @@ else if (global.params.verbose) { - fprintf(global.stdmsg, "library %.*s\n", cast(int)se.len, se.string); + fprintf(global.params.verbose, "library %.*s\n", cast(int)se.len, se.string); } } }