pit_wit_bridge/
into.rs

1use std::{
2    collections::{BTreeMap, BTreeSet},
3    mem::{replace, swap, take},
4};
5
6use nonempty::NonEmpty;
7use pit_core::{Arg, Interface, Sig};
8use waffle::{
9    util::new_sig, Block, ExportKind, Func, FuncDecl, FunctionBody, Memory, Module, Operator, Signature, SignatureData, Type, Value, WithNullable
10};
11use wit_bindgen_core::{
12    abi::{Bindgen, Bitcast, WasmType},
13    wit_parser::{self, Record, Resolve, Tuple},
14};
15
16pub struct State<'a, 'b, 'c> {
17    pub module: &'a mut Module<'b>,
18    pub func: &'c mut FunctionBody,
19    pub scratch: Memory,
20    pub block_stack: NonEmpty<Block>,
21    pub ids: Vec<Func>,
22    pub storage: BTreeSet<Interface>,
23}
24
25impl<'a, 'b, 'c> State<'a, 'b, 'c> {
26    pub fn waffle(&self, a: &WasmType) -> Type {
27        let p = if self.module.memories[self.scratch].memory64 {
28            Type::I64
29        } else {
30            Type::I32
31        };
32        match a {
33            WasmType::I32 => Type::I32,
34            WasmType::I64 => Type::I64,
35            WasmType::F32 => Type::F32,
36            WasmType::F64 => Type::F64,
37            WasmType::Pointer => p,
38            WasmType::PointerOrI64 => p,
39            WasmType::Length => p,
40        }
41    }
42    pub fn ty(&mut self, t: &wit_parser::Type, resolve: &Resolve) -> Arg {
43        match t {
44            wit_parser::Type::Bool => Arg::I32,
45            wit_parser::Type::U8 => Arg::I32,
46            wit_parser::Type::U16 => Arg::I32,
47            wit_parser::Type::U32 => Arg::I32,
48            wit_parser::Type::U64 => Arg::I64,
49            wit_parser::Type::S8 => Arg::I32,
50            wit_parser::Type::S16 => Arg::I32,
51            wit_parser::Type::S32 => Arg::I32,
52            wit_parser::Type::S64 => Arg::I64,
53            wit_parser::Type::F32 => Arg::F32,
54            wit_parser::Type::F64 => Arg::F64,
55            wit_parser::Type::Char => Arg::I32,
56            wit_parser::Type::String => todo!(),
57            wit_parser::Type::Id(id) => {
58                let def: &wit_parser::TypeDef = &resolve.types[*id];
59                match &def.kind {
60                    wit_parser::TypeDefKind::Record(record) => Arg::Resource {
61                        ty: pit_core::ResTy::Of(self.record(record, resolve).rid()),
62                        nullable: true,
63                        take: false,
64                        ann: vec![],
65                    },
66                    wit_parser::TypeDefKind::Resource => Arg::Resource {
67                        ty: pit_core::ResTy::None,
68                        nullable: true,
69                        take: false,
70                        ann: vec![],
71                    },
72                    wit_parser::TypeDefKind::Handle(handle) => todo!(),
73                    wit_parser::TypeDefKind::Flags(flags) => todo!(),
74                    wit_parser::TypeDefKind::Tuple(tuple) => Arg::Resource {
75                        ty: pit_core::ResTy::Of(self.tuple(tuple, resolve).rid()),
76                        nullable: true,
77                        take: false,
78                        ann: vec![],
79                    },
80                    wit_parser::TypeDefKind::Variant(variant) => todo!(),
81                    wit_parser::TypeDefKind::Enum(_) => todo!(),
82                    wit_parser::TypeDefKind::Option(_) => todo!(),
83                    wit_parser::TypeDefKind::Result(result) => todo!(),
84                    wit_parser::TypeDefKind::List(_) => todo!(),
85                    wit_parser::TypeDefKind::Future(_) => todo!(),
86                    wit_parser::TypeDefKind::Stream(stream) => todo!(),
87                    wit_parser::TypeDefKind::Type(_) => todo!(),
88                    wit_parser::TypeDefKind::Unknown => todo!(),
89                }
90            }
91        }
92    }
93    pub fn record(&mut self, r: &Record, resolve: &Resolve) -> Interface {
94        let i = Interface {
95            methods: r
96                .fields
97                .iter()
98                .map(|f: &wit_bindgen_core::wit_parser::Field| {
99                    (
100                        f.name.clone(),
101                        Sig {
102                            ann: vec![],
103                            params: vec![],
104                            rets: vec![self.ty(&f.ty, resolve)],
105                        },
106                    )
107                })
108                .collect(),
109            ann: vec![],
110        };
111        self.storage.insert(i.clone());
112        return i;
113    }
114    pub fn tuple(&mut self, r: &Tuple, resolve: &Resolve) -> Interface {
115        let i = Interface {
116            methods: r
117                .types
118                .iter()
119                .enumerate()
120                .map(|(v, f)| {
121                    (
122                        format!("v{v}"),
123                        Sig {
124                            ann: vec![],
125                            params: vec![],
126                            rets: vec![self.ty(&f, resolve)],
127                        },
128                    )
129                })
130                .collect(),
131            ann: vec![],
132        };
133        self.storage.insert(i.clone());
134
135        return i;
136    }
137    fn lfn(&self, n: &str) -> Option<Func> {
138        return self.module.exports.iter().find_map(|a| {
139            if a.name == n {
140                match &a.kind {
141                    ExportKind::Func(f) => Some(*f),
142                    _ => None,
143                }
144            } else {
145                None
146            }
147        });
148    }
149    fn bitcast(&mut self, o: Value, c: &Bitcast) -> Value {
150        let k = self.block_stack.last().clone();
151        match c {
152            Bitcast::F32ToI32 => {
153                self.func
154                    .add_op(k, Operator::I32ReinterpretF32, &[o], &[Type::I32])
155            }
156            Bitcast::F64ToI64 => {
157                self.func
158                    .add_op(k, Operator::I64ReinterpretF64, &[o], &[Type::I64])
159            }
160            Bitcast::I32ToI64 => self
161                .func
162                .add_op(k, Operator::I64ExtendI32U, &[o], &[Type::I64]),
163            Bitcast::F32ToI64 => {
164                let o = self.bitcast(o, &Bitcast::F32ToI32);
165                self.bitcast(o, &Bitcast::I32ToI64)
166            }
167            Bitcast::I32ToF32 => {
168                self.func
169                    .add_op(k, Operator::F32ReinterpretI32, &[o], &[Type::F32])
170            }
171            Bitcast::I64ToF64 => {
172                self.func
173                    .add_op(k, Operator::F64ReinterpretI64, &[o], &[Type::F64])
174            }
175            Bitcast::I64ToI32 => self
176                .func
177                .add_op(k, Operator::I32WrapI64, &[o], &[Type::I32]),
178            Bitcast::I64ToF32 => {
179                let o = self.bitcast(o, &Bitcast::I64ToI32);
180                self.bitcast(o, &Bitcast::I32ToF32)
181            }
182            Bitcast::P64ToI64 => o,
183            Bitcast::I64ToP64 => o,
184            Bitcast::P64ToP | Bitcast::I64ToL => {
185                if self.module.memories[self.scratch].memory64 {
186                    o
187                } else {
188                    self.bitcast(o, &Bitcast::I64ToI32)
189                }
190            }
191            Bitcast::PToP64 | Bitcast::LToI64 => {
192                if self.module.memories[self.scratch].memory64 {
193                    o
194                } else {
195                    self.bitcast(o, &Bitcast::I32ToI64)
196                }
197            }
198            Bitcast::I32ToP | Bitcast::I32ToL => {
199                if self.module.memories[self.scratch].memory64 {
200                    self.bitcast(o, &Bitcast::I32ToI64)
201                } else {
202                    o
203                }
204            }
205            Bitcast::PToI32 | Bitcast::LToI32 => {
206                if self.module.memories[self.scratch].memory64 {
207                    self.bitcast(o, &Bitcast::I64ToI32)
208                } else {
209                    o
210                }
211            }
212            Bitcast::PToL => o,
213            Bitcast::LToP => o,
214            Bitcast::Sequence(a) => {
215                let o = self.bitcast(o, &a[0]);
216                self.bitcast(o, &a[1])
217            }
218            Bitcast::None => o,
219        }
220    }
221    fn pop_block(&mut self) -> Func {
222        let sig = new_sig(
223            self.module,
224            SignatureData::Func {
225                params: vec![Type::Heap(WithNullable { value: waffle::HeapType::ExternRef, nullable: true })],
226                returns: self.func.rets.clone(),
227            },
228        );
229        let id = self.ids.pop().unwrap();
230        swap(self.module.funcs[id].body_mut().unwrap(), &mut self.func);
231        if let FuncDecl::Body(s, _, _) = &mut self.module.funcs[id] {
232            *s = sig;
233        }
234        return id;
235    }
236}
237impl<'a, 'b, 'c> Bindgen for State<'a, 'b, 'c> {
238    type Operand = Value;
239
240    fn emit(
241        &mut self,
242        resolve: &wit_bindgen_core::wit_parser::Resolve,
243        inst: &wit_bindgen_core::abi::Instruction<'_>,
244        operands: &mut Vec<Self::Operand>,
245        results: &mut Vec<Self::Operand>,
246    ) {
247        let k = self.block_stack.last().clone();
248        match inst {
249            wit_bindgen_core::abi::Instruction::GetArg { nth } => {
250                results.push(self.func.blocks[self.func.entry].params[*nth].1);
251            }
252            wit_bindgen_core::abi::Instruction::I32Const { val } => results.push(self.func.add_op(
253                k,
254                waffle::Operator::I32Const { value: *val as u32 },
255                &[],
256                &[Type::I32],
257            )),
258            wit_bindgen_core::abi::Instruction::Bitcasts { casts } => {
259                results.extend(
260                    operands
261                        .drain(..)
262                        .zip(casts.iter())
263                        .map(|(o, c)| self.bitcast(o, c)),
264                );
265            }
266            wit_bindgen_core::abi::Instruction::ConstZero { tys } => {
267                results.extend(tys.iter().map(|a| {
268                    let w = self.waffle(a);
269                    match &w {
270                        Type::I32 => {
271                            self.func
272                                .add_op(k, waffle::Operator::I32Const { value: 0 }, &[], &[w])
273                        }
274                        Type::I64 => {
275                            self.func
276                                .add_op(k, waffle::Operator::I64Const { value: 0 }, &[], &[w])
277                        }
278                        Type::F32 => {
279                            self.func
280                                .add_op(k, waffle::Operator::F32Const { value: 0 }, &[], &[w])
281                        }
282                        Type::F64 => {
283                            self.func
284                                .add_op(k, waffle::Operator::F64Const { value: 0 }, &[], &[w])
285                        }
286                        _ => unreachable!(),
287                    }
288                }));
289            }
290            wit_bindgen_core::abi::Instruction::I32Load { offset } => {
291                results.push(self.func.add_op(
292                    k,
293                    Operator::I32Load {
294                        memory: waffle::MemoryArg {
295                            align: 2,
296                            offset: *offset as u64,
297                            memory: self.scratch,
298                        },
299                    },
300                    &[operands.pop().unwrap()],
301                    &[Type::I32],
302                ));
303            }
304            wit_bindgen_core::abi::Instruction::I32Load8U { offset } => {
305                results.push(self.func.add_op(
306                    k,
307                    Operator::I32Load8U {
308                        memory: waffle::MemoryArg {
309                            align: 0,
310                            offset: *offset as u64,
311                            memory: self.scratch,
312                        },
313                    },
314                    &[operands.pop().unwrap()],
315                    &[Type::I32],
316                ));
317            }
318            wit_bindgen_core::abi::Instruction::I32Load8S { offset } => {
319                results.push(self.func.add_op(
320                    k,
321                    Operator::I32Load8S {
322                        memory: waffle::MemoryArg {
323                            align: 0,
324                            offset: *offset as u64,
325                            memory: self.scratch,
326                        },
327                    },
328                    &[operands.pop().unwrap()],
329                    &[Type::I32],
330                ));
331            }
332            wit_bindgen_core::abi::Instruction::I32Load16U { offset } => {
333                results.push(self.func.add_op(
334                    k,
335                    Operator::I32Load16U {
336                        memory: waffle::MemoryArg {
337                            align: 1,
338                            offset: *offset as u64,
339                            memory: self.scratch,
340                        },
341                    },
342                    &[operands.pop().unwrap()],
343                    &[Type::I32],
344                ));
345            }
346            wit_bindgen_core::abi::Instruction::I32Load16S { offset } => {
347                results.push(self.func.add_op(
348                    k,
349                    Operator::I32Load16S {
350                        memory: waffle::MemoryArg {
351                            align: 1,
352                            offset: *offset as u64,
353                            memory: self.scratch,
354                        },
355                    },
356                    &[operands.pop().unwrap()],
357                    &[Type::I32],
358                ));
359            }
360            wit_bindgen_core::abi::Instruction::I64Load { offset } => {
361                results.push(self.func.add_op(
362                    k,
363                    Operator::I64Load {
364                        memory: waffle::MemoryArg {
365                            align: 3,
366                            offset: *offset as u64,
367                            memory: self.scratch,
368                        },
369                    },
370                    &[operands.pop().unwrap()],
371                    &[Type::I64],
372                ));
373            }
374            wit_bindgen_core::abi::Instruction::F32Load { offset } => {
375                results.push(self.func.add_op(
376                    k,
377                    Operator::F32Load {
378                        memory: waffle::MemoryArg {
379                            align: 2,
380                            offset: *offset as u64,
381                            memory: self.scratch,
382                        },
383                    },
384                    &[operands.pop().unwrap()],
385                    &[Type::F32],
386                ));
387            }
388            wit_bindgen_core::abi::Instruction::F64Load { offset } => {
389                results.push(self.func.add_op(
390                    k,
391                    Operator::F64Load {
392                        memory: waffle::MemoryArg {
393                            align: 3,
394                            offset: *offset as u64,
395                            memory: self.scratch,
396                        },
397                    },
398                    &[operands.pop().unwrap()],
399                    &[Type::F64],
400                ));
401            }
402            wit_bindgen_core::abi::Instruction::PointerLoad { offset }
403            | wit_bindgen_core::abi::Instruction::LengthLoad { offset } => {
404                let (op, ty) = if self.module.memories[self.scratch].memory64 {
405                    (
406                        Operator::I64Load {
407                            memory: waffle::MemoryArg {
408                                align: 3,
409                                offset: *offset as u64,
410                                memory: self.scratch,
411                            },
412                        },
413                        Type::I64,
414                    )
415                } else {
416                    (
417                        Operator::I32Load {
418                            memory: waffle::MemoryArg {
419                                align: 2,
420                                offset: *offset as u64,
421                                memory: self.scratch,
422                            },
423                        },
424                        Type::I32,
425                    )
426                };
427                results.push(self.func.add_op(k, op, &[operands.pop().unwrap()], &[ty]));
428            }
429            wit_bindgen_core::abi::Instruction::I32Store { offset } => {
430                let ptr = operands.pop().unwrap();
431                let val = operands.pop().unwrap();
432                self.func.add_op(
433                    k,
434                    Operator::I32Store {
435                        memory: waffle::MemoryArg {
436                            align: 2,
437                            offset: *offset as u64,
438                            memory: self.scratch,
439                        },
440                    },
441                    &[ptr, val],
442                    &[],
443                );
444            }
445            wit_bindgen_core::abi::Instruction::I32Store8 { offset } => {
446                let ptr = operands.pop().unwrap();
447                let val = operands.pop().unwrap();
448                self.func.add_op(
449                    k,
450                    Operator::I32Store8 {
451                        memory: waffle::MemoryArg {
452                            align: 0,
453                            offset: *offset as u64,
454                            memory: self.scratch,
455                        },
456                    },
457                    &[ptr, val],
458                    &[],
459                );
460            }
461            wit_bindgen_core::abi::Instruction::I32Store16 { offset } => {
462                let ptr = operands.pop().unwrap();
463                let val = operands.pop().unwrap();
464                self.func.add_op(
465                    k,
466                    Operator::I32Store16 {
467                        memory: waffle::MemoryArg {
468                            align: 1,
469                            offset: *offset as u64,
470                            memory: self.scratch,
471                        },
472                    },
473                    &[ptr, val],
474                    &[],
475                );
476            }
477            wit_bindgen_core::abi::Instruction::I64Store { offset } => {
478                let ptr = operands.pop().unwrap();
479                let val = operands.pop().unwrap();
480                self.func.add_op(
481                    k,
482                    Operator::I64Store {
483                        memory: waffle::MemoryArg {
484                            align: 3,
485                            offset: *offset as u64,
486                            memory: self.scratch,
487                        },
488                    },
489                    &[ptr, val],
490                    &[],
491                );
492            }
493            wit_bindgen_core::abi::Instruction::F32Store { offset } => {
494                let ptr = operands.pop().unwrap();
495                let val = operands.pop().unwrap();
496                self.func.add_op(
497                    k,
498                    Operator::F32Store {
499                        memory: waffle::MemoryArg {
500                            align: 2,
501                            offset: *offset as u64,
502                            memory: self.scratch,
503                        },
504                    },
505                    &[ptr, val],
506                    &[],
507                );
508            }
509            wit_bindgen_core::abi::Instruction::F64Store { offset } => {
510                let ptr = operands.pop().unwrap();
511                let val = operands.pop().unwrap();
512                self.func.add_op(
513                    k,
514                    Operator::F64Store {
515                        memory: waffle::MemoryArg {
516                            align: 3,
517                            offset: *offset as u64,
518                            memory: self.scratch,
519                        },
520                    },
521                    &[ptr, val],
522                    &[],
523                );
524            }
525            wit_bindgen_core::abi::Instruction::PointerStore { offset }
526            | wit_bindgen_core::abi::Instruction::LengthStore { offset } => {
527                let ptr = operands.pop().unwrap();
528                let val = operands.pop().unwrap();
529                self.func.add_op(
530                    k,
531                    if self.module.memories[self.scratch].memory64 {
532                        Operator::I64Store {
533                            memory: waffle::MemoryArg {
534                                align: 3,
535                                offset: *offset as u64,
536                                memory: self.scratch,
537                            },
538                        }
539                    } else {
540                        Operator::I32Store {
541                            memory: waffle::MemoryArg {
542                                align: 2,
543                                offset: *offset as u64,
544                                memory: self.scratch,
545                            },
546                        }
547                    },
548                    &[ptr, val],
549                    &[],
550                );
551            }
552            wit_bindgen_core::abi::Instruction::I32FromChar => swap(operands, results),
553            wit_bindgen_core::abi::Instruction::I64FromU64 => swap(operands, results),
554            wit_bindgen_core::abi::Instruction::I64FromS64 => swap(operands, results),
555            wit_bindgen_core::abi::Instruction::I32FromU32 => swap(operands, results),
556            wit_bindgen_core::abi::Instruction::I32FromS32 => swap(operands, results),
557            wit_bindgen_core::abi::Instruction::I32FromU16 => swap(operands, results),
558            wit_bindgen_core::abi::Instruction::I32FromS16 => swap(operands, results),
559            wit_bindgen_core::abi::Instruction::I32FromU8 => swap(operands, results),
560            wit_bindgen_core::abi::Instruction::I32FromS8 => swap(operands, results),
561            wit_bindgen_core::abi::Instruction::CoreF32FromF32 => swap(operands, results),
562            wit_bindgen_core::abi::Instruction::CoreF64FromF64 => swap(operands, results),
563            wit_bindgen_core::abi::Instruction::S8FromI32 => swap(operands, results),
564            wit_bindgen_core::abi::Instruction::U8FromI32 => swap(operands, results),
565            wit_bindgen_core::abi::Instruction::S16FromI32 => swap(operands, results),
566            wit_bindgen_core::abi::Instruction::U16FromI32 => swap(operands, results),
567            wit_bindgen_core::abi::Instruction::S32FromI32 => swap(operands, results),
568            wit_bindgen_core::abi::Instruction::U32FromI32 => swap(operands, results),
569            wit_bindgen_core::abi::Instruction::S64FromI64 => swap(operands, results),
570            wit_bindgen_core::abi::Instruction::U64FromI64 => swap(operands, results),
571            wit_bindgen_core::abi::Instruction::CharFromI32 => swap(operands, results),
572            wit_bindgen_core::abi::Instruction::F32FromCoreF32 => swap(operands, results),
573            wit_bindgen_core::abi::Instruction::F64FromCoreF64 => swap(operands, results),
574            wit_bindgen_core::abi::Instruction::BoolFromI32 => swap(operands, results),
575            wit_bindgen_core::abi::Instruction::I32FromBool => swap(operands, results),
576            wit_bindgen_core::abi::Instruction::ListCanonLower { element, realloc } => todo!(),
577            wit_bindgen_core::abi::Instruction::StringLower { realloc } => todo!(),
578            wit_bindgen_core::abi::Instruction::ListLower { element, realloc } => todo!(),
579            wit_bindgen_core::abi::Instruction::ListCanonLift { element, ty } => todo!(),
580            wit_bindgen_core::abi::Instruction::StringLift => todo!(),
581            wit_bindgen_core::abi::Instruction::ListLift { element, ty } => todo!(),
582            wit_bindgen_core::abi::Instruction::IterElem { element } => todo!(),
583            wit_bindgen_core::abi::Instruction::IterBasePointer => todo!(),
584            wit_bindgen_core::abi::Instruction::RecordLower { record, name, ty } => todo!(),
585            wit_bindgen_core::abi::Instruction::RecordLift { record, name, ty } => todo!(),
586            wit_bindgen_core::abi::Instruction::HandleLower { handle, name, ty } => todo!(),
587            wit_bindgen_core::abi::Instruction::HandleLift { handle, name, ty } => todo!(),
588            wit_bindgen_core::abi::Instruction::TupleLower { tuple, ty } => {
589                let t = self.tuple(&**tuple, resolve);
590                let funcs = pit_patch::util::waffle_funcs(&mut self.module, &t, false);
591                let funcs = tuple
592                    .types
593                    .iter()
594                    .enumerate()
595                    .filter_map(|(v, _)| funcs.get(&format!("v{v}")))
596                    .cloned()
597                    .collect::<Vec<_>>();
598                let val = operands.pop().unwrap();
599                results.extend(funcs.into_iter().map(|f| {
600                    let tys = self.module.funcs[f].sig();
601                    let SignatureData::Func { params, returns } = &self.module.signatures[tys] else{
602                        todo!()
603                    };
604                    let tys = &*returns;
605                    let v = self
606                        .func
607                        .add_op(k, Operator::Call { function_index: f }, &[val], tys);
608                    v
609                }));
610            }
611            wit_bindgen_core::abi::Instruction::TupleLift { tuple, ty } => {
612                let t = self.tuple(&**tuple, resolve);
613                let c = pit_patch::util::canon(&mut self.module, &t,None,"canon");
614                results.push(self.func.add_op(
615                    k,
616                    Operator::Call { function_index: c },
617                    &operands,
618                    &[Type::Heap(WithNullable{nullable: true, value: waffle::HeapType::ExternRef})],
619                ));
620            }
621            wit_bindgen_core::abi::Instruction::FlagsLower { flags, name, ty } => todo!(),
622            wit_bindgen_core::abi::Instruction::FlagsLift { flags, name, ty } => todo!(),
623            wit_bindgen_core::abi::Instruction::VariantPayloadName => todo!(),
624            wit_bindgen_core::abi::Instruction::VariantLower {
625                variant,
626                name,
627                ty,
628                results,
629            } => todo!(),
630            wit_bindgen_core::abi::Instruction::VariantLift { variant, name, ty } => todo!(),
631            wit_bindgen_core::abi::Instruction::EnumLower { enum_, name, ty } => todo!(),
632            wit_bindgen_core::abi::Instruction::EnumLift { enum_, name, ty } => todo!(),
633            wit_bindgen_core::abi::Instruction::OptionLower {
634                payload,
635                ty,
636                results,
637            } => todo!(),
638            wit_bindgen_core::abi::Instruction::OptionLift { payload, ty } => todo!(),
639            wit_bindgen_core::abi::Instruction::ResultLower {
640                result,
641                ty,
642                results,
643            } => todo!(),
644            wit_bindgen_core::abi::Instruction::ResultLift { result, ty } => todo!(),
645            wit_bindgen_core::abi::Instruction::CallWasm { name, sig } => todo!(),
646            wit_bindgen_core::abi::Instruction::CallInterface { func } => todo!(),
647            wit_bindgen_core::abi::Instruction::Return { amt, func } => {
648                self.func.set_terminator(
649                    k,
650                    waffle::Terminator::Return {
651                        values: take(operands),
652                    },
653                );
654                *self.block_stack.last_mut() = self.func.add_block();
655            }
656            wit_bindgen_core::abi::Instruction::Malloc {
657                realloc,
658                size,
659                align,
660            } => todo!(),
661            wit_bindgen_core::abi::Instruction::GuestDeallocate { size, align } => todo!(),
662            wit_bindgen_core::abi::Instruction::GuestDeallocateString => todo!(),
663            wit_bindgen_core::abi::Instruction::GuestDeallocateList { element } => todo!(),
664            wit_bindgen_core::abi::Instruction::GuestDeallocateVariant { blocks } => todo!(),
665        }
666    }
667
668    fn return_pointer(&mut self, size: usize, align: usize) -> Self::Operand {
669        todo!()
670    }
671
672    fn push_block(&mut self) {
673        let sig = new_sig(
674            self.module,
675            SignatureData::Func {
676                params: vec![Type::Heap(WithNullable{nullable: true, value: waffle::HeapType::ExternRef})],
677                returns: vec![],
678            },
679        );
680        let mut new = FunctionBody::new(&self.module, sig);
681        self.block_stack.push(new.entry);
682        new = replace(&mut self.func, new);
683        self.ids.push(self.module.funcs.push(waffle::FuncDecl::Body(
684            sig,
685            format!("component/synthetic"),
686            new,
687        )));
688    }
689
690    fn finish_block(&mut self, operand: &mut Vec<Self::Operand>) {
691        self.func.rets = operand
692            .iter()
693            .filter_map(|a| self.func.values[*a].ty(&self.func.type_pool))
694            .collect();
695        self.func.set_terminator(
696            *self.block_stack.last(),
697            waffle::Terminator::Return {
698                values: take(operand),
699            },
700        );
701    }
702
703    fn sizes(&self) -> &wit_bindgen_core::wit_parser::SizeAlign {
704        todo!()
705    }
706
707    fn is_list_canonical(
708        &self,
709        resolve: &wit_bindgen_core::wit_parser::Resolve,
710        element: &wit_bindgen_core::wit_parser::Type,
711    ) -> bool {
712        todo!()
713    }
714}