brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 9beb46e Raw
54 lines · cpp
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-exception6//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 14namespace Fortran::runtime {15extern "C" {16RT_EXT_API_GROUP_BEGIN17 18bool RTDEF(IsContiguous)(const Descriptor &descriptor) {19  return descriptor.IsContiguous();20}21 22bool RTDEF(IsContiguousUpTo)(const Descriptor &descriptor, int dim) {23  return descriptor.IsContiguous(dim);24}25 26bool RTDEF(IsAssumedSize)(const Descriptor &descriptor) {27  return ISO::IsAssumedSize(&descriptor.raw());28}29 30void 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 51RT_EXT_API_GROUP_END52} // extern "C"53} // namespace Fortran::runtime54