diff --git a/flang/docs/CMakeLists.txt b/flang/docs/CMakeLists.txt --- a/flang/docs/CMakeLists.txt +++ b/flang/docs/CMakeLists.txt @@ -109,13 +109,12 @@ COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/Source") - - # Copies FIRLangRef into the same directory as the - # other .md files, so sphinx can use them - add_custom_command(TARGET docs-flang-html POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy - "${CMAKE_CURRENT_BINARY_DIR}/Dialect/FIRLangRef.md" - "${CMAKE_CURRENT_BINARY_DIR}/Source/FIRLangRef.md") + + # Runs a python script prior to HTML generation to prepend a header to FIRLangRef, + # Without the header, the page is incorrectly formatted, as it assumes the first entry is the page title. + add_custom_command(TARGET copy-flang-src-docs + COMMAND "${Python3_EXECUTABLE}" + ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py) endif() if (${SPHINX_OUTPUT_MAN}) diff --git a/flang/docs/FIR/CreateFIRLangRef.py b/flang/docs/FIR/CreateFIRLangRef.py new file mode 100644 --- /dev/null +++ b/flang/docs/FIR/CreateFIRLangRef.py @@ -0,0 +1,14 @@ +header_path = 'Source/FIR/FIRLangRef_Header.md' +docs_path = 'Dialect/FIRLangRef.md' +output_path = 'Source/FIRLangRef.md' + +# 1. Writes line 1 from docs to output, (comment line that the file is autogenerated) +# 2. Adds a new line +# 3. Writes the entire header to the output file +# 4. Writes the remainder of docs to the output file +with open(output_path, 'w') as output: + with open(header_path, 'r') as header, open(docs_path, 'r') as docs: + output.write(docs.readline()) + output.write("\n") + output.write(header.read()) + output.write(docs.read()) diff --git a/flang/docs/FIR/FIRLangRef_Header.md b/flang/docs/FIR/FIRLangRef_Header.md new file mode 100644 --- /dev/null +++ b/flang/docs/FIR/FIRLangRef_Header.md @@ -0,0 +1,3 @@ +# FIR Language Reference + +This page contains an overview of the Fortran IR operations, their syntax, and example usages. diff --git a/flang/docs/_templates/indexsidebar.html b/flang/docs/_templates/indexsidebar.html --- a/flang/docs/_templates/indexsidebar.html +++ b/flang/docs/_templates/indexsidebar.html @@ -5,7 +5,6 @@ <ul class="want-points"> <li><a href="https://github.com/llvm/llvm-project/blob/main/flang/README.md#getting-started">Getting Started</a></li> - <li><a class="reference internal" href="FIRLangRef.html">Fortran IR Language Reference</a></li> </ul> <h3>Getting Involved</h3> diff --git a/flang/docs/index.md b/flang/docs/index.md --- a/flang/docs/index.md +++ b/flang/docs/index.md @@ -44,6 +44,7 @@ Directives DoConcurrent Extensions + FIRLangRef FlangDriver FortranIR FortranLLVMTestSuite