• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "testing.h"
2 #include "../../runtime/descriptor.h"
3 #include "../../runtime/transformational.h"
4 #include <cinttypes>
5 
6 using namespace Fortran::common;
7 using namespace Fortran::runtime;
8 
main()9 int main() {
10   static const SubscriptValue ones[]{1, 1, 1};
11   static const SubscriptValue sourceExtent[]{2, 3, 4};
12   auto source{Descriptor::Create(TypeCategory::Integer, sizeof(std::int32_t),
13       nullptr, 3, sourceExtent, CFI_attribute_allocatable)};
14   source->Check();
15   MATCH(3, source->rank());
16   MATCH(sizeof(std::int32_t), source->ElementBytes());
17   TEST(source->IsAllocatable());
18   TEST(!source->IsPointer());
19   TEST(source->Allocate(ones, sourceExtent) == CFI_SUCCESS);
20   TEST(source->IsAllocated());
21   MATCH(2, source->GetDimension(0).Extent());
22   MATCH(3, source->GetDimension(1).Extent());
23   MATCH(4, source->GetDimension(2).Extent());
24   MATCH(24, source->Elements());
25   for (std::size_t j{0}; j < 24; ++j) {
26     *source->OffsetElement<std::int32_t>(j * sizeof(std::int32_t)) = j;
27   }
28 
29   static const std::int16_t shapeData[]{8, 4};
30   static const SubscriptValue shapeExtent{2};
31   auto shape{Descriptor::Create(TypeCategory::Integer,
32       static_cast<int>(sizeof shapeData[0]),
33       const_cast<void *>(reinterpret_cast<const void *>(shapeData)), 1,
34       &shapeExtent, CFI_attribute_pointer)};
35   shape->Check();
36   MATCH(1, shape->rank());
37   MATCH(2, shape->GetDimension(0).Extent());
38   TEST(shape->IsPointer());
39   TEST(!shape->IsAllocatable());
40 
41   StaticDescriptor<3> padDescriptor;
42   Descriptor &pad{padDescriptor.descriptor()};
43   static const std::int32_t padData[]{24, 25, 26, 27, 28, 29, 30, 31};
44   static const SubscriptValue padExtent[]{2, 2, 3};
45   pad.Establish(TypeCategory::Integer, static_cast<int>(sizeof padData[0]),
46       const_cast<void *>(reinterpret_cast<const void *>(padData)), 3, padExtent,
47       CFI_attribute_pointer);
48   padDescriptor.Check();
49   pad.Check();
50   MATCH(3, pad.rank());
51   MATCH(2, pad.GetDimension(0).Extent());
52   MATCH(2, pad.GetDimension(1).Extent());
53   MATCH(3, pad.GetDimension(2).Extent());
54 
55   auto result{RESHAPE(*source, *shape, &pad)};
56   TEST(result.get() != nullptr);
57   result->Check();
58   MATCH(sizeof(std::int32_t), result->ElementBytes());
59   MATCH(2, result->rank());
60   TEST(result->type().IsInteger());
61   for (std::int32_t j{0}; j < 32; ++j) {
62     MATCH(j, *result->OffsetElement<std::int32_t>(j * sizeof(std::int32_t)));
63   }
64   for (std::int32_t j{0}; j < 32; ++j) {
65     SubscriptValue ss[2]{1 + (j % 8), 1 + (j / 8)};
66     MATCH(j, *result->Element<std::int32_t>(ss));
67   }
68 
69   // TODO: test ORDER=
70 
71   return testing::Complete();
72 }
73