@@ -9,7 +9,7 @@ import binary.types;
9
9
import std.algorithm : each;
10
10
import std.bitmanip : read;
11
11
import std.exception : enforce;
12
- import std.range : popFrontExactly;
12
+ import std.range : front, popFront, popFrontExactly;
13
13
import std.system : Endian;
14
14
import std.typecons : Tuple , tuple;
15
15
@@ -116,12 +116,19 @@ Limits decodeLimits(ref const(ubyte)[] input)
116
116
}
117
117
118
118
// /
119
- uint decodeExpr (ref const (ubyte )[] input)
119
+ const (Instruction)[] decodeExpr (ref const (ubyte )[] input)
120
120
{
121
- input.leb128! uint (); // i32.const
122
- auto offset = input.leb128! uint ();
123
- input.leb128! uint (); // end
124
- return offset;
121
+ typeof (return ) insns = [];
122
+ while (true )
123
+ {
124
+ if (0x0b == input.front)
125
+ {
126
+ input.popFront();
127
+ return insns;
128
+ }
129
+ insns ~= input.decodeInstruction();
130
+ }
131
+ assert (false );
125
132
}
126
133
127
134
// /
@@ -219,6 +226,15 @@ Function decodeFunctionBody(ref const(ubyte)[] input, ref uint remaining)
219
226
return body ;
220
227
}
221
228
229
+ // /
230
+ Instruction decodeInstruction (ref const (ubyte )[] input)
231
+ {
232
+ // FIXME: use @("nolint(dscanner.could_be_immutable_check)")
233
+ // once it works someday...
234
+ uint dummy;
235
+ return decodeInstruction (input, dummy);
236
+ }
237
+
222
238
// /
223
239
Instruction decodeInstruction (ref const (ubyte )[] input, ref uint remaining)
224
240
{
@@ -586,14 +602,26 @@ unittest
586
602
tuple(
587
603
" source/fixtures/data.wat" ,
588
604
[
589
- Data(memoryIndex: 0 , offset: 0 , bytes: cast (ubyte []) " hello" )
605
+ Data(
606
+ memoryIndex: 0 ,
607
+ offset: [Instruction(I32Const(0 ))],
608
+ bytes: cast (ubyte []) " hello"
609
+ )
590
610
]
591
611
),
592
612
tuple(
593
613
" source/fixtures/memory.wat" ,
594
614
[
595
- Data(memoryIndex: 0 , offset: 0 , bytes: cast (ubyte []) " hello" ),
596
- Data(memoryIndex: 0 , offset: 5 , bytes: cast (ubyte []) " world" )
615
+ Data(
616
+ memoryIndex: 0 ,
617
+ offset: [Instruction(I32Const(0 ))],
618
+ bytes: cast (ubyte []) " hello"
619
+ ),
620
+ Data(
621
+ memoryIndex: 0 ,
622
+ offset: [Instruction(I32Const(5 ))],
623
+ bytes: cast (ubyte []) " world"
624
+ )
597
625
]
598
626
599
627
)
0 commit comments