Skip to content

Commit

Permalink
docs: generate_summary
Browse files Browse the repository at this point in the history
  • Loading branch information
xieby1 committed Dec 20, 2024
1 parent 8f4c8e1 commit a5fc840
Show file tree
Hide file tree
Showing 27 changed files with 57 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ book
*_py.dot
*_py.svg
__pycache__
*extract.md
*.mkd
docs/SUMMARY.md
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
.NOTINTERMEDIATE:

PYSVGs=$(subst _dot.py,_py.svg,$(shell find docs/ -name "*_dot.py"))
EXTRACTMDs=docs/reference/default_extract.md
doc: $(shell find . -name "*.md") ${PYSVGs} ${EXTRACTMDs}
EXTRACTMKDs=docs/references/default_extract.mkd
MDs=$(shell find . -name "*.md")
doc: ${MDs} docs/SUMMARY.md ${PYSVGs} ${EXTRACTMKDs}
mdbook build

%_py.dot: %_dot.py docs/designs/builders/images/common.py
docs/SUMMARY.md: ./docs/generate_summary.py $(filter-out %SUMMARY.md,${MDs})
$< $(dir $<) > $@

%_py.dot: %_dot.py docs/designs/4.builders/images/common.py
python3 $<
%.svg: %.dot
dot -Tsvg $< -o $@
# css can only recognize intrinsic size in px
# https://developer.mozilla.org/en-US/docs/Glossary/Intrinsic_Size
sed -i 's/\([0-9]\+\)pt/\1px/g' $@

docs/reference/default_extract.md: ./docs/extract_comments.py default.nix
docs/references/default_extract.mkd: ./docs/extract_comments.py default.nix
$^ $@
33 changes: 0 additions & 33 deletions docs/SUMMARY.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TODO:
# SPEC CPU 2006

## Preparing SPEC CPU2006 Source Code

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions docs/generate_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
import glob, re, sys

if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <docs_dir>")
sys.exit(1)

def generate_section_body(root_dir:str, sub_dir:str) -> list[str]:
mds_path = glob.glob(f"{sub_dir}/**/*.md", root_dir=root_dir, recursive=True)
mds_path = sorted(mds_path, key=lambda path: path.rstrip("index.md"))
entries: list[str] = []
levels: list[int] = []
for md_path in mds_path:
level = md_path.count('/')
if md_path.endswith("index.md"):
level -= 1
title: str
with open(f"{root_dir}/{md_path}", 'r') as f: title = (re.findall("^# (.*)", f.readline())+[""])[0]
entries.append(f"{' '*level}* [{title}]({md_path})")
levels.append(level)
min_level = min(levels)
well_indented_entries = [entry[2*min_level:] for entry in entries]
return well_indented_entries

print("# Summary")
print("")
print("# 入门(Get Started)")
print("")
print("* [🏠README.md](./index.md)")
print("")
print("# 使用(Usages)")
print("")
for line in generate_section_body(sys.argv[1], "usages/"):
print(line)
print("")
print("# 设计(Designs)")
print("")
for line in generate_section_body(sys.argv[1], "designs/"):
print(line)
print("")
print("# 参考(References)")
print("")
for line in generate_section_body(sys.argv[1], "references/"):
print(line)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# 🧾可配参数(Configurable Arguments)

{{ #include ./default_extract.md }}
{{ #include ./default_extract.mkd }}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Running on Gem5
# Running on Gem5

The checkpoints generated by this repository can be run on Gem5, Nemu, and XiangShan RTL in the XiangShan repository. Here we explain the considerations for running on Gem5.

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit a5fc840

Please sign in to comment.