clang: lib/Interpreter/IncrementalAction.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

10

20#include "llvm/IR/Module.h"

21#include "llvm/Support/Error.h"

22#include "llvm/Support/ErrorHandling.h"

23

26 llvm::LLVMContext &LLVMCtx,

28 std::unique_ptr Consumer)

30 llvm::ErrorAsOutParameter EAO(&Err);

31 std::unique_ptr Act;

32 switch (Instance.getFrontendOpts().ProgramAction) {

33 default:

34 Err = llvm::createStringError(

35 std::errc::state_not_recoverable,

36 "Driver initialization failed. "

37 "Incremental mode for action %d is not supported",

38 Instance.getFrontendOpts().ProgramAction);

39 return Act;

44 break;

52 break;

53 }

54 return Act;

55 }()),

56 Interp(I), CI(Instance), Consumer(std::move(Consumer)) {}

57

58std::unique_ptr

60 StringRef InFile) {

61 std::unique_ptr C =

63

64 if (Consumer) {

65 std::vector<std::unique_ptr> Cs;

66 Cs.push_back(std::move(Consumer));

67 Cs.push_back(std::move(C));

68 return std::make_unique(std::move(Cs));

69 }

70

71 return std::make_unique(std::move(C), Interp);

72}

73

78

83

85 assert(!IsTerminating && "Already finalized!");

86 IsTerminating = true;

88}

89

93

95 return CachedInCodeGenModule.get();

96}

97

99 static unsigned ID = 0;

101

102

103

104

105

106

107

108 assert(((!CachedInCodeGenModule ||

109 !CI.getPreprocessorOpts().Includes.empty() ||

110 !CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) ||

111 (CachedInCodeGenModule->empty() &&

112 CachedInCodeGenModule->global_empty() &&

113 CachedInCodeGenModule->alias_empty() &&

114 CachedInCodeGenModule->ifunc_empty())) &&

115 "CodeGen wrote to a readonly module");

116 std::unique_ptrllvm::Module M(CG->ReleaseModule());

117 CG->StartModule("incr_module_" + std::to_string(ID++), M->getContext());

118 return M;

119 }

120 return nullptr;

121}

122

125 if (!WrappedAct || !WrappedAct->hasIRSupport())

126 return nullptr;

127 return static_cast<CodeGenAction *>(WrappedAct)->getCodeGenerator();

128}

129

133

136 return true;

137

141 return true;

142

143 for (Decl *D : DGR)

144 if (auto *TLSD = llvm::dyn_cast(D))

145 if (TLSD && TLSD->isSemiMissing()) {

146 auto ExprOrErr = Interp.convertExprToValue(cast(TLSD->getStmt()));

147 if (llvm::Error E = ExprOrErr.takeError()) {

148 llvm::logAllUnhandledErrors(std::move(E), llvm::errs(),

149 "Value printing failed: ");

150 return false;

151 }

152 TLSD->setStmt(*ExprOrErr);

153 }

154

156}

157

158}

The primary public interface to the Clang code generator.

CompilerInstance - Helper class for managing a single instance of the Clang compiler.

DiagnosticsEngine & getDiagnostics() const

Get the current diagnostics engine.

Decl - This represents one declaration (or definition), e.g.

Concrete class used by the front-end to report problems and issues.

bool hasErrorOccurred() const

Abstract base class for actions which can be performed by the frontend.

virtual bool hasIRSupport() const

Does this action support use with IR files?

CompilerInstance & getCompilerInstance() const

InProcessPrintingASTConsumer(std::unique_ptr< ASTConsumer > C, Interpreter &I)

Definition IncrementalAction.cpp:130

bool HandleTopLevelDecl(DeclGroupRef DGR) override

HandleTopLevelDecl - Handle the specified top-level declaration.

Definition IncrementalAction.cpp:134

llvm::Module * getCachedCodeGenModule() const

Access the cached CodeGen module.

Definition IncrementalAction.cpp:94

void FinalizeAction()

Definition IncrementalAction.cpp:84

void ExecuteAction() override

Callback to run the program action, using the initialized compiler instance.

Definition IncrementalAction.cpp:74

std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override

Create the AST consumer object for this action, if supported.

Definition IncrementalAction.cpp:59

CodeGenerator * getCodeGen() const

Access the current code generator.

Definition IncrementalAction.cpp:123

void CacheCodeGenModule()

Cache the current CodeGen module to preserve internal references.

Definition IncrementalAction.cpp:90

IncrementalAction(CompilerInstance &Instance, llvm::LLVMContext &LLVMCtx, llvm::Error &Err, Interpreter &I, std::unique_ptr< ASTConsumer > Consumer=nullptr)

Definition IncrementalAction.cpp:25

FrontendAction * getWrapped() const

void EndSourceFile() override

Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...

Definition IncrementalAction.cpp:79

std::unique_ptr< llvm::Module > GenModule()

Generate an LLVM module for the most recent parsed input.

Definition IncrementalAction.cpp:98

Provides top-level interfaces for incremental compilation and execution.

bool HandleTopLevelDecl(DeclGroupRef D) override

HandleTopLevelDecl - Handle the specified top-level declaration.

MultiplexConsumer(std::vector< std::unique_ptr< ASTConsumer > > C)

DeclContext * CurContext

CurContext - This is the current declaration context of parsing.

void ExecuteAction() override

Callback to run the program action, using the initialized compiler instance.

WrapperFrontendAction(std::unique_ptr< FrontendAction > WrappedAction)

Construct a WrapperFrontendAction from an existing action, taking ownership of it.

std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override

Create the AST consumer object for this action, if supported.

void EndSourceFile() override

Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...

@ PrintPreprocessedInput

-E mode.

@ ParseSyntaxOnly

Parse and perform semantic analysis.

@ PluginAction

Run a plugin action,.

@ ASTPrint

Parse ASTs and print them.

@ ASTDump

Parse ASTs and dump them.

@ EmitAssembly

Emit a .s file.

@ EmitLLVMOnly

Generate LLVM IR, but do not emit anything.

The JSON file list parser is used to communicate input to InstallAPI.

std::unique_ptr< FrontendAction > CreateFrontendAction(CompilerInstance &CI)

Construct the FrontendAction of a compiler invocation based on the options specified for the compiler...

U cast(CodeGen::Address addr)