Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Interpreter/Interpreter.h
Line
Count
Source (jump to first uncovered line)
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
17
#include "clang/Interpreter/PartialTranslationUnit.h"
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 ThreadSafeContext;
30
}
31
} // namespace llvm
32
33
namespace clang {
34
35
class CompilerInstance;
36
class IncrementalExecutor;
37
class IncrementalParser;
38
39
/// Create a pre-configured \c CompilerInstance for incremental processing.
40
class IncrementalCompilerBuilder {
41
public:
42
  static llvm::Expected<std::unique_ptr<CompilerInstance>>
43
  create(std::vector<const char *> &ClangArgv);
44
};
45
46
/// Provides top-level interfaces for incremental compilation and execution.
47
class Interpreter {
48
  std::unique_ptr<llvm::orc::ThreadSafeContext> TSCtx;
49
  std::unique_ptr<IncrementalParser> IncrParser;
50
  std::unique_ptr<IncrementalExecutor> IncrExecutor;
51
52
  Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err);
53
54
public:
55
  ~Interpreter();
56
  static llvm::Expected<std::unique_ptr<Interpreter>>
57
  create(std::unique_ptr<CompilerInstance> CI);
58
  const CompilerInstance *getCompilerInstance() const;
59
  llvm::Expected<PartialTranslationUnit &> Parse(llvm::StringRef Code);
60
  llvm::Error Execute(PartialTranslationUnit &T);
61
38
  llvm::Error ParseAndExecute(llvm::StringRef Code) {
62
38
    auto PTU = Parse(Code);
63
38
    if (!PTU)
64
0
      return PTU.takeError();
65
38
    if (PTU->TheModule)
66
21
      return Execute(*PTU);
67
17
    return llvm::Error::success();
68
38
  }
69
70
  /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses
71
  /// the CodeGenModule's internal mangling cache to avoid recomputing the
72
  /// mangled name.
73
  llvm::Expected<llvm::JITTargetAddress> getSymbolAddress(GlobalDecl GD) const;
74
75
  /// \returns the \c JITTargetAddress of a given name as written in the IR.
76
  llvm::Expected<llvm::JITTargetAddress>
77
  getSymbolAddress(llvm::StringRef IRName) const;
78
79
  /// \returns the \c JITTargetAddress of a given name as written in the object
80
  /// file.
81
  llvm::Expected<llvm::JITTargetAddress>
82
  getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
83
};
84
} // namespace clang
85
86
#endif // LLVM_CLANG_INTERPRETER_INTERPRETER_H