1 | //===-- lib/Common/Fortran.cpp --------------------------------------------===// |
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/Common/Fortran.h" |
10 | |
11 | namespace Fortran::common { |
12 | |
13 | const char *AsFortran(NumericOperator opr) { |
14 | switch (opr) { |
15 | SWITCH_COVERS_ALL_CASES |
16 | case NumericOperator::Power: |
17 | return "**" ; |
18 | case NumericOperator::Multiply: |
19 | return "*" ; |
20 | case NumericOperator::Divide: |
21 | return "/" ; |
22 | case NumericOperator::Add: |
23 | return "+" ; |
24 | case NumericOperator::Subtract: |
25 | return "-" ; |
26 | } |
27 | } |
28 | |
29 | const char *AsFortran(LogicalOperator opr) { |
30 | switch (opr) { |
31 | SWITCH_COVERS_ALL_CASES |
32 | case LogicalOperator::And: |
33 | return ".and." ; |
34 | case LogicalOperator::Or: |
35 | return ".or." ; |
36 | case LogicalOperator::Eqv: |
37 | return ".eqv." ; |
38 | case LogicalOperator::Neqv: |
39 | return ".neqv." ; |
40 | case LogicalOperator::Not: |
41 | return ".not." ; |
42 | } |
43 | } |
44 | |
45 | const char *AsFortran(RelationalOperator opr) { |
46 | switch (opr) { |
47 | SWITCH_COVERS_ALL_CASES |
48 | case RelationalOperator::LT: |
49 | return "<" ; |
50 | case RelationalOperator::LE: |
51 | return "<=" ; |
52 | case RelationalOperator::EQ: |
53 | return "==" ; |
54 | case RelationalOperator::NE: |
55 | return "/=" ; |
56 | case RelationalOperator::GE: |
57 | return ">=" ; |
58 | case RelationalOperator::GT: |
59 | return ">" ; |
60 | } |
61 | } |
62 | |
63 | const char *AsFortran(DefinedIo x) { |
64 | switch (x) { |
65 | SWITCH_COVERS_ALL_CASES |
66 | case DefinedIo::ReadFormatted: |
67 | return "read(formatted)" ; |
68 | case DefinedIo::ReadUnformatted: |
69 | return "read(unformatted)" ; |
70 | case DefinedIo::WriteFormatted: |
71 | return "write(formatted)" ; |
72 | case DefinedIo::WriteUnformatted: |
73 | return "write(unformatted)" ; |
74 | } |
75 | } |
76 | |
77 | std::string AsFortran(IgnoreTKRSet tkr) { |
78 | std::string result; |
79 | if (tkr.test(IgnoreTKR::Type)) { |
80 | result += 'T'; |
81 | } |
82 | if (tkr.test(IgnoreTKR::Kind)) { |
83 | result += 'K'; |
84 | } |
85 | if (tkr.test(IgnoreTKR::Rank)) { |
86 | result += 'R'; |
87 | } |
88 | if (tkr.test(IgnoreTKR::Device)) { |
89 | result += 'D'; |
90 | } |
91 | if (tkr.test(IgnoreTKR::Managed)) { |
92 | result += 'M'; |
93 | } |
94 | if (tkr.test(IgnoreTKR::Contiguous)) { |
95 | result += 'C'; |
96 | } |
97 | return result; |
98 | } |
99 | |
100 | bool AreCompatibleCUDADataAttrs(std::optional<CUDADataAttr> x, |
101 | std::optional<CUDADataAttr> y, IgnoreTKRSet ignoreTKR) { |
102 | if (!x && !y) { |
103 | return true; |
104 | } else if (x && y && *x == *y) { |
105 | return true; |
106 | } else if (ignoreTKR.test(IgnoreTKR::Device) && |
107 | x.value_or(CUDADataAttr::Device) == CUDADataAttr::Device && |
108 | y.value_or(CUDADataAttr::Device) == CUDADataAttr::Device) { |
109 | return true; |
110 | } else if (ignoreTKR.test(IgnoreTKR::Managed) && |
111 | x.value_or(CUDADataAttr::Managed) == CUDADataAttr::Managed && |
112 | y.value_or(CUDADataAttr::Managed) == CUDADataAttr::Managed) { |
113 | return true; |
114 | } else { |
115 | return false; |
116 | } |
117 | } |
118 | |
119 | } // namespace Fortran::common |
120 | |