Skip to content

Commit 8675d4c

Browse files
committed
addressed comments and fixed formatting
1 parent ac227cd commit 8675d4c

File tree

1 file changed

+110
-80
lines changed

1 file changed

+110
-80
lines changed

libc/docs/dev/header_generation.rst

Lines changed: 110 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Generating Public and Internal headers
55
======================================
66

77
This is a new implementation of the previous libc header generator. The old
8-
header generator (libc-hdrgen aka headergen”) is based on tablegen, which
9-
creates an awkward dependency on the rest of LLVM for our build system. By
8+
header generator (libc-hdrgen aka "headergen") was based on tablegen, which
9+
created an awkward dependency on the rest of LLVM for our build system. By
1010
creating a new standalone headergen we can eliminate these dependencies for
1111
easier cross compatibility.
1212

@@ -22,11 +22,11 @@ and extra macro and type inclusions from the .h.def file.
2222

2323

2424
Instructions
25-
-----------------------------
25+
------------
2626

2727
Required Versions:
2828

29-
- Python Version: 3.11.8 [subject to be lower]
29+
- Python Version: 3.11.8
3030
- CMake Version: 3.20.0
3131

3232
1. Make sure to have `LLVM <https://llvm.org/docs/GettingStarted.html>`_ on your
@@ -39,46 +39,47 @@ Required Versions:
3939
directory ``ninja check-newhdrgen`` to ensure that the integration tests are
4040
passing.
4141
5. Then enter in the command line ``ninja libc`` to generate headers. Headers
42-
will be in build/projects/libc/include or build/libc/include in a runtime
42+
will be in ``build/projects/libc/include`` or ``build/libc/include`` in a runtime
4343
build. Sys spec headers will be located in
4444
``build/projects/libc/include/sys``.
4545

4646

47-
New Headergen is turned on by default, but if you wanted to use old headergen,
47+
New Headergen is turned on by default, but if you want to use old headergen,
4848
you can include this statement when building: ``-DLIBC_USE_NEW_HEADER_GEN=OFF``
4949

5050
To add a function to the yaml files, you can either manually enter it in the
51-
yaml file depending on the header spec or enter it through the command line.
51+
yaml file corresponding to the header it belongs to or add it through the
52+
command line.
5253

53-
To enter through the command line:
54+
To add through the command line:
5455

5556
1. Make sure you are in the llvm-project directory.
5657

5758
2. Enter in the command line:
58-
``python3 libc/newhdrgen/yaml_to_classes.py
59-
libc/newhdrgen/yaml/[yaml_file.yaml] --add_function <return_type>
60-
<function_name> <function_arg1, function_arg2> <standard> <guard>
59+
:raw-html:`<br />` ``python3 libc/newhdrgen/yaml_to_classes.py
60+
libc/newhdrgen/yaml/[yaml_file.yaml] --add_function "<return_type>"
61+
<function_name> "<function_arg1, function_arg2>" <standard> <guard>
6162
<attribute>``
6263

6364
Example:
64-
``python3 libc/newhdrgen/yaml_to_classes.py
65-
libc/newhdrgen/yaml/ctype.yaml --add_function char example_funtion int,
66-
void, const void stdc example_float example_attribute``
65+
:raw-html:`<br />` ``python3 libc/newhdrgen/yaml_to_classes.py
66+
libc/newhdrgen/yaml/ctype.yaml --add_function "char" example_funtion "int,
67+
void, const void" stdc example_float example_attribute``
6768

6869
Keep in mind only the return_type and arguments have quotes around them. If
69-
you do not have any guards or attributes you may enter null for both.
70+
you do not have any guards or attributes you may enter "null" for both.
7071

7172
3. Check the yaml file that the added function is present. You will also get a
7273
generated header file with the new addition in the newhdrgen directory to
7374
examine.
7475

7576

7677
Testing
77-
-----------------------------
78+
-------
7879

7980
New Headergen has an integration test that you may run once you have configured
8081
your CMake within the build directory. In the command line, enter the following:
81-
ninja check -newhdrgen. The integration test is one test that ensures the
82+
``ninja check-newhdrgen``. The integration test is one test that ensures the
8283
process of yaml to classes to generate headers works properly. If there are any
8384
new additions on formatting headers, make sure the test is updated with the
8485
specific addition.
@@ -90,71 +91,100 @@ File to modify if adding something to formatting:
9091

