diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CodeGenABITypes.cpp | 50 | ||||
-rw-r--r-- | clang/lib/CodeGen/ModuleBuilder.cpp | 44 |
2 files changed, 62 insertions, 32 deletions
diff --git a/clang/lib/CodeGen/CodeGenABITypes.cpp b/clang/lib/CodeGen/CodeGenABITypes.cpp index 16a7db47c80..166f44f816f 100644 --- a/clang/lib/CodeGen/CodeGenABITypes.cpp +++ b/clang/lib/CodeGen/CodeGenABITypes.cpp @@ -26,45 +26,41 @@ using namespace clang; using namespace CodeGen; -CodeGenABITypes::CodeGenABITypes(ASTContext &C, llvm::Module &M, - CoverageSourceInfo *CoverageInfo) - : CGO(new CodeGenOptions), HSO(new HeaderSearchOptions), - PPO(new PreprocessorOptions), - CGM(new CodeGen::CodeGenModule(C, *HSO, *PPO, *CGO, M, C.getDiagnostics(), - CoverageInfo)) {} - -// Explicitly out-of-line because ~CodeGenModule() is private but -// CodeGenABITypes.h is part of clang's API. -CodeGenABITypes::~CodeGenABITypes() = default; - const CGFunctionInfo & -CodeGenABITypes::arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD, - QualType receiverType) { - return CGM->getTypes().arrangeObjCMessageSendSignature(MD, receiverType); +CodeGen::arrangeObjCMessageSendSignature(CodeGenModule &CGM, + const ObjCMethodDecl *MD, + QualType receiverType) { + return CGM.getTypes().arrangeObjCMessageSendSignature(MD, receiverType); } const CGFunctionInfo & -CodeGenABITypes::arrangeFreeFunctionType(CanQual<FunctionProtoType> Ty, - const FunctionDecl *FD) { - return CGM->getTypes().arrangeFreeFunctionType(Ty, FD); +CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM, + CanQual<FunctionProtoType> Ty, + const FunctionDecl *FD) { + return CGM.getTypes().arrangeFreeFunctionType(Ty, FD); } const CGFunctionInfo & -CodeGenABITypes::arrangeFreeFunctionType(CanQual<FunctionNoProtoType> Ty) { - return CGM->getTypes().arrangeFreeFunctionType(Ty); +CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM, + CanQual<FunctionNoProtoType> Ty) { + return CGM.getTypes().arrangeFreeFunctionType(Ty); } const CGFunctionInfo & -CodeGenABITypes::arrangeCXXMethodType(const CXXRecordDecl *RD, - const FunctionProtoType *FTP, - const CXXMethodDecl *MD) { - return CGM->getTypes().arrangeCXXMethodType(RD, FTP, MD); +CodeGen::arrangeCXXMethodType(CodeGenModule &CGM, + const CXXRecordDecl *RD, + const FunctionProtoType *FTP, + const CXXMethodDecl *MD) { + return CGM.getTypes().arrangeCXXMethodType(RD, FTP, MD); } -const CGFunctionInfo &CodeGenABITypes::arrangeFreeFunctionCall( - CanQualType returnType, ArrayRef<CanQualType> argTypes, - FunctionType::ExtInfo info, RequiredArgs args) { - return CGM->getTypes().arrangeLLVMFunctionInfo( +const CGFunctionInfo & +CodeGen::arrangeFreeFunctionCall(CodeGenModule &CGM, + CanQualType returnType, + ArrayRef<CanQualType> argTypes, + FunctionType::ExtInfo info, + RequiredArgs args) { + return CGM.getTypes().arrangeLLVMFunctionInfo( returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes, info, {}, args); } diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp index 042712965b0..952d1627fa8 100644 --- a/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/clang/lib/CodeGen/ModuleBuilder.cpp @@ -25,7 +25,9 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include <memory> + using namespace clang; +using namespace CodeGen; namespace { class CodeGeneratorImpl : public CodeGenerator { @@ -65,7 +67,7 @@ namespace { SmallVector<CXXMethodDecl *, 8> DeferredInlineMethodDefinitions; public: - CodeGeneratorImpl(DiagnosticsEngine &diags, const std::string &ModuleName, + CodeGeneratorImpl(DiagnosticsEngine &diags, llvm::StringRef ModuleName, const HeaderSearchOptions &HSO, const PreprocessorOptions &PPO, const CodeGenOptions &CGO, llvm::LLVMContext &C, @@ -82,11 +84,19 @@ namespace { Diags.hasErrorOccurred()); } - llvm::Module* GetModule() override { + CodeGenModule &CGM() { + return *Builder; + } + + llvm::Module *GetModule() { return M.get(); } - const Decl *GetDeclForMangledName(StringRef MangledName) override { + llvm::Module *ReleaseModule() { + return M.release(); + } + + const Decl *GetDeclForMangledName(StringRef MangledName) { GlobalDecl Result; if (!Builder->lookupRepresentativeDecl(MangledName, Result)) return nullptr; @@ -101,7 +111,9 @@ namespace { return D; } - llvm::Module *ReleaseModule() override { return M.release(); } + llvm::Constant *GetAddrOfGlobal(GlobalDecl global, bool isForDefinition) { + return Builder->GetAddrOfGlobal(global, isForDefinition); + } void Initialize(ASTContext &Context) override { Ctx = &Context; @@ -275,8 +287,30 @@ namespace { void CodeGenerator::anchor() { } +CodeGenModule &CodeGenerator::CGM() { + return static_cast<CodeGeneratorImpl*>(this)->CGM(); +} + +llvm::Module *CodeGenerator::GetModule() { + return static_cast<CodeGeneratorImpl*>(this)->GetModule(); +} + +llvm::Module *CodeGenerator::ReleaseModule() { + return static_cast<CodeGeneratorImpl*>(this)->ReleaseModule(); +} + +const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) { + return static_cast<CodeGeneratorImpl*>(this)->GetDeclForMangledName(name); +} + +llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global, + bool isForDefinition) { + return static_cast<CodeGeneratorImpl*>(this) + ->GetAddrOfGlobal(global, isForDefinition); +} + CodeGenerator *clang::CreateLLVMCodeGen( - DiagnosticsEngine &Diags, const std::string &ModuleName, + DiagnosticsEngine &Diags, llvm::StringRef ModuleName, const HeaderSearchOptions &HeaderSearchOpts, const PreprocessorOptions &PreprocessorOpts, const CodeGenOptions &CGO, llvm::LLVMContext &C, CoverageSourceInfo *CoverageInfo) { |