Memory.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "llvm/Support/Valgrind.h"
  16. #ifndef NDEBUG
  17. #include "llvm/Support/raw_ostream.h"
  18. #endif // ifndef NDEBUG
  19. // Include the platform-specific parts of this class.
  20. #ifdef LLVM_ON_UNIX
  21. #include "Unix/Memory.inc"
  22. #endif
  23. #ifdef _WIN32
  24. #include "Windows/Memory.inc"
  25. #endif
  26. #ifndef NDEBUG
  27. namespace llvm {
  28. namespace sys {
  29. raw_ostream &operator<<(raw_ostream &OS, const Memory::ProtectionFlags &PF) {
  30. assert((PF & ~(Memory::MF_READ | Memory::MF_WRITE | Memory::MF_EXEC)) == 0 &&
  31. "Unrecognized flags");
  32. return OS << (PF & Memory::MF_READ ? 'R' : '-')
  33. << (PF & Memory::MF_WRITE ? 'W' : '-')
  34. << (PF & Memory::MF_EXEC ? 'X' : '-');
  35. }
  36. raw_ostream &operator<<(raw_ostream &OS, const MemoryBlock &MB) {
  37. return OS << "[ " << MB.base() << " .. "
  38. << (void *)((char *)MB.base() + MB.allocatedSize()) << " ] ("
  39. << MB.allocatedSize() << " bytes)";
  40. }
  41. } // end namespace sys
  42. } // end namespace llvm
  43. #endif // ifndef NDEBUG