clang 22.0.0git
clang::CodeGenAction Class Reference

#include "clang/CodeGen/CodeGenAction.h"

Inheritance diagram for clang::CodeGenAction:
[legend]

Public Member Functions

 ~CodeGenAction () override
std::unique_ptr< llvm::Module > takeModule ()
 Take the generated LLVM module, for use after the action has been run.
llvm::LLVMContext * takeLLVMContext ()
 Take the LLVM context used by this action.
CodeGeneratorgetCodeGenerator () const
Public Member Functions inherited from clang::ASTFrontendAction
 ASTFrontendAction ()
bool usesPreprocessorOnly () const override
 Does this action only use the preprocessor?
Public Member Functions inherited from clang::FrontendAction
 FrontendAction ()
virtual ~FrontendAction ()
CompilerInstancegetCompilerInstance () const
void setCompilerInstance (CompilerInstance *Value)
bool isCurrentFileAST () const
const FrontendInputFilegetCurrentInput () const
StringRef getCurrentFile () const
StringRef getCurrentFileOrBufferName () const
InputKind getCurrentFileKind () const
ASTUnitgetCurrentASTUnit () const
ModulegetCurrentModule () const
std::unique_ptr< ASTUnittakeCurrentASTUnit ()
void setCurrentInput (const FrontendInputFile &CurrentInput, std::unique_ptr< ASTUnit > AST=nullptr)
virtual bool isModelParsingAction () const
 Is this action invoked on a model file?
virtual TranslationUnitKind getTranslationUnitKind ()
 For AST-based actions, the kind of translation unit we're handling.
virtual bool hasPCHSupport () const
 Does this action support use with PCH?
virtual bool hasASTFileSupport () const
 Does this action support use with AST files?
virtual bool hasCodeCompletionSupport () const
 Does this action support use with code completion?
bool PrepareToExecute (CompilerInstance &CI)
 Prepare the action to execute on the given compiler instance.
bool BeginSourceFile (CompilerInstance &CI, const FrontendInputFile &Input)
 Prepare the action for processing the input file Input.
llvm::Error Execute ()
 Set the source manager's main input file, and run the action.
virtual void EndSourceFile ()
 Perform any per-file post processing, deallocate per-file objects, and run statistics and output file cleanup code.

Public Attributes

BackendConsumerBEConsumer = nullptr

Protected Member Functions

bool BeginSourceFileAction (CompilerInstance &CI) override
 Callback at the start of processing a single input.
 CodeGenAction (unsigned _Act, llvm::LLVMContext *_VMContext=nullptr)
 Create a new code generation action.
bool hasIRSupport () const override
 Does this action support use with IR files?
std::unique_ptr< ASTConsumerCreateASTConsumer (CompilerInstance &CI, StringRef InFile) override
 Create the AST consumer object for this action, if supported.
void ExecuteAction () override
 Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer.
void EndSourceFileAction () override
 Callback at the end of processing a single input.
Protected Member Functions inherited from clang::FrontendAction
virtual bool PrepareToExecuteAction (CompilerInstance &CI)
 Prepare to execute the action on the given CompilerInstance.
virtual bool BeginInvocation (CompilerInstance &CI)
 Callback before starting processing a single input, giving the opportunity to modify the CompilerInvocation or do some other action before BeginSourceFileAction is called.
virtual bool shouldEraseOutputFiles ()
 Callback at the end of processing a single input, to determine if the output files should be erased or not.

Friends

class BackendConsumer

Detailed Description

Definition at line 24 of file CodeGenAction.h.

Constructor & Destructor Documentation

◆ CodeGenAction()

CodeGenAction::CodeGenAction ( unsigned _Act,
llvm::LLVMContext * _VMContext = nullptr )
protected

Create a new code generation action.

If the optional _VMContext parameter is supplied, the action uses it without taking ownership, otherwise it creates a fresh LLVM context and takes ownership.

Definition at line 868 of file CodeGenAction.cpp.

