FLANG
extensions.h
1//===-- include/flang/Runtime/extensions.h ----------------------*- 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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// These C-coded entry points with Fortran-mangled names implement legacy
10// extensions that will eventually be implemented in Fortran.
11
12#ifndef FORTRAN_RUNTIME_EXTENSIONS_H_
13#define FORTRAN_RUNTIME_EXTENSIONS_H_
14
15#include "flang/Runtime/entry-names.h"
16#include <cstddef>
17#include <cstdint>
18
19#define FORTRAN_PROCEDURE_NAME(name) name##_
20
21#ifdef _WIN32
22// UID and GID don't exist on Windows, these exist to avoid errors.
23typedef std::uint32_t uid_t;
24typedef std::uint32_t gid_t;
25#else
26#include "sys/types.h" //pid_t
27#endif
28namespace Fortran {
29namespace runtime {
30class Descriptor;
31}
32} // namespace Fortran
33
34extern "C" {
35
36// PGI extension function DSECNDS(refTime)
37double FORTRAN_PROCEDURE_NAME(dsecnds)(double *refTime);
38double RTNAME(Dsecnds)(double *refTime, const char *sourceFile, int line);
39
40// CALL FLUSH(n) antedates the Fortran 2003 FLUSH statement.
41void FORTRAN_PROCEDURE_NAME(flush)(const int &unit);
42void RTNAME(Flush)(int unit);
43
44// GNU extension subroutine FDATE
45void FORTRAN_PROCEDURE_NAME(fdate)(char *string, std::int64_t length);
46
47void RTNAME(Free)(std::intptr_t ptr);
48
49// Common extensions FSEEK & FTELL, variously named
50std::int32_t RTNAME(Fseek)(int unit, std::int64_t zeroBasedPos, int whence,
51 const char *sourceFileName, int lineNumber);
52std::int64_t RTNAME(Ftell)(int unit);
53
54// FNUM maps a Fortran unit number to its UNIX file descriptor
55std::int32_t FORTRAN_PROCEDURE_NAME(fnum)(const int &unitNumber);
56
57// GNU Fortran 77 compatibility function IARGC.
58std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
59
60// GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
61void FORTRAN_PROCEDURE_NAME(getarg)(
62 std::int32_t &n, char *arg, std::int64_t length);
63
64// Calls getgid()
65gid_t RTNAME(GetGID)();
66
67// Calls getuid()
68uid_t RTNAME(GetUID)();
69
70// GNU extension subroutine GETLOG(C).
71void FORTRAN_PROCEDURE_NAME(getlog)(char *name, std::int64_t length);
72
73// GNU extension subroutine HOSTNM(C)
74int FORTRAN_PROCEDURE_NAME(hostnm)(char *hn, int length);
75
76std::intptr_t RTNAME(Malloc)(std::size_t size);
77
78// GNU extension function STATUS = SIGNAL(number, handler)
79std::int64_t RTNAME(Signal)(std::int64_t number, void (*handler)(int));
80
81// GNU extension subroutine SLEEP(SECONDS)
82void RTNAME(Sleep)(std::int64_t seconds);
83
84// GNU extension function TIME()
85std::int64_t RTNAME(time)();
86
87// GNU extension function ACCESS(NAME, MODE)
88// TODO: not supported on Windows
89#ifndef _WIN32
90std::int64_t FORTRAN_PROCEDURE_NAME(access)(const char *name,
91 std::int64_t nameLength, const char *mode, std::int64_t modeLength);
92#endif
93
94// GNU extension subroutine CHDIR(NAME, [STATUS])
95int RTNAME(Chdir)(const char *name);
96
97// GNU extension function IERRNO()
98int FORTRAN_PROCEDURE_NAME(ierrno)();
99
100// GNU extension subroutine PERROR(STRING)
101void RTNAME(Perror)(const char *str);
102
103// MCLOCK -- returns accumulated time in ticks
104int FORTRAN_PROCEDURE_NAME(mclock)();
105
106// GNU extension subroutine SECNDS(refTime)
107float FORTRAN_PROCEDURE_NAME(secnds)(float *refTime);
108float RTNAME(Secnds)(float *refTime, const char *sourceFile, int line);
109
110// GNU extension function IRAND(I)
111int RTNAME(Irand)(int *i);
112
113// GNU extension function RAND(I)
114float RTNAME(Rand)(int *i, const char *sourceFile, int line);
115
116// GNU extension subroutine SRAND(SEED)
117void FORTRAN_PROCEDURE_NAME(srand)(int *seed);
118
119// flang extension subroutine SHOW_DESCRIPTOR(D)
120void RTNAME(ShowDescriptor)(const Fortran::runtime::Descriptor *descr);
121
122} // extern "C"
123#endif // FORTRAN_RUNTIME_EXTENSIONS_H_
Definition bit-population-count.h:20