| 1 | //===----- FunctionInfo.cpp - ABI Function Information ----------- C++ ----===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/ABI/FunctionInfo.h" |
| 10 | #include <optional> |
| 11 | |
| 12 | using namespace llvm; |
| 13 | using namespace llvm::abi; |
| 14 | |
| 15 | FunctionInfo *FunctionInfo::create(CallingConv::ID CC, const Type *ReturnType, |
| 16 | ArrayRef<const Type *> ArgTypes, |
| 17 | std::optional<unsigned> NumRequired) { |
| 18 | |
| 19 | assert(!NumRequired || *NumRequired <= ArgTypes.size()); |
| 20 | |
| 21 | void *Buffer = operator new(totalSizeToAlloc<ArgEntry>(Counts: ArgTypes.size())); |
| 22 | |
| 23 | FunctionInfo *FI = |
| 24 | new (Buffer) FunctionInfo(CC, ReturnType, ArgTypes.size(), NumRequired); |
| 25 | |
| 26 | ArgEntry *Args = FI->getTrailingObjects(); |
| 27 | for (unsigned I = 0; I < ArgTypes.size(); ++I) |
| 28 | new (&Args[I]) ArgEntry(ArgTypes[I]); |
| 29 | |
| 30 | return FI; |
| 31 | } |
| 32 |