blob: 0b756e1696e8d852945595c69a5fb29639d3ef86 [file] [log] [blame] [view]
Tim Keith18cee3e2018-05-01 19:50:341<!--
Steve Scalponec90ce542019-03-20 06:47:182Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
Tim Keith18cee3e2018-05-01 19:50:343-->
4
Steve Scalponec90ce542019-03-20 06:47:185# F18
Stephane Chauveau63141a02018-05-03 12:54:536
Steve Scalponeb6ca16e2019-03-20 21:09:357F18 is a ground-up implementation of a Fortran front end written in modern C++.
Steve Scalponec90ce542019-03-20 06:47:188F18, when combined with LLVM, is intended to replace the Flang compiler.
Stephane Chauveau63141a02018-05-03 12:54:539
Steve Scalponec90ce542019-03-20 06:47:1810Flang is a Fortran compiler targeting LLVM.
11Visit the [Flang wiki](https://github.com/flang-compiler/flang/wiki)
12for more information about Flang.
Stephane Chauveau63141a02018-05-03 12:54:5313
Steve Scalponec90ce542019-03-20 06:47:1814## Getting Started
Stephane Chauveau63141a02018-05-03 12:54:5315
Steve Scalponec90ce542019-03-20 06:47:1816Read more about f18 in the [documentation directory](documentation).
17Start with the [compiler overview](documentation/Overview.md).
psteinfeld1b50ccd2019-02-25 17:39:2718
Steve Scalponec90ce542019-03-20 06:47:1819To better understand Fortran as a language
20and the specific grammar accepted by f18,
21read [Fortran For C Programmers](documentation/FortranForCProgrammers.md)
22and
23f18's specifications of the [Fortran grammar](documentation/f2018-grammar.txt)
24and
25the [OpenMP grammar](documentation/OpenMP-4.5-grammar.txt).
psteinfeld1b50ccd2019-02-25 17:39:2726
Steve Scalponec90ce542019-03-20 06:47:1827Treatment of language extensions is covered
28in [this document](documentation/Extensions.md).
29
30To understand the compilers handling of intrinsics,
31see the [discussion of intrinsics](documentation/Intrinsics.md).
32
33To understand how an f18 program communicates with libraries at runtime,
34see the discussion of [runtime descriptors](documentation/RuntimeDescriptor.md).
35
36If you're interested in contributing to the compiler,
37read the [style guide](documentation/C++style.md)
38and
39also review [how f18 uses modern C++ features](documentation/C++17.md).
Stephane Chauveau63141a02018-05-03 12:54:5340
Steve Scalpone2a696002018-05-18 20:02:5841## Building F18
Stephane Chauveau63141a02018-05-03 12:54:5342
Steve Scalponec90ce542019-03-20 06:47:1843### Get the Source Code
44
45```
46cd where/you/want/the/source
47git clone https://github.com/flang-compiler/f18.git
48```
49
50### Supported C++ compilers
Stephane Chauveau63141a02018-05-03 12:54:5351
Steve Scalpone2a696002018-05-18 20:02:5852F18 is written in C++17.
Stephane Chauveau63141a02018-05-03 12:54:5353
Steve Scalpone2a696002018-05-18 20:02:5854The code has been compiled and tested with
peter klauslerfd3a8272018-08-03 23:11:2955GCC versions 7.2.0, 7.3.0, 8.1.0, and 8.2.0.
Stephane Chauveau63141a02018-05-03 12:54:5356
Steve Scalponec90ce542019-03-20 06:47:1857The code has been compiled and tested with
58clang version 7.0 and 8.0
59using either GNU's libstdc++ or LLVM's libc++.
60
61### LLVM dependency
62
63F18 uses components from LLVM.
64
65The instructions to build LLVM can be found at
66https://llvm.org/docs/GettingStarted.html.
67
68We highly recommend using the same compiler to compile both llvm and f18.
69
70The f18 CMakeList.txt file uses
71the variable `LLVM_DIR` to find the installed components.
72
73To get the correct LLVM libraries included in your f18 build,
74define LLVM_DIR on the cmake command line.
75```
76LLVM=<LLVM_INSTALLATION_DIR>/lib/cmake/llvm cmake -DLLVM_DIR=$LLVM ...
77```
78where `LLVM_INSTALLATION_DIR` is
79the top-level directory
80where llvm is installed.
81
82### Building f18 with GCC
peter klausler1e036b22018-05-07 21:39:3683
Steve Scalpone2a696002018-05-18 20:02:5884By default,
85cmake will search for g++ on your PATH.
Steve Scalponec90ce542019-03-20 06:47:1886The g++ version must be one of the supported versions
87in order to build f18.
Stephane Chauveau63141a02018-05-03 12:54:5388
Steve Scalponec90ce542019-03-20 06:47:1889Or,
Steve Scalpone2a696002018-05-18 20:02:5890cmake will use the variable CXX to find the C++ compiler.
91CXX should include the full path to the compiler
92or a name that will be found on your PATH,
93e.g. g++-7.2, assuming g++-7.2 is on your PATH.
94```
95export CXX=g++-7.2
96```
Steve Scalponec90ce542019-03-20 06:47:1897or
98```
99CXX=/opt/gcc-7.2/bin/g++-7.2 cmake ...
100```
101There's a third option!
102The CMakeList.txt file uses the variable GCC
103as the path to the bin directory containing the C++ compiler.
Stephane Chauveau63141a02018-05-03 12:54:53104
Steve Scalpone2a696002018-05-18 20:02:58105GCC can be defined on the cmake command line
106where `<GCC_DIRECTORY>` is the path to a GCC installation with bin, lib, etc:
107```
Steve Scalponec90ce542019-03-20 06:47:18108cmake -DGCC=<GCC_DIRECTORY> ...
109```
110
111### Building f18 with clang
112
113To build f18 with clang,
114cmake needs to know how to find clang++
115and the GCC library and tools that were used to build clang++.
116
117The CMakeList.txt file expects either CXX or BUILD_WITH_CLANG to be set.
118
119CXX should include the full path to clang++
120or clang++ should be found on your PATH.
121```
122export CXX=clang++
123```
124BUILD_WITH_CLANG can be defined on the cmake command line
125where `<CLANG_DIRECTORY>`
126is the path to a clang installation with bin, lib, etc:
127```
128cmake -DBUILD_WITH_CLANG=<CLANG_DIRECTORY>
Steve Scalpone2a696002018-05-18 20:02:58129```
Steve Scalponec90ce542019-03-20 06:47:18130Or GCC can be defined on the f18 cmake command line
131where `<GCC_DIRECTORY>` is the path to a GCC installation with bin, lib, etc:
132```
133cmake -DGCC=<GCC_DIRECTORY> ...
134```
Steve Scalponeb6ca16e2019-03-20 21:09:35135To use f18 after it is built,
136the environment variables PATH and LD_LIBRARY_PATH
137must be set to use GCC and its associated libraries.
Steve Scalpone2a696002018-05-18 20:02:58138
139### Installation Directory
140
141To specify a custom install location,
142add
143`-DCMAKE_INSTALL_PREFIX=<INSTALL_PREFIX>`
144to the cmake command
145where `<INSTALL_PREFIX>`
146is the path where f18 should be installed.
147
148### Build Types
149
150To create a debug build,
151add
152`-DCMAKE_BUILD_TYPE=Debug`
153to the cmake command.
154Debug builds execute slowly.
155
156To create a release build,
157add
158`-DCMAKE_BUILD_TYPE=Release`
159to the cmake command.
160Release builds execute quickly.
161
Steve Scalpone2a696002018-05-18 20:02:58162### Build F18
163```
Steve Scalponeb6ca16e2019-03-20 21:09:35164cd ~/f18/build
165cmake -DLLVM_DIR=$LLVM ~/f18/src
Steve Scalpone2a696002018-05-18 20:02:58166make
167```