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