diff options
author | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2022-04-29 17:36:26 +0000 |
---|---|---|
committer | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2022-05-14 10:27:06 +0000 |
commit | 1e462fafdf8be70137c8eaf856f4eb886f8b4d4c (patch) | |
tree | d64943482d513c786e2abeb877d9ca79c595e121 /flang/lib/FrontendTool | |
parent | cc88212d817ca4e16a90668e85f16526da16bc5e (diff) | |
download | llvm-1e462fafdf8be70137c8eaf856f4eb886f8b4d4c.zip llvm-1e462fafdf8be70137c8eaf856f4eb886f8b4d4c.tar.gz llvm-1e462fafdf8be70137c8eaf856f4eb886f8b4d4c.tar.bz2 |
[flang][driver] Switch to the MLIR coding style in the driver (nfc)
This patch re-factors the driver code in LLVM Flang (frontend +
compiler) to use the MLIR style. For more context, please see:
https://discourse.llvm.org/t/rfc-coding-style-in-the-driver/
Most changes here are rather self-explanatory. Accessors are renamed to
be more consistent with the rest of LLVM (e.g. allSource -->
getAllSources). Additionally, MLIR clang-tidy files are added in the
affected directories.
clang-tidy and clang-format files were copied from MLIR. Small
additional changes are made to silence clang-tidy/clang-format
warnings.
[1] https://mlir.llvm.org/getting_started/DeveloperGuide/
Differential Revision: https://reviews.llvm.org/D125007
Diffstat (limited to 'flang/lib/FrontendTool')
-rw-r--r-- | flang/lib/FrontendTool/.clang-format | 2 | ||||
-rw-r--r-- | flang/lib/FrontendTool/.clang-tidy | 9 | ||||
-rw-r--r-- | flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp | 57 |
3 files changed, 42 insertions, 26 deletions
diff --git a/flang/lib/FrontendTool/.clang-format b/flang/lib/FrontendTool/.clang-format new file mode 100644 index 0000000..a74fda4 --- /dev/null +++ b/flang/lib/FrontendTool/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: LLVM +AlwaysBreakTemplateDeclarations: Yes diff --git a/flang/lib/FrontendTool/.clang-tidy b/flang/lib/FrontendTool/.clang-tidy new file mode 100644 index 0000000..9a0c8a6 --- /dev/null +++ b/flang/lib/FrontendTool/.clang-tidy @@ -0,0 +1,9 @@ +Checks: '-readability-braces-around-statements,readability-identifier-naming,llvm-include-order,clang-diagnostic-*' +InheritParentConfig: true +CheckOptions: + - key: readability-identifier-naming.MemberCase + value: camelBack + - key: readability-identifier-naming.ParameterCase + value: camelBack + - key: readability-identifier-naming.VariableCase + value: camelBack diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 7aef815..a797fd5 100644 --- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -10,24 +10,29 @@ // minimize the impact of pulling in essentially everything else in Flang. // //===----------------------------------------------------------------------===// +// +// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ +// +//===----------------------------------------------------------------------===// #include "flang/Frontend/CompilerInstance.h" #include "flang/Frontend/FrontendActions.h" #include "flang/Frontend/FrontendPluginRegistry.h" + +#include "mlir/IR/MLIRContext.h" +#include "mlir/Pass/PassManager.h" #include "clang/Driver/Options.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" #include "llvm/Support/BuryPointer.h" #include "llvm/Support/CommandLine.h" -#include "mlir/IR/MLIRContext.h" -#include "mlir/Pass/PassManager.h" namespace Fortran::frontend { -static std::unique_ptr<FrontendAction> CreateFrontendAction( - CompilerInstance &ci) { +static std::unique_ptr<FrontendAction> +createFrontendAction(CompilerInstance &ci) { - switch (ci.frontendOpts().programAction) { + switch (ci.getFrontendOpts().programAction) { case InputOutputTest: return std::make_unique<InputOutputTestAction>(); case PrintPreprocessedInput: @@ -77,14 +82,14 @@ static std::unique_ptr<FrontendAction> CreateFrontendAction( case PluginAction: { for (const FrontendPluginRegistry::entry &plugin : FrontendPluginRegistry::entries()) { - if (plugin.getName() == ci.frontendOpts().ActionName) { + if (plugin.getName() == ci.getFrontendOpts().actionName) { std::unique_ptr<PluginParseTreeAction> p(plugin.instantiate()); return std::move(p); } } - unsigned diagID = ci.diagnostics().getCustomDiagID( + unsigned diagID = ci.getDiagnostics().getCustomDiagID( clang::DiagnosticsEngine::Error, "unable to find plugin '%0'"); - ci.diagnostics().Report(diagID) << ci.frontendOpts().ActionName; + ci.getDiagnostics().Report(diagID) << ci.getFrontendOpts().actionName; return nullptr; } } @@ -92,9 +97,9 @@ static std::unique_ptr<FrontendAction> CreateFrontendAction( llvm_unreachable("Invalid program action!"); } -bool ExecuteCompilerInvocation(CompilerInstance *flang) { +bool executeCompilerInvocation(CompilerInstance *flang) { // Honor -help. - if (flang->frontendOpts().showHelp) { + if (flang->getFrontendOpts().showHelp) { clang::driver::getDriverOptTable().printHelp(llvm::outs(), "flang-new -fc1 [options] file...", "LLVM 'Flang' Compiler", /*Include=*/clang::driver::options::FC1Option, @@ -104,61 +109,61 @@ bool ExecuteCompilerInvocation(CompilerInstance *flang) { } // Honor -version. - if (flang->frontendOpts().showVersion) { + if (flang->getFrontendOpts().showVersion) { llvm::cl::PrintVersionMessage(); return true; } // Load any requested plugins. - for (const std::string &Path : flang->frontendOpts().plugins) { - std::string Error; - if (llvm::sys::DynamicLibrary::LoadLibraryPermanently( - Path.c_str(), &Error)) { - unsigned diagID = flang->diagnostics().getCustomDiagID( + for (const std::string &path : flang->getFrontendOpts().plugins) { + std::string error; + if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(path.c_str(), + &error)) { + unsigned diagID = flang->getDiagnostics().getCustomDiagID( clang::DiagnosticsEngine::Error, "unable to load plugin '%0': '%1'"); - flang->diagnostics().Report(diagID) << Path << Error; + flang->getDiagnostics().Report(diagID) << path << error; } } // Honor -mllvm. This should happen AFTER plugins have been loaded! - if (!flang->frontendOpts().llvmArgs.empty()) { - unsigned numArgs = flang->frontendOpts().llvmArgs.size(); + if (!flang->getFrontendOpts().llvmArgs.empty()) { + unsigned numArgs = flang->getFrontendOpts().llvmArgs.size(); auto args = std::make_unique<const char *[]>(numArgs + 2); args[0] = "flang (LLVM option parsing)"; for (unsigned i = 0; i != numArgs; ++i) - args[i + 1] = flang->frontendOpts().llvmArgs[i].c_str(); + args[i + 1] = flang->getFrontendOpts().llvmArgs[i].c_str(); args[numArgs + 1] = nullptr; llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get()); } // Honor -mmlir. This should happen AFTER plugins have been loaded! - if (!flang->frontendOpts().mlirArgs.empty()) { + if (!flang->getFrontendOpts().mlirArgs.empty()) { mlir::registerMLIRContextCLOptions(); mlir::registerPassManagerCLOptions(); - unsigned numArgs = flang->frontendOpts().mlirArgs.size(); + unsigned numArgs = flang->getFrontendOpts().mlirArgs.size(); auto args = std::make_unique<const char *[]>(numArgs + 2); args[0] = "flang (MLIR option parsing)"; for (unsigned i = 0; i != numArgs; ++i) - args[i + 1] = flang->frontendOpts().mlirArgs[i].c_str(); + args[i + 1] = flang->getFrontendOpts().mlirArgs[i].c_str(); args[numArgs + 1] = nullptr; llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get()); } // If there were errors in processing arguments, don't do anything else. - if (flang->diagnostics().hasErrorOccurred()) { + if (flang->getDiagnostics().hasErrorOccurred()) { return false; } // Create and execute the frontend action. - std::unique_ptr<FrontendAction> act(CreateFrontendAction(*flang)); + std::unique_ptr<FrontendAction> act(createFrontendAction(*flang)); if (!act) return false; - bool success = flang->ExecuteAction(*act); + bool success = flang->executeAction(*act); return success; } |