mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-05 15:42:24 +00:00
9381eb1045
I thought for a while about how to remove it, but it looks like we can just copy the file for now. Of course I'm not happy about that, but it's just less than 50 lines of code, and we already have duplicate code in Error.h and some other places. I want to solve them all at once later. Differential Revision: https://reviews.llvm.org/D27819 llvm-svn: 290062
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
//===- Memory.h -------------------------------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Linker
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// See ELF/Memory.h
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLD_COFF_MEMORY_H
|
|
#define LLD_COFF_MEMORY_H
|
|
|
|
#include "llvm/Support/Allocator.h"
|
|
#include "llvm/Support/StringSaver.h"
|
|
#include <vector>
|
|
|
|
namespace lld {
|
|
namespace coff {
|
|
|
|
extern llvm::BumpPtrAllocator BAlloc;
|
|
extern llvm::StringSaver Saver;
|
|
|
|
struct SpecificAllocBase {
|
|
SpecificAllocBase() { Instances.push_back(this); }
|
|
virtual ~SpecificAllocBase() = default;
|
|
virtual void reset() = 0;
|
|
static std::vector<SpecificAllocBase *> Instances;
|
|
};
|
|
|
|
template <class T> struct SpecificAlloc : public SpecificAllocBase {
|
|
void reset() override { Alloc.DestroyAll(); }
|
|
llvm::SpecificBumpPtrAllocator<T> Alloc;
|
|
};
|
|
|
|
template <typename T, typename... U> T *make(U &&... Args) {
|
|
static SpecificAlloc<T> Alloc;
|
|
return new (Alloc.Alloc.Allocate()) T(std::forward<U>(Args)...);
|
|
}
|
|
|
|
inline void freeArena() {
|
|
for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances)
|
|
Alloc->reset();
|
|
BAlloc.Reset();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|