1 | //===-- lib/runtime/support.cpp ---------------------------------*- 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 "flang/Runtime/support.h" |
10 | #include "ISO_Fortran_util.h" |
11 | #include "flang-rt/runtime/descriptor.h" |
12 | #include "flang-rt/runtime/type-info.h" |
13 | |
14 | namespace Fortran::runtime { |
15 | extern "C" { |
16 | RT_EXT_API_GROUP_BEGIN |
17 | |
18 | bool RTDEF(IsContiguous)(const Descriptor &descriptor) { |
19 | return descriptor.IsContiguous(); |
20 | } |
21 | |
22 | bool RTDEF(IsContiguousUpTo)(const Descriptor &descriptor, int dim) { |
23 | return descriptor.IsContiguous(dim); |
24 | } |
25 | |
26 | bool RTDEF(IsAssumedSize)(const Descriptor &descriptor) { |
27 | return ISO::IsAssumedSize(&descriptor.raw()); |
28 | } |
29 | |
30 | void RTDEF(CopyAndUpdateDescriptor)(Descriptor &to, const Descriptor &from, |
31 | const typeInfo::DerivedType *newDynamicType, |
32 | ISO::CFI_attribute_t newAttribute, enum LowerBoundModifier newLowerBounds) { |
33 | to = from; |
34 | if (newDynamicType) { |
35 | DescriptorAddendum *toAddendum{to.Addendum()}; |
36 | INTERNAL_CHECK(toAddendum); |
37 | toAddendum->set_derivedType(newDynamicType); |
38 | to.raw().elem_len = newDynamicType->sizeInBytes(); |
39 | } |
40 | to.raw().attribute = newAttribute; |
41 | if (newLowerBounds != LowerBoundModifier::Preserve) { |
42 | const ISO::CFI_index_t newLowerBound{ |
43 | newLowerBounds == LowerBoundModifier::SetToOnes ? 1 : 0}; |
44 | const int rank{to.rank()}; |
45 | for (int i = 0; i < rank; ++i) { |
46 | to.GetDimension(i).SetLowerBound(newLowerBound); |
47 | } |
48 | } |
49 | } |
50 | |
51 | RT_EXT_API_GROUP_END |
52 | } // extern "C" |
53 | } // namespace Fortran::runtime |
54 | |