123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116openJs_of_ocaml.JsopenJs_of_ocaml.Js.UnsafemoduleFeature=structtypet=intletmvp:t=global##.binaryen##.Features##.MVPletatomics:t=global##.binaryen##.Features##.Atomicsletbulk_memory:t=global##.binaryen##.Features##.BulkMemoryletmutable_globals:t=global##.binaryen##.Features##.MutableGlobalsletnontrapping_fp_to_int:t=global##.binaryen##.Features##.NontrappingFPToIntletsign_ext:t=global##.binaryen##.Features##.SignExtletsimd128:t=global##.binaryen##.Features##.SIMD128letexception_handling:t=global##.binaryen##.Features##.ExceptionHandlinglettail_call:t=global##.binaryen##.Features##.TailCallletreference_types:t=global##.binaryen##.Features##.ReferenceTypesletmultivalue:t=global##.binaryen##.Features##.Multivalueletgc:t=global##.binaryen##.Features##.GCletmemory64:t=global##.binaryen##.Features##.Memory64lettyped_function_references:t=global##.binaryen##.Features##.TypedFunctionReferencesletrelaxed_simd:t=global##.binaryen##.Features##.RelaxedSIMDletall:t=global##.binaryen##.Features##.Allendexternalu8a_to_bytes:'a->bytes="caml_bytes_of_array"(* TODO: Verify this converts to bytes correctly? *)externalbytes_to_u8a:bytes->'a="caml_array_of_bytes"externalstring_to_u8a:string->'a="caml_array_of_string"typetletcreate()=new_objglobal##.binaryen##.Module[||]letdisposewasm_mod=ignore(meth_callwasm_mod"dispose"[||])(* TODO: Check the unit8Array conversion *)letadd_custom_sectionwasm_modnamecontents=letcontents=string_to_u8acontentsinignore(meth_callwasm_mod"addCustomSection"[|inject(stringname);injectcontents|])letparsetext=meth_callglobal##.binaryen"parseText"[|inject(stringtext)|]letprintwasm_mod=lettext=meth_callwasm_mod"emitText"[||]inprint_string(to_stringtext)letprint_asmjswasm_mod=letasm=meth_callwasm_mod"emitAsmjs"[||]inprint_string(to_stringasm)letvalidatewasm_mod=meth_callwasm_mod"validate"[||]letoptimizewasm_mod=meth_callwasm_mod"optimize"[||]letget_featureswasm_mod=letfeatures_int=meth_callwasm_mod"getFeatures"[||]inletrecsplit_features=function|0->[]|featurewhenfeatures_intlandfeature>0->feature::split_features(featurelsr1)|feature->split_features(featurelsr1)in(* Support 32-bit OCaml where integers are 31 bits *)(* This supports up to 31 Binaryen features *)split_features0x40000000letset_featureswasm_modfeatures=meth_callwasm_mod"setFeatures"[|inject(List.fold_left(lor)0features)|]letrun_passeswasm_modpasses=meth_callwasm_mod"runPasses"[|inject(array(Array.of_list(List.mapstringpasses)))|]letauto_dropwasm_mod=meth_callwasm_mod"autoDrop"[||]letwritewasm_modsourcemap_url=matchsourcemap_urlwith|Someurl->letobj=meth_callwasm_mod"emitBinary"[|injecturl|]inletbinary=getobj"binary"inletsoucemap=getobj"soureMap"in(u8a_to_bytesbinary,Somesoucemap)|None->letbinary=meth_callwasm_mod"emitBinary"[||]in(u8a_to_bytesbinary,None)letwrite_textwasm_mod=lettext=meth_callwasm_mod"emitText"[||]into_stringtextletreadbyts=letdata=bytes_to_u8abytsinmeth_callglobal##.binaryen"readBinary"[|injectdata|]letinterpretwasm_mod=meth_callwasm_mod"interpret"[||]letadd_debug_info_filenamewasm_modfilename=meth_callwasm_mod"addDebugInfoFileName"[|inject(stringfilename)|]letget_debug_info_filenamewasm_modindex=meth_callwasm_mod"getDebugInfoFileName"[|injectindex|](* The JS version doesn't expose `update_maps` *)letupdate_mapswasm_mod=()