@@ -2,7 +2,7 @@ use heck::*;
2
2
use std:: collections:: { BTreeSet , HashMap , HashSet } ;
3
3
use std:: mem;
4
4
use wit_bindgen_gen_core:: wit_parser:: abi:: {
5
- AbiVariant , Bindgen , Bitcast , Instruction , LiftLower , WasmType , WitxInstruction ,
5
+ AbiVariant , Bindgen , Bitcast , Instruction , LiftLower , WasmType ,
6
6
} ;
7
7
use wit_bindgen_gen_core:: { wit_parser:: * , Direction , Files , Generator , Ns } ;
8
8
@@ -173,12 +173,7 @@ impl C {
173
173
TypeDefKind :: Type ( t) => self . is_arg_by_pointer ( iface, t) ,
174
174
TypeDefKind :: Variant ( v) => !v. is_enum ( ) ,
175
175
TypeDefKind :: Record ( r) if r. is_flags ( ) => false ,
176
- TypeDefKind :: Pointer ( _)
177
- | TypeDefKind :: ConstPointer ( _)
178
- | TypeDefKind :: Record ( _)
179
- | TypeDefKind :: List ( _)
180
- | TypeDefKind :: PushBuffer ( _)
181
- | TypeDefKind :: PullBuffer ( _) => true ,
176
+ TypeDefKind :: Record ( _) | TypeDefKind :: List ( _) => true ,
182
177
} ,
183
178
_ => false ,
184
179
}
@@ -257,24 +252,12 @@ impl C {
257
252
self . print_ty_name ( iface, & Type :: Id ( * id) ) ;
258
253
self . src . h ( "_t" ) ;
259
254
}
260
- TypeDefKind :: Pointer ( t) => {
261
- self . print_ty ( iface, t) ;
262
- self . src . h ( "*" ) ;
263
- }
264
- TypeDefKind :: ConstPointer ( t) => {
265
- self . src . h ( "const " ) ;
266
- self . print_ty ( iface, t) ;
267
- self . src . h ( "*" ) ;
268
- }
269
255
TypeDefKind :: List ( Type :: Char ) => {
270
256
self . print_namespace ( iface) ;
271
257
self . src . h ( "string_t" ) ;
272
258
self . needs_string = true ;
273
259
}
274
- TypeDefKind :: Record ( _)
275
- | TypeDefKind :: List ( _)
276
- | TypeDefKind :: PushBuffer ( _)
277
- | TypeDefKind :: PullBuffer ( _) => {
260
+ TypeDefKind :: Record ( _) | TypeDefKind :: List ( _) => {
278
261
self . public_anonymous_types . insert ( * id) ;
279
262
self . private_anonymous_types . remove ( id) ;
280
263
self . print_namespace ( iface) ;
@@ -339,27 +322,11 @@ impl C {
339
322
unimplemented ! ( ) ;
340
323
}
341
324
}
342
- TypeDefKind :: Pointer ( t) => {
343
- self . src . h ( "ptr_" ) ;
344
- self . print_ty_name ( iface, t) ;
345
- }
346
- TypeDefKind :: ConstPointer ( t) => {
347
- self . src . h ( "const_ptr_ " ) ;
348
- self . print_ty_name ( iface, t) ;
349
- }
350
325
TypeDefKind :: List ( Type :: Char ) => self . src . h ( "string" ) ,
351
326
TypeDefKind :: List ( t) => {
352
327
self . src . h ( "list_" ) ;
353
328
self . print_ty_name ( iface, t) ;
354
329
}
355
- TypeDefKind :: PushBuffer ( t) => {
356
- self . src . h ( "push_buffer_" ) ;
357
- self . print_ty_name ( iface, t) ;
358
- }
359
- TypeDefKind :: PullBuffer ( t) => {
360
- self . src . h ( "pull_buffer_" ) ;
361
- self . print_ty_name ( iface, t) ;
362
- }
363
330
}
364
331
}
365
332
}
@@ -370,7 +337,7 @@ impl C {
370
337
self . src . h ( "typedef " ) ;
371
338
let kind = & iface. types [ ty] . kind ;
372
339
match kind {
373
- TypeDefKind :: Type ( _) | TypeDefKind :: Pointer ( _ ) | TypeDefKind :: ConstPointer ( _ ) => {
340
+ TypeDefKind :: Type ( _) => {
374
341
unreachable ! ( )
375
342
}
376
343
TypeDefKind :: Record ( r) => {
@@ -424,17 +391,6 @@ impl C {
424
391
self . src . h ( "size_t len;\n " ) ;
425
392
self . src . h ( "}" ) ;
426
393
}
427
- TypeDefKind :: PushBuffer ( t) | TypeDefKind :: PullBuffer ( t) => {
428
- self . src . h ( "struct {\n " ) ;
429
- self . src . h ( "int32_t is_handle;\n " ) ;
430
- if let TypeDefKind :: PullBuffer ( _) = kind {
431
- self . src . h ( "const " ) ;
432
- }
433
- self . print_ty ( iface, t) ;
434
- self . src . h ( " *ptr;\n " ) ;
435
- self . src . h ( "size_t len;\n " ) ;
436
- self . src . h ( "}" ) ;
437
- }
438
394
}
439
395
self . src . h ( " " ) ;
440
396
self . print_namespace ( iface) ;
@@ -565,11 +521,6 @@ impl C {
565
521
}
566
522
self . src . c ( "}\n " ) ;
567
523
}
568
-
569
- TypeDefKind :: PushBuffer ( _)
570
- | TypeDefKind :: PullBuffer ( _)
571
- | TypeDefKind :: Pointer ( _)
572
- | TypeDefKind :: ConstPointer ( _) => { }
573
524
}
574
525
self . src . c ( "}\n " ) ;
575
526
}
@@ -584,8 +535,6 @@ impl C {
584
535
TypeDefKind :: Type ( t) => self . owns_anything ( iface, t) ,
585
536
TypeDefKind :: Record ( r) => r. fields . iter ( ) . any ( |t| self . owns_anything ( iface, & t. ty ) ) ,
586
537
TypeDefKind :: List ( _) => true ,
587
- TypeDefKind :: PushBuffer ( _) | TypeDefKind :: PullBuffer ( _) => false ,
588
- TypeDefKind :: Pointer ( _) | TypeDefKind :: ConstPointer ( _) => false ,
589
538
TypeDefKind :: Variant ( v) => v
590
539
. cases
591
540
. iter ( )
@@ -640,14 +589,7 @@ impl Return {
640
589
TypeDefKind :: Record ( _) => self . splat_tuples ( iface, ty, orig_ty) ,
641
590
642
591
// other records/lists/buffers always go to return pointers
643
- TypeDefKind :: List ( _) | TypeDefKind :: PushBuffer ( _) | TypeDefKind :: PullBuffer ( _) => {
644
- self . retptrs . push ( * orig_ty)
645
- }
646
-
647
- // pointers are scalars
648
- TypeDefKind :: Pointer ( _) | TypeDefKind :: ConstPointer ( _) => {
649
- self . scalar = Some ( Scalar :: Type ( * orig_ty) ) ;
650
- }
592
+ TypeDefKind :: List ( _) => self . retptrs . push ( * orig_ty) ,
651
593
652
594
// Enums are scalars (this includes bools)
653
595
TypeDefKind :: Variant ( v) if v. is_enum ( ) => {
@@ -713,7 +655,7 @@ impl Return {
713
655
impl Generator for C {
714
656
fn preprocess_one ( & mut self , iface : & Interface , dir : Direction ) {
715
657
let variant = Self :: abi_variant ( dir) ;
716
- self . sizes . fill ( variant , iface) ;
658
+ self . sizes . fill ( iface) ;
717
659
self . in_import = variant == AbiVariant :: GuestImport ;
718
660
719
661
for func in iface. functions . iter ( ) {
@@ -879,56 +821,10 @@ impl Generator for C {
879
821
. insert ( id, mem:: replace ( & mut self . src . header , prev) ) ;
880
822
}
881
823
882
- fn type_pointer (
883
- & mut self ,
884
- iface : & Interface ,
885
- _id : TypeId ,
886
- name : & str ,
887
- const_ : bool ,
888
- ty : & Type ,
889
- docs : & Docs ,
890
- ) {
891
- drop ( ( iface, _id, name, const_, ty, docs) ) ;
892
- }
893
-
894
824
fn type_builtin ( & mut self , iface : & Interface , _id : TypeId , name : & str , ty : & Type , docs : & Docs ) {
895
825
drop ( ( iface, _id, name, ty, docs) ) ;
896
826
}
897
827
898
- fn type_push_buffer (
899
- & mut self ,
900
- iface : & Interface ,
901
- id : TypeId ,
902
- name : & str ,
903
- ty : & Type ,
904
- docs : & Docs ,
905
- ) {
906
- self . type_pull_buffer ( iface, id, name, ty, docs) ;
907
- }
908
-
909
- fn type_pull_buffer (
910
- & mut self ,
911
- iface : & Interface ,
912
- id : TypeId ,
913
- name : & str ,
914
- ty : & Type ,
915
- docs : & Docs ,
916
- ) {
917
- let prev = mem:: take ( & mut self . src . header ) ;
918
- self . docs ( docs) ;
919
- self . src . h ( "typedef struct {\n " ) ;
920
- self . src . h ( "int32_t is_handle;\n " ) ;
921
- self . print_ty ( iface, ty) ;
922
- self . src . h ( " *ptr;\n " ) ;
923
- self . src . h ( "size_t len;\n " ) ;
924
- self . src . h ( "} " ) ;
925
- self . print_namespace ( iface) ;
926
- self . src . h ( & name. to_snake_case ( ) ) ;
927
- self . src . h ( "_t;\n " ) ;
928
- self . types
929
- . insert ( id, mem:: replace ( & mut self . src . header , prev) ) ;
930
- }
931
-
932
828
fn import ( & mut self , iface : & Interface , func : & Function ) {
933
829
assert ! ( !func. is_async, "async not supported yet" ) ;
934
830
let prev = mem:: take ( & mut self . src ) ;
@@ -1365,13 +1261,6 @@ impl Bindgen for FunctionBindgen<'_> {
1365
1261
self . blocks . push ( ( src. into ( ) , mem:: take ( operands) ) ) ;
1366
1262
}
1367
1263
1368
- fn allocate_typed_space ( & mut self , iface : & Interface , ty : TypeId ) -> String {
1369
- let ty = self . gen . type_string ( iface, & Type :: Id ( ty) ) ;
1370
- let name = self . locals . tmp ( "tmp" ) ;
1371
- self . src . push_str ( & format ! ( "{} {};\n " , ty, name) ) ;
1372
- format ! ( "(int32_t) (&{})" , name)
1373
- }
1374
-
1375
1264
fn i64_return_pointer_area ( & mut self , amt : usize ) -> String {
1376
1265
assert ! ( amt <= self . gen . i64_return_pointer_area_size) ;
1377
1266
let ptr = self . locals . tmp ( "ptr" ) ;
@@ -1672,18 +1561,6 @@ impl Bindgen for FunctionBindgen<'_> {
1672
1561
Instruction :: IterElem { .. } => results. push ( "e" . to_string ( ) ) ,
1673
1562
Instruction :: IterBasePointer => results. push ( "base" . to_string ( ) ) ,
1674
1563
1675
- Instruction :: BufferLowerPtrLen { .. } => {
1676
- drop ( self . blocks . pop ( ) . unwrap ( ) ) ;
1677
- results. push ( format ! ( "({}).is_handle" , operands[ 0 ] ) ) ;
1678
- results. push ( format ! ( "(int32_t) ({}).ptr" , operands[ 0 ] ) ) ;
1679
- results. push ( format ! ( "({}).len" , operands[ 0 ] ) ) ;
1680
- }
1681
-
1682
- Instruction :: BufferLiftHandle { .. } => {
1683
- drop ( self . blocks . pop ( ) . unwrap ( ) ) ;
1684
- results. push ( format ! ( "({}).idx" , operands[ 0 ] ) ) ;
1685
- }
1686
-
1687
1564
Instruction :: CallWasm { sig, .. } => {
1688
1565
match sig. results . len ( ) {
1689
1566
0 => { }
@@ -1897,21 +1774,6 @@ impl Bindgen for FunctionBindgen<'_> {
1897
1774
self . src . push_str ( "INVALIDSTORE" ) ;
1898
1775
}
1899
1776
1900
- Instruction :: Witx { instr } => match instr {
1901
- WitxInstruction :: I32FromPointer | WitxInstruction :: I32FromConstPointer => {
1902
- results. push ( format ! ( "(int32_t) ({})" , operands[ 0 ] ) )
1903
- }
1904
- WitxInstruction :: AddrOf => {
1905
- results. push ( format ! ( "(int32_t) (&{})" , operands[ 0 ] ) ) ;
1906
- }
1907
- WitxInstruction :: ReuseReturn => {
1908
- results. push ( self . wasm_return . clone ( ) . unwrap ( ) ) ;
1909
- }
1910
- i => unimplemented ! ( "{:?}" , i) ,
1911
- } ,
1912
-
1913
- Instruction :: BufferPayloadName => results. push ( "INVALID" . into ( ) ) ,
1914
-
1915
1777
i => unimplemented ! ( "{:?}" , i) ,
1916
1778
}
1917
1779
}
0 commit comments