Skip to content

Commit 4b9f7cd

Browse files
authored
[flang] flang manpage overhaul (#144948)
Make the flang man page look more like the one clang is having.
1 parent 98e8ef2 commit 4b9f7cd

File tree

5 files changed

+103
-37
lines changed

5 files changed

+103
-37
lines changed

flang/docs/CMakeLists.txt

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,14 @@ if (LLVM_ENABLE_DOXYGEN)
8282
endif()
8383
endif()
8484

85-
function (gen_rst_file_from_td output_file td_option source)
85+
function (gen_rst_file_from_td output_file td_option source target)
8686
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
8787
message(FATAL_ERROR "Cannot find source file: ${source} in ${CMAKE_CURRENT_SOURCE_DIR}")
8888
endif()
8989
get_filename_component(TABLEGEN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY)
9090
list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}")
9191
list(APPEND LLVM_TABLEGEN_FLAGS "-I${CMAKE_CURRENT_SOURCE_DIR}/../../clang/include/clang/Driver/")
92-
clang_tablegen(Source/${output_file} ${td_option} SOURCE ${source} TARGET "gen-${output_file}")
93-
# clang_tablegen() does not create the output directory automatically,
94-
# so we have to create it explicitly.
95-
add_custom_target(create-flang-rst-output-dir
96-
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/Source
97-
)
98-
add_dependencies("gen-${output_file}" create-flang-rst-output-dir)
92+
clang_tablegen(Source/${output_file} ${td_option} SOURCE ${source} TARGET ${target})
9993
endfunction()
10094

10195
if (LLVM_ENABLE_SPHINX)
@@ -107,14 +101,22 @@ if (LLVM_ENABLE_SPHINX)
107101
# CLANG_TABLEGEN_EXE variable needs to be set for clang_tablegen to run without error
108102
find_program(CLANG_TABLEGEN_EXE "clang-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
109103

110-
# Generate the RST file from TableGen (shared by both HTML and MAN builds)
111-
gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs FlangOptionsDocs.td)
104+
# Generate the RST file from TableGen (for both HTML and MAN builds)
105+
gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs FlangOptionsDocs.td "gen-FlangCommandLineReference.rst")
106+
gen_rst_file_from_td(FlangCommandLineOptions.rst -gen-opt-docs FlangOptionsMan.td "gen-FlangCommandLineOptions.rst")
107+
# clang_tablegen() (called from gen_rst_file_from_td()) does not create the
108+
# output directory automatically, so we have to create it explicitly.
109+
add_custom_target(create-flang-rst-output-dir
110+
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/Source
111+
)
112+
add_dependencies("gen-FlangCommandLineReference.rst" create-flang-rst-output-dir)
113+
add_dependencies("gen-FlangCommandLineOptions.rst" create-flang-rst-output-dir)
112114

113115
if (${SPHINX_OUTPUT_HTML})
114116
message(STATUS "Using index.md for html build")
115117

116118
# Copy the entire flang/docs directory to the build Source dir,
117-
# then remove the index.rst file, to avoid clash with index.md
119+
# then remove the index.rst file, to avoid clash with index.md
118120
# which is used for the HTML build.
119121
add_custom_target(copy-flang-src-docs-html
120122
COMMAND "${CMAKE_COMMAND}" -E copy_directory
@@ -141,26 +143,26 @@ if (LLVM_ENABLE_SPHINX)
141143
# MAN BUILD SETUP
142144
# ----------------------------
143145
if (${SPHINX_OUTPUT_MAN})
144-
message(STATUS "NOTE: The Flang man page is currently a placeholder with a TODO. See docs/CommandGuide/index.rst for details")
146+
message(STATUS "Using CommandGuide/index.rst for man build")
145147

146148
# Create minimal Source dir with ONLY the files needed for man build:
147149
# - conf.py (Sphinx config)
148150
# - index.rst (top-level man page)
149-
# - FlangCommandLineReference.rst (generated reference)
151+
# - FlangCommandLineOptions.rst (generated reference)
150152
add_custom_target(copy-flang-src-docs-man
151153
COMMAND "${CMAKE_COMMAND}" -E make_directory
152154
"${FLANG_DOCS_MAN_DIR}"
153155
COMMAND "${CMAKE_COMMAND}" -E copy
154156
"${CMAKE_CURRENT_SOURCE_DIR}/conf.py"
155157
"${FLANG_DOCS_MAN_DIR}/conf.py"
156158
COMMAND "${CMAKE_COMMAND}" -E copy
157-
"${CMAKE_CURRENT_BINARY_DIR}/Source/FlangCommandLineReference.rst"
158-
"${FLANG_DOCS_MAN_DIR}/FlangCommandLineReference.rst"
159+
"${CMAKE_CURRENT_BINARY_DIR}/Source/FlangCommandLineOptions.rst"
160+
"${FLANG_DOCS_MAN_DIR}/FlangCommandLineOptions.rst"
159161
COMMAND "${CMAKE_COMMAND}" -E copy
160162
"${CMAKE_CURRENT_SOURCE_DIR}/CommandGuide/index.rst"
161163
"${FLANG_DOCS_MAN_DIR}/index.rst"
162-
DEPENDS flang-doc gen-FlangCommandLineReference.rst)
163-
164+
DEPENDS flang-doc gen-FlangCommandLineOptions.rst)
165+
164166
add_sphinx_target(man flang SOURCE_DIR "${FLANG_DOCS_MAN_DIR}")
165167
add_dependencies(docs-flang-man copy-flang-src-docs-man)
166168
endif()

