1 //===-- runtime/pseudo-unit.cpp -------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Implemenation of ExternalFileUnit and PseudoOpenFile for
10 // RT_USE_PSEUDO_FILE_UNIT=1.
12 //===----------------------------------------------------------------------===//
18 // NOTE: the header files above may define OpenMP declare target
19 // variables, so they have to be included unconditionally
20 // so that the offload entries are consistent between host and device.
21 #if defined(RT_USE_PSEUDO_FILE_UNIT)
24 namespace Fortran::runtime::io
{
26 void FlushOutputOnCrash(const Terminator
&) {}
28 ExternalFileUnit
*ExternalFileUnit::LookUp(int) {
29 Terminator
{__FILE__
, __LINE__
}.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
32 ExternalFileUnit
*ExternalFileUnit::LookUpOrCreate(
33 int, const Terminator
&, bool &) {
34 Terminator
{__FILE__
, __LINE__
}.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
37 ExternalFileUnit
*ExternalFileUnit::LookUpOrCreateAnonymous(int unit
,
38 Direction direction
, Fortran::common::optional
<bool>,
39 IoErrorHandler
&handler
) {
40 if (direction
!= Direction::Output
) {
41 handler
.Crash("ExternalFileUnit only supports output IO");
43 return New
<ExternalFileUnit
>{handler
}(unit
).release();
46 ExternalFileUnit
*ExternalFileUnit::LookUp(const char *, std::size_t) {
47 Terminator
{__FILE__
, __LINE__
}.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
50 ExternalFileUnit
&ExternalFileUnit::CreateNew(int, const Terminator
&) {
51 Terminator
{__FILE__
, __LINE__
}.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
54 ExternalFileUnit
*ExternalFileUnit::LookUpForClose(int) {
55 Terminator
{__FILE__
, __LINE__
}.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
58 ExternalFileUnit
&ExternalFileUnit::NewUnit(const Terminator
&, bool) {
59 Terminator
{__FILE__
, __LINE__
}.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
62 bool ExternalFileUnit::OpenUnit(Fortran::common::optional
<OpenStatus
> status
,
63 Fortran::common::optional
<Action
>, Position
, OwningPtr
<char> &&,
64 std::size_t, Convert
, IoErrorHandler
&handler
) {
65 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
68 bool ExternalFileUnit::OpenAnonymousUnit(Fortran::common::optional
<OpenStatus
>,
69 Fortran::common::optional
<Action
>, Position
, Convert convert
,
70 IoErrorHandler
&handler
) {
71 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
74 void ExternalFileUnit::CloseUnit(CloseStatus
, IoErrorHandler
&handler
) {
75 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
78 void ExternalFileUnit::DestroyClosed() {
79 Terminator
{__FILE__
, __LINE__
}.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
82 Iostat
ExternalFileUnit::SetDirection(Direction direction
) {
83 if (direction
!= Direction::Output
) {
84 return IostatReadFromWriteOnly
;
86 direction_
= direction
;
90 void ExternalFileUnit::CloseAll(IoErrorHandler
&) {}
92 void ExternalFileUnit::FlushAll(IoErrorHandler
&) {}
94 int ExternalFileUnit::GetAsynchronousId(IoErrorHandler
&handler
) {
95 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
98 bool ExternalFileUnit::Wait(int) {
99 Terminator
{__FILE__
, __LINE__
}.Crash("unsupported");
102 void PseudoOpenFile::set_mayAsynchronous(bool yes
) {
104 Terminator
{__FILE__
, __LINE__
}.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
108 Fortran::common::optional
<PseudoOpenFile::FileOffset
>
109 PseudoOpenFile::knownSize() const {
110 Terminator
{__FILE__
, __LINE__
}.Crash("unsupported");
113 void PseudoOpenFile::Open(OpenStatus
, Fortran::common::optional
<Action
>,
114 Position
, IoErrorHandler
&handler
) {
115 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
118 void PseudoOpenFile::Close(CloseStatus
, IoErrorHandler
&handler
) {
119 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
122 std::size_t PseudoOpenFile::Read(
123 FileOffset
, char *, std::size_t, std::size_t, IoErrorHandler
&handler
) {
124 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
127 std::size_t PseudoOpenFile::Write(FileOffset at
, const char *buffer
,
128 std::size_t bytes
, IoErrorHandler
&handler
) {
130 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
132 // TODO: use persistent string buffer that can be reallocated
133 // as needed, and only freed at destruction of *this.
134 auto string
{SizedNew
<char>{handler
}(bytes
+ 1)};
135 std::memcpy(string
.get(), buffer
, bytes
);
136 string
.get()[bytes
] = '\0';
137 std::printf("%s", string
.get());
141 void PseudoOpenFile::Truncate(FileOffset
, IoErrorHandler
&handler
) {
142 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
145 int PseudoOpenFile::ReadAsynchronously(
146 FileOffset
, char *, std::size_t, IoErrorHandler
&handler
) {
147 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
150 int PseudoOpenFile::WriteAsynchronously(
151 FileOffset
, const char *, std::size_t, IoErrorHandler
&handler
) {
152 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
155 void PseudoOpenFile::Wait(int, IoErrorHandler
&handler
) {
156 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
159 void PseudoOpenFile::WaitAll(IoErrorHandler
&handler
) {
160 handler
.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
163 Position
PseudoOpenFile::InquirePosition() const {
164 Terminator
{__FILE__
, __LINE__
}.Crash("%s: unsupported", RT_PRETTY_FUNCTION
);
167 } // namespace Fortran::runtime::io
169 #endif // defined(RT_USE_PSEUDO_FILE_UNIT)