package binaryen

  1. Overview
  2. Docs

Source file expression.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
type t

type kind =
  | Invalid
  | Nop
  | Block
  | If
  | Loop
  | Break
  | Switch
  | Call
  | CallIndirect
  | LocalGet
  | LocalSet
  | GlobalGet
  | GlobalSet
  | Load
  | Store
  | AtomicRMW
  | AtomicCmpxchg
  | AtomicWait
  | AtomicNotify
  | AtomicFence
  | SIMDExtract
  | SIMDReplace
  | SIMDShuffle
  | SIMDTernary
  | SIMDShift
  | SIMDLoad
  | SIMDLoadStoreLane
  | MemoryInit
  | DataDrop
  | MemoryCopy
  | MemoryFill
  | Const
  | Unary
  | Binary
  | Select
  | Drop
  | Return
  | MemorySize
  | MemoryGrow
  | Unreachable
  | Pop
  | RefNull
  | RefIs
  | RefFunc
  | RefEq
  | Try
  | Throw
  | Rethrow
  | TupleMake
  | TupleExtract
  | I31New
  | I31Get
  | CallRef
  | RefTest
  | RefCast
  | BrOn
  | RttCanon
  | RttSub
  | StructNew
  | StructGet
  | StructSet
  | ArrayNew
  | ArrayGet
  | ArraySet
  | ArrayLen
  | RefAs

external get_id : t -> int = "caml_binaryen_expression_get_id"

external id_invalid : unit -> int = "caml_binaryen_expression_id_invalid"

let id_invalid = id_invalid ()

external id_nop : unit -> int = "caml_binaryen_expression_id_nop"

let id_nop = id_nop ()

external id_block : unit -> int = "caml_binaryen_expression_id_block"

let id_block = id_block ()

external id_if : unit -> int = "caml_binaryen_expression_id_if"

let id_if = id_if ()

external id_loop : unit -> int = "caml_binaryen_expression_id_loop"

let id_loop = id_loop ()

external id_break : unit -> int = "caml_binaryen_expression_id_break"

let id_break = id_break ()

external id_switch : unit -> int = "caml_binaryen_expression_id_switch"

let id_switch = id_switch ()

external id_call : unit -> int = "caml_binaryen_expression_id_call"

let id_call = id_call ()

external id_call_indirect : unit -> int
  = "caml_binaryen_expression_id_call_indirect"

let id_call_indirect = id_call_indirect ()

external id_local_get : unit -> int = "caml_binaryen_expression_id_local_get"

let id_local_get = id_local_get ()

external id_local_set : unit -> int = "caml_binaryen_expression_id_local_set"

let id_local_set = id_local_set ()

external id_global_get : unit -> int = "caml_binaryen_expression_id_global_get"

let id_global_get = id_global_get ()

external id_global_set : unit -> int = "caml_binaryen_expression_id_global_set"

let id_global_set = id_global_set ()

external id_load : unit -> int = "caml_binaryen_expression_id_load"

let id_load = id_load ()

external id_store : unit -> int = "caml_binaryen_expression_id_store"

let id_store = id_store ()

external id_atomic_rmw : unit -> int = "caml_binaryen_expression_id_atomic_rmw"

let id_atomic_rmw = id_atomic_rmw ()

external id_atomic_cmpxchg : unit -> int
  = "caml_binaryen_expression_id_atomic_cmpxchg"

let id_atomic_cmpxchg = id_atomic_cmpxchg ()

external id_atomic_wait : unit -> int
  = "caml_binaryen_expression_id_atomic_wait"

let id_atomic_wait = id_atomic_wait ()

external id_atomic_notify : unit -> int
  = "caml_binaryen_expression_id_atomic_notify"

let id_atomic_notify = id_atomic_notify ()

external id_atomic_fence : unit -> int
  = "caml_binaryen_expression_id_atomic_fence"

let id_atomic_fence = id_atomic_fence ()

external id_simd_extract : unit -> int
  = "caml_binaryen_expression_id_simd_extract"

let id_simd_extract = id_simd_extract ()

