Memory.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===- Memory.cpp - Memory Handling Support ---------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines some helpful functions for allocating memory and dealing
  10. // with memory mapped files
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/Support/Memory.h"
  14. #include "llvm/Config/llvm-config.h"
  15. #ifndef NDEBUG
  16. #include "llvm/Support/raw_ostream.h"
  17. #endif // ifndef NDEBUG
  18. // Include the platform-specific parts of this class.
  19. #ifdef LLVM_ON_UNIX
  20. #include "Unix/Memory.inc"
  21. #endif
  22. #ifdef _WIN32
  23. #include "Windows/Memory.inc"
  24. #endif
  25. #ifndef NDEBUG
  26. namespace llvm {
  27. namespace sys {
  28. raw_ostream &operator<<(raw_ostream &OS, const Memory::ProtectionFlags &PF) {
  29. assert((PF & ~(Memory::MF_READ | Memory::MF_WRITE | Memory::MF_EXEC)) == 0 &&
  30. "Unrecognized flags");
  31. return OS << (PF & Memory::MF_READ ? 'R' : '-')
  32. << (PF & Memory::MF_WRITE ? 'W' : '-')
  33. << (PF & Memory::MF_EXEC ? 'X' : '-');
  34. }
  35. raw_ostream &operator<<(raw_ostream &OS, const MemoryBlock &MB) {
  36. return OS << "[ " << MB.base() << " .. "
  37. << (void *)((char *)MB.base() + MB.allocatedSize()) << " ] ("
  38. << MB.allocatedSize() << " bytes)";
  39. }
  40. } // end namespace sys
  41. } // end namespace llvm
  42. #endif // ifndef NDEBUG