1+ mod def_visitor;
2+
13use std:: io:: Write ;
24use std:: process:: Stdio ;
35
4- use syn:: parse:: Parser ;
56use syn:: visit:: Visit ;
67use syn:: Ident ;
78
9+ use crate :: def_visitor:: { DefVisitor , LlvmIntrinsicDef } ;
10+
811fn main ( ) {
912 println ! ( "Running rustc -Zunpretty=expanded --edition=2021 core_arch/src/lib.rs ..." ) ;
1013 let expanded_file = std:: process:: Command :: new ( "rustc" )
@@ -20,7 +23,7 @@ fn main() {
2023 let file = syn:: parse_str :: < syn:: File > ( std:: str:: from_utf8 ( & expanded_file) . unwrap ( ) ) . unwrap ( ) ;
2124
2225 println ! ( "Visting all LLVM intrinsics" ) ;
23- let mut visitor = Visitor { llvm_intrinsics : vec ! [ ] , structs : vec ! [ ] , aliases : vec ! [ ] } ;
26+ let mut visitor = DefVisitor { llvm_intrinsics : vec ! [ ] , structs : vec ! [ ] , aliases : vec ! [ ] } ;
2427 visitor. visit_file ( & file) ;
2528
2629 println ! ( ) ;
@@ -102,133 +105,3 @@ fn main() {
102105 let status = child. wait ( ) . unwrap ( ) ;
103106 assert ! ( status. success( ) , "{status}" ) ;
104107}
105-
106- struct Visitor {
107- llvm_intrinsics : Vec < LlvmIntrinsicDef > ,
108- structs : Vec < syn:: ItemStruct > ,
109- aliases : Vec < syn:: ItemType > ,
110- }
111-
112- struct LlvmIntrinsicDef {
113- abi : String ,
114- link_name : String ,
115- sig : syn:: Signature ,
116- }
117-
118- impl < ' ast > Visit < ' ast > for Visitor {
119- fn visit_item_struct ( & mut self , i : & ' ast syn:: ItemStruct ) {
120- let Some ( repr_attr) = i. attrs . iter ( ) . find ( |attr| attr. path ( ) . is_ident ( "repr" ) ) else {
121- return ;
122- } ;
123-
124- if !repr_attr
125- . parse_args :: < syn:: Ident > ( )
126- . map_or ( false , |repr| repr. to_owned ( ) == "simd" || repr. to_owned ( ) == "C" )
127- {
128- return ;
129- }
130-
131- let mut ty = i. clone ( ) ;
132- ty. attrs = ty. attrs . into_iter ( ) . filter ( |attr| attr. path ( ) . is_ident ( "repr" ) ) . collect ( ) ;
133-
134- self . structs . push ( ty) ;
135- }
136-
137- fn visit_item_type ( & mut self , i : & ' ast syn:: ItemType ) {
138- let mut alias = i. clone ( ) ;
139- alias. attrs = alias. attrs . into_iter ( ) . filter ( |attr| attr. path ( ) . is_ident ( "repr" ) ) . collect ( ) ;
140-
141- self . aliases . push ( alias) ;
142- }
143-
144- fn visit_item_foreign_mod ( & mut self , i : & ' ast syn:: ItemForeignMod ) {
145- let abi = i. abi . name . as_ref ( ) . unwrap ( ) . value ( ) ;
146-
147- ' items: for item in & i. items {
148- match & item {
149- syn:: ForeignItem :: Fn ( i) => {
150- let link_name_attr =
151- i. attrs . iter ( ) . find ( |attr| attr. path ( ) . is_ident ( "link_name" ) ) . unwrap ( ) ;
152-
153- let link_name =
154- match link_name_attr. meta . require_name_value ( ) . unwrap ( ) . value . clone ( ) {
155- syn:: Expr :: Lit ( syn:: ExprLit {
156- lit : syn:: Lit :: Str ( link_name) , ..
157- } ) => link_name. value ( ) ,
158- _ => unreachable ! ( ) ,
159- } ;
160-
161- assert ! (
162- i. attrs
163- . iter( )
164- . filter( |attr| !attr. path( ) . is_ident( "link_name" ) )
165- . collect:: <Vec <_>>( )
166- . is_empty( )
167- ) ;
168-
169- let mut sig = i. sig . clone ( ) ;
170-
171- if link_name == "llvm.x86.avx512.mask.cvtss2sd.round" {
172- match sig. inputs . iter_mut ( ) . nth ( 1 ) . unwrap ( ) {
173- syn:: FnArg :: Typed ( syn:: PatType { ref mut pat, .. } ) => match & mut * * pat
174- {
175- syn:: Pat :: Ident ( name) => {
176- name. ident = Ident :: new ( "b" , name. ident . span ( ) ) ;
177- }
178- _ => unreachable ! ( ) ,
179- } ,
180- _ => unreachable ! ( ) ,
181- }
182- }
183-
184- // FIXME remove this patching
185- match sig. inputs . iter_mut ( ) . nth ( 0 ) {
186- Some ( syn:: FnArg :: Typed ( syn:: PatType { ref mut pat, .. } ) ) => {
187- match & mut * * pat {
188- syn:: Pat :: Wild ( _) => {
189- * * pat =
190- syn:: Pat :: parse_single. parse2 ( quote:: quote! { a } ) . unwrap ( ) ;
191- }
192- _ => { }
193- }
194- }
195- _ => { }
196- }
197-
198- // FIXME remove this skipping
199- match & * link_name {
200- _ if link_name. starts_with ( "llvm.aarch64.neon.ld" ) => continue ' items,
201- _ if link_name. starts_with ( "llvm.aarch64.neon.st" ) => continue ' items,
202- _ if link_name. starts_with ( "llvm.aarch64.neon.rshrn" ) => continue ' items,
203- _ if link_name. starts_with ( "llvm.aarch64.neon.sq" ) => continue ' items,
204- _ if link_name. starts_with ( "llvm.aarch64.neon.uq" ) => continue ' items,
205- _ if link_name. starts_with ( "llvm.aarch64.neon.vcvt" ) => continue ' items,
206- _ if link_name. starts_with ( "llvm.aarch64.neon.vsli" ) => continue ' items,
207- _ if link_name. starts_with ( "llvm.aarch64.neon.vsri" ) => continue ' items,
208-
209- "llvm.prefetch"
210- | "llvm.aarch64.dmb"
211- | "llvm.aarch64.dsb"
212- | "llvm.aarch64.hint"
213- | "llvm.aarch64.isb"
214- | "llvm.aarch64.crypto.xar" => continue ' items,
215-
216- "llvm.aarch64.crypto.sm3tt1a"
217- | "llvm.aarch64.crypto.sm3tt1b"
218- | "llvm.aarch64.crypto.sm3tt2a"
219- | "llvm.aarch64.crypto.sm3tt2b"
220- | "llvm.aarch64.tcancel" => continue ' items,
221- _ => { }
222- }
223-
224- self . llvm_intrinsics . push ( LlvmIntrinsicDef {
225- abi : abi. clone ( ) ,
226- link_name,
227- sig,
228- } ) ;
229- }
230- _ => { }
231- }
232- }
233- }
234- }
0 commit comments