9192

9293
Common Errors
93-
-----------------------------
94-
1. ``"/llvm-project/libc/newhdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"]``
95-
96-
If you receive this error or any error pertaining to
97-
``function_data[function_specific_component]`` while building the headers that
98-
means the function specific component is missing within the yaml files.
99-
Through the call stack, you will be able to find the header file which has the
100-
issue. Ensure there is no missing function specific component for that yaml
101-
header file.
102-
103-
2. ``CMake Error at:
104-
/llvm-project/libc/cmake/modules/LLVMLibCHeaderRules.cmake:86 (message):
105-
'add_gen_hdr2' rule requires GEN_HDR to be specified.
106-
Call Stack (most recent call first):
107-
/llvm-project/libc/include/CMakeLists.txt:22 (add_gen_header2)
108-
/llvm-project/libc/include/CMakeLists.txt:62 (add_header_macro)``
109-
110-
If you receive this error, there is a missing yaml_file, h_def file, or
111-
header name within the ``libc/include/CMakeLists.txt``. The last line in the
112-
error call stack will point to the header where there is a specific
113-
component missing. Ensure the correct style and required files are present:
114-
115-
| ``[header_name]``
116-
| ``[../libc/newhdrgen/yaml/[yaml_file.yaml]``
117-
| ``[header_name.h.def]``
118-
| ``[header_name.h]``
119-
| ``DEPENDS``
120-
| ``{Necessary Depend Files}``
121-
122-
3. ``usage: yaml_to_classes.py [-h] [--output_dir OUTPUT_DIR]
123-
[--h_def_file H_DEF_FILE] [--add_function RETURN_TYPE NAME ARGUMENTS
124-
STANDARDS GUARD ATTRIBUTES][--e ENTRY_POINTS] [--export-decls] yaml_file
125-
yaml_to_classes.py: error: argument --add_function: expected 6 arguments``
126-
127-
In the process of adding a function, you may run into an issue where the
128-
command line is requiring more arguments than what you currently have.Ensure that all components of the new function are filled. Even if you do
129-
not have a guard or attribute, make sure to put null in those two areas.
130-
131-
4. ``File "/llvm-project/libc/newhdrgen/header.py", line 60, in __str__ for function in self.functions: AttributeError: 'HeaderFile' object has no attribute 'functions'``
132-
133-
When running ninja libc in the build directory to generate headers you may
134-
receive the error above. Essentially this means that in
135-
``libc/newhdrgen/header.py`` there is a missing attribute named functions.
136-
Make sure all function components are defined within this file and there are
137-
no missing functions to add these components.
138-
139-
5. ``/llvm-project/build/projects/libc/include/sched.h:20:25: error: unknown type name 'size_t'; did you mean 'time_t'?``
140-
:raw-html:`<br />` ``20 | int_sched_getcpucount(size_t, const cpu_set_t*) __NOEXCEPT``
141-
:raw-html:`<br />` ``/llvm-project/build/projects/libc/include/llvm-libc-types/time_t.h:15:24: note: 'time_t' declared here``
142-
:raw-html:`<br />` ``15 | typedef __INT64_TYPE__ time_t;``
143-
144-
During the header generation process errors like the one above may occur
145-
because there are missing types for a specific header file. Check the yaml
146-
file corresponding to the header file and make sure all the necessary types
147-
that are being used are input into the types as well. Delete the specific
148-
header file from the build folder and re-run ninja libc to ensure the types
149-
are being recognized.
150-
151-
6. Test Integration Errors: Sometimes the integration test will fail but that
94+
-------------
95+
1. Missing function specific component
96+
97+
Example:
98+
:raw-html:`<br />` ``"/llvm-project/libc/newhdrgen/yaml_to_classes.py", line
99+
67, in yaml_to_classes function_data["return_type"]``
100+
101+
If you receive this error or any error pertaining to
102+
``function_data[function_specific_component]`` while building the headers
103+
that means the function specific component is missing within the yaml files.
104+
Through the call stack, you will be able to find the header file which has the
105+
issue. Ensure there is no missing function specific component for that yaml
106+
header file.
107+
108+
2. CMake Error: require argument to be specified
109+
110+
Example:
111+
:raw-html:`<br />` ``CMake Error at:
112+
/llvm-project/libc/cmake/modules/LLVMLibCHeaderRules.cmake:86 (message):``
113+
:raw-html:`<br />` ``'add_gen_hdr2' rule requires GEN_HDR to be specified.``
114+
:raw-html:`<br />` ``Call Stack (most recent call first):
115+
/llvm-project/libc/include/CMakeLists.txt:22 (add_gen_header2)
116+
/llvm-project/libc/include/CMakeLists.txt:62 (add_header_macro)``
117+
118+
If you receive this error, there is a missing yaml_file, h_def file, or header
119+
name within the ``libc/include/CMakeLists.txt``. The last line in the error
120+
call stack will point to the header where there is a specific component
121+
missing. Ensure the correct style and required files are present:
122+
123+
| ``[header_name]``
124+
| ``[../libc/newhdrgen/yaml/[yaml_file.yaml]``
125+
| ``[header_name.h.def]``
126+
| ``[header_name.h]``
127+
| ``DEPENDS``
128+
| ``{Necessary Depend Files}``
129+
130+
3. Command line: expected arguments
131+
132+
Example:
133+
:raw-html:`<br />` ``usage: yaml_to_classes.py [-h]
134+
[--output_dir OUTPUT_DIR] [--h_def_file H_DEF_FILE] [--add_function
135+
RETURN_TYPE NAME ARGUMENTS STANDARDS GUARD ATTRIBUTES][--e ENTRY_POINTS]
136+
[--export-decls] yaml_file yaml_to_classes.py: error: argument
137+
--add_function: expected 6 arguments``
138+
139+
In the process of adding a function, you may run into an issue where the
140+
command line is requiring more arguments than what you currently have. Ensure
141+
that all components of the new function are filled. Even if you do not have a
142+
guard or attribute, make sure to put null in those two areas.
143+
144+
4. Object has no attribute
145+
146+
Example:
147+
:raw-html:`<br />` ``File "/llvm-project/libc/newhdrgen/header.py", line 60,
148+
in __str__ for function in self.functions: AttributeError: 'HeaderFile'
149+
object has no attribute 'functions'``
150+
151+
When running ninja libc in the build directory to generate headers you may
152+
receive the error above. Essentially this means that in
153+
``libc/newhdrgen/header.py`` there is a missing attribute named functions.
154+
Make sure all function components are defined within this file and there are
155+
no missing functions to add these components.
156+
157+
5. Unknown type name
158+
159+
Example:
160+
:raw-html:`<br />`
161+
``/llvm-project/build/projects/libc/include/sched.h:20:25: error: unknown
162+
type name 'size_t'; did you mean 'time_t'?``
163+
:raw-html:`<br />` ``20 | int_sched_getcpucount(size_t, const cpu_set_t*)
164+
__NOEXCEPT``
165+
:raw-html:`<br />`
166+
``/llvm-project/build/projects/libc/include/llvm-libc-types/time_t.h:15:24:
167+
note: 'time_t' declared here``
168+
:raw-html:`<br />` ``15 | typedef __INT64_TYPE__ time_t;``
169+
170+
During the header generation process errors like the one above may occur
171+
because there are missing types for a specific header file. Check the yaml
172+
file corresponding to the header file and make sure all the necessary types
173+
that are being used are input into the types as well. Delete the specific
174+
header file from the build folder and re-run ninja libc to ensure the types
175+
are being recognized.
176+
177+
6. Test Integration Errors
178+
179+
Sometimes the integration test will fail but that
152180
still means the process is working unless the comparison between the output
153181
and expected_output is not showing. If that is the case make sure in
154182
``libc/newhdrgen/tests/test_integration.py`` there are no missing arguments
155183
that run through the script.
184+
156185
If the integration tests are failing due to mismatching of lines or small
157-
errors in spacing that is nothing to worry about. If this is happening
158-
while you are making a new change to the formatting of the headers, then
159-
ensure the expected output file ``libc/newhdrgen/tests/expected_output/test_header.h``
160-
has the changes you are applying.
186+
errors in spacing that is nothing to worry about. If this is happening while
187+
you are making a new change to the formatting of the headers, then
188+
ensure the expected output file
189+
``libc/newhdrgen/tests/expected_output/test_header.h`` has the changes you
190+
are applying.

0 commit comments

Comments
 (0)