xref: /llvm-project/flang/docs/FIR/CreateFIRLangRef.py (revision f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c)
1e7f05f2aSDylan Fleming# This script combines FIRLangRef_Header.md with the auto-generated Dialect/FIRLangRef.md
2d5fa11c4SDylan Fleming# for the purpose of creating an introduction header/paragraph for FIRLangRef.html.
3e7f05f2aSDylan Fleming
4d5fa11c4SDylan Flemingimport os
5d5fa11c4SDylan Fleming
6d5fa11c4SDylan Fleming# These paths are relative to flang/docs in the build directory, not source, as that's where this tool is executed.
7*f98ee40fSTobias HietaHEADER_PATH = os.path.join("Source", "FIR", "FIRLangRef_Header.md")
8*f98ee40fSTobias HietaDOCS_PATH = os.path.join("Dialect", "FIRLangRef.md")
9*f98ee40fSTobias HietaOUTPUT_PATH = os.path.join("Source", "FIRLangRef.md")
10e7f05f2aSDylan Fleming
11e7f05f2aSDylan Fleming# 1. Writes line 1 from docs to output, (comment line that the file is autogenerated)
12e7f05f2aSDylan Fleming# 2. Adds a new line
13e7f05f2aSDylan Fleming# 3. Writes the entire header to the output file
14e7f05f2aSDylan Fleming# 4. Writes the remainder of docs to the output file
15*f98ee40fSTobias Hietawith open(OUTPUT_PATH, "w") as output:
16*f98ee40fSTobias Hieta    with open(HEADER_PATH, "r") as header, open(DOCS_PATH, "r") as docs:
17e7f05f2aSDylan Fleming        output.write(docs.readline())
18e7f05f2aSDylan Fleming        output.write("\n")
19e7f05f2aSDylan Fleming        output.write(header.read())
20e7f05f2aSDylan Fleming        output.write(docs.read())
21