brintos

brintos / llvm-project-archived public Read only

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