1 //===--- LayoutOverrideSource.h --Override Record Layouts -----------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H 11 #define LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H 12 13 #include "clang/AST/ExternalASTSource.h" 14 #include "clang/Basic/LLVM.h" 15 #include "llvm/ADT/StringMap.h" 16 #include "llvm/ADT/StringRef.h" 17 18 namespace clang { 19 /// \brief An external AST source that overrides the layout of 20 /// a specified set of record types. 21 /// 22 /// This class is used only for testing the ability of external AST sources 23 /// to override the layout of record types. Its input is the output format 24 /// of the command-line argument -fdump-record-layouts. 25 class LayoutOverrideSource : public ExternalASTSource { 26 /// \brief The layout of a given record. 27 struct Layout { 28 /// \brief The size of the record. 29 uint64_t Size; 30 31 /// \brief The alignment of the record. 32 uint64_t Align; 33 34 /// \brief The offsets of the fields, in source order. 35 SmallVector<uint64_t, 8> FieldOffsets; 36 }; 37 38 /// \brief The set of layouts that will be overridden. 39 llvm::StringMap<Layout> Layouts; 40 41 public: 42 /// \brief Create a new AST source that overrides the layout of some 43 /// set of record types. 44 /// 45 /// The file is the result of passing -fdump-record-layouts to a file. 46 explicit LayoutOverrideSource(StringRef Filename); 47 48 /// \brief If this particular record type has an overridden layout, 49 /// return that layout. 50 bool 51 layoutRecordType(const RecordDecl *Record, 52 uint64_t &Size, uint64_t &Alignment, 53 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, 54 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, 55 llvm::DenseMap<const CXXRecordDecl *, 56 CharUnits> &VirtualBaseOffsets) override; 57 58 /// \brief Dump the overridden layouts. 59 void dump(); 60 }; 61 } 62 63 #endif 64