• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- ConvertExpr.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/idioms.h"
10 #include "flang/Lower/IntrinsicCall.h"
11 #include "flang/Lower/Support/BoxValue.h"
12 
getBase(const fir::ExtendedValue & ex)13 mlir::Value fir::getBase(const fir::ExtendedValue &ex) {
14   return std::visit(Fortran::common::visitors{
15                         [](const fir::UnboxedValue &x) { return x; },
16                         [](const auto &x) { return x.getAddr(); },
17                     },
18                     ex.box);
19 }
20 
operator <<(llvm::raw_ostream & os,const fir::CharBoxValue & box)21 llvm::raw_ostream &fir::operator<<(llvm::raw_ostream &os,
22                                    const fir::CharBoxValue &box) {
23   os << "boxchar { addr: " << box.getAddr() << ", len: " << box.getLen()
24      << " }";
25   return os;
26 }
27 
operator <<(llvm::raw_ostream & os,const fir::ArrayBoxValue & box)28 llvm::raw_ostream &fir::operator<<(llvm::raw_ostream &os,
29                                    const fir::ArrayBoxValue &box) {
30   os << "boxarray { addr: " << box.getAddr();
31   if (box.getLBounds().size()) {
32     os << ", lbounds: [";
33     llvm::interleaveComma(box.getLBounds(), os);
34     os << "]";
35   } else {
36     os << ", lbounds: all-ones";
37   }
38   os << ", shape: [";
39   llvm::interleaveComma(box.getExtents(), os);
40   os << "]}";
41   return os;
42 }
43 
operator <<(llvm::raw_ostream & os,const fir::CharArrayBoxValue & box)44 llvm::raw_ostream &fir::operator<<(llvm::raw_ostream &os,
45                                    const fir::CharArrayBoxValue &box) {
46   os << "boxchararray { addr: " << box.getAddr() << ", len : " << box.getLen();
47   if (box.getLBounds().size()) {
48     os << ", lbounds: [";
49     llvm::interleaveComma(box.getLBounds(), os);
50     os << "]";
51   } else {
52     os << " lbounds: all-ones";
53   }
54   os << ", shape: [";
55   llvm::interleaveComma(box.getExtents(), os);
56   os << "]}";
57   return os;
58 }
59 
operator <<(llvm::raw_ostream & os,const fir::BoxValue & box)60 llvm::raw_ostream &fir::operator<<(llvm::raw_ostream &os,
61                                    const fir::BoxValue &box) {
62   os << "box { addr: " << box.getAddr();
63   if (box.getLen())
64     os << ", size: " << box.getLen();
65   if (box.params.size()) {
66     os << ", type params: [";
67     llvm::interleaveComma(box.params, os);
68     os << "]";
69   }
70   if (box.getLBounds().size()) {
71     os << ", lbounds: [";
72     llvm::interleaveComma(box.getLBounds(), os);
73     os << "]";
74   }
75   if (box.getExtents().size()) {
76     os << ", shape: [";
77     llvm::interleaveComma(box.getExtents(), os);
78     os << "]";
79   }
80   os << "}";
81   return os;
82 }
83 
operator <<(llvm::raw_ostream & os,const fir::ProcBoxValue & box)84 llvm::raw_ostream &fir::operator<<(llvm::raw_ostream &os,
85                                    const fir::ProcBoxValue &box) {
86   os << "boxproc: { addr: " << box.getAddr() << ", context: " << box.hostContext
87      << "}";
88   return os;
89 }
90 
operator <<(llvm::raw_ostream & os,const fir::ExtendedValue & ex)91 llvm::raw_ostream &fir::operator<<(llvm::raw_ostream &os,
92                                    const fir::ExtendedValue &ex) {
93   std::visit([&](const auto &value) { os << value; }, ex.box);
94   return os;
95 }
96