diff options
author | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2021-06-16 08:00:50 +0000 |
---|---|---|
committer | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2021-06-16 08:00:50 +0000 |
commit | 062644bb399bd05fd0aeb3cb9d52fa0014db0bdd (patch) | |
tree | 22029a324041a482ffd19851f4b24f6536f10a5f /flang/examples | |
parent | a6be6e31f1810012922e50dab0d4c15cdf990d2e (diff) | |
download | llvm-062644bb399bd05fd0aeb3cb9d52fa0014db0bdd.tar.gz |
[flang][nfc] Move `external-hello-world` to flang/examples
As `external-hello-world` is not really a test, I am moving it from
`flang/unittest/Runtime` to `flang/examples` (it makes a lot of sense as
an example). I've not modified the source code (apart from adjusting the
include paths).
Differential Revision: https://reviews.llvm.org/D104320
Diffstat (limited to 'flang/examples')
-rw-r--r-- | flang/examples/CMakeLists.txt | 8 | ||||
-rw-r--r-- | flang/examples/external-hello.cpp | 51 |
2 files changed, 59 insertions, 0 deletions
diff --git a/flang/examples/CMakeLists.txt b/flang/examples/CMakeLists.txt new file mode 100644 index 000000000000..3ca9feddf33e --- /dev/null +++ b/flang/examples/CMakeLists.txt @@ -0,0 +1,8 @@ +# This test is not run by default as it requires input. +add_executable(external-hello-world + external-hello.cpp +) + +target_link_libraries(external-hello-world + FortranRuntime +) diff --git a/flang/examples/external-hello.cpp b/flang/examples/external-hello.cpp new file mode 100644 index 000000000000..7c300d702cae --- /dev/null +++ b/flang/examples/external-hello.cpp @@ -0,0 +1,51 @@ +#include "../runtime/io-api.h" +#include "../runtime/main.h" +#include "../runtime/stop.h" +#include <cstring> +#include <limits> + +using namespace Fortran::runtime::io; + +void output1() { + auto io{IONAME(BeginExternalListOutput)()}; + 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); + 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()); + IONAME(OutputComplex64)(io, 123.0, -234.0); + IONAME(OutputLogical)(io, false); + IONAME(OutputLogical)(io, true); + IONAME(EndIoStatement)(io); +} + +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)(); + RTNAME(ProgramEndStatement)(); + return 0; +} |