llvm::SmallString<256> GuardVName;
llvm::raw_svector_ostream GuardVOut(GuardVName);
- mangleGuardVariable(&D, getContext(), GuardVOut);
+ mangleGuardVariable(CGM.getMangleContext(), &D, GuardVOut);
// Create the guard variable.
llvm::GlobalValue *GuardV =
CXXCtorType Type) {
llvm::SmallString<256> Name;
llvm::raw_svector_ostream Out(Name);
- mangleCXXCtor(D, Type, Context, Out);
+ mangleCXXCtor(getMangleContext(), D, Type, Out);
Name += '\0';
return UniqueMangledName(Name.begin(), Name.end());
CXXDtorType Type) {
llvm::SmallString<256> Name;
llvm::raw_svector_ostream Out(Name);
- mangleCXXDtor(D, Type, Context, Out);
+ mangleCXXDtor(getMangleContext(), D, Type, Out);
Name += '\0';
return UniqueMangledName(Name.begin(), Name.end());
llvm::raw_svector_ostream Out(OutName);
QualType ClassTy;
ClassTy = getContext().getTagDeclType(RD);
- mangleCXXRtti(ClassTy, getContext(), Out);
+ mangleCXXRtti(getMangleContext(), ClassTy, Out);
llvm::GlobalVariable::LinkageTypes linktype;
linktype = llvm::GlobalValue::WeakAnyLinkage;
std::vector<llvm::Constant *> info;
llvm::raw_svector_ostream Out(OutName);
QualType ClassTy;
ClassTy = getContext().getTagDeclType(RD);
- mangleCXXVtable(ClassTy, getContext(), Out);
+ mangleCXXVtable(CGM.getMangleContext(), ClassTy, Out);
llvm::GlobalVariable::LinkageTypes linktype;
linktype = llvm::GlobalValue::WeakAnyLinkage;
std::vector<llvm::Constant *> methods;
int64_t nv, int64_t v) {
llvm::SmallString<256> OutName;
llvm::raw_svector_ostream Out(OutName);
- mangleThunk(MD, nv, v, getContext(), Out);
+ mangleThunk(getMangleContext(), MD, nv, v, Out);
llvm::GlobalVariable::LinkageTypes linktype;
linktype = llvm::GlobalValue::WeakAnyLinkage;
if (!Extern)
int64_t v_r) {
llvm::SmallString<256> OutName;
llvm::raw_svector_ostream Out(OutName);
- mangleCovariantThunk(MD, nv_t, v_t, nv_r, v_r, getContext(), Out);
+ mangleCovariantThunk(getMangleContext(), MD, nv_t, v_t, nv_r, v_r, Out);
llvm::GlobalVariable::LinkageTypes linktype;
linktype = llvm::GlobalValue::WeakAnyLinkage;
if (!Extern)
Diagnostic &diags)
: BlockModule(C, M, TD, Types, *this), Context(C),
Features(C.getLangOptions()), CompileOpts(compileOpts), TheModule(M),
- TheTargetData(TD), Diags(diags), Types(C, M, TD), Runtime(0),
+ TheTargetData(TD), Diags(diags), Types(C, M, TD), MangleCtx(C), Runtime(0),
MemCpyFn(0), MemMoveFn(0), MemSetFn(0), CFConstantStringClassRef(0),
VMContext(M.getContext()) {
llvm::SmallString<256> Name;
llvm::raw_svector_ostream Out(Name);
- if (!mangleName(ND, Context, Out)) {
+ if (!mangleName(getMangleContext(), ND, Out)) {
assert(ND->getIdentifier() && "Attempt to mangle unnamed decl.");
return ND->getNameAsCString();
}
#include "CGCall.h"
#include "CGCXX.h"
#include "CodeGenTypes.h"
+#include "Mangle.h"
#include "llvm/Module.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
const llvm::TargetData &TheTargetData;
Diagnostic &Diags;
CodeGenTypes Types;
+ MangleContext MangleCtx;
+
CGObjCRuntime* Runtime;
CGDebugInfo* DebugInfo;
-
+
llvm::Function *MemCpyFn;
llvm::Function *MemMoveFn;
llvm::Function *MemSetFn;
const LangOptions &getLangOptions() const { return Features; }
llvm::Module &getModule() const { return TheModule; }
CodeGenTypes &getTypes() { return Types; }
+ MangleContext &getMangleContext() { return MangleCtx; }
Diagnostic &getDiags() const { return Diags; }
const llvm::TargetData &getTargetData() const { return TheTargetData; }
llvm::LLVMContext &getLLVMContext() { return VMContext; }
namespace {
class VISIBILITY_HIDDEN CXXNameMangler {
- ASTContext &Context;
+ MangleContext &Context;
llvm::raw_ostream &Out;
const CXXMethodDecl *Structor;
llvm::DenseMap<uintptr_t, unsigned> Substitutions;
public:
- CXXNameMangler(ASTContext &C, llvm::raw_ostream &os)
+ CXXNameMangler(MangleContext &C, llvm::raw_ostream &os)
: Context(C), Out(os), Structor(0), StructorType(0) { }
bool mangle(const NamedDecl *D);
// (always).
if (!FD->hasAttr<OverloadableAttr>()) {
// C functions are not mangled, and "main" is never mangled.
- if (!Context.getLangOptions().CPlusPlus || FD->isMain())
+ if (!Context.getASTContext().getLangOptions().CPlusPlus || FD->isMain())
return false;
// No mangling in an "implicit extern C" header.
if (FD->getLocation().isValid() &&
- Context.getSourceManager().isInExternCSystemHeader(FD->getLocation()))
+ Context.getASTContext().getSourceManager().
+ isInExternCSystemHeader(FD->getLocation()))
return false;
// No name mangling in a C linkage specification.
return mangleFunctionDecl(FD);
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
- if (!Context.getLangOptions().CPlusPlus ||
+ if (!Context.getASTContext().getLangOptions().CPlusPlus ||
isInCLinkageSpecification(D) ||
D->getDeclContext()->isTranslationUnit())
return false;
case DeclarationName::CXXConversionFunctionName:
// <operator-name> ::= cv <type> # (cast)
Out << "cv";
- mangleType(Context.getCanonicalType(Name.getCXXNameType()));
+ mangleType(Context.getASTContext().getCanonicalType(Name.getCXXNameType()));
break;
case DeclarationName::CXXOperatorName:
void CXXNameMangler::mangleType(QualType T) {
// Only operate on the canonical type!
- T = Context.getCanonicalType(T);
+ T = Context.getASTContext().getCanonicalType(T);
bool IsSubstitutable = !isa<BuiltinType>(T);
if (IsSubstitutable && mangleSubstitution(T))
/// and this routine will return false. In this case, the caller should just
/// emit the identifier of the declaration (\c D->getIdentifier()) as its
/// name.
- bool mangleName(const NamedDecl *D, ASTContext &Context,
+ bool mangleName(MangleContext &Context, const NamedDecl *D,
llvm::raw_ostream &os) {
assert(!isa<CXXConstructorDecl>(D) &&
"Use mangleCXXCtor for constructor decls!");
"Use mangleCXXDtor for destructor decls!");
PrettyStackTraceDecl CrashInfo(const_cast<NamedDecl *>(D), SourceLocation(),
- Context.getSourceManager(),
+ Context.getASTContext().getSourceManager(),
"Mangling declaration");
CXXNameMangler Mangler(Context, os);
/// \brief Mangles the a thunk with the offset n for the declaration D and
/// emits that name to the given output stream.
- void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v,
- ASTContext &Context, llvm::raw_ostream &os) {
+ void mangleThunk(MangleContext &Context, const FunctionDecl *FD,
+ int64_t nv, int64_t v, llvm::raw_ostream &os) {
// FIXME: Hum, we might have to thunk these, fix.
assert(!isa<CXXDestructorDecl>(FD) &&
"Use mangleCXXDtor for destructor decls!");
/// \brief Mangles the a covariant thunk for the declaration D and emits that
/// name to the given output stream.
- void mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, int64_t v_t,
- int64_t nv_r, int64_t v_r, ASTContext &Context,
+ void mangleCovariantThunk(MangleContext &Context, const FunctionDecl *FD,
+ int64_t nv_t, int64_t v_t,
+ int64_t nv_r, int64_t v_r,
llvm::raw_ostream &os) {
// FIXME: Hum, we might have to thunk these, fix.
assert(!isa<CXXDestructorDecl>(FD) &&
/// mangleGuardVariable - Returns the mangled name for a guard variable
/// for the passed in VarDecl.
- void mangleGuardVariable(const VarDecl *D, ASTContext &Context,
+ void mangleGuardVariable(MangleContext &Context, const VarDecl *D,
llvm::raw_ostream &os) {
CXXNameMangler Mangler(Context, os);
Mangler.mangleGuardVariable(D);
os.flush();
}
- void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
- ASTContext &Context, llvm::raw_ostream &os) {
+ void mangleCXXCtor(MangleContext &Context, const CXXConstructorDecl *D,
+ CXXCtorType Type, llvm::raw_ostream &os) {
CXXNameMangler Mangler(Context, os);
Mangler.mangleCXXCtor(D, Type);
os.flush();
}
- void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
- ASTContext &Context, llvm::raw_ostream &os) {
+ void mangleCXXDtor(MangleContext &Context, const CXXDestructorDecl *D,
+ CXXDtorType Type, llvm::raw_ostream &os) {
CXXNameMangler Mangler(Context, os);
Mangler.mangleCXXDtor(D, Type);
os.flush();
}
- void mangleCXXVtable(QualType Type, ASTContext &Context,
+ void mangleCXXVtable(MangleContext &Context, QualType Type,
llvm::raw_ostream &os) {
CXXNameMangler Mangler(Context, os);
Mangler.mangleCXXVtable(Type);
os.flush();
}
- void mangleCXXRtti(QualType Type, ASTContext &Context,
+ void mangleCXXRtti(MangleContext &Context, QualType Type,
llvm::raw_ostream &os) {
CXXNameMangler Mangler(Context, os);
Mangler.mangleCXXRtti(Type);
class NamedDecl;
class VarDecl;
- bool mangleName(const NamedDecl *D, ASTContext &Context,
+ class MangleContext {
+ ASTContext &Context;
+ public:
+ explicit MangleContext(ASTContext &Context)
+ : Context(Context) { }
+
+ ASTContext &getASTContext() const { return Context; }
+ };
+
+ bool mangleName(MangleContext &Context, const NamedDecl *D,
llvm::raw_ostream &os);
- void mangleThunk(const FunctionDecl *FD, int64_t n, int64_t vn,
- ASTContext &Context, llvm::raw_ostream &os);
- void mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, int64_t v_t,
- int64_t nv_r, int64_t v_r, ASTContext &Context,
+ void mangleThunk(MangleContext &Context, const FunctionDecl *FD,
+ int64_t n, int64_t vn, llvm::raw_ostream &os);
+ void mangleCovariantThunk(MangleContext &Context, const FunctionDecl *FD,
+ int64_t nv_t, int64_t v_t,
+ int64_t nv_r, int64_t v_r,
llvm::raw_ostream &os);
- void mangleGuardVariable(const VarDecl *D, ASTContext &Context,
+ void mangleGuardVariable(MangleContext &Context, const VarDecl *D,
llvm::raw_ostream &os);
- void mangleCXXVtable(QualType T, ASTContext &Context, llvm::raw_ostream &os);
- void mangleCXXRtti(QualType T, ASTContext &Context, llvm::raw_ostream &os);
- void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
- ASTContext &Context, llvm::raw_ostream &os);
- void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
- ASTContext &Context, llvm::raw_ostream &os);
+ void mangleCXXVtable(MangleContext &Context, QualType T, llvm::raw_ostream &os);
+ void mangleCXXRtti(MangleContext &Context, QualType T, llvm::raw_ostream &os);
+ void mangleCXXCtor(MangleContext &Context, const CXXConstructorDecl *D,
+ CXXCtorType Type, llvm::raw_ostream &os);
+ void mangleCXXDtor(MangleContext &Context, const CXXDestructorDecl *D,
+ CXXDtorType Type, llvm::raw_ostream &os);
}
#endif