Warning: This file is not a C or C++ file. It does not have highlighting.

1//===-- include/flang/Runtime/temporary-stack.h -----------------*- 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// Runtime functions for storing a dynamically resizable number of temporaries.
9// For use in HLFIR lowering.
10//===----------------------------------------------------------------------===//
11
12#ifndef FORTRAN_RUNTIME_TEMPORARY_STACK_H_
13#define FORTRAN_RUNTIME_TEMPORARY_STACK_H_
14
15#include "flang/Runtime/entry-names.h"
16#include <stdint.h>
17
18namespace Fortran::runtime {
19class Descriptor;
20extern "C" {
21
22// Stores both the descriptor and a copy of the value in a dynamically resizable
23// data structure identified by opaquePtr. All value stacks must be destroyed
24// at the end of their lifetime and not used afterwards.
25// Popped descriptors point to the copy of the value, not the original address
26// of the value. This copy is dynamically allocated, it is up to the caller to
27// free the value pointed to by the box. The copy operation is a simple memcpy.
28// The sourceFile and line number used when creating the stack are shared for
29// all operations.
30// Opaque pointers returned from these are incompatible with those returned by
31// the flavours for storing descriptors.
32[[nodiscard]] void *RTNAME(CreateValueStack)(
33 const char *sourceFile = nullptr, int line = 0);
34void RTNAME(PushValue)(void *opaquePtr, const Descriptor &value);
35// Note: retValue should be large enough to hold the right number of dimensions,
36// and the optional descriptor addendum
37void RTNAME(PopValue)(void *opaquePtr, Descriptor &retValue);
38// Return the i'th element into retValue (which must be the right size). An
39// exact copy of this descriptor remains in this storage so this one should not
40// be deallocated
41void RTNAME(ValueAt)(void *opaquePtr, uint64_t i, Descriptor &retValue);
42void RTNAME(DestroyValueStack)(void *opaquePtr);
43
44// Stores descriptors value in a dynamically resizable data structure identified
45// by opaquePtr. All descriptor stacks must be destroyed at the end of their
46// lifetime and not used afterwards.
47// Popped descriptors are identical to those which were pushed.
48// The sourceFile and line number used when creating the stack are shared for
49// all operations.
50// Opaque pointers returned from these are incompatible with those returned by
51// the flavours for storing both descriptors and values.
52[[nodiscard]] void *RTNAME(CreateDescriptorStack)(
53 const char *sourceFile = nullptr, int line = 0);
54void RTNAME(PushDescriptor)(void *opaquePtr, const Descriptor &value);
55// Note: retValue should be large enough to hold the right number of dimensions,
56// and the optional descriptor addendum
57void RTNAME(PopDescriptor)(void *opaquePtr, Descriptor &retValue);
58// Return the i'th element into retValue (which must be the right size). An
59// exact copy of this descriptor remains in this storage so this one should not
60// be deallocated
61void RTNAME(DescriptorAt)(void *opaquePtr, uint64_t i, Descriptor &retValue);
62void RTNAME(DestroyDescriptorStack)(void *opaquePtr);
63
64} // extern "C"
65} // namespace Fortran::runtime
66
67#endif // FORTRAN_RUNTIME_TEMPORARY_STACK_H_
68

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of flang/include/flang/Runtime/temporary-stack.h