external id_simd_replace : unit -> int
  = "caml_binaryen_expression_id_simd_replace"

let id_simd_replace = id_simd_replace ()

external id_simd_shuffle : unit -> int
  = "caml_binaryen_expression_id_simd_shuffle"

let id_simd_shuffle = id_simd_shuffle ()

external id_simd_ternary : unit -> int
  = "caml_binaryen_expression_id_simd_ternary"

let id_simd_ternary = id_simd_ternary ()

external id_simd_shift : unit -> int = "caml_binaryen_expression_id_simd_shift"

let id_simd_shift = id_simd_shift ()

external id_simd_load : unit -> int = "caml_binaryen_expression_id_simd_load"

let id_simd_load = id_simd_load ()

external id_simd_load_store_lane : unit -> int
  = "caml_binaryen_expression_id_simd_load_store_lane"

let id_simd_load_store_lane = id_simd_load_store_lane ()

external id_memory_init : unit -> int
  = "caml_binaryen_expression_id_memory_init"

let id_memory_init = id_memory_init ()

external id_data_drop : unit -> int = "caml_binaryen_expression_id_data_drop"

let id_data_drop = id_data_drop ()

external id_memory_copy : unit -> int
  = "caml_binaryen_expression_id_memory_copy"

let id_memory_copy = id_memory_copy ()

external id_memory_fill : unit -> int
  = "caml_binaryen_expression_id_memory_fill"

let id_memory_fill = id_memory_fill ()

external id_const : unit -> int = "caml_binaryen_expression_id_const"

let id_const = id_const ()

external id_unary : unit -> int = "caml_binaryen_expression_id_unary"

let id_unary = id_unary ()

external id_binary : unit -> int = "caml_binaryen_expression_id_binary"

let id_binary = id_binary ()

external id_select : unit -> int = "caml_binaryen_expression_id_select"

let id_select = id_select ()

external id_drop : unit -> int = "caml_binaryen_expression_id_drop"

let id_drop = id_drop ()

external id_return : unit -> int = "caml_binaryen_expression_id_return"

let id_return = id_return ()

external id_memory_size : unit -> int
  = "caml_binaryen_expression_id_memory_size"

let id_memory_size = id_memory_size ()

external id_memory_grow : unit -> int
  = "caml_binaryen_expression_id_memory_grow"

let id_memory_grow = id_memory_grow ()

external id_unreachable : unit -> int
  = "caml_binaryen_expression_id_unreachable"

let id_unreachable = id_unreachable ()

external id_pop : unit -> int = "caml_binaryen_expression_id_pop"

let id_pop = id_pop ()

external id_ref_null : unit -> int = "caml_binaryen_expression_id_ref_null"

let id_ref_null = id_ref_null ()

external id_ref_is : unit -> int = "caml_binaryen_expression_id_ref_is"

let id_ref_is = id_ref_is ()

external id_ref_func : unit -> int = "caml_binaryen_expression_id_ref_func"

let id_ref_func = id_ref_func ()

external id_ref_eq : unit -> int = "caml_binaryen_expression_id_ref_eq"

let id_ref_eq = id_ref_eq ()

external id_try : unit -> int = "caml_binaryen_expression_id_try"

let id_try = id_try ()

external id_throw : unit -> int = "caml_binaryen_expression_id_throw"

let id_throw = id_throw ()

external id_rethrow : unit -> int = "caml_binaryen_expression_id_rethrow"

let id_rethrow = id_rethrow ()

external id_tuple_make : unit -> int = "caml_binaryen_expression_id_tuple_make"

let id_tuple_make = id_tuple_make ()

external id_tuple_extract : unit -> int
  = "caml_binaryen_expression_id_tuple_extract"

let id_tuple_extract = id_tuple_extract ()

external id_i31_new : unit -> int = "caml_binaryen_expression_id_i31_new"

let id_i31_new = id_i31_new ()

external id_i31_get : unit -> int = "caml_binaryen_expression_id_i31_get"

let id_i31_get = id_i31_get ()

