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
28
29extern "C" {
30
31// PGI extension function DSECNDS(refTime)
32double FORTRAN_PROCEDURE_NAME(dsecnds)(double *refTime);
33double RTNAME(Dsecnds)(double *refTime, const char *sourceFile, int line);
34
35// CALL FLUSH(n) antedates the Fortran 2003 FLUSH statement.
36void FORTRAN_PROCEDURE_NAME(flush)(const int &unit);
37
38// GNU extension subroutine FDATE
39void FORTRAN_PROCEDURE_NAME(fdate)(char *string, std::int64_t length);
40
41void RTNAME(Free)(std::intptr_t ptr);
42
43// Common extensions FSEEK & FTELL, variously named
44std::int32_t RTNAME(Fseek)(int unit, std::int64_t zeroBasedPos, int whence,
45 const char *sourceFileName, int lineNumber);
46std::int64_t RTNAME(Ftell)(int unit);
47
48// FNUM maps a Fortran unit number to its UNIX file descriptor
49std::int32_t FORTRAN_PROCEDURE_NAME(fnum)(const int &unitNumber);
50
51// GNU Fortran 77 compatibility function IARGC.
52std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
53
54// GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
55void FORTRAN_PROCEDURE_NAME(getarg)(
56 std::int32_t &n, char *arg, std::int64_t length);
57
58// Calls getgid()
59gid_t RTNAME(GetGID)();
60
61// Calls getuid()
62uid_t RTNAME(GetUID)();
63
64// GNU extension subroutine GETLOG(C).
65void FORTRAN_PROCEDURE_NAME(getlog)(char *name, std::int64_t length);
66
67// GNU extension subroutine HOSTNM(C)
68int FORTRAN_PROCEDURE_NAME(hostnm)(char *hn, int length);
69
70std::intptr_t RTNAME(Malloc)(std::size_t size);
71
72// GNU extension function STATUS = SIGNAL(number, handler)
73std::int64_t RTNAME(Signal)(std::int64_t number, void (*handler)(int));
74
75// GNU extension subroutine SLEEP(SECONDS)
76void RTNAME(Sleep)(std::int64_t seconds);
77
78// GNU extension function TIME()
79std::int64_t RTNAME(time)();
80
81// GNU extension function ACCESS(NAME, MODE)
82// TODO: not supported on Windows
83#ifndef _WIN32
84std::int64_t FORTRAN_PROCEDURE_NAME(access)(const char *name,
85 std::int64_t nameLength, const char *mode, std::int64_t modeLength);
86#endif
87
88// GNU extension subroutine CHDIR(NAME, [STATUS])
89int RTNAME(Chdir)(const char *name);
90
91// GNU extension function IERRNO()
92int FORTRAN_PROCEDURE_NAME(ierrno)();
93
94// GNU extension subroutine PERROR(STRING)
95void RTNAME(Perror)(const char *str);
96
97// MCLOCK -- returns accumulated time in ticks
98int FORTRAN_PROCEDURE_NAME(mclock)();
99
100// GNU extension subroutine SECNDS(refTime)
101float FORTRAN_PROCEDURE_NAME(secnds)(float *refTime);
102float RTNAME(Secnds)(float *refTime, const char *sourceFile, int line);
103
104} // extern "C"
105#endif // FORTRAN_RUNTIME_EXTENSIONS_H_