llvm-project
169 строк · 5.5 Кб
1//===-- runtime/pseudo-unit.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// Implemenation of ExternalFileUnit and PseudoOpenFile for
10// RT_USE_PSEUDO_FILE_UNIT=1.
11//
12//===----------------------------------------------------------------------===//
13
14#include "io-error.h"15#include "tools.h"16#include "unit.h"17
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)22#include <cstdio>23
24namespace Fortran::runtime::io {25
26void FlushOutputOnCrash(const Terminator &) {}27
28ExternalFileUnit *ExternalFileUnit::LookUp(int) {29Terminator{__FILE__, __LINE__}.Crash("%s: unsupported", RT_PRETTY_FUNCTION);30}
31
32ExternalFileUnit *ExternalFileUnit::LookUpOrCreate(33int, const Terminator &, bool &) {34Terminator{__FILE__, __LINE__}.Crash("%s: unsupported", RT_PRETTY_FUNCTION);35}
36
37ExternalFileUnit *ExternalFileUnit::LookUpOrCreateAnonymous(int unit,38Direction direction, Fortran::common::optional<bool>,39IoErrorHandler &handler) {40if (direction != Direction::Output) {41handler.Crash("ExternalFileUnit only supports output IO");42}43return New<ExternalFileUnit>{handler}(unit).release();44}
45
46ExternalFileUnit *ExternalFileUnit::LookUp(const char *, std::size_t) {47Terminator{__FILE__, __LINE__}.Crash("%s: unsupported", RT_PRETTY_FUNCTION);48}
49
50ExternalFileUnit &ExternalFileUnit::CreateNew(int, const Terminator &) {51Terminator{__FILE__, __LINE__}.Crash("%s: unsupported", RT_PRETTY_FUNCTION);52}
53
54ExternalFileUnit *ExternalFileUnit::LookUpForClose(int) {55Terminator{__FILE__, __LINE__}.Crash("%s: unsupported", RT_PRETTY_FUNCTION);56}
57
58ExternalFileUnit &ExternalFileUnit::NewUnit(const Terminator &, bool) {59Terminator{__FILE__, __LINE__}.Crash("%s: unsupported", RT_PRETTY_FUNCTION);60}
61
62bool ExternalFileUnit::OpenUnit(Fortran::common::optional<OpenStatus> status,63Fortran::common::optional<Action>, Position, OwningPtr<char> &&,64std::size_t, Convert, IoErrorHandler &handler) {65handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);66}
67
68bool ExternalFileUnit::OpenAnonymousUnit(Fortran::common::optional<OpenStatus>,69Fortran::common::optional<Action>, Position, Convert convert,70IoErrorHandler &handler) {71handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);72}
73
74void ExternalFileUnit::CloseUnit(CloseStatus, IoErrorHandler &handler) {75handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);76}
77
78void ExternalFileUnit::DestroyClosed() {79Terminator{__FILE__, __LINE__}.Crash("%s: unsupported", RT_PRETTY_FUNCTION);80}
81
82Iostat ExternalFileUnit::SetDirection(Direction direction) {83if (direction != Direction::Output) {84return IostatReadFromWriteOnly;85}86direction_ = direction;87return IostatOk;88}
89
90void ExternalFileUnit::CloseAll(IoErrorHandler &) {}91
92void ExternalFileUnit::FlushAll(IoErrorHandler &) {}93
94int ExternalFileUnit::GetAsynchronousId(IoErrorHandler &handler) {95handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);96}
97
98bool ExternalFileUnit::Wait(int) {99Terminator{__FILE__, __LINE__}.Crash("unsupported");100}
101
102void PseudoOpenFile::set_mayAsynchronous(bool yes) {103if (yes) {104Terminator{__FILE__, __LINE__}.Crash("%s: unsupported", RT_PRETTY_FUNCTION);105}106}
107
108Fortran::common::optional<PseudoOpenFile::FileOffset>109PseudoOpenFile::knownSize() const {110Terminator{__FILE__, __LINE__}.Crash("unsupported");111}
112
113void PseudoOpenFile::Open(OpenStatus, Fortran::common::optional<Action>,114Position, IoErrorHandler &handler) {115handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);116}
117
118void PseudoOpenFile::Close(CloseStatus, IoErrorHandler &handler) {119handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);120}
121
122std::size_t PseudoOpenFile::Read(123FileOffset, char *, std::size_t, std::size_t, IoErrorHandler &handler) {124handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);125}
126
127std::size_t PseudoOpenFile::Write(FileOffset at, const char *buffer,128std::size_t bytes, IoErrorHandler &handler) {129if (at) {130handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);131}132// TODO: use persistent string buffer that can be reallocated133// as needed, and only freed at destruction of *this.134auto string{SizedNew<char>{handler}(bytes + 1)};135std::memcpy(string.get(), buffer, bytes);136string.get()[bytes] = '\0';137std::printf("%s", string.get());138return bytes;139}
140
141void PseudoOpenFile::Truncate(FileOffset, IoErrorHandler &handler) {142handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);143}
144
145int PseudoOpenFile::ReadAsynchronously(146FileOffset, char *, std::size_t, IoErrorHandler &handler) {147handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);148}
149
150int PseudoOpenFile::WriteAsynchronously(151FileOffset, const char *, std::size_t, IoErrorHandler &handler) {152handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);153}
154
155void PseudoOpenFile::Wait(int, IoErrorHandler &handler) {156handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);157}
158
159void PseudoOpenFile::WaitAll(IoErrorHandler &handler) {160handler.Crash("%s: unsupported", RT_PRETTY_FUNCTION);161}
162
163Position PseudoOpenFile::InquirePosition() const {164Terminator{__FILE__, __LINE__}.Crash("%s: unsupported", RT_PRETTY_FUNCTION);165}
166
167} // namespace Fortran::runtime::io168
169#endif // defined(RT_USE_PSEUDO_FILE_UNIT)170