Skip to content

[flang] Move parser invocations into ParserActions #130309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions flang/include/flang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

#include "flang/Frontend/CompilerInvocation.h"
#include "flang/Frontend/FrontendAction.h"
#include "flang/Frontend/ParserActions.h"
#include "flang/Frontend/PreprocessorOptions.h"
#include "flang/Parser/parsing.h"
#include "flang/Parser/provenance.h"
#include "flang/Semantics/runtime-type-info.h"
#include "flang/Semantics/semantics.h"
#include "flang/Support/StringOstream.h"
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Frontend/CompilerInvocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "flang/Frontend/PreprocessorOptions.h"
#include "flang/Frontend/TargetOptions.h"
#include "flang/Lower/LoweringOptions.h"
#include "flang/Parser/parsing.h"
#include "flang/Parser/options.h"
#include "flang/Semantics/semantics.h"
#include "flang/Support/LangOptions.h"
#include "mlir/Support/Timing.h"
Expand All @@ -29,7 +29,7 @@

namespace llvm {
class TargetMachine;
}
} // namespace llvm

namespace Fortran::frontend {

Expand Down
19 changes: 1 addition & 18 deletions flang/include/flang/Frontend/FrontendActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
#ifndef FORTRAN_FRONTEND_FRONTENDACTIONS_H
#define FORTRAN_FRONTEND_FRONTENDACTIONS_H

#include "flang/Frontend/CodeGenOptions.h"
#include "flang/Frontend/FrontendAction.h"
#include "flang/Parser/parsing.h"
#include "flang/Semantics/semantics.h"
#include "flang/Frontend/ParserActions.h"

#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/OwningOpRef.h"
Expand All @@ -26,21 +24,6 @@

namespace Fortran::frontend {

// TODO: This is a copy from f18.cpp. It doesn't really belong here and should
// be moved to a more suitable place in future.
struct MeasurementVisitor {
template <typename A>
bool Pre(const A &) {
return true;
}
template <typename A>
void Post(const A &) {
++objects;
bytes += sizeof(A);
}
size_t objects{0}, bytes{0};
};

//===----------------------------------------------------------------------===//
// Custom Consumer Actions
//===----------------------------------------------------------------------===//
Expand Down
67 changes: 67 additions & 0 deletions flang/include/flang/Frontend/ParserActions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//===- ParserActions.h -------------------------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_PARSER_ACTIONS_H_
#define FORTRAN_PARSER_ACTIONS_H_

#include <string>

namespace llvm {
class raw_string_ostream;
class raw_ostream;
class StringRef;
} // namespace llvm

namespace Fortran::lower {
class LoweringBridge;
} // namespace Fortran::lower

namespace Fortran::parser {
class Parsing;
class AllCookedSources;
} // namespace Fortran::parser

namespace lower::pft {
class Program;
} // namespace lower::pft

//=== Frontend Parser helpers ===

namespace Fortran::frontend {
class CompilerInstance;

parser::AllCookedSources &getAllCooked(CompilerInstance &ci);

void parseAndLowerTree(CompilerInstance &ci, lower::LoweringBridge &lb);

void dumpTree(CompilerInstance &ci);

void dumpProvenance(CompilerInstance &ci);

void dumpPreFIRTree(CompilerInstance &ci);

void formatOrDumpPrescanner(std::string &buf,
llvm::raw_string_ostream &outForPP,
CompilerInstance &ci);

void debugMeasureParseTree(CompilerInstance &ci, llvm::StringRef filename);

void debugUnparseNoSema(CompilerInstance &ci, llvm::raw_ostream &out);

void debugUnparseWithSymbols(CompilerInstance &ci);

void debugUnparseWithModules(CompilerInstance &ci);

void debugDumpParsingLog(CompilerInstance &ci);
} // namespace Fortran::frontend

#endif // FORTRAN_PARSER_ACTIONS_H_
43 changes: 43 additions & 0 deletions flang/include/flang/Parser/options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===-- include/flang/Parser/options.h --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_PARSER_OPTIONS_H_
#define FORTRAN_PARSER_OPTIONS_H_

#include "characters.h"
#include "flang/Support/Fortran-features.h"

#include <optional>
#include <string>
#include <vector>

namespace Fortran::parser {

struct Options {
Options() {}

using Predefinition = std::pair<std::string, std::optional<std::string>>;

bool isFixedForm{false};
int fixedFormColumns{72};
common::LanguageFeatureControl features;
std::vector<std::string> searchDirectories;
std::vector<std::string> intrinsicModuleDirectories;
std::vector<Predefinition> predefinitions;
bool instrumentedParse{false};
bool isModuleFile{false};
bool needProvenanceRangeToCharBlockMappings{false};
Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8};
bool prescanAndReformat{false}; // -E
bool expandIncludeLinesInPreprocessedOutput{true};
bool showColors{false};
};

} // namespace Fortran::parser

#endif // FORTRAN_PARSER_OPTIONS_H_
25 changes: 1 addition & 24 deletions flang/include/flang/Parser/parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,18 @@
#ifndef FORTRAN_PARSER_PARSING_H_
#define FORTRAN_PARSER_PARSING_H_

#include "characters.h"
#include "instrumented-parser.h"
#include "message.h"
#include "options.h"
#include "parse-tree.h"
#include "provenance.h"
#include "flang/Parser/preprocessor.h"
#include "flang/Support/Fortran-features.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
#include <string>
#include <utility>
#include <vector>

namespace Fortran::parser {

struct Options {
Options() {}

using Predefinition = std::pair<std::string, std::optional<std::string>>;

bool isFixedForm{false};
int fixedFormColumns{72};
common::LanguageFeatureControl features;
std::vector<std::string> searchDirectories;
std::vector<std::string> intrinsicModuleDirectories;
std::vector<Predefinition> predefinitions;
bool instrumentedParse{false};
bool isModuleFile{false};
bool needProvenanceRangeToCharBlockMappings{false};
Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8};
bool prescanAndReformat{false}; // -E
bool expandIncludeLinesInPreprocessedOutput{true};
bool showColors{false};
};

class Parsing {
public:
explicit Parsing(AllCookedSources &);
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_flang_library(flangFrontend
CompilerInstance.cpp
CompilerInvocation.cpp
CodeGenOptions.cpp
ParserActions.cpp
FrontendAction.cpp
FrontendActions.cpp
FrontendOptions.cpp
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "flang/Frontend/FrontendActions.h"
#include "flang/Frontend/FrontendOptions.h"
#include "flang/Frontend/FrontendPluginRegistry.h"
#include "flang/Parser/parsing.h"
#include "clang/Basic/DiagnosticFrontend.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/VirtualFileSystem.h"
Expand Down
Loading