external id_call_ref : unit -> int = "caml_binaryen_expression_id_call_ref"

let id_call_ref = id_call_ref ()

external id_ref_test : unit -> int = "caml_binaryen_expression_id_ref_test"

let id_ref_test = id_ref_test ()

external id_ref_cast : unit -> int = "caml_binaryen_expression_id_ref_cast"

let id_ref_cast = id_ref_cast ()

external id_br_on : unit -> int = "caml_binaryen_expression_id_br_on"

let id_br_on = id_br_on ()

external id_rtt_canon : unit -> int = "caml_binaryen_expression_id_rtt_canon"

let id_rtt_canon = id_rtt_canon ()

external id_rtt_sub : unit -> int = "caml_binaryen_expression_id_rtt_sub"

let id_rtt_sub = id_rtt_sub ()

external id_struct_new : unit -> int = "caml_binaryen_expression_id_struct_new"

let id_struct_new = id_struct_new ()

external id_struct_get : unit -> int = "caml_binaryen_expression_id_struct_get"

let id_struct_get = id_struct_get ()

external id_struct_set : unit -> int = "caml_binaryen_expression_id_struct_set"

let id_struct_set = id_struct_set ()

external id_array_new : unit -> int = "caml_binaryen_expression_id_array_new"

let id_array_new = id_array_new ()

external id_array_get : unit -> int = "caml_binaryen_expression_id_array_get"

let id_array_get = id_array_get ()

external id_array_set : unit -> int = "caml_binaryen_expression_id_array_set"

let id_array_set = id_array_set ()

external id_array_len : unit -> int = "caml_binaryen_expression_id_array_len"

let id_array_len = id_array_len ()

external id_ref_as : unit -> int = "caml_binaryen_expression_id_ref_as"

let id_ref_as = id_ref_as ()

let get_kind expr =
  let id = get_id expr in
  match id with
  | n when n = id_invalid -> Invalid
  | n when n = id_nop -> Nop
  | n when n = id_block -> Block
  | n when n = id_if -> If
  | n when n = id_loop -> Loop
  | n when n = id_break -> Break
  | n when n = id_switch -> Switch
  | n when n = id_call -> Call
  | n when n = id_call_indirect -> CallIndirect
  | n when n = id_local_get -> LocalGet
  | n when n = id_local_set -> LocalSet
  | n when n = id_global_get -> GlobalGet
  | n when n = id_global_set -> GlobalSet
  | n when n = id_load -> Load
  | n when n = id_store -> Store
  | n when n = id_atomic_rmw -> AtomicRMW
  | n when n = id_atomic_cmpxchg -> AtomicCmpxchg
  | n when n = id_atomic_wait -> AtomicWait
  | n when n = id_atomic_notify -> AtomicNotify
  | n when n = id_atomic_fence -> AtomicFence
  | n when n = id_simd_extract -> SIMDExtract
  | n when n = id_simd_replace -> SIMDReplace
  | n when n = id_simd_shuffle -> SIMDShuffle
  | n when n = id_simd_ternary -> SIMDTernary
  | n when n = id_simd_shift -> SIMDShift
  | n when n = id_simd_load -> SIMDLoad
  | n when n = id_simd_load_store_lane -> SIMDLoadStoreLane
  | n when n = id_memory_init -> MemoryInit
  | n when n = id_data_drop -> DataDrop
  | n when n = id_memory_copy -> MemoryCopy
  | n when n = id_memory_fill -> MemoryFill
  | n when n = id_const -> Const
  | n when n = id_unary -> Unary
  | n when n = id_binary -> Binary
  | n when n = id_select -> Select
  | n when n = id_drop -> Drop
  | n when n = id_return -> Return
  | n when n = id_memory_size -> MemorySize
  | n when n = id_memory_grow -> MemoryGrow
  | n when n = id_unreachable -> Unreachable
  | n when n = id_pop -> Pop
  | n when n = id_ref_null -> RefNull
  | n when n = id_ref_is -> RefIs
  | n when n = id_ref_func -> RefFunc
  | n when n = id_ref_eq -> RefEq
  | n when n = id_try -> Try
  | n when n = id_throw -> Throw
  | n when n = id_rethrow -> Rethrow
  | n when n = id_tuple_make -> TupleMake
  | n when n = id_tuple_extract -> TupleExtract
  | n when n = id_i31_new -> I31New
  | n when n = id_i31_get -> I31Get
  | n when n = id_call_ref -> CallRef
  | n when n = id_ref_test -> RefTest
  | n when n = id_ref_cast -> RefCast
  | n when n = id_br_on -> BrOn
  | n when n = id_rtt_canon -> RttCanon
  | n when n = id_rtt_sub -> RttSub
  | n when n = id_struct_new -> StructNew
  | n when n = id_struct_get -> StructGet
  | n when n = id_struct_set -> StructSet
  | n when n = id_array_new -> ArrayNew
  | n when n = id_array_get -> ArrayGet
  | n when n = id_array_set -> ArraySet
  | n when n = id_array_len -> ArrayLen
  | n when n = id_ref_as -> RefAs
  | _ -> failwith "unknown expression kind"

