LayoutOverrideSource.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- LayoutOverrideSource.h --Override Record Layouts -------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H
  14. #define LLVM_CLANG_FRONTEND_LAYOUTOVERRIDESOURCE_H
  15. #include "clang/AST/ExternalASTSource.h"
  16. #include "clang/Basic/LLVM.h"
  17. #include "llvm/ADT/StringMap.h"
  18. #include "llvm/ADT/StringRef.h"
  19. namespace clang {
  20. /// An external AST source that overrides the layout of
  21. /// a specified set of record types.
  22. ///
  23. /// This class is used only for testing the ability of external AST sources
  24. /// to override the layout of record types. Its input is the output format
  25. /// of the command-line argument -fdump-record-layouts.
  26. class LayoutOverrideSource : public ExternalASTSource {
  27. /// The layout of a given record.
  28. struct Layout {
  29. /// The size of the record.
  30. uint64_t Size;
  31. /// The alignment of the record.
  32. uint64_t Align;
  33. /// The offsets of the fields, in source order.
  34. SmallVector<uint64_t, 8> FieldOffsets;
  35. };
  36. /// The set of layouts that will be overridden.
  37. llvm::StringMap<Layout> Layouts;
  38. public:
  39. /// Create a new AST source that overrides the layout of some
  40. /// set of record types.
  41. ///
  42. /// The file is the result of passing -fdump-record-layouts to a file.
  43. explicit LayoutOverrideSource(StringRef Filename);
  44. /// If this particular record type has an overridden layout,
  45. /// return that layout.
  46. bool
  47. layoutRecordType(const RecordDecl *Record,
  48. uint64_t &Size, uint64_t &Alignment,
  49. llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
  50. llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
  51. llvm::DenseMap<const CXXRecordDecl *,
  52. CharUnits> &VirtualBaseOffsets) override;
  53. /// Dump the overridden layouts.
  54. void dump();
  55. };
  56. }
  57. #endif
  58. #ifdef __GNUC__
  59. #pragma GCC diagnostic pop
  60. #endif