[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / flang / tools / flang-driver / fc1_main.cpp
blobb5b062aaac26719a7aa676517ad3c8142ded486d
1 //===-- fc1_main.cpp - Flang FC1 Compiler Frontend ------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This is the entry point to the flang -fc1 functionality, which implements the
10 // core compiler functionality along with a number of additional tools for
11 // demonstration and testing purposes.
13 //===----------------------------------------------------------------------===//
15 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
17 //===----------------------------------------------------------------------===//
19 #include "flang/Frontend/CompilerInstance.h"
20 #include "flang/Frontend/CompilerInvocation.h"
21 #include "flang/Frontend/TextDiagnosticBuffer.h"
22 #include "flang/FrontendTool/Utils.h"
23 #include "clang/Driver/DriverDiagnostic.h"
24 #include "llvm/Option/Arg.h"
25 #include "llvm/Option/ArgList.h"
26 #include "llvm/Option/OptTable.h"
27 #include "llvm/Support/TargetSelect.h"
29 #include <cstdio>
31 using namespace Fortran::frontend;
33 int fc1_main(llvm::ArrayRef<const char *> argv, const char *argv0) {
34 // Create CompilerInstance
35 std::unique_ptr<CompilerInstance> flang(new CompilerInstance());
37 // Create DiagnosticsEngine for the frontend driver
38 flang->createDiagnostics();
39 if (!flang->hasDiagnostics())
40 return 1;
42 // We will buffer diagnostics from argument parsing so that we can output
43 // them using a well formed diagnostic object.
44 TextDiagnosticBuffer *diagsBuffer = new TextDiagnosticBuffer;
46 // Create CompilerInvocation - use a dedicated instance of DiagnosticsEngine
47 // for parsing the arguments
48 llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID(
49 new clang::DiagnosticIDs());
50 llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts =
51 new clang::DiagnosticOptions();
52 clang::DiagnosticsEngine diags(diagID, &*diagOpts, diagsBuffer);
53 bool success = CompilerInvocation::createFromArgs(flang->getInvocation(),
54 argv, diags, argv0);
56 // Initialize targets first, so that --version shows registered targets.
57 llvm::InitializeAllTargets();
58 llvm::InitializeAllTargetMCs();
59 llvm::InitializeAllAsmPrinters();
61 diagsBuffer->flushDiagnostics(flang->getDiagnostics());
63 if (!success)
64 return 1;
66 // Execute the frontend actions.
67 success = executeCompilerInvocation(flang.get());
69 // Delete output files to free Compiler Instance
70 flang->clearOutputFiles(/*EraseFiles=*/false);
72 return !success;