//===- MCContext.h - Machine Code Context -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_MC_MCCONTEXT_H #define LLVM_MC_MCCONTEXT_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/BinaryFormat/XCOFF.h" #include "llvm/MC/MCAsmMacro.h" #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCPseudoProbe.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSymbolTableEntry.h" #include "llvm/MC/SectionKind.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Error.h" #include "llvm/Support/MD5.h" #include "llvm/Support/StringSaver.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <cassert> #include <cstddef> #include <cstdint> #include <functional> #include <map> #include <memory> #include <optional> #include <string> #include <utility> #include <vector> namespace llvm { class CodeViewContext; class MCAsmInfo; class MCDataFragment; class MCInst; class MCLabel; class MCObjectFileInfo; class MCRegisterInfo; class MCSection; class MCSectionCOFF; class MCSectionDXContainer; class MCSectionELF; class MCSectionGOFF; class MCSectionMachO; class MCSectionSPIRV; class MCSectionWasm; class MCSectionXCOFF; class MCStreamer; class MCSubtargetInfo; class MCSymbol; class MCSymbolELF; class MCSymbolWasm; class MCSymbolXCOFF; class MCTargetOptions; class MDNode; template <typename T> class SmallVectorImpl; class SMDiagnostic; class SMLoc; class SourceMgr; enum class EmitDwarfUnwindType; namespace wasm { struct WasmSignature; } /// Context object for machine code objects. This class owns all of the /// sections that it creates. /// class MCContext { … }; } // end namespace llvm // operator new and delete aren't allowed inside namespaces. // The throw specifications are mandated by the standard. /// Placement new for using the MCContext's allocator. /// /// This placement form of operator new uses the MCContext's allocator for /// obtaining memory. It is a non-throwing new, which means that it returns /// null on error. (If that is what the allocator does. The current does, so if /// this ever changes, this operator will have to be changed, too.) /// Usage looks like this (assuming there's an MCContext 'Context' in scope): /// \code /// // Default alignment (8) /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments); /// // Specific alignment /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments); /// \endcode /// Please note that you cannot use delete on the pointer; it must be /// deallocated using an explicit destructor call followed by /// \c Context.Deallocate(Ptr). /// /// \param Bytes The number of bytes to allocate. Calculated by the compiler. /// \param C The MCContext that provides the allocator. /// \param Alignment The alignment of the allocated memory (if the underlying /// allocator supports it). /// \return The allocated memory. Could be NULL. inline void *operator new(size_t Bytes, llvm::MCContext &C, size_t Alignment = 8) noexcept { … } /// Placement delete companion to the new above. /// /// This operator is just a companion to the new above. There is no way of /// invoking it directly; see the new operator for more details. This operator /// is called implicitly by the compiler if a placement new expression using /// the MCContext throws in the object constructor. inline void operator delete(void *Ptr, llvm::MCContext &C, size_t) noexcept { … } /// This placement form of operator new[] uses the MCContext's allocator for /// obtaining memory. It is a non-throwing new[], which means that it returns /// null on error. /// Usage looks like this (assuming there's an MCContext 'Context' in scope): /// \code /// // Default alignment (8) /// char *data = new (Context) char[10]; /// // Specific alignment /// char *data = new (Context, 4) char[10]; /// \endcode /// Please note that you cannot use delete on the pointer; it must be /// deallocated using an explicit destructor call followed by /// \c Context.Deallocate(Ptr). /// /// \param Bytes The number of bytes to allocate. Calculated by the compiler. /// \param C The MCContext that provides the allocator. /// \param Alignment The alignment of the allocated memory (if the underlying /// allocator supports it). /// \return The allocated memory. Could be NULL. inline void *operator new[](size_t Bytes, llvm::MCContext &C, size_t Alignment = 8) noexcept { … } /// Placement delete[] companion to the new[] above. /// /// This operator is just a companion to the new[] above. There is no way of /// invoking it directly; see the new[] operator for more details. This operator /// is called implicitly by the compiler if a placement new[] expression using /// the MCContext throws in the object constructor. inline void operator delete[](void *Ptr, llvm::MCContext &C) noexcept { … } #endif // LLVM_MC_MCCONTEXT_H