-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
470e8b8
commit 75edb18
Showing
7 changed files
with
190 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//===---- CIRGenConsumer.h - CIR Code Generation Consumer ------*- C++ -*--===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_CIR_CIRGENCONSUMER_H | ||
#define LLVM_CLANG_CIR_CIRGENCONSUMER_H | ||
|
||
#include "clang/AST/ASTConsumer.h" | ||
#include "clang/CIR/CIRGenerator.h" | ||
#include "clang/CIRFrontendAction/CIRGenAction.h" | ||
#include "clang/Frontend/CompilerInstance.h" | ||
|
||
namespace llvm { | ||
class raw_pwrite_stream; | ||
} | ||
|
||
namespace clang { | ||
class DiagnosticsEngine; | ||
class HeaderSearchOptions; | ||
class CodeGenOptions; | ||
class TargetOptions; | ||
class LangOptions; | ||
class FrontendOptions; | ||
} // namespace clang | ||
|
||
namespace cir { | ||
|
||
class CIRGenConsumer : public clang::ASTConsumer { | ||
protected: | ||
virtual void anchor(); | ||
|
||
CIRGenAction::OutputType action; | ||
|
||
clang::DiagnosticsEngine &diagnosticsEngine; | ||
const clang::HeaderSearchOptions &headerSearchOptions; | ||
const clang::CodeGenOptions &codeGenOptions; | ||
const clang::TargetOptions &targetOptions; | ||
const clang::LangOptions &langOptions; | ||
const clang::FrontendOptions &feOptions; | ||
|
||
std::unique_ptr<llvm::raw_pwrite_stream> outputStream; | ||
|
||
clang::ASTContext *astContext{nullptr}; | ||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS; | ||
std::unique_ptr<CIRGenerator> gen; | ||
|
||
public: | ||
CIRGenConsumer(CIRGenAction::OutputType action, | ||
clang::DiagnosticsEngine &diagnosticsEngine, | ||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, | ||
const clang::HeaderSearchOptions &headerSearchOptions, | ||
const clang::CodeGenOptions &codeGenOptions, | ||
const clang::TargetOptions &targetOptions, | ||
const clang::LangOptions &langOptions, | ||
const clang::FrontendOptions &feOptions, | ||
std::unique_ptr<llvm::raw_pwrite_stream> os) | ||
: action(action), diagnosticsEngine(diagnosticsEngine), | ||
headerSearchOptions(headerSearchOptions), | ||
codeGenOptions(codeGenOptions), targetOptions(targetOptions), | ||
langOptions(langOptions), feOptions(feOptions), | ||
outputStream(std::move(os)), FS(VFS), | ||
gen(std::make_unique<CIRGenerator>(diagnosticsEngine, std::move(VFS), | ||
codeGenOptions)) {} | ||
|
||
void Initialize(clang::ASTContext &ctx) override; | ||
|
||
bool HandleTopLevelDecl(clang::DeclGroupRef D) override; | ||
|
||
void HandleCXXStaticMemberVarInstantiation(clang::VarDecl *VD) override; | ||
void HandleInlineFunctionDefinition(clang::FunctionDecl *D) override; | ||
|
||
void HandleInterestingDecl(clang::DeclGroupRef D) override; | ||
|
||
void HandleTranslationUnit(clang::ASTContext &C) override {} | ||
|
||
void HandleTagDeclDefinition(clang::TagDecl *D) override; | ||
|
||
void HandleTagDeclRequiredDefinition(const clang::TagDecl *D) override; | ||
|
||
void CompleteTentativeDefinition(clang::VarDecl *D) override; | ||
|
||
void CompleteExternalDeclaration(clang::VarDecl *D) override; | ||
|
||
void AssignInheritanceModel(clang::CXXRecordDecl *RD) override; | ||
|
||
void HandleVTable(clang::CXXRecordDecl *RD) override; | ||
}; | ||
|
||
inline std::unique_ptr<clang::ASTConsumer> | ||
createCIRAnalysisOnlyConsumer(clang::CompilerInstance &ci) { | ||
return std::make_unique<cir::CIRGenConsumer>( | ||
CIRGenAction::OutputType::None, ci.getDiagnostics(), | ||
&ci.getVirtualFileSystem(), ci.getHeaderSearchOpts(), ci.getCodeGenOpts(), | ||
ci.getTargetOpts(), ci.getLangOpts(), ci.getFrontendOpts(), nullptr); | ||
} | ||
} // namespace cir | ||
|
||
#endif // LLVM_CLANG_CIR_CIRGENCONSUMER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//===--- CIRGenConsumer.cpp -ClangIR Generator Consumer -------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "clang/CIRFrontendAction/CIRGenConsumer.h" | ||
|
||
using namespace cir; | ||
using namespace clang; | ||
|
||
void CIRGenConsumer::Initialize(ASTContext &ctx) { | ||
assert(!astContext && "initialized multiple times"); | ||
|
||
astContext = &ctx; | ||
|
||
gen->Initialize(ctx); | ||
} | ||
|
||
bool CIRGenConsumer::HandleTopLevelDecl(DeclGroupRef D) { | ||
PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(), | ||
astContext->getSourceManager(), | ||
"LLVM IR generation of declaration"); | ||
gen->HandleTopLevelDecl(D); | ||
return true; | ||
} | ||
|
||
void CIRGenConsumer::HandleCXXStaticMemberVarInstantiation(clang::VarDecl *VD) { | ||
gen->HandleCXXStaticMemberVarInstantiation(VD); | ||
} | ||
|
||
void CIRGenConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) { | ||
gen->HandleInlineFunctionDefinition(D); | ||
} | ||
|
||
void CIRGenConsumer::HandleInterestingDecl(DeclGroupRef D) { | ||
llvm_unreachable("NYI"); | ||
} | ||
|
||
void CIRGenConsumer::HandleTagDeclDefinition(TagDecl *D) { | ||
PrettyStackTraceDecl CrashInfo(D, SourceLocation(), | ||
astContext->getSourceManager(), | ||
"CIR generation of declaration"); | ||
gen->HandleTagDeclDefinition(D); | ||
} | ||
|
||
void CIRGenConsumer::HandleTagDeclRequiredDefinition(const TagDecl *D) { | ||
gen->HandleTagDeclRequiredDefinition(D); | ||
} | ||
|
||
void CIRGenConsumer::CompleteTentativeDefinition(VarDecl *D) { | ||
gen->CompleteTentativeDefinition(D); | ||
} | ||
|
||
void CIRGenConsumer::CompleteExternalDeclaration(VarDecl *D) { | ||
llvm_unreachable("NYI"); | ||
} | ||
|
||
void CIRGenConsumer::AssignInheritanceModel(CXXRecordDecl *RD) { | ||
llvm_unreachable("NYI"); | ||
} | ||
|
||
void CIRGenConsumer::HandleVTable(CXXRecordDecl *RD) { gen->HandleVTable(RD); } | ||
|
||
void CIRGenConsumer::anchor() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters