mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-01 13:20:25 +00:00
Provide a convenient function to allocate and initialize objects.
You can now write make<T>(Args) instead of new (alloc<T>()) T(Args). llvm-svn: 285760
This commit is contained in:
parent
05c03845e7
commit
d52adb3917
@ -131,7 +131,7 @@ void LinkerDriver::addFile(StringRef Path) {
|
||||
MemoryBufferRef MBRef = *Buffer;
|
||||
|
||||
if (InBinary) {
|
||||
Files.push_back(new (alloc<BinaryFile>()) BinaryFile(MBRef));
|
||||
Files.push_back(make<BinaryFile>(MBRef));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ void LinkerDriver::addFile(StringRef Path) {
|
||||
Files.push_back(createObjectFile(MB, Path));
|
||||
return;
|
||||
}
|
||||
Files.push_back(new (alloc<ArchiveFile>()) ArchiveFile(MBRef));
|
||||
Files.push_back(make<ArchiveFile>(MBRef));
|
||||
return;
|
||||
case file_magic::elf_shared_object:
|
||||
if (Config->Relocatable) {
|
||||
@ -156,7 +156,7 @@ void LinkerDriver::addFile(StringRef Path) {
|
||||
return;
|
||||
default:
|
||||
if (InLib)
|
||||
Files.push_back(new (alloc<LazyObjectFile>()) LazyObjectFile(MBRef));
|
||||
Files.push_back(make<LazyObjectFile>(MBRef));
|
||||
else
|
||||
Files.push_back(createObjectFile(MBRef));
|
||||
}
|
||||
|
@ -407,8 +407,7 @@ elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec,
|
||||
// If -r is given, we do not interpret or apply relocation
|
||||
// but just copy relocation sections to output.
|
||||
if (Config->Relocatable)
|
||||
return new (alloc<InputSection<ELFT>>())
|
||||
InputSection<ELFT>(this, &Sec, Name);
|
||||
return make<InputSection<ELFT>>(this, &Sec, Name);
|
||||
|
||||
// Find the relocation target section and associate this
|
||||
// section with it.
|
||||
@ -450,13 +449,11 @@ elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec,
|
||||
// .eh_frame_hdr section for runtime. So we handle them with a special
|
||||
// class. For relocatable outputs, they are just passed through.
|
||||
if (Name == ".eh_frame" && !Config->Relocatable)
|
||||
return new (alloc<EhInputSection<ELFT>>())
|
||||
EhInputSection<ELFT>(this, &Sec, Name);
|
||||
return make<EhInputSection<ELFT>>(this, &Sec, Name);
|
||||
|
||||
if (shouldMerge(Sec))
|
||||
return new (alloc<MergeInputSection<ELFT>>())
|
||||
MergeInputSection<ELFT>(this, &Sec, Name);
|
||||
return new (alloc<InputSection<ELFT>>()) InputSection<ELFT>(this, &Sec, Name);
|
||||
return make<MergeInputSection<ELFT>>(this, &Sec, Name);
|
||||
return make<InputSection<ELFT>>(this, &Sec, Name);
|
||||
}
|
||||
|
||||
template <class ELFT> void elf::ObjectFile<ELFT>::initializeSymbols() {
|
||||
@ -825,13 +822,13 @@ static InputFile *createELFFile(MemoryBufferRef MB) {
|
||||
|
||||
InputFile *Obj;
|
||||
if (Size == ELFCLASS32 && Endian == ELFDATA2LSB)
|
||||
Obj = new (alloc<T<ELF32LE>>()) T<ELF32LE>(MB);
|
||||
Obj = make<T<ELF32LE>>(MB);
|
||||
else if (Size == ELFCLASS32 && Endian == ELFDATA2MSB)
|
||||
Obj = new (alloc<T<ELF32BE>>()) T<ELF32BE>(MB);
|
||||
Obj = make<T<ELF32BE>>(MB);
|
||||
else if (Size == ELFCLASS64 && Endian == ELFDATA2LSB)
|
||||
Obj = new (alloc<T<ELF64LE>>()) T<ELF64LE>(MB);
|
||||
Obj = make<T<ELF64LE>>(MB);
|
||||
else if (Size == ELFCLASS64 && Endian == ELFDATA2MSB)
|
||||
Obj = new (alloc<T<ELF64BE>>()) T<ELF64BE>(MB);
|
||||
Obj = make<T<ELF64BE>>(MB);
|
||||
else
|
||||
fatal("invalid file class: " + MB.getBufferIdentifier());
|
||||
|
||||
|
@ -49,9 +49,9 @@ template <class T> struct SpecificAlloc : public SpecificAllocBase {
|
||||
|
||||
// Use this arean if your object have a destructor.
|
||||
// Your destructor will be invoked from freeArena().
|
||||
template <class T> static T *alloc() {
|
||||
template <typename T, typename... U> static T *make(U &&... Args) {
|
||||
static SpecificAlloc<T> Alloc;
|
||||
return Alloc.Alloc.Allocate();
|
||||
return new (Alloc.Alloc.Allocate()) T(std::forward<U>(Args)...);
|
||||
}
|
||||
|
||||
void freeArena();
|
||||
|
Loading…
Reference in New Issue
Block a user