Skip to content

Commit fd48b12

Browse files
committed
added non-inline code blocks, removed unnecessary instructions
1 parent 8675d4c commit fd48b12

File tree

1 file changed

+65
-69
lines changed

1 file changed

+65
-69
lines changed

libc/docs/dev/header_generation.rst

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
.. role:: raw-html(raw)
2-
:format: html
3-
41
Generating Public and Internal headers
52
======================================
63

74
This is a new implementation of the previous libc header generator. The old
8-
header generator (libc-hdrgen aka "headergen") was based on tablegen, which
5+
header generator (libc-hdrgen aka "Headergen") was based on Tablegen, which
96
created an awkward dependency on the rest of LLVM for our build system. By
10-
creating a new standalone headergen we can eliminate these dependencies for
7+
creating a new standalone Headergen we can eliminate these dependencies for
118
easier cross compatibility.
129

1310
There are 3 main components of the new Headergen. The first component are the
14-
yaml files that contain all the function header information and are separated by
11+
YAML files that contain all the function header information and are separated by
1512
header specification and standard. The second component are the classes that are
1613
created for each component of the function header: macros, enumerations, types,
17-
function, arguments, and objects. The third component is the python script that
18-
uses the class representation to deserialize yaml files into its specific
14+
function, arguments, and objects. The third component is the Python script that
15+
uses the class representation to deserialize YAML files into its specific
1916
components and then reserializes the components into the function header. The
20-
python script also combines the generated header content with header definitions
17+
Python script also combines the generated header content with header definitions
2118
and extra macro and type inclusions from the .h.def file.
2219

2320

@@ -27,49 +24,44 @@ Instructions
2724
Required Versions:
2825

2926
- Python Version: 3.11.8
30-
- CMake Version: 3.20.0
31-
32-
1. Make sure to have `LLVM <https://llvm.org/docs/GettingStarted.html>`_ on your
33-
system.
34-
2. Make sure you have created a build directory within your LLVM directory.
35-
3. When generating the necessary files by your build make sure to include:
36-
``-DLLVM_LIBC_FULL_BUILD=ON`` within the CMake command since new headergen
37-
only runs on full-build.
38-
4. Once the build is complete, enter in the command line within the build
27+
28+
1. Keep full-build mode on when building, otherwise headers will not be
29+
generated.
30+
2. Once the build is complete, enter in the command line within the build
3931
directory ``ninja check-newhdrgen`` to ensure that the integration tests are
4032
passing.
41-
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
43-
build. Sys spec headers will be located in
33+
3. Then enter in the command line ``ninja libc`` to generate headers. Headers
34+
will be in ``build/projects/libc/include`` or ``build/libc/include`` in a
35+
runtime build. Sys spec headers will be located in
4436
``build/projects/libc/include/sys``.
4537

4638

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

50-
To add a function to the yaml files, you can either manually enter it in the
51-
yaml file corresponding to the header it belongs to or add it through the
42+
To add a function to the YAML files, you can either manually enter it in the
43+
YAML file corresponding to the header it belongs to or add it through the
5244
command line.
5345

5446
To add through the command line:
5547

5648
1. Make sure you are in the llvm-project directory.
5749

58-
2. Enter in the command line:
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>
62-
<attribute>``
50+
2. Enter in the command line: ::
51+
52+
python3 libc/newhdrgen/yaml_to_classes.py
53+
libc/newhdrgen/yaml/[yaml_file.yaml] --add_function "<return_type>" <function_name> "<function_arg1, function_arg2>" <standard> <guard> <attribute>
6354

64-
Example:
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``
55+
Example: ::
56+
57+
python3 libc/newhdrgen/yaml_to_classes.py
58+
libc/newhdrgen/yaml/ctype.yaml --add_function "char" example_funtion
59+
"int, void, const void" stdc example_float example_attribute
6860
6961
Keep in mind only the return_type and arguments have quotes around them. If
7062
you do not have any guards or attributes you may enter "null" for both.
7163