external print : t -> unit = "caml_binaryen_expression_print"
(** Print an expression to the console. *)

external finalize : t -> unit = "caml_binaryen_expression_finalize"

external copy : t -> Module.t -> t = "caml_binaryen_expression_copy"

(** Expression manipulation *)

module Block = struct
  external make : Module.t -> string -> t list -> Type.t -> t
    = "caml_binaryen_block"
  (** Module, block name, expression list. *)

  let make ?(return_type = Type.auto) wasm_mod name exprs =
    make wasm_mod name exprs return_type

  external get_name : t -> string option = "caml_binaryen_block_get_name"

  external set_name : t -> string -> unit = "caml_binaryen_block_set_name"

  external get_num_children : t -> int = "caml_binaryen_block_get_num_children"

  external get_child_at : t -> int -> t = "caml_binaryen_block_get_child_at"

  external set_child_at : t -> int -> t -> unit
    = "caml_binaryen_block_set_child_at"

  external append_child : t -> t -> int = "caml_binaryen_block_append_child"

  external insert_child_at : t -> int -> t -> unit
    = "caml_binaryen_block_insert_child_at"

  external remove_child_at : t -> int -> t
    = "caml_binaryen_block_remove_child_at"
end

module If = struct
  external make : Module.t -> t -> t -> t -> t = "caml_binaryen_if"
  (** Module, condition, true branch, false branch. False branch may be null. *)

  external get_condition : t -> t = "caml_binaryen_if_get_condition"

  external set_condition : t -> t -> unit = "caml_binaryen_if_set_condition"

  external get_if_true : t -> t = "caml_binaryen_if_get_if_true"

  external set_if_true : t -> t -> unit = "caml_binaryen_if_set_if_true"

  external get_if_false : t -> t option = "caml_binaryen_if_get_if_false"

  external set_if_false : t -> t -> unit = "caml_binaryen_if_set_if_false"
end

module Loop = struct
  external make : Module.t -> string -> t -> t = "caml_binaryen_loop"
  (** Module, loop name, body. *)

  external get_name : t -> string = "caml_binaryen_loop_get_name"

  external set_name : t -> string -> unit = "caml_binaryen_loop_set_name"

  external get_body : t -> t = "caml_binaryen_loop_get_body"

  external set_body : t -> t -> unit = "caml_binaryen_loop_set_body"
end

module Break = struct
  external make : Module.t -> string -> t -> t -> t = "caml_binaryen_break"
  (** Module, block name, condition, result. Value and condition may be null. *)

  external get_name : t -> string = "caml_binaryen_break_get_name"

  external set_name : t -> string -> unit = "caml_binaryen_break_set_name"

  external get_condition : t -> t option = "caml_binaryen_break_get_condition"

  external set_condition : t -> t -> unit = "caml_binaryen_break_set_condition"

  external get_value : t -> t option = "caml_binaryen_break_get_value"

  external set_value : t -> t -> unit = "caml_binaryen_break_set_value"
