blob: 767ba21d7ada57f16078157f33ad1c8e5a6fffc0 [file] [log] [blame]
//===--- SILAllocated.h - Defines the SILAllocated class --------*- C++ -*-===//
// This source file is part of the open source project
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
// See for license information
// See for the list of Swift project authors
#include "swift/Basic/LLVM.h"
#include "swift/Basic/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include <stddef.h>
namespace swift {
class SILModule;
/// SILAllocated - This class enforces that derived classes are allocated out of
/// the SILModule bump pointer allocator.
template <typename DERIVED>
class SILAllocated {
/// Disable non-placement new.
void *operator new(size_t) = delete;
void *operator new[](size_t) = delete;
/// Disable non-placement delete.
void operator delete(void *) = delete;
void operator delete[](void *) = delete;
/// Custom version of 'new' that uses the SILModule's BumpPtrAllocator with
/// precise alignment knowledge. This is templated on the allocator type so
/// that this doesn't require including SILModule.h.
template <typename ContextTy>
void *operator new(size_t Bytes, const ContextTy &C,
size_t Alignment = alignof(DERIVED)) {
return C.allocate(Bytes, Alignment);
} // end swift namespace