[flang][driver] Add support for `-fget-symbols-sources`

Adds support for `-fget-symbols-sources` in the new Flang driver. All
relevant tests are updated to use the new driver when
`FLANG_BUILD_NEW_DRIVER` is set.

`RUN` lines in tests are updated so `-fsyntax-only`
comes before `-fget-symbols-sources`. That's because:
  * both `-fsyntax-only` and `-fget-symbols-sources` are
    action flags, and
  * the new driver, flang-new, will only consider the right-most
    action flag.
In other words, this change is needed so that the tests work with both
`f18` (requires both flags) and `flang-new` (only considers the last
action flag).

Differential Revision: https://reviews.llvm.org/D98191
This commit is contained in:
Andrzej Warzynski 2021-03-08 16:54:11 +00:00
parent e6ce0db378
commit eefda605fe
12 changed files with 34 additions and 8 deletions

View File

@ -4364,6 +4364,8 @@ def fdebug_pre_fir_tree : Flag<["-"], "fdebug-pre-fir-tree">, Group<Action_Group
HelpText<"Dump the pre-FIR tree">;
def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">,
HelpText<"Enable debug messages while writing module files">;
def fget_symbols_sources : Flag<["-"], "fget-symbols-sources">, Group<Action_Group>,
HelpText<"Dump symbols and their source code locations">;
}

View File

@ -100,6 +100,10 @@ class DebugPreFIRTreeAction : public PrescanAndSemaAction {
void ExecuteAction() override;
};
class GetSymbolsSourcesAction : public PrescanAndSemaAction {
void ExecuteAction() override;
};
class ParseSyntaxOnlyAction : public PrescanAndSemaAction {
void ExecuteAction() override;
};

View File

@ -58,7 +58,10 @@ enum ActionKind {
DebugMeasureParseTree,
/// Parse, run semantics and then output the pre-FIR tree
DebugPreFIRTree
DebugPreFIRTree,
/// Parse, run semantics and then dump symbol sources map
GetSymbolsSources
/// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
/// EmitCodeGenOnly, EmitAssembly, (...)

View File

@ -143,6 +143,9 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts,
case clang::driver::options::OPT_fdebug_pre_fir_tree:
opts.programAction_ = DebugPreFIRTree;
break;
case clang::driver::options::OPT_fget_symbols_sources:
opts.programAction_ = GetSymbolsSources;
break;
// TODO:
// case calng::driver::options::OPT_emit_llvm:

View File

@ -16,6 +16,7 @@
#include "flang/Parser/provenance.h"
#include "flang/Parser/source.h"
#include "flang/Parser/unparse.h"
#include "flang/Semantics/runtime-type-info.h"
#include "flang/Semantics/semantics.h"
#include "flang/Semantics/unparse-with-symbols.h"
#include "llvm/ADT/StringRef.h"
@ -314,6 +315,15 @@ void DebugDumpParsingLogAction::ExecuteAction() {
ci.parsing().DumpParsingLog(llvm::outs());
}
void GetSymbolsSourcesAction::ExecuteAction() {
// Report and exit if fatal semantic errors are present
if (reportFatalSemanticErrors(semantics(), this->instance().diagnostics(),
GetCurrentFileOrBufferName()))
return;
semantics().DumpSymbolsSources(llvm::outs());
}
void EmitObjAction::ExecuteAction() {
CompilerInstance &ci = this->instance();
unsigned DiagID = ci.diagnostics().getCustomDiagID(

View File

@ -61,6 +61,9 @@ static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
case DebugPreFIRTree:
return std::make_unique<DebugPreFIRTreeAction>();
break;
case GetSymbolsSources:
return std::make_unique<GetSymbolsSourcesAction>();
break;
default:
break;
// TODO:

View File

@ -80,6 +80,7 @@
! HELP-FC1-NEXT: -ffixed-line-length=<value>
! HELP-FC1-NEXT: Use <value> as character line width in fixed mode
! HELP-FC1-NEXT: -ffree-form Process source files in free form
! HELP-FC1-NEXT: -fget-symbols-sources Dump symbols and their source code locations
! HELP-FC1-NEXT: -fimplicit-none No implicit typing allowed unless overridden by IMPLICIT statements
! HELP-FC1-NEXT: -finput-charset=<value> Specify the default character set for source files
! HELP-FC1-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics

View File

@ -15,7 +15,7 @@ contains
end function
end module
! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
! RUN: %flang_fc1 -fsyntax-only -fget-symbols-sources %s 2>&1 | FileCheck %s
! CHECK-COUNT-1:f:{{.*}}getsymbols01.f90, 12, 26-27
! CHECK-COUNT-1:mm1:{{.*}}getsymbols01.f90, 2, 8-11
! CHECK-COUNT-1:s:{{.*}}getsymbols01.f90, 5, 18-19

View File

@ -7,8 +7,8 @@ PROGRAM helloworld
i = callget5()
ENDPROGRAM
! RUN: %f18 -fsyntax-only %S/Inputs/getsymbols02-a.f90
! RUN: %f18 -fsyntax-only %S/Inputs/getsymbols02-b.f90
! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
! RUN: %flang_fc1 -fsyntax-only %S/Inputs/getsymbols02-a.f90
! RUN: %flang_fc1 -fsyntax-only %S/Inputs/getsymbols02-b.f90
! RUN: %flang_fc1 -fsyntax-only -fget-symbols-sources %s 2>&1 | FileCheck %s
! CHECK: callget5: .{{[/\\]}}mm2b.mod,
! CHECK: get5: .{{[/\\]}}mm2a.mod,

View File

@ -7,7 +7,7 @@ program main
x = f
end program
! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
! RUN: %flang_fc1 -fsyntax-only -fget-symbols-sources %s 2>&1 | FileCheck %s
! CHECK:f:{{.*}}getsymbols03-b.f90, 2, 12-13
! CHECK:main:{{.*}}getsymbols03-a.f90, 4, 9-13
! CHECK:mm3:{{.*}}getsymbols03-a.f90, 5, 6-9

View File

@ -6,7 +6,7 @@ program main
x = y
end program
! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
! RUN: %flang_fc1 -fsyntax-only -fget-symbols-sources %s 2>&1 | FileCheck %s
! CHECK:x:{{.*}}getsymbols04.f90, 3, 14-15
! CHECK:x:{{.*}}getsymbols04.f90, 5, 11-12
! CHECK:y:{{.*}}getsymbols04.f90, 4, 14-15

View File

@ -9,7 +9,7 @@ program main
x = y
end program
! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
! RUN: %flang_fc1 -fsyntax-only -fget-symbols-sources %s 2>&1 | FileCheck %s
! CHECK:x:{{.*}}getsymbols05.f90, 3, 14-15
! CHECK:x:{{.*}}getsymbols05.f90, 6, 16-17
! CHECK:y:{{.*}}getsymbols05.f90, 4, 14-15