clang 17.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
20
21#include "llvm/ExecutionEngine/JITSymbol.h"
22#include "llvm/Support/Error.h"
23
24#include <memory>
25#include <vector>
26
27namespace llvm {
28namespace orc {
29class LLJIT;
30class ThreadSafeContext;
31}
32} // namespace llvm
33
34namespace clang {
35
36class CompilerInstance;
37class IncrementalExecutor;
38class IncrementalParser;
39
40/// Create a pre-configured \c CompilerInstance for incremental processing.
42public:
44 create(std::vector<const char *> &ClangArgv);
45};
46
47/// Provides top-level interfaces for incremental compilation and execution.
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
55public:
58 create(std::unique_ptr<CompilerInstance> CI);
60 const llvm::orc::LLJIT *getExecutionEngine() const;
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 /// Undo N previous incremental inputs.
73 llvm::Error Undo(unsigned N = 1);
74
75 /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses
76 /// the CodeGenModule's internal mangling cache to avoid recomputing the
77 /// mangled name.
79
80 /// \returns the \c JITTargetAddress of a given name as written in the IR.
82 getSymbolAddress(llvm::StringRef IRName) const;
83
84 /// \returns the \c JITTargetAddress of a given name as written in the object
85 /// file.
87 getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
88};
89} // namespace clang
90
91#endif // LLVM_CLANG_INTERPRETER_INTERPRETER_H
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
Create a pre-configured CompilerInstance for incremental processing.
Definition: Interpreter.h:41
static llvm::Expected< std::unique_ptr< CompilerInstance > > create(std::vector< const char * > &ClangArgv)
Provides top-level interfaces for incremental compilation and execution.
Definition: Interpreter.h:48
llvm::Error Execute(PartialTranslationUnit &T)
llvm::Expected< llvm::JITTargetAddress > getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const
const CompilerInstance * getCompilerInstance() const
const llvm::orc::LLJIT * getExecutionEngine() const
llvm::Expected< llvm::JITTargetAddress > getSymbolAddress(GlobalDecl GD) const
llvm::Error ParseAndExecute(llvm::StringRef Code)
Definition: Interpreter.h:63
static llvm::Expected< std::unique_ptr< Interpreter > > create(std::unique_ptr< CompilerInstance > CI)
llvm::Expected< PartialTranslationUnit & > Parse(llvm::StringRef Code)
llvm::Error Undo(unsigned N=1)
Undo N previous incremental inputs.
YAML serialization mapping.
Definition: Dominators.h:30
The class keeps track of various objects created as part of processing incremental inputs.