[all-commits] [llvm/llvm-project] fd21d1: [flang] Refine output file generation

Andrzej WarzyƄski via All-commits all-commits at lists.llvm.org
Thu Aug 19 23:47:01 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fd21d1e198e381a2b9e7af1701044462b2d386cd
      https://github.com/llvm/llvm-project/commit/fd21d1e198e381a2b9e7af1701044462b2d386cd
  Author: Andrzej Warzynski <andrzej.warzynski at arm.com>
  Date:   2021-08-20 (Fri, 20 Aug 2021)

  Changed paths:
    M flang/include/flang/Frontend/CompilerInstance.h
    M flang/lib/Frontend/CompilerInstance.cpp
    M flang/lib/Frontend/FrontendActions.cpp
    A flang/test/Driver/output-paths.f90

  Log Message:
  -----------
  [flang] Refine output file generation

This patch refactors the file generation API in Flang's frontend driver.
It improves the layering between `CreateDefaultOutputFile`,
`CreateOutputFile` (`CompilerInstance` methods) and their various
clients.

List of changes:
* Rename `CreateOutputFile` as `CreateOutputFileImpl` and make it
private. This method is an implementation detail.
* Instead of passing an `std::error_code` out parameter into
`CreateOutputFileImpl`, have it return Expected<>. This is a bit shorter
and more idiomatic LLVM.
* Make `CreateDefaultOutputFile` (which calls `CreateOutputFileImpl`)
issue an error when file creation fails. The error code from
`CreateOutputFileImpl` is used to generate a meaningful diagnostic
message.
* Remove error reporting from `PrintPreprocessedAction::ExecuteAction`.
This is only for cases when output file generation fails. This is
handled in `CreateDefaultOutputFile` instead (see the previous point).
* Inline `AddOutputFile` into its only caller,
`CreateDefaultOutputFile`.
* Switch from `lvm::buffer_ostream` to `llvm::buffer_unique_ostream>`
for non-seekable output streams. This simplifies the logic in the driver
and was introduced for this very reason in [1]
* Moke sure that the diagnostics from the prescanner when running `-E`
(`PrintPreprocessedAction::ExecuteAction`) are printed before the actual
output is generated.
* Update comments, add test.

[1] https://reviews.llvm.org/D93260

Differential Revision: https://reviews.llvm.org/D108390




More information about the All-commits mailing list