1 //===- CompilerInvocation.h - Compiler Invocation Helper Data ---*- C -*-===//
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 #ifndef LLVM_FLANG_FRONTEND_COMPILERINVOCATION_H
9 #define LLVM_FLANG_FRONTEND_COMPILERINVOCATION_H
10 
11 #include "flang/Frontend/FrontendOptions.h"
12 #include "clang/Basic/Diagnostic.h"
13 #include "clang/Basic/DiagnosticOptions.h"
14 
15 namespace Fortran::frontend {
16 class CompilerInvocationBase {
17 public:
18   /// Options controlling the diagnostic engine.$
19   llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagnosticOpts_;
20 
21   CompilerInvocationBase();
22   CompilerInvocationBase(const CompilerInvocationBase &x);
23   ~CompilerInvocationBase();
24 
25   clang::DiagnosticOptions &GetDiagnosticOpts() {
26     return *diagnosticOpts_.get();
27   }
28   const clang::DiagnosticOptions &GetDiagnosticOpts() const {
29     return *diagnosticOpts_.get();
30   }
31 };
32 
33 class CompilerInvocation : public CompilerInvocationBase {
34   /// Options controlling the frontend itself.
35   FrontendOptions frontendOpts_;
36 
37 public:
38   CompilerInvocation() = default;
39 
40   FrontendOptions &GetFrontendOpts() { return frontendOpts_; }
41   const FrontendOptions &GetFrontendOpts() const { return frontendOpts_; }
42 
43   /// Create a compiler invocation from a list of input options.
44   /// \returns true on success.
45   /// \returns false if an error was encountered while parsing the arguments
46   /// \param [out] res - The resulting invocation.
47   static bool CreateFromArgs(CompilerInvocation &res,
48       llvm::ArrayRef<const char *> commandLineArgs,
49       clang::DiagnosticsEngine &diags);
50 };
51 
52 } // end namespace Fortran::frontend
53 #endif // LLVM_FLANG_FRONTEND_COMPILERINVOCATION_H
54