@@ -154,12 +154,12 @@ let value_type s =
154
154
| Some n when n > 0x70 -> NumType (num_type s)
155
155
| _ -> RefType (ref_type s)
156
156
157
- let stack_type s = vec value_type s
157
+ let result_type s = vec value_type s
158
158
let func_type s =
159
159
match vs7 s with
160
160
| - 0x20 ->
161
- let ins = stack_type s in
162
- let out = stack_type s in
161
+ let ins = result_type s in
162
+ let out = result_type s in
163
163
FuncType (ins, out)
164
164
| _ -> error s (pos s - 1 ) " malformed function type"
165
165
@@ -759,21 +759,28 @@ let data_count_section s =
759
759
760
760
let custom size s =
761
761
let start = pos s in
762
- let _id = name s in
763
- skip (size - (pos s - start)) s;
764
- true
762
+ let id = name s in
763
+ let bs = get_string (size - (pos s - start)) s in
764
+ Some (id, bs)
765
765
766
766
let custom_section s =
767
- section_with_size `CustomSection custom false s
767
+ section_with_size `CustomSection custom None s
768
+
769
+ let non_custom_section s =
770
+ match id s with
771
+ | None | Some `CustomSection -> None
772
+ | _ -> skip 1 s; sized skip s; Some ()
768
773
769
774
770
775
(* Modules *)
771
776
772
- let rec iterate f s = if f s then iterate f s
777
+ let rec iterate f s = if f s <> None then iterate f s
778
+
779
+ let magic = 0x6d736100l
773
780
774
781
let module_ s =
775
- let magic = u32 s in
776
- require (magic = 0x6d736100l ) s 0 " magic header not detected" ;
782
+ let header = u32 s in
783
+ require (header = magic ) s 0 " magic header not detected" ;
777
784
let version = u32 s in
778
785
require (version = Encode. version) s 4 " unknown binary version" ;
779
786
iterate custom_section s;
@@ -816,3 +823,18 @@ let module_ s =
816
823
817
824
818
825
let decode name bs = at module_ (stream name bs)
826
+
827
+ let all_custom tag s =
828
+ let header = u32 s in
829
+ require (header = magic) s 0 " magic header not detected" ;
830
+ let version = u32 s in
831
+ require (version = Encode. version) s 4 " unknown binary version" ;
832
+ let rec collect () =
833
+ iterate non_custom_section s;
834
+ match custom_section s with
835
+ | None -> []
836
+ | Some (n , s ) when n = tag -> s :: collect ()
837
+ | Some _ -> collect ()
838
+ in collect ()
839
+
840
+ let decode_custom tag name bs = all_custom tag (stream name bs)
0 commit comments