This patch adds support for generating MLIR files in Flang's frontend driver (i.e. `flang-new -fc1`). `-emit-fir` is added as an alias for `-emit-mlir`. We may want to decide to split the two in the future. A new parent class for code-gen frontend actions is introduced: `CodeGenAction`. We will be using this class to encapsulate logic shared between all code-generation actions, but not required otherwise. For now, it will: * run prescanning, parsing and semantic checks, * lower the input to MLIR. `EmitObjAction` is updated to inherit from this class. This means that the behaviour of `flang-new -fc1 -emit-obj` is also updated (previously, it would just exit immediately). This change required `flang/test/Driver/syntax-only.f90` to be updated. For `-emit-fir`, a specialisation of `CodeGenAction` is introduced: `EmitMLIRAction`. The key logic for this class is implemented in `EmitMLIRAction::ExecuteAction`. Differential Revision: https://reviews.llvm.org/D118985
28 lines
667 B
Fortran
28 lines
667 B
Fortran
! Test the `-emit-mlir` option
|
|
|
|
!-------------
|
|
! RUN COMMANDS
|
|
!-------------
|
|
! RUN: %flang_fc1 -emit-mlir %s -o - | FileCheck %s
|
|
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
|
|
|
|
! Verify that an `.mlir` file is created when `-emit-mlir` is used. Do it in a temporary directory, which will be cleaned up by the
|
|
! LIT runner.
|
|
! RUN: rm -rf %t-dir && mkdir -p %t-dir && cd %t-dir
|
|
! RUN: cp %s .
|
|
! RUN: %flang_fc1 -emit-mlir emit-mlir.f90 && ls emit-mlir.mlir
|
|
|
|
!----------------
|
|
! EXPECTED OUTPUT
|
|
!----------------
|
|
! CHECK: module attributes {
|
|
! CHECK-LABEL: func @_QQmain() {
|
|
! CHECK-NEXT: return
|
|
! CHECK-NEXT: }
|
|
! CHECK-NEXT: }
|
|
|
|
!------
|
|
! INPUT
|
|
!------
|
|
end program
|