@@ -5,8 +5,8 @@ Generating Public and Internal headers
5
5
======================================
6
6
7
7
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
10
10
creating a new standalone headergen we can eliminate these dependencies for
11
11
easier cross compatibility.
12
12
@@ -22,11 +22,11 @@ and extra macro and type inclusions from the .h.def file.
22
22
23
23
24
24
Instructions
25
- -----------------------------
25
+ ------------
26
26
27
27
Required Versions:
28
28
29
- - Python Version: 3.11.8 [subject to be lower]
29
+ - Python Version: 3.11.8
30
30
- CMake Version: 3.20.0
31
31
32
32
1. Make sure to have `LLVM <https://llvm.org/docs/GettingStarted.html >`_ on your
@@ -39,46 +39,47 @@ Required Versions:
39
39
directory ``ninja check-newhdrgen `` to ensure that the integration tests are
40
40
passing.
41
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
42
+ will be in `` build/projects/libc/include `` or `` build/libc/include `` in a runtime
43
43
build. Sys spec headers will be located in
44
44
``build/projects/libc/include/sys ``.
45
45
46
46
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,
48
48
you can include this statement when building: ``-DLIBC_USE_NEW_HEADER_GEN=OFF ``
49
49
50
50
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.
52
53
53
- To enter through the command line:
54
+ To add through the command line:
54
55
55
56
1. Make sure you are in the llvm-project directory.
56
57
57
58
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>
61
62
<attribute> ``
62
63
63
64
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 ``
67
68
68
69
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.
70
71
71
72
3. Check the yaml file that the added function is present. You will also get a
72
73
generated header file with the new addition in the newhdrgen directory to
73
74
examine.
74
75
75
76
76
77
Testing
77
- -----------------------------
78
+ -------
78
79
79
80
New Headergen has an integration test that you may run once you have configured
80
81
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
82
83
process of yaml to classes to generate headers works properly. If there are any
83
84
new additions on formatting headers, make sure the test is updated with the
84
85
specific addition.
@@ -90,71 +91,100 @@ File to modify if adding something to formatting:
90
91
91
92
92
93
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
152
180
still means the process is working unless the comparison between the output
153
181
and expected_output is not showing. If that is the case make sure in
154
182
``libc/newhdrgen/tests/test_integration.py `` there are no missing arguments
155
183
that run through the script.
184
+
156
185
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