@@ -15,13 +15,55 @@ use crate::{
1515 } ,
1616 TranslationError ,
1717 } ,
18- ir:: { BranchOffset , Op , Slot } ,
18+ ir:: { self , BranchOffset , Encode as _ , Op , Slot } ,
1919 Engine ,
2020 Error ,
2121 ValType ,
2222} ;
2323use alloc:: vec:: { self , Vec } ;
2424
25+ #[ derive( Debug , Default ) ]
26+ #[ expect( unused) ]
27+ pub struct EncodedOps {
28+ buffer : Vec < u8 > ,
29+ }
30+
31+ impl ir:: Encoder for EncodedOps {
32+ type Pos = OpPos ;
33+ type Error = TranslationError ;
34+
35+ fn write_bytes ( & mut self , bytes : & [ u8 ] ) -> Result < Self :: Pos , Self :: Error > {
36+ let pos = self . buffer . len ( ) ;
37+ self . buffer . extend ( bytes) ;
38+ Ok ( OpPos :: from ( pos) )
39+ }
40+
41+ fn encode_op_code ( & mut self , code : ir:: OpCode ) -> Result < Self :: Pos , Self :: Error > {
42+ // Note: this implements encoding for indirect threading.
43+ //
44+ // For direct threading we need to know ahead of time about the
45+ // function pointers of all operator execution handlers which
46+ // are defined in the Wasmi executor and available to the translator.
47+ u16:: from ( code) . encode ( self )
48+ }
49+
50+ fn branch_offset (
51+ & mut self ,
52+ _pos : Self :: Pos ,
53+ _branch_offset : BranchOffset ,
54+ ) -> Result < ( ) , Self :: Error > {
55+ todo ! ( )
56+ }
57+
58+ fn block_fuel (
59+ & mut self ,
60+ _pos : Self :: Pos ,
61+ _block_fuel : ir:: BlockFuel ,
62+ ) -> Result < ( ) , Self :: Error > {
63+ todo ! ( )
64+ }
65+ }
66+
2567/// Creates and encodes the buffer of encoded [`Op`]s for a function.
2668#[ derive( Debug , Default ) ]
2769pub struct OpEncoder {
0 commit comments