@@ -3,150 +3,3 @@ Internal commands for developers
33
44.. autocmdgroup :: internal
55 :members:
6-
7- Writing command help
8- --------------------
9-
10- - use `chformal ` as an example
11- - generated help content below
12-
13- .. _chformal autocmd :
14-
15- .. autocmd :: chformal
16- :noindex:
17-
18- The ``formatted_help() `` method
19- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20-
21- - ``PrettyHelp::get_current() ``
22- - ``PrettyHelp::set_group() ``
23-
24- + used with ``.. autocmdgroup:: <group> ``
25- + can assign group and return false
26- + if no group is set, will try to use ``source_location `` and assign group
27- from path to source file
28-
29- - return value
30-
31- + true means help content added to current ``PrettyHelp ``
32- + false to use ``Pass::help() ``
33-
34- - adding content
35-
36- + help content is a list of ``ContentListing `` nodes, each one having a type,
37- body, and its own list of children ``ContentListing ``\ s
38- + ``PrettyHelp::get_root() `` returns the root ``ContentListing `` (``type="root" ``)
39- + ``ContentListing::{usage, option, codeblock, paragraph} `` each add a
40- ``ContentListing `` to the current node, with type the same as the method
41-
42- * the first argument is the body of the new node
43- * ``usage `` shows how to call the command (i.e. its "signature")
44- * ``paragraph `` content is formatted as a paragraph of text with line breaks
45- added automatically
46- * ``codeblock `` content is displayed verbatim, use line breaks as desired;
47- takes an optional ``language `` argument for assigning the language in RST
48- output for code syntax highlighting (use ``yoscrypt `` for yosys script
49- syntax highlighting)
50- * ``option `` lists a single option for the command, usually starting with a
51- dash (``- ``); takes an optional second argument which adds a paragraph
52- node as a means of description
53-
54- + ``ContentListing::open_usage `` creates and returns a new usage node, can be
55- used to e.g. add text/options specific to a given usage of the command
56- + ``ContentListing::open_option `` creates and returns a new option node, can
57- be used to e.g. add multiple paragraphs to an option's description
58- + paragraphs are treated as raw RST, allowing for inline formatting and
59- references as if it were written in the RST file itself
60-
61- .. literalinclude :: /generated/chformal.cc
62- :language: c++
63- :start-at: bool formatted_help()
64- :end-before: void execute
65- :caption: ``ChformalPass::formatted_help() `` from :file: `passes/cmds/chformal.cc `
66-
67- Dumping command help to json
68- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69-
70- - `help -dump-cmds-json cmds.json `
71-
72- + generates a ``ContentListing `` for each command registered in Yosys
73- + tries to parse unformatted ``Pass::help() `` output if
74- ``Pass::formatted_help() `` is unimplemented or returns false
75-
76- * if a line starts with four spaces followed by the name of the command then
77- a space, it is parsed as a signature (usage node)
78- * if a line is indented and starts with a dash (``- ``), it is parsed as an
79- option
80- * anything else is parsed as a codeblock and added to either the root node
81- or the current option depending on the indentation
82-
83- + dictionary of command name to ``ContentListing ``
84-
85- * uses ``ContentListing::to_json() `` recursively for each node in root
86- * root node used for source location of class definition
87- * includes flags set during pass constructor (e.g. ``experimental_flag `` set
88- by ``Pass::experimental() ``)
89- * also title (``short_help `` argument in ``Pass::Pass ``), group, and class
90- name
91-
92- + dictionary of group name to list of commands in that group
93-
94- - used by sphinx autodoc to generate help content
95-
96- .. literalinclude :: /generated/cmds.json
97- :language: json
98- :start-at: "chformal": {
99- :end-before: "chparam": {
100- :caption: `chformal ` in generated :file: `cmds.json `
101-
102- .. note :: Synthesis command scripts are special cased
103-
104- If the final block of help output starts with the string `"The following
105- commands are executed by this synthesis command:\n " `, then the rest of the
106- code block is formatted as ``yoscrypt `` (e.g. `synth_ice40 `). The caveat
107- here is that if the ``script() `` calls ``run() `` on any commands *prior * to
108- the first ``check_label `` then the auto detection will break and revert to
109- unformatted code (e.g. `synth_fabulous `).
110-
111- Command line rendering
112- ~~~~~~~~~~~~~~~~~~~~~~
113-
114- - if ``Pass::formatted_help() `` returns true, will call
115- ``PrettyHelp::log_help() ``
116-
117- + traverse over the children of the root node and render as plain text
118- + effectively the reverse of converting unformatted ``Pass::help() `` text
119- + lines are broken at 80 characters while maintaining indentation (controlled
120- by ``MAX_LINE_LEN `` in :file: `kernel/log_help.cc `)
121- + each line is broken into words separated by spaces, if a given word starts
122- and ends with backticks they will be stripped
123-
124- - if it returns false it will call ``Pass::help() `` which should call ``log() ``
125- directly to print and format help text
126-
127- + if ``Pass::help() `` is not overridden then a default message about missing
128- help will be displayed
129-
130- .. literalinclude :: /generated/chformal.log
131- :lines: 2-
132-
133- RST generated from autocmd
134- ~~~~~~~~~~~~~~~~~~~~~~~~~~
135-
136- - below is the raw RST output from ``autocmd `` (``YosysCmdDocumenter `` class in
137- :file: `docs/util/cmd_documenter.py `) for `chformal ` command
138- - heading will be rendered as a subheading of the most recent heading (see
139- `chformal autocmd `_ above rendered under `Writing command help `_)
140- - ``.. cmd:def:: <cmd> `` line is indexed for cross references with ``:cmd:ref: ``
141- directive (`chformal autocmd `_ above uses ``:noindex: `` option so that
142- `chformal ` still links to the correct location)
143-
144- + ``:title: `` option controls text that appears when hovering over the
145- `chformal ` link
146-
147- - commands with warning flags (experimental or internal) add a ``.. warning ``
148- block before any of the help content
149- - if a command has no ``source_location `` the ``.. note `` at the bottom will
150- instead link to :doc: `/cmd/index_other `
151-
152- .. autocmd_rst :: chformal
0 commit comments