flang/docs/CommandGuide/index.rst

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,63 @@
1-
Flang Manual Page (In Progress)
2-
==================================================
3-
4-
.. note::
5-
This man page is under development.
6-
7-
For full documentation, please see the online HTML docs:
8-
9-
https://flang.llvm.org/docs/
10-
11-
..
12-
The placeholder text "FlangCommandLineReference" below should eventually be replaced with the actual man page contents.
13-
14-
----
15-
16-
Flang Command Line Reference
17-
----------------------------
1+
flang - the Flang Fortran compiler
2+
==================================
3+
4+
SYNOPSIS
5+
--------
6+
7+
:program:`flang` [*options*] *filename ...*
8+
9+
DESCRIPTION
10+
-----------
11+
12+
:program:`flang` is a Fortran compiler which supports all of the Fortran 95 and
13+
many newer language features. Flang supports OpenMP and has some support for
14+
OpenACC and CUDA. It encompasses preprocessing, parsing, optimization, code
15+
generation, assembly, and linking. Depending on the options passed in, Flang
16+
will perform only some, or all, of these actions. While Flang is highly
17+
integrated, it is important to understand the stages of compilation in order to
18+
understand how to invoke it. These stages are:
19+
20+
Driver
21+
The flang executable is actually a small driver that orchestrates the
22+
execution of other tools such as the compiler, assembler and linker.
23+
Typically you do not need to interact with the driver, but you
24+
transparently use it to run the other tools.
25+
26+
Preprocessing
27+
This stage performs tokenization of the input source file, macro expansion,
28+
#include expansion and handles other preprocessor directives.
29+
30+
Parsing and Semantic Analysis
31+
This stage parses the input file, translating preprocessor tokens into a
32+
parse tree. Once in the form of a parse tree, it applies semantic
33+
analysis to compute types for expressions and determine whether
34+
the code is well formed. Parse errors and most compiler warnings
35+
are generated by this stage.
36+
37+
Code Generation and Optimization
38+
This stage translates the parse tree into intermediate code (known as
39+
"LLVM IR") and, ultimately, machine code. It also optimizes this
40+
intermediate code and handles target-specific code generation. The output
41+
of this stage is typically a ".s" file, referred to as an "assembly" file.
42+
43+
Flang also supports the use of an integrated assembler, in which the code
44+
generator produces object files directly. This avoids the overhead of
45+
generating the ".s" file and calling the target assembler explicitly.
46+
47+
Assembler
48+
This stage runs the target assembler to translate the output of the
49+
compiler into a target object file. The output of this stage is typically
50+
a ".o" file, referred to as an "object" file.
51+
52+
Linker
53+
This stage runs the target linker to merge multiple object files into an
54+
executable or dynamic library. The output of this stage is typically
55+
an "a.out", ".dylib" or ".so" file.
56+
57+
OPTIONS
58+
-------
1859

1960
.. toctree::
2061
:maxdepth: 1
2162

22-
FlangCommandLineReference
63+
FlangCommandLineOptions

flang/docs/FlangOptionsDocs.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//==--- FlangOptionDocs.td - Option documentation -------------------------===//
1+
//==--- FlangOptionsDocs.td - Options documentation -----------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

flang/docs/FlangOptionsMan.td

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//==--- FlangOptionsMan.td - Options documentation ------------------------===//
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+
def GlobalDocumentation {
10+
code Intro =[{..
11+
-------------------------------------------------------------------
12+
NOTE: This file is automatically generated by running clang-tblgen
13+
-gen-opt-docs. Do not edit this file by hand!!
14+
-------------------------------------------------------------------
15+
}];
16+
17+
string Program = "Flang";
18+
list<string> VisibilityMask = ["FlangOption"];
19+
list<string> IgnoreFlags = ["HelpHidden", "Unsupported", "Ignored"];
20+
}
21+
22+
#define GENERATING_DOCS
23+
include "Options.td"

flang/docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
(
234234
"index",
235235
"flang",
236-
"Flang Documentation (In Progress)",
236+
"flang - the Flang Fortran compiler",
237237
["Flang Contributors"],
238238
1,
239239
)

0 commit comments

Comments
 (0)