diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-04-12 18:14:18 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-04-12 18:14:18 +0000 |
commit | 93c62967d4ac7620a8ed2c5f875daab9adb416f0 (patch) | |
tree | f1c0a9d3fb848c825485c50f609098b600db508e /lib/CodeGen | |
parent | a7a98c97e650545e69f4d868c95f0e3370971b0f (diff) |
IRgen: Add CGRecordLayout::dump, and dump (irgen) record layouts as part of -fdump-record-layouts.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101051 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGRecordLayout.h | 9 | ||||
-rw-r--r-- | lib/CodeGen/CGRecordLayoutBuilder.cpp | 39 |
2 files changed, 47 insertions, 1 deletions
diff --git a/lib/CodeGen/CGRecordLayout.h b/lib/CodeGen/CGRecordLayout.h index 86c57d10c4..2fb8191cf2 100644 --- a/lib/CodeGen/CGRecordLayout.h +++ b/lib/CodeGen/CGRecordLayout.h @@ -13,12 +13,15 @@ #include "llvm/ADT/DenseMap.h" #include "clang/AST/Decl.h" namespace llvm { + class raw_ostream; class Type; } namespace clang { namespace CodeGen { +/// Helper object for describing how to generate the code for access to a +/// bit-field. class CGBitFieldInfo { public: CGBitFieldInfo(const llvm::Type *FieldTy, unsigned FieldNo, @@ -32,6 +35,9 @@ public: unsigned Start; unsigned Size; bool IsSigned : 1; + + void print(llvm::raw_ostream &OS) const; + void dump() const; }; /// CGRecordLayout - This class handles struct and union layout info while @@ -90,6 +96,9 @@ public: assert(it != BitFields.end() && "Unable to find bitfield info"); return it->second; } + + void print(llvm::raw_ostream &OS) const; + void dump() const; }; } // end namespace CodeGen diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index fdd8d05926..57438e6b06 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -18,8 +18,9 @@ #include "clang/AST/Expr.h" #include "clang/AST/RecordLayout.h" #include "CodeGenTypes.h" -#include "llvm/Type.h" #include "llvm/DerivedTypes.h" +#include "llvm/Type.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetData.h" using namespace clang; using namespace CodeGen; @@ -496,5 +497,41 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) { for (unsigned i = 0, e = Builder.LLVMBitFields.size(); i != e; ++i) RL->BitFields.insert(Builder.LLVMBitFields[i]); + if (getContext().getLangOptions().DumpRecordLayouts) + RL->dump(); + return RL; } + +void CGRecordLayout::print(llvm::raw_ostream &OS) const { + OS << "<CGRecordLayout\n"; + OS << " LLVMType:" << *LLVMType << "\n"; + OS << " ContainsPointerToDataMember:" << ContainsPointerToDataMember << "\n"; + OS << " BitFields:[\n"; + for (llvm::DenseMap<const FieldDecl*, CGBitFieldInfo>::const_iterator + it = BitFields.begin(), ie = BitFields.end(); + it != ie; ++it) { + OS << " "; + it->second.print(OS); + OS << "\n"; + } + OS << "]>\n"; +} + +void CGRecordLayout::dump() const { + print(llvm::errs()); +} + +void CGBitFieldInfo::print(llvm::raw_ostream &OS) const { + OS << "<CGBitFieldInfo"; + OS << " FieldTy:" << *FieldTy; + OS << " FieldNo:" << FieldNo; + OS << " Start:" << Start; + OS << " Size:" << Size; + OS << " IsSigned:" << IsSigned; + OS << ">"; +} + +void CGBitFieldInfo::dump() const { + print(llvm::errs()); +} |