Referenced by clang::EmitAssemblyAction::EmitAssemblyAction(), clang::EmitBCAction::EmitBCAction(), clang::EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(), clang::EmitLLVMAction::EmitLLVMAction(), clang::EmitLLVMOnlyAction::EmitLLVMOnlyAction(), and clang::EmitObjAction::EmitObjAction().

◆ ~CodeGenAction()

CodeGenAction::~CodeGenAction ( )
override

Definition at line 872 of file CodeGenAction.cpp.

Member Function Documentation

◆ BeginSourceFileAction()

bool CodeGenAction::BeginSourceFileAction ( CompilerInstance & CI)
overrideprotectedvirtual

Callback at the start of processing a single input.

Returns
True on success; on failure ExecutionAction() and EndSourceFileAction() will not be called.

Reimplemented from clang::FrontendAction.

Definition at line 934 of file CodeGenAction.cpp.

References clang::FrontendAction::BeginSourceFileAction(), clang::LangOptionsBase::CMK_ModuleInterface, clang::FrontendOptions::GenReducedBMI, clang::CompilerInstance::getFrontendOpts(), and clang::CompilerInstance::getLangOpts().

◆ CreateASTConsumer()

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

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

This routine is called as part of BeginSourceFile(), which will fail if the AST consumer cannot be created. This will not be called if the action has indicated that it only uses the preprocessor.

Parameters
CI- The current compiler instance, provided as a convenience, see getCompilerInstance().
InFile- The current input file, provided as a convenience, see getCurrentFile().
Returns
The new AST consumer, or null on failure.

Implements clang::FrontendAction.

Definition at line 961 of file CodeGenAction.cpp.

References clang::Preprocessor::addPPCallbacks(), clang::Backend_EmitNothing, BackendConsumer, BEConsumer, clang::FrontendOptions::GenReducedBMI, clang::CompilerInstance::getCodeGenOpts(), clang::CompilerInstance::getFrontendOpts(), clang::CompilerInstance::getModuleCache(), GetOutputStream(), clang::CompilerInstance::getPreprocessor(), clang::CompilerInstance::getVirtualFileSystemPtr(), clang::FrontendOptions::ModuleOutputPath, clang::Result, clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks(), and clang::CompilerInstance::takeOutputStream().

◆ EndSourceFileAction()

void CodeGenAction::EndSourceFileAction ( )
overrideprotectedvirtual

Callback at the end of processing a single input.

This is guaranteed to only be called following a successful call to BeginSourceFileAction (and BeginSourceFile).

Reimplemented from clang::FrontendAction.

Definition at line 910 of file CodeGenAction.cpp.

References BEConsumer, clang::FrontendAction::EndSourceFileAction(), and clang::FrontendAction::getCompilerInstance().

◆ ExecuteAction()

◆ getCodeGenerator()

CodeGenerator * CodeGenAction::getCodeGenerator ( ) const

Definition at line 930 of file CodeGenAction.cpp.

References BEConsumer.

◆ hasIRSupport()

bool CodeGenAction::hasIRSupport ( ) const
overrideprotectedvirtual

Does this action support use with IR files?

Reimplemented from clang::FrontendAction.

Definition at line 908 of file CodeGenAction.cpp.

◆ takeLLVMContext()

llvm::LLVMContext * CodeGenAction::takeLLVMContext ( )

Take the LLVM context used by this action.

Definition at line 925 of file CodeGenAction.cpp.

◆ takeModule()

std::unique_ptr< llvm::Module > CodeGenAction::takeModule ( )

Take the generated LLVM module, for use after the action has been run.

The result may be null on failure.

Definition at line 921 of file CodeGenAction.cpp.

◆ BackendConsumer

friend class BackendConsumer
friend

Definition at line 27 of file CodeGenAction.h.

References BackendConsumer.

Referenced by BackendConsumer, CreateASTConsumer(), and ExecuteAction().

Member Data Documentation

◆ BEConsumer

BackendConsumer* clang::CodeGenAction::BEConsumer = nullptr

Definition at line 88 of file CodeGenAction.h.

Referenced by CreateASTConsumer(), EndSourceFileAction(), and getCodeGenerator().


The documentation for this class was generated from the following files: