[frontend] Implemented support for emitting serialized diagnostics.

Reworked the -serialize-diagnostics option, so that it is now just a flag
indicating that the frontend should generate serialized diagnostics. The path at
which the diagnostics will be serialized is now specified by the
-serialized-diagnostics-path option, which is a frontend-only option. (The
frontend treats -serialized-diagnostics-path as implying -serialize-diagnostics.)

If -serialize-diagnostics is passed but -serialized-diagnostics-path is not
passed, the frontend will choose an output path from a few default values:

- If the frontend has a non-stdout output path, replace that path's extension
  with .dia.
- If there is a primary input filename, use that input's base name as the base
  name for the serialized diagnostics file.
- Otherwise, use the module name as the base name for the serialized diagnostics
  file.

Added support for setting up a serialized diagnostics DiagnosticConsumer in
frontend_main() if FrontendOptions::SerializedDiagnosticsPath is non-empty.

Swift SVN r12251
This commit is contained in:
Connor Wakamo
2014-01-13 21:38:03 +00:00
parent 8b2ca31095
commit 00f076daa5
4 changed files with 63 additions and 8 deletions

View File

@@ -71,10 +71,6 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
Opts.OutputFilename = A->getValue();
}
if (const Arg *A = Args.getLastArg(OPT_serialize_diagnostics)) {
Opts.SerializedDiagnosticsPath = A->getValue();
}
if (Args.hasArg(OPT_emit_verbose_sil)) {
Opts.EmitVerboseSIL = true;
}
@@ -220,6 +216,33 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
Opts.ModuleName = ModuleName;
}
if (const Arg *A = Args.getLastArg(OPT_serialized_diagnostics_path)) {
// Claim -serialize-diagnostics, if present.
Args.ClaimAllArgs(OPT_serialize_diagnostics);
Opts.SerializedDiagnosticsPath = A->getValue();
} else if (Args.hasArg(OPT_serialize_diagnostics)) {
// -serialize-diagnostics has been passed without
// -serialized-diagnostics-path, so determine a path based on other inputs.
static const char *const DiagnosticsFilePathExtension = "dia";
StringRef OriginalPath;
if (!Opts.OutputFilename.empty() && Opts.OutputFilename != "-")
// Put the serialized diagnostics file next to the output file.
OriginalPath = Opts.OutputFilename;
else if (Opts.PrimaryInput.hasValue() && Opts.PrimaryInput->isFilename())
// We have a primary input, so use that as the basis for the name of the
// serialized diagnostics file.
OriginalPath = llvm::sys::path::filename(
Opts.InputFilenames[Opts.PrimaryInput->Index]);
else
// We don't have any better indication of name, so fall back on the
// module name.
OriginalPath = Opts.ModuleName;
llvm::SmallString<128> Path(OriginalPath);
llvm::sys::path::replace_extension(Path, DiagnosticsFilePathExtension);
Opts.SerializedDiagnosticsPath = Path.str();
}
return false;
}