72-
3. Check the yaml file that the added function is present. You will also get a
64+
3. Check the YAML file that the added function is present. You will also get a
7365
generated header file with the new addition in the newhdrgen directory to
7466
examine.
7567

@@ -80,7 +72,7 @@ Testing
8072
New Headergen has an integration test that you may run once you have configured
8173
your CMake within the build directory. In the command line, enter the following:
8274
``ninja check-newhdrgen``. The integration test is one test that ensures the
83-
process of yaml to classes to generate headers works properly. If there are any
75+
process of YAML to classes to generate headers works properly. If there are any
8476
new additions on formatting headers, make sure the test is updated with the
8577
specific addition.
8678

@@ -94,28 +86,29 @@ Common Errors
9486
-------------
9587
1. Missing function specific component
9688

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"]``
89+
Example: ::
90+
91+
"/llvm-project/libc/newhdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"]
10092

10193
If you receive this error or any error pertaining to
10294
``function_data[function_specific_component]`` while building the headers
103-
that means the function specific component is missing within the yaml files.
95+
that means the function specific component is missing within the YAML files.
10496
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
97+
issue. Ensure there is no missing function specific component for that YAML
10698
header file.
10799

108100
2. CMake Error: require argument to be specified
109101

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)``
102+
Example: ::
117103

118-
If you receive this error, there is a missing yaml_file, h_def file, or header
104+
CMake Error at:
105+
/llvm-project/libc/cmake/modules/LLVMLibCHeaderRules.cmake:86 (message):
106+
'add_gen_hdr2' rule requires GEN_HDR to be specified.
107+
Call Stack (most recent call first):
108+
/llvm-project/libc/include/CMakeLists.txt:22 (add_gen_header2)
109+
/llvm-project/libc/include/CMakeLists.txt:62 (add_header_macro)
110+
111+
If you receive this error, there is a missing YAML file, h_def file, or header
119112
name within the ``libc/include/CMakeLists.txt``. The last line in the error
120113
call stack will point to the header where there is a specific component
121114
missing. Ensure the correct style and required files are present:
@@ -129,12 +122,14 @@ Common Errors
129122
130123
3. Command line: expected arguments
131124

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``
125+
Example: ::
126+
127+
usage: yaml_to_classes.py [-h] [--output_dir OUTPUT_DIR] [--h_def_file H_DEF_FILE]
128+
[--add_function RETURN_TYPE NAME ARGUMENTS STANDARDS GUARD ATTRIBUTES]
129+
[--e ENTRY_POINTS] [--export-decls]
130+
yaml_file
131+
yaml_to_classes.py:
132+
error: argument --add_function: expected 6 arguments
138133

139134
In the process of adding a function, you may run into an issue where the
140135
command line is requiring more arguments than what you currently have. Ensure
@@ -143,10 +138,11 @@ Common Errors
143138

144139
4. Object has no attribute
145140

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'``
141+
Example: ::
142+
143+
File "/llvm-project/libc/newhdrgen/header.py", line 60, in __str__ for
144+
function in self.functions: AttributeError: 'HeaderFile' object has no
145+
attribute 'functions'
150146

151147
When running ninja libc in the build directory to generate headers you may
152148
receive the error above. Essentially this means that in
@@ -156,19 +152,19 @@ Common Errors
156152

157153
5. Unknown type name
158154

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;``
155+
Example: ::
156+
157+
/llvm-project/build/projects/libc/include/sched.h:20:25: error: unknown type
158+
name 'size_t'; did you mean 'time_t'?
159+
20 | int_sched_getcpucount(size_t, const cpu_set_t*) __NOEXCEPT
160+
| ^
161+
/llvm-project/build/projects/libc/include/llvm-libc-types/time_t.h:15:24:
162+
note: 'time_t' declared here
163+
15 | typedef __INT64_TYPE__ time_t;
164+
| ^
169165

170166
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
167+
because there are missing types for a specific header file. Check the YAML
172168
file corresponding to the header file and make sure all the necessary types
173169
that are being used are input into the types as well. Delete the specific
174170
header file from the build folder and re-run ninja libc to ensure the types

0 commit comments

Comments
 (0)