summaryrefslogtreecommitdiff
path: root/flang/runtime/connection.h
diff options
context:
space:
mode:
authorpeter klausler <pklausler@nvidia.com>2020-02-04 16:55:45 -0800
committerpeter klausler <pklausler@nvidia.com>2020-02-13 10:31:26 -0800
commit95696d563b927cb51f4a55976e7f64992e1c0acf (patch)
tree959b42e045042b29aeb94066d393c7ef739badc1 /flang/runtime/connection.h
parentdbea781d199babb68a71d08a0694522184b93e2d (diff)
downloadllvm-95696d563b927cb51f4a55976e7f64992e1c0acf.tar.gz
[flang] Progress on Fortran I/O runtime
Use internal units for internal I/O state Replace use of virtual functions reference_wrapper Internal formatted output to array descriptor Delete dead code Begin list-directed internal output Refactorings and renamings for clarity List-directed external I/O (character) COMPLEX list-directed output Control list items First cut at unformatted I/O More OPEN statement work; rename class to ExternalFileUnit Complete OPEN (exc. for POSITION=), add CLOSE() OPEN(POSITION=) Flush buffers on crash and for terminal output; clean up Documentation Fix backquote in documentation Fix typo in comment Begin implementation of input Refactor binary floating-point properties to a new header, simplify numeric output editing Dodge spurious GCC 7.2 build warning Address review comments Original-commit: flang-compiler/f18@9c4bba11cf2329575ea9ee446f69e9caa797135c Reviewed-on: https://github.com/flang-compiler/f18/pull/982
Diffstat (limited to 'flang/runtime/connection.h')
-rw-r--r--flang/runtime/connection.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/flang/runtime/connection.h b/flang/runtime/connection.h
new file mode 100644
index 000000000000..85372dfa610d
--- /dev/null
+++ b/flang/runtime/connection.h
@@ -0,0 +1,50 @@
+//===-- runtime/connection.h ------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Fortran I/O connection state (internal & external)
+
+#ifndef FORTRAN_RUNTIME_IO_CONNECTION_H_
+#define FORTRAN_RUNTIME_IO_CONNECTION_H_
+
+#include "format.h"
+#include <cinttypes>
+#include <optional>
+
+namespace Fortran::runtime::io {
+
+enum class Access { Sequential, Direct, Stream };
+
+inline bool IsRecordFile(Access a) { return a != Access::Stream; }
+
+// These characteristics of a connection are immutable after being
+// established in an OPEN statement.
+struct ConnectionAttributes {
+ Access access{Access::Sequential}; // ACCESS='SEQUENTIAL', 'DIRECT', 'STREAM'
+ std::optional<std::size_t> recordLength; // RECL= when fixed-length
+ bool isUnformatted{false}; // FORM='UNFORMATTED'
+ bool isUTF8{false}; // ENCODING='UTF-8'
+};
+
+struct ConnectionState : public ConnectionAttributes {
+ std::size_t RemainingSpaceInRecord() const;
+ // Positions in a record file (sequential or direct, but not stream)
+ std::int64_t recordOffsetInFile{0};
+ std::int64_t currentRecordNumber{1}; // 1 is first
+ std::int64_t positionInRecord{0}; // offset in current record
+ std::int64_t furthestPositionInRecord{0}; // max(positionInRecord)
+ bool nonAdvancing{false}; // ADVANCE='NO'
+ // Set at end of non-advancing I/O data transfer
+ std::optional<std::int64_t> leftTabLimit; // offset in current record
+ // currentRecordNumber value captured after ENDFILE/REWIND/BACKSPACE statement
+ // on a sequential access file
+ std::optional<std::int64_t> endfileRecordNumber;
+ // Mutable modes set at OPEN() that can be overridden in READ/WRITE & FORMAT
+ MutableModes modes; // BLANK=, DECIMAL=, SIGN=, ROUND=, PAD=, DELIM=, kP
+};
+}
+#endif // FORTRAN_RUNTIME_IO_CONNECTION_H_