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