[RISCV] Relax march string order constraint (#78120)
[llvm-project.git] / flang / lib / Common / Fortran.cpp
blob27ff31ef78da2823edefe4d7e9303ab6f612117b
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 //===----------------------------------------------------------------------===//
9 #include "flang/Common/Fortran.h"
11 namespace Fortran::common {
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 "-";
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.";
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 ">";
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)";
77 std::string AsFortran(IgnoreTKRSet tkr) {
78 std::string result;
79 if (tkr.test(IgnoreTKR::Type)) {
80 result += 'T';
82 if (tkr.test(IgnoreTKR::Kind)) {
83 result += 'K';
85 if (tkr.test(IgnoreTKR::Rank)) {
86 result += 'R';
88 if (tkr.test(IgnoreTKR::Device)) {
89 result += 'D';
91 if (tkr.test(IgnoreTKR::Managed)) {
92 result += 'M';
94 if (tkr.test(IgnoreTKR::Contiguous)) {
95 result += 'C';
97 return result;
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;
119 } // namespace Fortran::common