[cfe-commits] r83442 - in /cfe/trunk/lib/CodeGen: CGCXX.cpp CodeGenModule.cpp CodeGenModule.h Mangle.cpp Mangle.h
Daniel Dunbar
daniel at zuster.org
Tue Oct 20 08:42:02 PDT 2009
Hi Anders,
Shouldn't the mangle functions just be methods on the MangleContext? I
think this simplifies things.
Once that is done it probably makes sense to make MangleContext an
abstract class and have CXXNameMangler be its concrete implementation.
- Daniel
On Tue, Oct 6, 2009 at 6:06 PM, Anders Carlsson <andersca at mac.com> wrote:
> Author: andersca
> Date: Tue Oct 6 20:06:45 2009
> New Revision: 83442
>
> URL: http://llvm.org/viewvc/llvm-project?rev=83442&view=rev
> Log:
> Add a MangleContext and pass it to all mangle functions. It will be used for keeping state, such as identifiers assigned to anonymous structs as well as scope encoding.
>
> Modified:
> cfe/trunk/lib/CodeGen/CGCXX.cpp
> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> cfe/trunk/lib/CodeGen/CodeGenModule.h
> cfe/trunk/lib/CodeGen/Mangle.cpp
> cfe/trunk/lib/CodeGen/Mangle.h
>
> Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=83442&r1=83441&r2=83442&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Oct 6 20:06:45 2009
> @@ -135,7 +135,7 @@
>
> 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 =
> @@ -607,7 +607,7 @@
> 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());
> @@ -643,7 +643,7 @@
> 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());
> @@ -661,7 +661,7 @@
> 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;
> @@ -1187,7 +1187,7 @@
> 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;
> @@ -1285,7 +1285,7 @@
> 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)
> @@ -1310,7 +1310,7 @@
> 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)
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=83442&r1=83441&r2=83442&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Oct 6 20:06:45 2009
> @@ -39,7 +39,7 @@
> 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()) {
>
> @@ -166,7 +166,7 @@
>
> 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();
> }
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=83442&r1=83441&r2=83442&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue Oct 6 20:06:45 2009
> @@ -22,6 +22,7 @@
> #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"
> @@ -123,9 +124,11 @@
> const llvm::TargetData &TheTargetData;
> Diagnostic &Diags;
> CodeGenTypes Types;
> + MangleContext MangleCtx;
> +
> CGObjCRuntime* Runtime;
> CGDebugInfo* DebugInfo;
> -
> +
> llvm::Function *MemCpyFn;
> llvm::Function *MemMoveFn;
> llvm::Function *MemSetFn;
> @@ -217,6 +220,7 @@
> 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; }
>
> Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=83442&r1=83441&r2=83442&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
> +++ cfe/trunk/lib/CodeGen/Mangle.cpp Tue Oct 6 20:06:45 2009
> @@ -29,7 +29,7 @@
>
> namespace {
> class VISIBILITY_HIDDEN CXXNameMangler {
> - ASTContext &Context;
> + MangleContext &Context;
> llvm::raw_ostream &Out;
>
> const CXXMethodDecl *Structor;
> @@ -39,7 +39,7 @@
> 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);
> @@ -127,12 +127,13 @@
> // (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.
> @@ -165,7 +166,7 @@
> 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;
> @@ -446,7 +447,7 @@
> 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:
> @@ -671,7 +672,7 @@
>
> 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))
> @@ -1291,7 +1292,7 @@
> /// 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!");
> @@ -1299,7 +1300,7 @@
> "Use mangleCXXDtor for destructor decls!");
>
> PrettyStackTraceDecl CrashInfo(const_cast<NamedDecl *>(D), SourceLocation(),
> - Context.getSourceManager(),
> + Context.getASTContext().getSourceManager(),
> "Mangling declaration");
>
> CXXNameMangler Mangler(Context, os);
> @@ -1312,8 +1313,8 @@
>
> /// \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!");
> @@ -1325,8 +1326,9 @@
>
> /// \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) &&
> @@ -1339,7 +1341,7 @@
>
> /// 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);
> @@ -1347,23 +1349,23 @@
> 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);
> @@ -1371,7 +1373,7 @@
> 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);
>
> Modified: cfe/trunk/lib/CodeGen/Mangle.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.h?rev=83442&r1=83441&r2=83442&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/Mangle.h (original)
> +++ cfe/trunk/lib/CodeGen/Mangle.h Tue Oct 6 20:06:45 2009
> @@ -33,21 +33,31 @@
> 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
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list