2021-09-02 07:00:53 +08:00
|
|
|
#include "flang/Runtime/io-api.h"
|
|
|
|
#include "flang/Runtime/main.h"
|
|
|
|
#include "flang/Runtime/stop.h"
|
2020-01-24 08:59:27 +08:00
|
|
|
#include <cstring>
|
2021-04-22 03:00:55 +08:00
|
|
|
#include <limits>
|
2020-01-24 08:59:27 +08:00
|
|
|
|
|
|
|
using namespace Fortran::runtime::io;
|
|
|
|
|
2020-07-05 05:24:32 +08:00
|
|
|
void output1() {
|
|
|
|
auto io{IONAME(BeginExternalListOutput)()};
|
2020-02-05 08:55:45 +08:00
|
|
|
const char str[]{"Hello, world!"};
|
|
|
|
IONAME(OutputAscii)(io, str, std::strlen(str));
|
|
|
|
IONAME(OutputInteger64)(io, 678);
|
|
|
|
IONAME(OutputReal64)(io, 0.0);
|
|
|
|
IONAME(OutputReal64)(io, 2.0 / 3.0);
|
|
|
|
IONAME(OutputReal64)(io, 1.0e99);
|
2021-04-22 03:00:55 +08:00
|
|
|
IONAME(OutputReal64)(io, std::numeric_limits<double>::infinity());
|
|
|
|
IONAME(OutputReal64)(io, -std::numeric_limits<double>::infinity());
|
|
|
|
IONAME(OutputReal64)(io, std::numeric_limits<double>::quiet_NaN());
|
2020-02-05 08:55:45 +08:00
|
|
|
IONAME(OutputComplex64)(io, 123.0, -234.0);
|
|
|
|
IONAME(OutputLogical)(io, false);
|
|
|
|
IONAME(OutputLogical)(io, true);
|
2020-01-24 08:59:27 +08:00
|
|
|
IONAME(EndIoStatement)(io);
|
2020-07-05 05:24:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void input1() {
|
|
|
|
auto io{IONAME(BeginExternalListOutput)()};
|
|
|
|
const char prompt[]{"Enter an integer value:"};
|
|
|
|
IONAME(OutputAscii)(io, prompt, std::strlen(prompt));
|
|
|
|
IONAME(EndIoStatement)(io);
|
|
|
|
|
|
|
|
io = IONAME(BeginExternalListInput)();
|
|
|
|
std::int64_t n{-666};
|
|
|
|
IONAME(InputInteger)(io, n);
|
|
|
|
IONAME(EndIoStatement)(io);
|
|
|
|
|
|
|
|
io = IONAME(BeginExternalListOutput)();
|
|
|
|
const char str[]{"Result:"};
|
|
|
|
IONAME(OutputAscii)(io, str, std::strlen(str));
|
|
|
|
IONAME(OutputInteger64)(io, n);
|
|
|
|
IONAME(EndIoStatement)(io);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char *argv[], const char *envp[]) {
|
|
|
|
RTNAME(ProgramStart)(argc, argv, envp);
|
|
|
|
output1();
|
|
|
|
input1();
|
|
|
|
RTNAME(PauseStatement)();
|
2020-01-24 08:59:27 +08:00
|
|
|
RTNAME(ProgramEndStatement)();
|
|
|
|
return 0;
|
|
|
|
}
|