Skip to content

Commit e7f05f2

Browse files
[Flang] Fix formatting for FIRLangRef.html
Previously, FIRLangRef.md was incorrectly formatted. This was due to how FIRLangRef.md had no page header, and so the first entry would render incorrectly. This patch introduces a header file, which is prepended to the FIRLangRef before it becomes a HTML file. The header is currently brief but can be expanded upon at a later date if required. This formatting fix also means the index page can correctly generate a link to FIRLangRef.html and as such, this patch also removes FIRLangRef from the sidebar and adds it to the main list of links. Depends on D128650 Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D129186
1 parent b379129 commit e7f05f2

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

flang/docs/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,14 @@ if (LLVM_ENABLE_SPHINX)
106106
COMMAND "${CMAKE_COMMAND}" -E copy_directory
107107
"${CMAKE_CURRENT_SOURCE_DIR}"
108108
"${CMAKE_CURRENT_BINARY_DIR}/Source"
109-
110-
COMMAND "${CMAKE_COMMAND}" -E copy
111-
"${CMAKE_CURRENT_BINARY_DIR}/Dialect/FIRLangRef.md"
112-
"${CMAKE_CURRENT_BINARY_DIR}/Source/FIRLangRef.md"
113-
114109
DEPENDS flang-doc)
115110

111+
# Runs a python script prior to HTML generation to prepend a header to FIRLangRef,
112+
# Without the header, the page is incorrectly formatted, as it assumes the first entry is the page title.
113+
add_custom_command(TARGET copy-flang-src-docs
114+
COMMAND "${Python3_EXECUTABLE}"
115+
ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py)
116+
116117
endif()
117118
if (${SPHINX_OUTPUT_MAN})
118119
add_sphinx_target(man flang)

flang/docs/FIR/CreateFIRLangRef.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This script combines FIRLangRef_Header.md with the auto-generated Dialect/FIRLangRef.md
2+
# for the purpose of creating an introduction header/paragraph for FIRLangRef.html
3+
4+
# These paths are relative from the build directroy, not source, as that's where this tool is exectued.
5+
header_path = 'Source/FIR/FIRLangRef_Header.md'
6+
docs_path = 'Dialect/FIRLangRef.md'
7+
output_path = 'Source/FIRLangRef.md'
8+
9+
# 1. Writes line 1 from docs to output, (comment line that the file is autogenerated)
10+
# 2. Adds a new line
11+
# 3. Writes the entire header to the output file
12+
# 4. Writes the remainder of docs to the output file
13+
with open(output_path, 'w') as output:
14+
with open(header_path, 'r') as header, open(docs_path, 'r') as docs:
15+
output.write(docs.readline())
16+
output.write("\n")
17+
output.write(header.read())
18+
output.write(docs.read())

flang/docs/FIR/FIRLangRef_Header.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# FIR Language Reference
2+
3+
This page contains an overview of the Fortran IR operations, their syntax, and example usages.

flang/docs/_templates/indexsidebar.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ <h3>Documentation</h3>
55

66
<ul class="want-points">
77
<li><a href="https://github.com/llvm/llvm-project/blob/main/flang/README.md#getting-started">Getting Started</a></li>
8-
<li><a class="reference internal" href="FIRLangRef.html">Fortran IR Language Reference</a></li>
98
</ul>
109

1110
<h3>Getting Involved</h3>

flang/docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ on how to get in touch with us and to learn more about the current status.
4444
Directives
4545
DoConcurrent
4646
Extensions
47+
FIRLangRef
4748
FlangDriver
4849
FortranIR
4950
FortranLLVMTestSuite

0 commit comments

Comments
 (0)