1195098Sed//===- MCContext.h - Machine Code Context -----------------------*- C++ -*-===// 2195098Sed// 3195098Sed// The LLVM Compiler Infrastructure 4195098Sed// 5195098Sed// This file is distributed under the University of Illinois Open Source 6195098Sed// License. See LICENSE.TXT for details. 7195098Sed// 8195098Sed//===----------------------------------------------------------------------===// 9195098Sed 10195098Sed#ifndef LLVM_MC_MCCONTEXT_H 11195098Sed#define LLVM_MC_MCCONTEXT_H 12195098Sed 13195098Sed#include "llvm/ADT/DenseMap.h" 14263509Sdim#include "llvm/ADT/SmallString.h" 15252723Sdim#include "llvm/ADT/SmallVector.h" 16195098Sed#include "llvm/ADT/StringMap.h" 17252723Sdim#include "llvm/MC/MCDwarf.h" 18252723Sdim#include "llvm/MC/SectionKind.h" 19195098Sed#include "llvm/Support/Allocator.h" 20235633Sdim#include "llvm/Support/Compiler.h" 21210299Sed#include "llvm/Support/raw_ostream.h" 22252723Sdim#include <map> 23212904Sdim#include <vector> // FIXME: Shouldn't be needed. 24195098Sed 25195098Sednamespace llvm { 26205218Srdivacky class MCAsmInfo; 27198396Srdivacky class MCExpr; 28195098Sed class MCSection; 29195098Sed class MCSymbol; 30208599Srdivacky class MCLabel; 31212904Sdim class MCDwarfFile; 32212904Sdim class MCDwarfLoc; 33226890Sdim class MCObjectFileInfo; 34226890Sdim class MCRegisterInfo; 35212904Sdim class MCLineSection; 36235633Sdim class SMLoc; 37198090Srdivacky class StringRef; 38198396Srdivacky class Twine; 39207618Srdivacky class MCSectionMachO; 40218893Sdim class MCSectionELF; 41263509Sdim class MCSectionCOFF; 42195098Sed 43198090Srdivacky /// MCContext - Context object for machine code objects. This class owns all 44198090Srdivacky /// of the sections that it creates. 45198090Srdivacky /// 46195098Sed class MCContext { 47245431Sdim MCContext(const MCContext&) LLVM_DELETED_FUNCTION; 48245431Sdim MCContext &operator=(const MCContext&) LLVM_DELETED_FUNCTION; 49224145Sdim public: 50224145Sdim typedef StringMap<MCSymbol*, BumpPtrAllocator&> SymbolTable; 51224145Sdim private: 52235633Sdim /// The SourceMgr for this object, if any. 53235633Sdim const SourceMgr *SrcMgr; 54195098Sed 55205218Srdivacky /// The MCAsmInfo for this target. 56263509Sdim const MCAsmInfo *MAI; 57195098Sed 58226890Sdim /// The MCRegisterInfo for this target. 59263509Sdim const MCRegisterInfo *MRI; 60218893Sdim 61226890Sdim /// The MCObjectFileInfo for this target. 62226890Sdim const MCObjectFileInfo *MOFI; 63226890Sdim 64221345Sdim /// Allocator - Allocator object used for creating machine code objects. 65221345Sdim /// 66221345Sdim /// We use a bump pointer allocator to avoid the need to track all allocated 67221345Sdim /// objects. 68221345Sdim BumpPtrAllocator Allocator; 69221345Sdim 70195098Sed /// Symbols - Bindings of names to symbols. 71224145Sdim SymbolTable Symbols; 72195098Sed 73218893Sdim /// UsedNames - Keeps tracks of names that were used both for used declared 74218893Sdim /// and artificial symbols. 75221345Sdim StringMap<bool, BumpPtrAllocator&> UsedNames; 76218893Sdim 77205218Srdivacky /// NextUniqueID - The next ID to dole out to an unnamed assembler temporary 78205218Srdivacky /// symbol. 79205218Srdivacky unsigned NextUniqueID; 80208599Srdivacky 81208599Srdivacky /// Instances of directional local labels. 82208599Srdivacky DenseMap<unsigned, MCLabel *> Instances; 83208599Srdivacky /// NextInstance() creates the next instance of the directional local label 84208599Srdivacky /// for the LocalLabelVal and adds it to the map if needed. 85208599Srdivacky unsigned NextInstance(int64_t LocalLabelVal); 86208599Srdivacky /// GetInstance() gets the current instance of the directional local label 87208599Srdivacky /// for the LocalLabelVal and adds it to the map if needed. 88208599Srdivacky unsigned GetInstance(int64_t LocalLabelVal); 89218893Sdim 90218893Sdim /// The file name of the log file from the environment variable 91210299Sed /// AS_SECURE_LOG_FILE. Which must be set before the .secure_log_unique 92210299Sed /// directive is used or it is an error. 93210299Sed char *SecureLogFile; 94210299Sed /// The stream that gets written to for the .secure_log_unique directive. 95210299Sed raw_ostream *SecureLog; 96210299Sed /// Boolean toggled when .secure_log_unique / .secure_log_reset is seen to 97210299Sed /// catch errors if .secure_log_unique appears twice without 98210299Sed /// .secure_log_reset appearing between them. 99210299Sed bool SecureLogUsed; 100210299Sed 101252723Sdim /// The compilation directory to use for DW_AT_comp_dir. 102263509Sdim SmallString<128> CompilationDir; 103252723Sdim 104252723Sdim /// The main file name if passed in explicitly. 105252723Sdim std::string MainFileName; 106252723Sdim 107212904Sdim /// The dwarf file and directory tables from the dwarf .file directive. 108252723Sdim /// We now emit a line table for each compile unit. To reduce the prologue 109252723Sdim /// size of each line table, the files and directories used by each compile 110252723Sdim /// unit are separated. 111252723Sdim typedef std::map<unsigned, SmallVector<MCDwarfFile *, 4> > MCDwarfFilesMap; 112252723Sdim MCDwarfFilesMap MCDwarfFilesCUMap; 113252723Sdim std::map<unsigned, SmallVector<StringRef, 4> > MCDwarfDirsCUMap; 114212904Sdim 115212904Sdim /// The current dwarf line information from the last dwarf .loc directive. 116212904Sdim MCDwarfLoc CurrentDwarfLoc; 117212904Sdim bool DwarfLocSeen; 118212904Sdim 119235633Sdim /// Generate dwarf debugging info for assembly source files. 120235633Sdim bool GenDwarfForAssembly; 121235633Sdim 122235633Sdim /// The current dwarf file number when generate dwarf debugging info for 123235633Sdim /// assembly source files. 124235633Sdim unsigned GenDwarfFileNumber; 125235633Sdim 126235633Sdim /// The default initial text section that we generate dwarf debugging line 127235633Sdim /// info for when generating dwarf assembly source files. 128235633Sdim const MCSection *GenDwarfSection; 129235633Sdim /// Symbols created for the start and end of this section. 130235633Sdim MCSymbol *GenDwarfSectionStartSym, *GenDwarfSectionEndSym; 131235633Sdim 132235633Sdim /// The information gathered from labels that will have dwarf label 133235633Sdim /// entries when generating dwarf assembly source files. 134235633Sdim std::vector<const MCGenDwarfLabelEntry *> MCGenDwarfLabelEntries; 135235633Sdim 136235633Sdim /// The string to embed in the debug information for the compile unit, if 137235633Sdim /// non-empty. 138235633Sdim StringRef DwarfDebugFlags; 139235633Sdim 140252723Sdim /// The string to embed in as the dwarf AT_producer for the compile unit, if 141252723Sdim /// non-empty. 142252723Sdim StringRef DwarfDebugProducer; 143252723Sdim 144221345Sdim /// Honor temporary labels, this is useful for debugging semantic 145221345Sdim /// differences between temporary and non-temporary labels (primarily on 146221345Sdim /// Darwin). 147221345Sdim bool AllowTemporaryLabels; 148221345Sdim 149212904Sdim /// The dwarf line information from the .loc directives for the sections 150212904Sdim /// with assembled machine instructions have after seeing .loc directives. 151212904Sdim DenseMap<const MCSection *, MCLineSection *> MCLineSections; 152218893Sdim /// We need a deterministic iteration order, so we remember the order 153218893Sdim /// the elements were added. 154218893Sdim std::vector<const MCSection *> MCLineSectionOrder; 155252723Sdim /// The Compile Unit ID that we are currently processing. 156252723Sdim unsigned DwarfCompileUnitID; 157252723Sdim /// The line table start symbol for each Compile Unit. 158252723Sdim DenseMap<unsigned, MCSymbol *> MCLineTableSymbols; 159212904Sdim 160208599Srdivacky void *MachOUniquingMap, *ELFUniquingMap, *COFFUniquingMap; 161218893Sdim 162252723Sdim /// Do automatic reset in destructor 163252723Sdim bool AutoReset; 164252723Sdim 165218893Sdim MCSymbol *CreateSymbol(StringRef Name); 166218893Sdim 167195098Sed public: 168263509Sdim explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI, 169252723Sdim const MCObjectFileInfo *MOFI, const SourceMgr *Mgr = 0, 170252723Sdim bool DoAutoReset = true); 171195098Sed ~MCContext(); 172218893Sdim 173235633Sdim const SourceMgr *getSourceManager() const { return SrcMgr; } 174235633Sdim 175263509Sdim const MCAsmInfo *getAsmInfo() const { return MAI; } 176195098Sed 177263509Sdim const MCRegisterInfo *getRegisterInfo() const { return MRI; } 178218893Sdim 179226890Sdim const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; } 180226890Sdim 181221345Sdim void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; } 182221345Sdim 183252723Sdim /// @name Module Lifetime Management 184252723Sdim /// @{ 185252723Sdim 186252723Sdim /// reset - return object to right after construction state to prepare 187252723Sdim /// to process a new module 188252723Sdim void reset(); 189252723Sdim 190252723Sdim /// @} 191252723Sdim 192218893Sdim /// @name Symbol Management 193198090Srdivacky /// @{ 194218893Sdim 195205218Srdivacky /// CreateTempSymbol - Create and return a new assembler temporary symbol 196205218Srdivacky /// with a unique but unspecified name. 197205218Srdivacky MCSymbol *CreateTempSymbol(); 198198090Srdivacky 199245431Sdim /// getUniqueSymbolID() - Return a unique identifier for use in constructing 200245431Sdim /// symbol names. 201245431Sdim unsigned getUniqueSymbolID() { return NextUniqueID++; } 202245431Sdim 203218893Sdim /// CreateDirectionalLocalSymbol - Create the definition of a directional 204218893Sdim /// local symbol for numbered label (used for "1:" definitions). 205208599Srdivacky MCSymbol *CreateDirectionalLocalSymbol(int64_t LocalLabelVal); 206208599Srdivacky 207208599Srdivacky /// GetDirectionalLocalSymbol - Create and return a directional local 208208599Srdivacky /// symbol for numbered label (used for "1b" or 1f" references). 209208599Srdivacky MCSymbol *GetDirectionalLocalSymbol(int64_t LocalLabelVal, int bORf); 210208599Srdivacky 211195098Sed /// GetOrCreateSymbol - Lookup the symbol inside with the specified 212204642Srdivacky /// @p Name. If it exists, return it. If not, create a forward 213195098Sed /// reference and return it. 214195098Sed /// 215195098Sed /// @param Name - The symbol name, which must be unique across all symbols. 216206083Srdivacky MCSymbol *GetOrCreateSymbol(StringRef Name); 217206083Srdivacky MCSymbol *GetOrCreateSymbol(const Twine &Name); 218198396Srdivacky 219204642Srdivacky /// LookupSymbol - Get the symbol for \p Name, or null. 220199481Srdivacky MCSymbol *LookupSymbol(StringRef Name) const; 221245431Sdim MCSymbol *LookupSymbol(const Twine &Name) const; 222195098Sed 223224145Sdim /// getSymbols - Get a reference for the symbol table for clients that 224224145Sdim /// want to, for example, iterate over all symbols. 'const' because we 225224145Sdim /// still want any modifications to the table itself to use the MCContext 226224145Sdim /// APIs. 227224145Sdim const SymbolTable &getSymbols() const { 228224145Sdim return Symbols; 229224145Sdim } 230224145Sdim 231198090Srdivacky /// @} 232218893Sdim 233218893Sdim /// @name Section Management 234207618Srdivacky /// @{ 235195098Sed 236207618Srdivacky /// getMachOSection - Return the MCSection for the specified mach-o section. 237207618Srdivacky /// This requires the operands to be valid. 238207618Srdivacky const MCSectionMachO *getMachOSection(StringRef Segment, 239207618Srdivacky StringRef Section, 240207618Srdivacky unsigned TypeAndAttributes, 241207618Srdivacky unsigned Reserved2, 242207618Srdivacky SectionKind K); 243207618Srdivacky const MCSectionMachO *getMachOSection(StringRef Segment, 244207618Srdivacky StringRef Section, 245207618Srdivacky unsigned TypeAndAttributes, 246207618Srdivacky SectionKind K) { 247207618Srdivacky return getMachOSection(Segment, Section, TypeAndAttributes, 0, K); 248207618Srdivacky } 249208599Srdivacky 250218893Sdim const MCSectionELF *getELFSection(StringRef Section, unsigned Type, 251218893Sdim unsigned Flags, SectionKind Kind); 252218893Sdim 253218893Sdim const MCSectionELF *getELFSection(StringRef Section, unsigned Type, 254218893Sdim unsigned Flags, SectionKind Kind, 255218893Sdim unsigned EntrySize, StringRef Group); 256218893Sdim 257218893Sdim const MCSectionELF *CreateELFGroupSection(); 258218893Sdim 259263509Sdim const MCSectionCOFF *getCOFFSection(StringRef Section, 260263509Sdim unsigned Characteristics, 261263509Sdim SectionKind Kind, 262263509Sdim StringRef COMDATSymName, 263263509Sdim int Selection, 264263509Sdim const MCSectionCOFF *Assoc = 0); 265208599Srdivacky 266263509Sdim const MCSectionCOFF *getCOFFSection(StringRef Section, 267263509Sdim unsigned Characteristics, 268263509Sdim SectionKind Kind); 269208599Srdivacky 270263509Sdim const MCSectionCOFF *getCOFFSection(StringRef Section); 271218893Sdim 272207618Srdivacky /// @} 273207618Srdivacky 274218893Sdim /// @name Dwarf Management 275212904Sdim /// @{ 276212904Sdim 277252723Sdim /// \brief Get the compilation directory for DW_AT_comp_dir 278252723Sdim /// This can be overridden by clients which want to control the reported 279252723Sdim /// compilation directory and have it be something other than the current 280252723Sdim /// working directory. 281263509Sdim /// Returns an empty string if the current directory cannot be determined. 282263509Sdim StringRef getCompilationDir() const { return CompilationDir; } 283252723Sdim 284252723Sdim /// \brief Set the compilation directory for DW_AT_comp_dir 285252723Sdim /// Override the default (CWD) compilation directory. 286252723Sdim void setCompilationDir(StringRef S) { CompilationDir = S.str(); } 287252723Sdim 288252723Sdim /// \brief Get the main file name for use in error messages and debug 289252723Sdim /// info. This can be set to ensure we've got the correct file name 290252723Sdim /// after preprocessing or for -save-temps. 291252723Sdim const std::string &getMainFileName() const { return MainFileName; } 292252723Sdim 293252723Sdim /// \brief Set the main file name and override the default. 294252723Sdim void setMainFileName(StringRef S) { MainFileName = S.str(); } 295252723Sdim 296212904Sdim /// GetDwarfFile - creates an entry in the dwarf file and directory tables. 297235633Sdim unsigned GetDwarfFile(StringRef Directory, StringRef FileName, 298252723Sdim unsigned FileNumber, unsigned CUID); 299212904Sdim 300252723Sdim bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0); 301212904Sdim 302218893Sdim bool hasDwarfFiles() const { 303252723Sdim // Traverse MCDwarfFilesCUMap and check whether each entry is empty. 304252723Sdim MCDwarfFilesMap::const_iterator MapB, MapE; 305252723Sdim for (MapB = MCDwarfFilesCUMap.begin(), MapE = MCDwarfFilesCUMap.end(); 306252723Sdim MapB != MapE; MapB++) 307252723Sdim if (!MapB->second.empty()) 308252723Sdim return true; 309252723Sdim return false; 310218893Sdim } 311218893Sdim 312252723Sdim const SmallVectorImpl<MCDwarfFile *> &getMCDwarfFiles(unsigned CUID = 0) { 313252723Sdim return MCDwarfFilesCUMap[CUID]; 314212904Sdim } 315252723Sdim const SmallVectorImpl<StringRef> &getMCDwarfDirs(unsigned CUID = 0) { 316252723Sdim return MCDwarfDirsCUMap[CUID]; 317212904Sdim } 318218893Sdim 319218893Sdim const DenseMap<const MCSection *, MCLineSection *> 320218893Sdim &getMCLineSections() const { 321212904Sdim return MCLineSections; 322212904Sdim } 323218893Sdim const std::vector<const MCSection *> &getMCLineSectionOrder() const { 324218893Sdim return MCLineSectionOrder; 325218893Sdim } 326218893Sdim void addMCLineSection(const MCSection *Sec, MCLineSection *Line) { 327218893Sdim MCLineSections[Sec] = Line; 328218893Sdim MCLineSectionOrder.push_back(Sec); 329218893Sdim } 330252723Sdim unsigned getDwarfCompileUnitID() { 331252723Sdim return DwarfCompileUnitID; 332252723Sdim } 333252723Sdim void setDwarfCompileUnitID(unsigned CUIndex) { 334252723Sdim DwarfCompileUnitID = CUIndex; 335252723Sdim } 336252723Sdim const DenseMap<unsigned, MCSymbol *> &getMCLineTableSymbols() const { 337252723Sdim return MCLineTableSymbols; 338252723Sdim } 339252723Sdim MCSymbol *getMCLineTableSymbol(unsigned ID) const { 340252723Sdim DenseMap<unsigned, MCSymbol *>::const_iterator CIter = 341252723Sdim MCLineTableSymbols.find(ID); 342252723Sdim if (CIter == MCLineTableSymbols.end()) 343252723Sdim return NULL; 344252723Sdim return CIter->second; 345252723Sdim } 346252723Sdim void setMCLineTableSymbol(MCSymbol *Sym, unsigned ID) { 347252723Sdim MCLineTableSymbols[ID] = Sym; 348252723Sdim } 349212904Sdim 350212904Sdim /// setCurrentDwarfLoc - saves the information from the currently parsed 351218893Sdim /// dwarf .loc directive and sets DwarfLocSeen. When the next instruction 352218893Sdim /// is assembled an entry in the line number table with this information and 353212904Sdim /// the address of the instruction will be created. 354212904Sdim void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column, 355218893Sdim unsigned Flags, unsigned Isa, 356218893Sdim unsigned Discriminator) { 357212904Sdim CurrentDwarfLoc.setFileNum(FileNum); 358212904Sdim CurrentDwarfLoc.setLine(Line); 359212904Sdim CurrentDwarfLoc.setColumn(Column); 360212904Sdim CurrentDwarfLoc.setFlags(Flags); 361212904Sdim CurrentDwarfLoc.setIsa(Isa); 362218893Sdim CurrentDwarfLoc.setDiscriminator(Discriminator); 363212904Sdim DwarfLocSeen = true; 364212904Sdim } 365218893Sdim void ClearDwarfLocSeen() { DwarfLocSeen = false; } 366212904Sdim 367212904Sdim bool getDwarfLocSeen() { return DwarfLocSeen; } 368212904Sdim const MCDwarfLoc &getCurrentDwarfLoc() { return CurrentDwarfLoc; } 369212904Sdim 370235633Sdim bool getGenDwarfForAssembly() { return GenDwarfForAssembly; } 371235633Sdim void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; } 372235633Sdim unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; } 373235633Sdim unsigned nextGenDwarfFileNumber() { return ++GenDwarfFileNumber; } 374235633Sdim const MCSection *getGenDwarfSection() { return GenDwarfSection; } 375235633Sdim void setGenDwarfSection(const MCSection *Sec) { GenDwarfSection = Sec; } 376235633Sdim MCSymbol *getGenDwarfSectionStartSym() { return GenDwarfSectionStartSym; } 377235633Sdim void setGenDwarfSectionStartSym(MCSymbol *Sym) { 378235633Sdim GenDwarfSectionStartSym = Sym; 379235633Sdim } 380235633Sdim MCSymbol *getGenDwarfSectionEndSym() { return GenDwarfSectionEndSym; } 381235633Sdim void setGenDwarfSectionEndSym(MCSymbol *Sym) { 382235633Sdim GenDwarfSectionEndSym = Sym; 383235633Sdim } 384235633Sdim const std::vector<const MCGenDwarfLabelEntry *> 385235633Sdim &getMCGenDwarfLabelEntries() const { 386235633Sdim return MCGenDwarfLabelEntries; 387235633Sdim } 388235633Sdim void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry *E) { 389235633Sdim MCGenDwarfLabelEntries.push_back(E); 390235633Sdim } 391235633Sdim 392235633Sdim void setDwarfDebugFlags(StringRef S) { DwarfDebugFlags = S; } 393235633Sdim StringRef getDwarfDebugFlags() { return DwarfDebugFlags; } 394235633Sdim 395252723Sdim void setDwarfDebugProducer(StringRef S) { DwarfDebugProducer = S; } 396252723Sdim StringRef getDwarfDebugProducer() { return DwarfDebugProducer; } 397252723Sdim 398212904Sdim /// @} 399212904Sdim 400210299Sed char *getSecureLogFile() { return SecureLogFile; } 401210299Sed raw_ostream *getSecureLog() { return SecureLog; } 402210299Sed bool getSecureLogUsed() { return SecureLogUsed; } 403210299Sed void setSecureLog(raw_ostream *Value) { 404210299Sed SecureLog = Value; 405210299Sed } 406210299Sed void setSecureLogUsed(bool Value) { 407210299Sed SecureLogUsed = Value; 408210299Sed } 409210299Sed 410195098Sed void *Allocate(unsigned Size, unsigned Align = 8) { 411195098Sed return Allocator.Allocate(Size, Align); 412195098Sed } 413198396Srdivacky void Deallocate(void *Ptr) { 414195098Sed } 415235633Sdim 416263509Sdim // Unrecoverable error has occurred. Display the best diagnostic we can 417235633Sdim // and bail via exit(1). For now, most MC backend errors are unrecoverable. 418235633Sdim // FIXME: We should really do something about that. 419235633Sdim LLVM_ATTRIBUTE_NORETURN void FatalError(SMLoc L, const Twine &Msg); 420195098Sed }; 421195098Sed 422195098Sed} // end namespace llvm 423195098Sed 424195098Sed// operator new and delete aren't allowed inside namespaces. 425195098Sed// The throw specifications are mandated by the standard. 426195098Sed/// @brief Placement new for using the MCContext's allocator. 427195098Sed/// 428195098Sed/// This placement form of operator new uses the MCContext's allocator for 429195098Sed/// obtaining memory. It is a non-throwing new, which means that it returns 430195098Sed/// null on error. (If that is what the allocator does. The current does, so if 431195098Sed/// this ever changes, this operator will have to be changed, too.) 432195098Sed/// Usage looks like this (assuming there's an MCContext 'Context' in scope): 433195098Sed/// @code 434195098Sed/// // Default alignment (16) 435195098Sed/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments); 436195098Sed/// // Specific alignment 437195098Sed/// IntegerLiteral *Ex2 = new (Context, 8) IntegerLiteral(arguments); 438195098Sed/// @endcode 439195098Sed/// Please note that you cannot use delete on the pointer; it must be 440195098Sed/// deallocated using an explicit destructor call followed by 441195098Sed/// @c Context.Deallocate(Ptr). 442195098Sed/// 443195098Sed/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 444195098Sed/// @param C The MCContext that provides the allocator. 445195098Sed/// @param Alignment The alignment of the allocated memory (if the underlying 446195098Sed/// allocator supports it). 447195098Sed/// @return The allocated memory. Could be NULL. 448195098Sedinline void *operator new(size_t Bytes, llvm::MCContext &C, 449195098Sed size_t Alignment = 16) throw () { 450195098Sed return C.Allocate(Bytes, Alignment); 451195098Sed} 452195098Sed/// @brief Placement delete companion to the new above. 453195098Sed/// 454195098Sed/// This operator is just a companion to the new above. There is no way of 455195098Sed/// invoking it directly; see the new operator for more details. This operator 456195098Sed/// is called implicitly by the compiler if a placement new expression using 457195098Sed/// the MCContext throws in the object constructor. 458195098Sedinline void operator delete(void *Ptr, llvm::MCContext &C, size_t) 459195098Sed throw () { 460195098Sed C.Deallocate(Ptr); 461195098Sed} 462195098Sed 463195098Sed/// This placement form of operator new[] uses the MCContext's allocator for 464195098Sed/// obtaining memory. It is a non-throwing new[], which means that it returns 465195098Sed/// null on error. 466195098Sed/// Usage looks like this (assuming there's an MCContext 'Context' in scope): 467195098Sed/// @code 468195098Sed/// // Default alignment (16) 469195098Sed/// char *data = new (Context) char[10]; 470195098Sed/// // Specific alignment 471195098Sed/// char *data = new (Context, 8) char[10]; 472195098Sed/// @endcode 473195098Sed/// Please note that you cannot use delete on the pointer; it must be 474195098Sed/// deallocated using an explicit destructor call followed by 475195098Sed/// @c Context.Deallocate(Ptr). 476195098Sed/// 477195098Sed/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 478195098Sed/// @param C The MCContext that provides the allocator. 479195098Sed/// @param Alignment The alignment of the allocated memory (if the underlying 480195098Sed/// allocator supports it). 481195098Sed/// @return The allocated memory. Could be NULL. 482195098Sedinline void *operator new[](size_t Bytes, llvm::MCContext& C, 483195098Sed size_t Alignment = 16) throw () { 484195098Sed return C.Allocate(Bytes, Alignment); 485195098Sed} 486195098Sed 487195098Sed/// @brief Placement delete[] companion to the new[] above. 488195098Sed/// 489195098Sed/// This operator is just a companion to the new[] above. There is no way of 490195098Sed/// invoking it directly; see the new[] operator for more details. This operator 491195098Sed/// is called implicitly by the compiler if a placement new[] expression using 492195098Sed/// the MCContext throws in the object constructor. 493195098Sedinline void operator delete[](void *Ptr, llvm::MCContext &C) throw () { 494195098Sed C.Deallocate(Ptr); 495195098Sed} 496195098Sed 497195098Sed#endif 498