clang  15.0.0git
Interpreter.h
Go to the documentation of this file.
1 //===--- Interpreter.h - Incremental Compilation and Execution---*- 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 //
9 // This file defines the component which performs incremental code
10 // compilation and execution.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H
15 #define LLVM_CLANG_INTERPRETER_INTERPRETER_H
16 
18 
19 #include "clang/AST/GlobalDecl.h"
20 
21 #include "llvm/ExecutionEngine/JITSymbol.h"
22 #include "llvm/Support/Error.h"
23 
24 #include <memory>
25 #include <vector>
26 
27 namespace llvm {
28 namespace orc {
29 class LLJIT;
30 class ThreadSafeContext;
31 }
32 } // namespace llvm
33 
34 namespace clang {
35 
36 class CompilerInstance;
37 class IncrementalExecutor;
38 class IncrementalParser;
39 
40 /// Create a pre-configured \c CompilerInstance for incremental processing.
42 public:
44  create(std::vector<const char *> &ClangArgv);
45 };
46 
47 /// Provides top-level interfaces for incremental compilation and execution.
48 class Interpreter {
49  std::unique_ptr<llvm::orc::ThreadSafeContext> TSCtx;
50  std::unique_ptr<IncrementalParser> IncrParser;
51  std::unique_ptr<IncrementalExecutor> IncrExecutor;
52 
53  Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err);
54 
55 public:
56  ~Interpreter();
58  create(std::unique_ptr<CompilerInstance> CI);
60  const llvm::orc::LLJIT *getExecutionEngine() const;
61  llvm::Expected<PartialTranslationUnit &> Parse(llvm::StringRef Code);
62  llvm::Error Execute(PartialTranslationUnit &T);
63  llvm::Error ParseAndExecute(llvm::StringRef Code) {
64  auto PTU = Parse(Code);
65  if (!PTU)
66  return PTU.takeError();
67  if (PTU->TheModule)
68  return Execute(*PTU);
69  return llvm::Error::success();
70  }
71 
72  /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses
73  /// the CodeGenModule's internal mangling cache to avoid recomputing the
74  /// mangled name.
76 
77  /// \returns the \c JITTargetAddress of a given name as written in the IR.
79  getSymbolAddress(llvm::StringRef IRName) const;
80 
81  /// \returns the \c JITTargetAddress of a given name as written in the object
82  /// file.
84  getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
85 };
86 } // namespace clang
87 
88 #endif // LLVM_CLANG_INTERPRETER_INTERPRETER_H
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::Interpreter::Parse
llvm::Expected< PartialTranslationUnit & > Parse(llvm::StringRef Code)
Definition: Interpreter.cpp:206
clang::Interpreter::getSymbolAddressFromLinkerName
llvm::Expected< llvm::JITTargetAddress > getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const
Definition: Interpreter.cpp:252
llvm::Expected
Definition: LLVM.h:41
PartialTranslationUnit.h
clang::Interpreter::getCompilerInstance
const CompilerInstance * getCompilerInstance() const
Definition: Interpreter.cpp:195
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
clang::Interpreter
Provides top-level interfaces for incremental compilation and execution.
Definition: Interpreter.h:48
clang::Interpreter::ParseAndExecute
llvm::Error ParseAndExecute(llvm::StringRef Code)
Definition: Interpreter.h:63
clang::IncrementalCompilerBuilder
Create a pre-configured CompilerInstance for incremental processing.
Definition: Interpreter.h:41
clang::Interpreter::getSymbolAddress
llvm::Expected< llvm::JITTargetAddress > getSymbolAddress(GlobalDecl GD) const
Definition: Interpreter.cpp:232
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:72
clang::IncrementalCompilerBuilder::create
static llvm::Expected< std::unique_ptr< CompilerInstance > > create(std::vector< const char * > &ClangArgv)
Definition: Interpreter.cpp:125
clang::Interpreter::getExecutionEngine
const llvm::orc::LLJIT * getExecutionEngine() const
Definition: Interpreter.cpp:199
clang::Interpreter::Execute
llvm::Error Execute(PartialTranslationUnit &T)
Definition: Interpreter.cpp:210
clang
Definition: CalledOnceCheck.h:17
clang::Interpreter::~Interpreter
~Interpreter()
Definition: Interpreter.cpp:183
clang::PartialTranslationUnit
The class keeps track of various objects created as part of processing incremental inputs.
Definition: PartialTranslationUnit.h:29
GlobalDecl.h
clang::Interpreter::create
static llvm::Expected< std::unique_ptr< Interpreter > > create(std::unique_ptr< CompilerInstance > CI)
Definition: Interpreter.cpp:186