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