end

module Switch = struct
  external make : Module.t -> string list -> string -> t -> t -> t
    = "caml_binaryen_switch"
  (** Module, branch names, default branch name, condition, value. Value may be null. *)

  external get_num_names : t -> int = "caml_binaryen_switch_get_num_names"

  external get_name_at : t -> int -> string = "caml_binaryen_switch_get_name_at"

  external set_name_at : t -> int -> string -> unit
    = "caml_binaryen_switch_set_name_at"

  external append_name : t -> string -> int = "caml_binaryen_switch_append_name"

  external insert_name_at : t -> int -> string -> unit
    = "caml_binaryen_switch_insert_name_at"

  external remove_name_at : t -> int -> string
    = "caml_binaryen_switch_remove_name_at"

  external get_default_name : t -> string option
    = "caml_binaryen_switch_get_default_name"

  external set_default_name : t -> string -> unit
    = "caml_binaryen_switch_set_default_name"

  external get_condition : t -> t = "caml_binaryen_switch_get_condition"

  external set_condition : t -> t -> unit = "caml_binaryen_switch_set_condition"

  external get_value : t -> t option = "caml_binaryen_switch_get_value"

  external set_value : t -> t -> unit = "caml_binaryen_switch_set_value"
end

module Call = struct
  external make : Module.t -> string -> t list -> Type.t -> t
    = "caml_binaryen_call"
  (** Module, function name, params, return type. *)

  external make_return : Module.t -> string -> t list -> Type.t -> t
    = "caml_binaryen_return_call"
  (** Module, function name, params, return type. *)

  external get_target : t -> string = "caml_binaryen_call_get_target"

  external set_target : t -> string -> unit = "caml_binaryen_call_set_target"

  external get_num_operands : t -> int = "caml_binaryen_call_get_num_operands"

  external get_operand_at : t -> int -> t = "caml_binaryen_call_get_operand_at"

  external set_operand_at : t -> int -> t -> unit
    = "caml_binaryen_call_set_operand_at"

  external append_operand : t -> t -> int = "caml_binaryen_call_append_operand"

  external insert_operand_at : t -> int -> t -> unit
    = "caml_binaryen_call_insert_operand_at"

  external remove_operand_at : t -> int -> t
    = "caml_binaryen_call_remove_operand_at"

  external is_return : t -> bool = "caml_binaryen_call_is_return"

  external set_return : t -> bool -> unit = "caml_binaryen_call_set_return"
end

module Call_indirect = struct
  external make : Module.t -> string -> t -> t list -> Type.t -> Type.t -> t
    = "caml_binaryen_call_indirect__bytecode" "caml_binaryen_call_indirect"
  (** Module, table, function value, params, params type, return type. *)

  external make_return :
    Module.t -> string -> t -> t list -> Type.t -> Type.t -> t
    = "caml_binaryen_return_call_indirect__bytecode" "caml_binaryen_return_call_indirect"
  (** Module, table, function value, params, params type, return type. *)

  external get_target : t -> t = "caml_binaryen_call_indirect_get_target"

  external set_target : t -> t -> unit
    = "caml_binaryen_call_indirect_set_target"

  external get_table : t -> string = "caml_binaryen_call_indirect_get_table"

  external set_table : t -> string -> unit
    = "caml_binaryen_call_indirect_set_table"

  external get_num_operands : t -> int
    = "caml_binaryen_call_indirect_get_num_operands"

  external get_operand_at : t -> int -> t
    = "caml_binaryen_call_indirect_get_operand_at"

  external set_operand_at : t -> int -> t -> unit
    = "caml_binaryen_call_indirect_set_operand_at"

  external append_operand : t -> t -> int
    = "caml_binaryen_call_indirect_append_operand"

  external insert_operand_at : t -> int -> t -> unit
    = "caml_binaryen_call_indirect_insert_operand_at"

  external remove_operand_at : t -> int -> t
    = "caml_binaryen_call_indirect_remove_operand_at"

  external is_return : t -> bool = "caml_binaryen_call_indirect_is_return"

  external set_return : t -> bool -> unit
    = "caml_binaryen_call_indirect_set_return"
