// We might split this into multiple files if it gets too unwieldy
+#include "CGCXXABI.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "Mangle.h"
return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
}
+
+CXXABI::~CXXABI() {}
--- /dev/null
+//===----- CGCXXABI.h - Interface to C++ ABIs -------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides an abstract class for C++ code generation. Concrete subclasses
+// of this implement code generation for specific C++ ABIs.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_CODEGEN_CXXABI_H
+#define CLANG_CODEGEN_CXXABI_H
+
+namespace clang {
+namespace CodeGen {
+ class CodeGenModule;
+ class MangleContext;
+
+/// Implements C++ ABI-specific code generation functions.
+class CXXABI {
+public:
+ virtual ~CXXABI();
+
+ /// Gets the mangle context.
+ virtual MangleContext &getMangleContext() = 0;
+};
+
+/// Creates an instance of a C++ ABI class.
+CXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
+}
+}
+
+#endif
CodeGenFunction.cpp
CodeGenModule.cpp
CodeGenTypes.cpp
+ ItaniumCXXABI.cpp
Mangle.cpp
ModuleBuilder.cpp
TargetInfo.cpp
)
-add_dependencies(clangCodeGen ClangStmtNodes)
\ No newline at end of file
+add_dependencies(clangCodeGen ClangStmtNodes)
Features(C.getLangOptions()), CodeGenOpts(CGO), TheModule(M),
TheTargetData(TD), TheTargetCodeGenInfo(0), Diags(diags),
Types(C, M, TD, getTargetCodeGenInfo().getABIInfo()),
- MangleCtx(C, diags), VTables(*this), Runtime(0),
+ VTables(*this), Runtime(0), ABI(0),
CFConstantStringClassRef(0),
NSConstantStringClassRef(0),
VMContext(M.getContext()) {
else
Runtime = CreateMacObjCRuntime(*this);
+ if (!Features.CPlusPlus)
+ ABI = 0;
+ else createCXXABI();
+
// If debug info generation is enabled, create the CGDebugInfo object.
DebugInfo = CodeGenOpts.DebugInfo ? new CGDebugInfo(*this) : 0;
}
CodeGenModule::~CodeGenModule() {
delete Runtime;
+ delete ABI;
delete DebugInfo;
}
Runtime = CreateMacObjCRuntime(*this);
}
+void CodeGenModule::createCXXABI() {
+ // For now, just create an Itanium ABI.
+ ABI = CreateItaniumCXXABI(*this);
+}
+
void CodeGenModule::Release() {
EmitDeferred();
EmitCXXGlobalInitFunc();
#include "CGCall.h"
#include "CGCXX.h"
#include "CGVTables.h"
+#include "CGCXXABI.h"
#include "CodeGenTypes.h"
#include "GlobalDecl.h"
#include "Mangle.h"
mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
Diagnostic &Diags;
CodeGenTypes Types;
- MangleContext MangleCtx;
/// VTables - Holds information about C++ vtables.
CodeGenVTables VTables;
friend class CodeGenVTables;
CGObjCRuntime* Runtime;
+ CXXABI* ABI;
CGDebugInfo* DebugInfo;
// WeakRefReferences - A set of references that have only been seen via
/// Lazily create the Objective-C runtime
void createObjCRuntime();
+ /// Lazily create the C++ ABI
+ void createCXXABI();
llvm::LLVMContext &VMContext;
public:
/// been configured.
bool hasObjCRuntime() { return !!Runtime; }
+ /// getCXXABI() - Return a reference to the configured
+ /// C++ ABI.
+ CXXABI &getCXXABI() {
+ if (!ABI) createCXXABI();
+ return *ABI;
+ }
+
+ /// hasCXXABI() - Return true iff a C++ ABI has been configured.
+ bool hasCXXABI() { return !!ABI; }
+
llvm::Value *getStaticLocalDeclAddress(const VarDecl *VD) {
return StaticLocalDeclMap[VD];
}
const LangOptions &getLangOptions() const { return Features; }
llvm::Module &getModule() const { return TheModule; }
CodeGenTypes &getTypes() { return Types; }
- MangleContext &getMangleContext() { return MangleCtx; }
+ MangleContext &getMangleContext() {
+ if (!ABI) createCXXABI();
+ return ABI->getMangleContext();
+ }
CodeGenVTables &getVTables() { return VTables; }
Diagnostic &getDiags() const { return Diags; }
const llvm::TargetData &getTargetData() const { return TheTargetData; }
--- /dev/null
+//===------- ItaniumCXXABI.cpp - Emit LLVM Code from ASTs for a Module ----===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides C++ code generation targetting the Itanium C++ ABI. The class
+// in this file generates structures that follow the Itanium C++ ABI, which is
+// documented at:
+// http://www.codesourcery.com/public/cxx-abi/abi.html
+// http://www.codesourcery.com/public/cxx-abi/abi-eh.html
+//===----------------------------------------------------------------------===//
+
+#include "CGCXXABI.h"
+#include "CodeGenModule.h"
+#include "Mangle.h"
+
+using namespace clang;
+
+namespace {
+class ItaniumCXXABI : public CodeGen::CXXABI {
+ CodeGen::MangleContext MangleCtx;
+public:
+ ItaniumCXXABI(CodeGen::CodeGenModule &CGM) :
+ MangleCtx(CGM.getContext(), CGM.getDiags()) { }
+
+ CodeGen::MangleContext &getMangleContext() {
+ return MangleCtx;
+ }
+};
+}
+
+CodeGen::CXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) {
+ return new ItaniumCXXABI(CGM);
+}
+