@@ -2,7 +2,7 @@ Generating Public and Internal headers
2
2
======================================
3
3
4
4
This is a new implementation of the previous libc header generator. The old
5
- header generator (libc-hdrgen aka "Headergen") was based on Tablegen , which
5
+ header generator (libc-hdrgen aka "Headergen") was based on TableGen , which
6
6
created an awkward dependency on the rest of LLVM for our build system. By
7
7
creating a new standalone Headergen we can eliminate these dependencies for
8
8
easier cross compatibility.
@@ -22,8 +22,7 @@ Instructions
22
22
------------
23
23
24
24
Required Versions:
25
-
26
- - Python Version: 3.11.8
25
+ - Python Version: 3.11.8
27
26
28
27
1. Keep full-build mode on when building, otherwise headers will not be
29
28
generated.
@@ -47,17 +46,21 @@ To add through the command line:
47
46
48
47
1. Make sure you are in the llvm-project directory.
49
48
50
- 2. Enter in the command line: ::
49
+ 2. Enter in the command line:
50
+
51
+ .. code-block :: none
52
+
53
+ python3 libc/newhdrgen/yaml_to_classes.py
54
+ libc/newhdrgen/yaml/[yaml_file.yaml] --add_function "<return_type>" <function_name> "<function_arg1, function_arg2>" <standard> <guard> <attribute>
51
55
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>
56
+ Example:
57
+
58
+ .. code-block :: none
59
+
60
+ python3 libc/newhdrgen/yaml_to_classes.py
61
+ libc/newhdrgen/yaml/ctype.yaml --add_function "char" example_function
62
+ "int, void, const void" stdc example_float example_attribute
54
63
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
60
-
61
64
Keep in mind only the return_type and arguments have quotes around them. If
62
65
you do not have any guards or attributes you may enter "null" for both.
63
66
@@ -85,93 +88,103 @@ File to modify if adding something to formatting:
85
88
Common Errors
86
89
-------------
87
90
1. Missing function specific component
88
-
89
- Example: ::
90
91
91
- "/llvm-project/libc/newhdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"]
92
+ Example:
93
+
94
+ .. code-block :: none
92
95
93
- If you receive this error or any error pertaining to
94
- ``function_data[function_specific_component] `` while building the headers
95
- that means the function specific component is missing within the YAML files.
96
- Through the call stack, you will be able to find the header file which has the
97
- issue. Ensure there is no missing function specific component for that YAML
98
- header file.
96
+ "/llvm-project/libc/newhdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"]
97
+
98
+ If you receive this error or any error pertaining to
99
+ ``function_data[function_specific_component] `` while building the headers
100
+ that means the function specific component is missing within the YAML files.
101
+ Through the call stack, you will be able to find the header file which has
102
+ the issue. Ensure there is no missing function specific component for that
103
+ YAML header file.
99
104
100
105
2. CMake Error: require argument to be specified
101
106
102
- Example: ::
107
+ Example:
108
+
109
+ .. code-block :: none
103
110
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)
111
+ CMake Error at:
112
+ /llvm-project/libc/cmake/modules/LLVMLibCHeaderRules.cmake:86 (message):
113
+ 'add_gen_hdr2' rule requires GEN_HDR to be specified.
114
+ 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)
110
117
111
- If you receive this error, there is a missing YAML file, h_def file, or header
112
- name within the ``libc/include/CMakeLists.txt ``. The last line in the error
113
- call stack will point to the header where there is a specific component
114
- missing. Ensure the correct style and required files are present:
118
+ If you receive this error, there is a missing YAML file, h_def file, or
119
+ header name within the ``libc/include/CMakeLists.txt ``. The last line in the
120
+ error call stack will point to the header where there is a specific component
121
+ missing. Ensure the correct style and required files are present:
115
122
116
- | ``[header_name]``
117
- | ``[../libc/newhdrgen/yaml/[yaml_file.yaml]``
118
- | ``[header_name.h.def]``
119
- | ``[header_name.h]``
120
- | ``DEPENDS``
121
- | ``{Necessary Depend Files}``
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}``
122
129
123
130
3. Command line: expected arguments
124
131
125
- Example: ::
132
+ Example:
133
+
134
+ .. code-block :: none
126
135
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
136
+ usage: yaml_to_classes.py [-h] [--output_dir OUTPUT_DIR] [--h_def_file H_DEF_FILE]
137
+ [--add_function RETURN_TYPE NAME ARGUMENTS STANDARDS GUARD ATTRIBUTES]
138
+ [--e ENTRY_POINTS] [--export-decls]
139
+ yaml_file
140
+ yaml_to_classes.py:
141
+ error: argument --add_function: expected 6 arguments
133
142
134
- In the process of adding a function, you may run into an issue where the
135
- command line is requiring more arguments than what you currently have. Ensure
136
- that all components of the new function are filled. Even if you do not have a
137
- guard or attribute, make sure to put null in those two areas.
143
+ In the process of adding a function, you may run into an issue where the
144
+ command line is requiring more arguments than what you currently have. Ensure
145
+ that all components of the new function are filled. Even if you do not have a
146
+ guard or attribute, make sure to put null in those two areas.
138
147
139
148
4. Object has no attribute
140
149
141
- Example: : :
150
+ Example :
142
151
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'
152
+ .. code-block :: none
146
153
147
- When running ninja libc in the build directory to generate headers you may
148
- receive the error above. Essentially this means that in
149
- ``libc/newhdrgen/header.py `` there is a missing attribute named functions.
150
- Make sure all function components are defined within this file and there are
151
- no missing functions to add these components.
154
+ File "/llvm-project/libc/newhdrgen/header.py", line 60, in __str__ for
155
+ function in self.functions: AttributeError: 'HeaderFile' object has no
156
+ attribute 'functions'
157
+
158
+ When running ``ninja libc `` in the build directory to generate headers you
159
+ may receive the error above. Essentially this means that in
160
+ ``libc/newhdrgen/header.py `` there is a missing attribute named functions.
161
+ Make sure all function components are defined within this file and there are
162
+ no missing functions to add these components.
152
163
153
164
5. Unknown type name
154
165
155
- Example: ::
166
+ Example:
167
+
168
+ .. code-block :: none
156
169
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
- | ^
170
+ /llvm-project/build/projects/libc/include/sched.h:20:25: error: unknown type
171
+ name 'size_t'; did you mean 'time_t'?
172
+ 20 | int_sched_getcpucount(size_t, const cpu_set_t*) __NOEXCEPT
173
+ | ^
174
+ /llvm-project/build/projects/libc/include/llvm-libc-types/time_t.h:15:24:
175
+ note: 'time_t' declared here
176
+ 15 | typedef __INT64_TYPE__ time_t;
177
+ | ^
165
178
166
- During the header generation process errors like the one above may occur
167
- because there are missing types for a specific header file. Check the YAML
168
- file corresponding to the header file and make sure all the necessary types
169
- that are being used are input into the types as well. Delete the specific
170
- header file from the build folder and re-run ninja libc to ensure the types
171
- are being recognized.
179
+ During the header generation process errors like the one above may occur
180
+ because there are missing types for a specific header file. Check the YAML
181
+ file corresponding to the header file and make sure all the necessary types
182
+ that are being used are input into the types as well. Delete the specific
183
+ header file from the build folder and re-run `` ninja libc `` to ensure the
184
+ types are being recognized.
172
185
173
186
6. Test Integration Errors
174
-
187
+
175
188
Sometimes the integration test will fail but that
176
189
still means the process is working unless the comparison between the output
177
190
and expected_output is not showing. If that is the case make sure in
@@ -183,4 +196,4 @@ Common Errors
183
196
you are making a new change to the formatting of the headers, then
184
197
ensure the expected output file
185
198
``libc/newhdrgen/tests/expected_output/test_header.h `` has the changes you
186
- are applying.
199
+ are applying.
0 commit comments