end

module Local_get = struct
  external make : Module.t -> int -> Type.t -> t = "caml_binaryen_local_get"
  (** Module, slot, type. *)
end

module Local_set = struct
  external make : Module.t -> int -> t -> t = "caml_binaryen_local_set"
  (** Module, slot, value. *)

  external get_value : t -> t = "caml_binaryen_local_set_get_value"

  external set_value : t -> t -> unit = "caml_binaryen_local_set_set_value"
end

module Local_tee = struct
  external make : Module.t -> int -> t -> Type.t -> t
    = "caml_binaryen_local_tee"
  (** Module, slot, value, type. *)
end

module Global_get = struct
  external make : Module.t -> string -> Type.t -> t = "caml_binaryen_global_get"
  (** Module, name, type. *)

  external get_name : t -> string = "caml_binaryen_global_get_get_name"

  external set_name : t -> string -> unit = "caml_binaryen_global_get_set_name"
end

module Global_set = struct
  external make : Module.t -> string -> t -> t = "caml_binaryen_global_set"
  (** Module, name, value. *)

  external get_name : t -> string = "caml_binaryen_global_set_get_name"

  external set_name : t -> string -> unit = "caml_binaryen_global_set_set_name"

  external get_value : t -> t = "caml_binaryen_global_set_get_value"

  external set_value : t -> t -> unit = "caml_binaryen_global_set_set_value"
end

module Load = struct
  external make : Module.t -> int -> bool -> int -> int -> Type.t -> t -> t
    = "caml_binaryen_load__bytecode" "caml_binaryen_load"

  (** Module, num_bytes, ?signed, offset, align, type, ptr. *)
  let make wasm_mod bytes ?(signed = false) offset align ty ptr =
    make wasm_mod bytes signed offset align ty ptr

  external get_ptr : t -> t = "caml_binaryen_load_get_ptr"

  external set_ptr : t -> t -> unit = "caml_binaryen_load_set_ptr"
end

module Store = struct
  external make : Module.t -> int -> int -> int -> t -> t -> Type.t -> t
    = "caml_binaryen_store__bytecode" "caml_binaryen_store"
  (** Module, num_bytes, offset, align, ptr, value, type. *)

  external get_ptr : t -> t = "caml_binaryen_store_get_ptr"

  external set_ptr : t -> t -> unit = "caml_binaryen_store_set_ptr"

  external get_value : t -> t = "caml_binaryen_store_get_value"

  external set_value : t -> t -> unit = "caml_binaryen_store_set_value"
end

module Const = struct
  external make : Module.t -> Literal.t -> t = "caml_binaryen_const"
end

module Unary = struct
  external make : Module.t -> Op.t -> t -> t = "caml_binaryen_unary"

  external get_value : t -> t = "caml_binaryen_unary_get_value"

  external set_value : t -> t -> unit = "caml_binaryen_unary_set_value"
end

module Binary = struct
  external make : Module.t -> Op.t -> t -> t -> t = "caml_binaryen_binary"

  external get_left : t -> t = "caml_binaryen_binary_get_left"

  external set_left : t -> t -> unit = "caml_binaryen_binary_set_left"

  external get_right : t -> t = "caml_binaryen_binary_get_right"

  external set_right : t -> t -> unit = "caml_binaryen_binary_set_right"
end

module Select = struct
  external make : Module.t -> t -> t -> t -> Type.t -> t
    = "caml_binaryen_select"

  (** Module, condition, true branch, false branch. *)
  let make wasm_mod cond tru fals = make wasm_mod cond tru fals Type.auto

  external get_if_true : t -> t = "caml_binaryen_select_get_if_true"

  external set_if_true : t -> t -> unit = "caml_binaryen_select_set_if_true"

  external get_if_false : t -> t = "caml_binaryen_select_get_if_false"

  external set_if_false : t -> t -> unit = "caml_binaryen_select_set_if_false"

  external get_condition : t -> t = "caml_binaryen_select_get_condition"

  external set_condition : t -> t -> unit = "caml_binaryen_select_set_condition"
