1
- .. role :: raw-html(raw)
2
- :format: html
3
-
4
1
Generating Public and Internal headers
5
2
======================================
6
3
7
4
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
9
6
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
11
8
easier cross compatibility.
12
9
13
10
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
15
12
header specification and standard. The second component are the classes that are
16
13
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
19
16
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
21
18
and extra macro and type inclusions from the .h.def file.
22
19
23
20
@@ -27,49 +24,44 @@ Instructions
27
24
Required Versions:
28
25
29
26
- 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
39
31
directory ``ninja check-newhdrgen `` to ensure that the integration tests are
40
32
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
44
36
``build/projects/libc/include/sys ``.
45
37
46
38
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 ,
48
40
you can include this statement when building: ``-DLIBC_USE_NEW_HEADER_GEN=OFF ``
49
41
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
52
44
command line.
53
45
54
46
To add through the command line:
55
47
56
48
1. Make sure you are in the llvm-project directory.
57
49
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>
63
54
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
68
60
69
61
Keep in mind only the return_type and arguments have quotes around them. If
70
62
you do not have any guards or attributes you may enter "null" for both.
71
63
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
73
65
generated header file with the new addition in the newhdrgen directory to
74
66
examine.
75
67
@@ -80,7 +72,7 @@ Testing
80
72
New Headergen has an integration test that you may run once you have configured
81
73
your CMake within the build directory. In the command line, enter the following:
82
74
``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
84
76
new additions on formatting headers, make sure the test is updated with the
85
77
specific addition.
86
78
@@ -94,28 +86,29 @@ Common Errors
94
86
-------------
95
87
1. Missing function specific component
96
88
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"]
100
92
101
93
If you receive this error or any error pertaining to
102
94
``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.
104
96
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
106
98
header file.
107
99
108
100
2. CMake Error: require argument to be specified
109
101
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: ::
117
103
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
119
112
name within the ``libc/include/CMakeLists.txt ``. The last line in the error
120
113
call stack will point to the header where there is a specific component
121
114
missing. Ensure the correct style and required files are present:
@@ -129,12 +122,14 @@ Common Errors
129
122
130
123
3. Command line: expected arguments
131
124
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
138
133
139
134
In the process of adding a function, you may run into an issue where the
140
135
command line is requiring more arguments than what you currently have. Ensure
@@ -143,10 +138,11 @@ Common Errors
143
138
144
139
4. Object has no attribute
145
140
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'
150
146
151
147
When running ninja libc in the build directory to generate headers you may
152
148
receive the error above. Essentially this means that in
@@ -156,19 +152,19 @@ Common Errors
156
152
157
153
5. Unknown type name
158
154
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
+ | ^
169
165
170
166
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
172
168
file corresponding to the header file and make sure all the necessary types
173
169
that are being used are input into the types as well. Delete the specific
174
170
header file from the build folder and re-run ninja libc to ensure the types
0 commit comments