9#ifndef FORTRAN_RUNTIME_IO_API_CONSTS_H_
10#define FORTRAN_RUNTIME_IO_API_CONSTS_H_
12#include "flang/Common/uint128.h"
13#include "flang/Runtime/entry-names.h"
14#include "flang/Runtime/iostat-consts.h"
15#include "flang/Runtime/magic-numbers.h"
19namespace Fortran::runtime {
23namespace Fortran::runtime::io {
25struct NonTbpDefinedIoTable;
27class IoStatementState;
28using Cookie = IoStatementState *;
29using ExternalUnit = int;
30using AsynchronousId = int;
32static constexpr ExternalUnit DefaultOutputUnit{FORTRAN_DEFAULT_OUTPUT_UNIT};
33static constexpr ExternalUnit DefaultInputUnit{FORTRAN_DEFAULT_INPUT_UNIT};
37using InquiryKeywordHash = std::uint64_t;
38constexpr InquiryKeywordHash HashInquiryKeyword(
const char *p) {
39 InquiryKeywordHash hash{1};
40 while (
char ch{*p++}) {
41 std::uint64_t letter{0};
42 if (ch >=
'a' && ch <=
'z') {
47 hash = 26 * hash + letter;
54#define IONAME(name) RTNAME(io##name)
57#define IODECL(name) RT_API_ATTRS IONAME(name)
61#define IODEF(name) RT_API_ATTRS IONAME(name)
79constexpr std::size_t RecommendedInternalIoScratchAreaBytes(
80 int maxFormatParenthesesNestingDepth) {
81 return 32 + 8 * maxFormatParenthesesNestingDepth;
90Cookie IODECL(BeginInternalArrayListOutput)(
const Descriptor &,
91 void **scratchArea =
nullptr, std::size_t scratchBytes = 0,
92 const char *sourceFile =
nullptr,
int sourceLine = 0);
93Cookie IODECL(BeginInternalArrayListInput)(
const Descriptor &,
94 void **scratchArea =
nullptr, std::size_t scratchBytes = 0,
95 const char *sourceFile =
nullptr,
int sourceLine = 0);
96Cookie IODECL(BeginInternalArrayFormattedOutput)(
const Descriptor &,
97 const char *format, std::size_t formatLength,
98 const Descriptor *formatDescriptor =
nullptr,
void **scratchArea =
nullptr,
99 std::size_t scratchBytes = 0,
const char *sourceFile =
nullptr,
101Cookie IODECL(BeginInternalArrayFormattedInput)(
const Descriptor &,
102 const char *format, std::size_t formatLength,
103 const Descriptor *formatDescriptor =
nullptr,
void **scratchArea =
nullptr,
104 std::size_t scratchBytes = 0,
const char *sourceFile =
nullptr,
109Cookie IODECL(BeginInternalListOutput)(
char *internal,
110 std::size_t internalLength,
void **scratchArea =
nullptr,
111 std::size_t scratchBytes = 0,
const char *sourceFile =
nullptr,
113Cookie IODECL(BeginInternalListInput)(
const char *internal,
114 std::size_t internalLength,
void **scratchArea =
nullptr,
115 std::size_t scratchBytes = 0,
const char *sourceFile =
nullptr,
117Cookie IODECL(BeginInternalFormattedOutput)(
char *internal,
118 std::size_t internalLength,
const char *format, std::size_t formatLength,
119 const Descriptor *formatDescriptor =
nullptr,
void **scratchArea =
nullptr,
120 std::size_t scratchBytes = 0,
const char *sourceFile =
nullptr,
122Cookie IODECL(BeginInternalFormattedInput)(
const char *internal,
123 std::size_t internalLength,
const char *format, std::size_t formatLength,
124 const Descriptor *formatDescriptor =
nullptr,
void **scratchArea =
nullptr,
125 std::size_t scratchBytes = 0,
const char *sourceFile =
nullptr,
137enum Iostat IODECL(CheckUnitNumberInRange64)(std::int64_t unit,
138 bool handleError,
char *ioMsg =
nullptr, std::size_t ioMsgLength = 0,
139 const char *sourceFile =
nullptr,
int sourceLine = 0);
140enum Iostat IODECL(CheckUnitNumberInRange128)(common::int128_t unit,
141 bool handleError,
char *ioMsg =
nullptr, std::size_t ioMsgLength = 0,
142 const char *sourceFile =
nullptr,
int sourceLine = 0);
145Cookie IODECL(BeginExternalListOutput)(ExternalUnit = DefaultOutputUnit,
146 const char *sourceFile =
nullptr,
int sourceLine = 0);
147Cookie IODECL(BeginExternalListInput)(ExternalUnit = DefaultInputUnit,
148 const char *sourceFile =
nullptr,
int sourceLine = 0);
149Cookie IODECL(BeginExternalFormattedOutput)(
const char *format, std::size_t,
150 const Descriptor *formatDescriptor =
nullptr,
151 ExternalUnit = DefaultOutputUnit,
const char *sourceFile =
nullptr,
153Cookie IODECL(BeginExternalFormattedInput)(
const char *format, std::size_t,
154 const Descriptor *formatDescriptor =
nullptr,
155 ExternalUnit = DefaultInputUnit,
const char *sourceFile =
nullptr,
157Cookie IODECL(BeginUnformattedOutput)(ExternalUnit = DefaultOutputUnit,
158 const char *sourceFile =
nullptr,
int sourceLine = 0);
159Cookie IODECL(BeginUnformattedInput)(ExternalUnit = DefaultInputUnit,
160 const char *sourceFile =
nullptr,
int sourceLine = 0);
163Cookie IODECL(BeginWait)(ExternalUnit, AsynchronousId,
164 const char *sourceFile =
nullptr,
int sourceLine = 0);
166Cookie IODECL(BeginWaitAll)(
167 ExternalUnit,
const char *sourceFile =
nullptr,
int sourceLine = 0);
170Cookie IODECL(BeginClose)(
171 ExternalUnit,
const char *sourceFile =
nullptr,
int sourceLine = 0);
172Cookie IODECL(BeginFlush)(
173 ExternalUnit,
const char *sourceFile =
nullptr,
int sourceLine = 0);
174Cookie IODECL(BeginBackspace)(
175 ExternalUnit,
const char *sourceFile =
nullptr,
int sourceLine = 0);
176Cookie IODECL(BeginEndfile)(
177 ExternalUnit,
const char *sourceFile =
nullptr,
int sourceLine = 0);
178Cookie IODECL(BeginRewind)(
179 ExternalUnit,
const char *sourceFile =
nullptr,
int sourceLine = 0);
182Cookie IODECL(BeginOpenUnit)(
183 ExternalUnit,
const char *sourceFile =
nullptr,
int sourceLine = 0);
184Cookie IODECL(BeginOpenNewUnit)(
185 const char *sourceFile =
nullptr,
int sourceLine = 0);
189Cookie IODECL(BeginInquireUnit)(
190 ExternalUnit,
const char *sourceFile =
nullptr,
int sourceLine = 0);
191Cookie IODECL(BeginInquireFile)(
const char *, std::size_t,
192 const char *sourceFile =
nullptr,
int sourceLine = 0);
193Cookie IODECL(BeginInquireIoLength)(
194 const char *sourceFile =
nullptr,
int sourceLine = 0);
212void IODECL(EnableHandlers)(Cookie,
bool hasIoStat =
false,
bool hasErr =
false,
213 bool hasEnd =
false,
bool hasEor =
false,
bool hasIoMsg =
false);
217bool IODECL(SetAsynchronous)(Cookie,
const char *, std::size_t);
224bool IODECL(SetAdvance)(Cookie,
const char *, std::size_t);
226bool IODECL(SetBlank)(Cookie,
const char *, std::size_t);
228bool IODECL(SetDecimal)(Cookie,
const char *, std::size_t);
230bool IODECL(SetDelim)(Cookie,
const char *, std::size_t);
232bool IODECL(SetPad)(Cookie,
const char *, std::size_t);
233bool IODECL(SetPos)(Cookie, std::int64_t);
234bool IODECL(SetRec)(Cookie, std::int64_t);
236bool IODECL(SetRound)(Cookie,
const char *, std::size_t);
238bool IODECL(SetSign)(Cookie,
const char *, std::size_t);
254bool IODECL(OutputDescriptor)(Cookie,
const Descriptor &);
255bool IODECL(InputDescriptor)(Cookie,
const Descriptor &);
257bool IODECL(OutputInteger8)(Cookie, std::int8_t);
258bool IODECL(OutputInteger16)(Cookie, std::int16_t);
259bool IODECL(OutputInteger32)(Cookie, std::int32_t);
260bool IODECL(OutputInteger64)(Cookie, std::int64_t);
261bool IODECL(OutputInteger128)(Cookie, common::int128_t);
262bool IODECL(InputInteger)(Cookie, std::int64_t &,
int kind = 8);
263bool IODECL(OutputReal32)(Cookie, float);
264bool IODECL(InputReal32)(Cookie,
float &);
265bool IODECL(OutputReal64)(Cookie, double);
266bool IODECL(InputReal64)(Cookie,
double &);
267bool IODECL(OutputComplex32)(Cookie, float, float);
268bool IODECL(InputComplex32)(Cookie,
float[2]);
269bool IODECL(OutputComplex64)(Cookie, double, double);
270bool IODECL(InputComplex64)(Cookie,
double[2]);
271bool IODECL(OutputCharacter)(Cookie,
const char *, std::size_t,
int kind = 1);
272bool IODECL(OutputAscii)(Cookie,
const char *, std::size_t);
273bool IODECL(InputCharacter)(Cookie,
char *, std::size_t,
int kind = 1);
274bool IODECL(InputAscii)(Cookie,
char *, std::size_t);
275bool IODECL(OutputLogical)(Cookie, bool);
276bool IODECL(InputLogical)(Cookie,
bool &);
280bool IODECL(OutputNamelist)(Cookie,
const NamelistGroup &);
281bool IODECL(InputNamelist)(Cookie,
const NamelistGroup &);
292bool IODECL(OutputDerivedType)(
293 Cookie,
const Descriptor &,
const NonTbpDefinedIoTable *);
294bool IODECL(InputDerivedType)(
295 Cookie,
const Descriptor &,
const NonTbpDefinedIoTable *);
302bool IODECL(SetAccess)(Cookie,
const char *, std::size_t);
304bool IODECL(SetAction)(Cookie,
const char *, std::size_t);
306bool IODECL(SetCarriagecontrol)(Cookie,
const char *, std::size_t);
308bool IODECL(SetConvert)(Cookie,
const char *, std::size_t);
310bool IODECL(SetEncoding)(Cookie,
const char *, std::size_t);
312bool IODECL(SetForm)(Cookie,
const char *, std::size_t);
314bool IODECL(SetPosition)(Cookie,
const char *, std::size_t);
315bool IODECL(SetRecl)(Cookie, std::size_t);
320bool IODECL(SetStatus)(Cookie,
const char *, std::size_t);
322bool IODECL(SetFile)(Cookie,
const char *, std::size_t chars);
325bool IODECL(GetNewUnit)(Cookie,
int &,
int kind = 4);
328std::size_t IODECL(GetSize)(Cookie);
331std::size_t IODECL(GetIoLength)(Cookie);
335void IODECL(GetIoMsg)(Cookie,
char *, std::size_t);
338AsynchronousId IODECL(GetAsynchronousId)(Cookie);
345bool IODECL(InquireCharacter)(Cookie, InquiryKeywordHash,
char *, std::size_t);
347bool IODECL(InquireLogical)(Cookie, InquiryKeywordHash,
bool &);
349bool IODECL(InquirePendingId)(Cookie, AsynchronousId,
bool &);
351bool IODECL(InquireInteger64)(
352 Cookie, InquiryKeywordHash, std::int64_t &,
int kind = 8);
363enum Iostat IODECL(EndIoStatement)(Cookie);