end

module Drop = struct
  external make : Module.t -> t -> t = "caml_binaryen_drop"

  external get_value : t -> t = "caml_binaryen_drop_get_value"

  external set_value : t -> t -> unit = "caml_binaryen_drop_set_value"
end

module Return = struct
  external make : Module.t -> t -> t = "caml_binaryen_return"

  external get_value : t -> t = "caml_binaryen_return_get_value"

  external set_value : t -> t -> unit = "caml_binaryen_return_set_value"
end

module Memory_size = struct
  external make : Module.t -> t = "caml_binaryen_memory_size"
end

module Memory_grow = struct
  external make : Module.t -> t -> t = "caml_binaryen_memory_grow"

  external get_delta : t -> t = "caml_binaryen_memory_grow_get_delta"

  external set_delta : t -> t -> unit = "caml_binaryen_memory_grow_set_delta"
end

module Memory_copy = struct
  external make : Module.t -> t -> t -> t -> t = "caml_binaryen_memory_copy"
  (** Module, destination, source, size. *)

  external get_dest : t -> t = "caml_binaryen_memory_copy_get_dest"

  external set_dest : t -> t -> unit = "caml_binaryen_memory_copy_set_dest"

  external get_source : t -> t = "caml_binaryen_memory_copy_get_source"

  external set_source : t -> t -> unit = "caml_binaryen_memory_copy_set_source"

  external get_size : t -> t = "caml_binaryen_memory_copy_get_size"

  external set_size : t -> t -> unit = "caml_binaryen_memory_copy_set_size"
end

module Memory_fill = struct
  external make : Module.t -> t -> t -> t -> t = "caml_binaryen_memory_fill"
  (** Module, destination, value, size. *)

  external get_dest : t -> t = "caml_binaryen_memory_fill_get_dest"

  external set_dest : t -> t -> unit = "caml_binaryen_memory_fill_set_dest"

  external get_value : t -> t = "caml_binaryen_memory_fill_get_value"

  external set_value : t -> t -> unit = "caml_binaryen_memory_fill_set_value"

  external get_size : t -> t = "caml_binaryen_memory_fill_get_size"

  external set_size : t -> t -> unit = "caml_binaryen_memory_fill_set_size"
end

module Tuple_make = struct
  external make : Module.t -> t list -> t = "caml_binaryen_tuple_make"
  (** Module, items *)

  external get_num_operands : t -> int
    = "caml_binaryen_tuple_make_get_num_operands"

  external get_operand_at : t -> int -> t
    = "caml_binaryen_tuple_make_get_operand_at"

  external set_operand_at : t -> int -> t -> unit
    = "caml_binaryen_tuple_make_set_operand_at"

  external append_operand : t -> t -> int
    = "caml_binaryen_tuple_make_append_operand"

  external insert_operand_at : t -> int -> t -> unit
    = "caml_binaryen_tuple_make_insert_operand_at"

  external remove_operand_at : t -> int -> t
    = "caml_binaryen_tuple_make_remove_operand_at"
end

module Tuple_extract = struct
  external make : Module.t -> t -> int -> t = "caml_binaryen_tuple_extract"
  (** Module, tuple, index *)

  external get_tuple : t -> t = "caml_binaryen_tuple_extract_get_tuple"

  external set_tuple : t -> t -> unit = "caml_binaryen_tuple_extract_set_tuple"
end

module Nop = struct
  external make : Module.t -> t = "caml_binaryen_nop"
end

module Unreachable = struct
  external make : Module.t -> t = "caml_binaryen_unreachable"
end

module Pop = struct
  external make : Module.t -> Type.t -> t = "caml_binaryen_pop"
  (** Module, type *)
end

module Null = struct
  external make : unit -> t = "caml_binaryen_null_expression"
  (** A null reference. *)
end
OCaml

Innovation. Community. Security.