/
binaryen_stubs_expressions.c
1710 lines (1553 loc) · 55.3 KB
/
binaryen_stubs_expressions.c
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
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define CAML_NAME_SPACE
#include <caml/mlvalues.h>
#include <caml/fail.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include "binaryen-c.h"
#include "ocaml_helpers.h"
/* Allocating an OCaml custom block to hold the given BinaryenExpressionRef */
static value alloc_BinaryenExpressionRef(BinaryenExpressionRef exp)
{
value v = caml_alloc_custom(&binaryen_ops, sizeof(BinaryenExpressionRef), 0, 1);
BinaryenExpressionRef_val(v) = exp;
return v;
}
CAMLprim value
caml_binaryen_expression_get_id(value _expr) {
CAMLparam1(_expr);
BinaryenExpressionRef expr = BinaryenExpressionRef_val(_expr);
CAMLreturn(Val_int(BinaryenExpressionGetId(expr)));
}
CAMLprim value
caml_binaryen_null_expression(value unit) {
CAMLparam1(unit);
CAMLreturn(alloc_BinaryenExpressionRef(NULL));
}
CAMLprim value
caml_binaryen_block(value _module, value _name, value _children, value _ty) {
CAMLparam4(_module, _name, _children, _ty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* name = Safe_String_val(_name);
_children = array_of_list(_children);
int childLen = array_length(_children);
BinaryenExpressionRef children[childLen];
for (int i = 0; i < childLen; i++) {
children[i] = BinaryenExpressionRef_val(Field(_children, i));
}
BinaryenType ty = BinaryenType_val(_ty);
BinaryenExpressionRef block = BinaryenBlock(module, name, children, childLen, ty);
CAMLreturn(alloc_BinaryenExpressionRef(block));
}
CAMLprim value
caml_binaryen_if(value _module, value _cond, value _tru, value _fals) {
CAMLparam4(_module, _cond, _tru, _fals);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef cond = BinaryenExpressionRef_val(_cond);
BinaryenExpressionRef tru = BinaryenExpressionRef_val(_tru);
BinaryenExpressionRef fals = BinaryenExpressionRef_val(_fals);
BinaryenExpressionRef exp = BinaryenIf(module, cond, tru, fals);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_loop(value _module, value _name, value _body) {
CAMLparam3(_module, _name, _body);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* name = Safe_String_val(_name);
BinaryenExpressionRef body = BinaryenExpressionRef_val(_body);
BinaryenExpressionRef exp = BinaryenLoop(module, name, body);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_break(value _module, value _name, value _cond, value _res) {
CAMLparam4(_module, _name, _cond, _res);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* name = Safe_String_val(_name);
BinaryenExpressionRef cond = BinaryenExpressionRef_val(_cond);
BinaryenExpressionRef res = BinaryenExpressionRef_val(_res);
BinaryenExpressionRef exp = BinaryenBreak(module, name, cond, res);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_switch(value _module, value _names, value _defaultName, value _cond, value _val) {
CAMLparam5(_module, _names, _defaultName, _cond, _val);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
_names = array_of_list(_names);
int namesLen = array_length(_names);
const char* names[namesLen];
for (int i = 0; i < namesLen; i++) {
names[i] = Safe_String_val(Field(_names, i));
}
char* defaultName = Safe_String_val(_defaultName);
BinaryenExpressionRef cond = BinaryenExpressionRef_val(_cond);
BinaryenExpressionRef val = BinaryenExpressionRef_val(_val);
BinaryenExpressionRef exp = BinaryenSwitch(module, names, namesLen, defaultName, cond, val);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_call(value _module, value _name, value _params, value _retty) {
CAMLparam4(_module, _name, _params, _retty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* name = Safe_String_val(_name);
_params = array_of_list(_params);
int paramsLen = array_length(_params);
BinaryenExpressionRef params[paramsLen];
for (int i = 0; i < paramsLen; i++) {
params[i] = BinaryenExpressionRef_val(Field(_params, i));
}
BinaryenType retty = BinaryenType_val(_retty);
BinaryenExpressionRef exp = BinaryenCall(module, name, params, paramsLen, retty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_call_indirect(value _module, value _table, value _target, value _params, value _paramsty, value _retty) {
CAMLparam5(_module, _table, _target, _params, _paramsty);
CAMLxparam1(_retty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* table = Safe_String_val(_table);
BinaryenExpressionRef target = BinaryenExpressionRef_val(_target);
_params = array_of_list(_params);
int paramsLen = array_length(_params);
BinaryenExpressionRef params[paramsLen];
for (int i = 0; i < paramsLen; i++) {
params[i] = BinaryenExpressionRef_val(Field(_params, i));
}
BinaryenType paramsty = BinaryenType_val(_paramsty);
BinaryenType retty = BinaryenType_val(_retty);
BinaryenExpressionRef exp = BinaryenCallIndirect(module, table, target, params, paramsLen, paramsty, retty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_call_indirect__bytecode(value * argv) {
return caml_binaryen_call_indirect(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
}
CAMLprim value
caml_binaryen_return_call(value _module, value _name, value _params, value _retty) {
CAMLparam4(_module, _name, _params, _retty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* name = Safe_String_val(_name);
_params = array_of_list(_params);
int paramsLen = array_length(_params);
BinaryenExpressionRef params[paramsLen];
for (int i = 0; i < paramsLen; i++) {
params[i] = BinaryenExpressionRef_val(Field(_params, i));
}
BinaryenType retty = BinaryenType_val(_retty);
BinaryenExpressionRef exp = BinaryenReturnCall(module, name, params, paramsLen, retty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_return_call_indirect(value _module, value _table, value _target, value _params, value _paramsty, value _retty) {
CAMLparam5(_module, _table, _target, _params, _paramsty);
CAMLxparam1(_retty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* table = Safe_String_val(_table);
BinaryenExpressionRef target = BinaryenExpressionRef_val(_target);
_params = array_of_list(_params);
int paramsLen = array_length(_params);
BinaryenExpressionRef params[paramsLen];
for (int i = 0; i < paramsLen; i++) {
params[i] = BinaryenExpressionRef_val(Field(_params, i));
}
BinaryenType paramsty = BinaryenType_val(_paramsty);
BinaryenType retty = BinaryenType_val(_retty);
BinaryenExpressionRef exp = BinaryenReturnCallIndirect(module, table, target, params, paramsLen, paramsty, retty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_return_call_indirect__bytecode(value * argv) {
return caml_binaryen_return_call_indirect(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
}
CAMLprim value
caml_binaryen_local_get(value _module, value _slot, value _ty) {
CAMLparam3(_module, _slot, _ty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
int slot = Int_val(_slot);
BinaryenType ty = BinaryenType_val(_ty);
BinaryenExpressionRef exp = BinaryenLocalGet(module, slot, ty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_local_set(value _module, value _slot, value _val) {
CAMLparam3(_module, _slot, _val);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
int slot = Int_val(_slot);
BinaryenExpressionRef val = BinaryenExpressionRef_val(_val);
BinaryenExpressionRef exp = BinaryenLocalSet(module, slot, val);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_local_tee(value _module, value _slot, value _val, value _ty) {
CAMLparam4(_module, _slot, _val, _ty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
int slot = Int_val(_slot);
BinaryenExpressionRef val = BinaryenExpressionRef_val(_val);
BinaryenType ty = BinaryenType_val(_ty);
BinaryenExpressionRef exp = BinaryenLocalTee(module, slot, val, ty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_global_get(value _module, value _name, value _ty) {
CAMLparam3(_module, _name, _ty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* name = Safe_String_val(_name);
BinaryenType ty = BinaryenType_val(_ty);
BinaryenExpressionRef exp = BinaryenGlobalGet(module, name, ty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_global_set(value _module, value _name, value _val) {
CAMLparam3(_module, _name, _val);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* name = Safe_String_val(_name);
BinaryenExpressionRef val = BinaryenExpressionRef_val(_val);
BinaryenExpressionRef exp = BinaryenGlobalSet(module, name, val);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_load(value _module, value _bytes, value _signed_, value _offset, value _align, value _ty, value _ptr) {
CAMLparam5(_module, _bytes, _signed_, _offset, _align);
CAMLxparam2(_ty, _ptr);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
int bytes = Int_val(_bytes);
int8_t signed_ = Bool_val(_signed_);
int offset = Int_val(_offset);
int align = Int_val(_align);
BinaryenType ty = BinaryenType_val(_ty);
BinaryenExpressionRef ptr = BinaryenExpressionRef_val(_ptr);
BinaryenExpressionRef exp = BinaryenLoad(module, bytes, signed_, offset, align, ty, ptr);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_load__bytecode(value * argv) {
return caml_binaryen_load(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
}
CAMLprim value
caml_binaryen_store(value _module, value _bytes, value _offset, value _align, value _ptr, value _val, value _ty) {
CAMLparam5(_module, _bytes, _offset, _align, _ptr);
CAMLxparam2(_val, _ty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
int bytes = Int_val(_bytes);
int offset = Int_val(_offset);
int align = Int_val(_align);
BinaryenExpressionRef ptr = BinaryenExpressionRef_val(_ptr);
BinaryenExpressionRef val = BinaryenExpressionRef_val(_val);
BinaryenType ty = BinaryenType_val(_ty);
BinaryenExpressionRef exp = BinaryenStore(module, bytes, offset, align, ptr, val, ty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_store__bytecode(value * argv) {
return caml_binaryen_store(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
}
CAMLprim value
caml_binaryen_const(value _module, value _lit) {
CAMLparam2(_module, _lit);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
struct BinaryenLiteral lit = BinaryenLiteral_val(_lit);
BinaryenExpressionRef exp = BinaryenConst(module, lit);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_unary(value _module, value _op, value _p) {
CAMLparam3(_module, _op, _p);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenOp op = BinaryenOp_val(_op);
BinaryenExpressionRef p = BinaryenExpressionRef_val(_p);
BinaryenExpressionRef exp = BinaryenUnary(module, op, p);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_binary(value _module, value _op, value _p1, value _p2) {
CAMLparam4(_module, _op, _p1, _p2);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenOp op = BinaryenOp_val(_op);
BinaryenExpressionRef p1 = BinaryenExpressionRef_val(_p1);
BinaryenExpressionRef p2 = BinaryenExpressionRef_val(_p2);
BinaryenExpressionRef exp = BinaryenBinary(module, op, p1, p2);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_select(value _module, value _cond, value _tru, value _fals, value _ty) {
CAMLparam5(_module, _cond, _tru, _fals, _ty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef cond = BinaryenExpressionRef_val(_cond);
BinaryenExpressionRef tru = BinaryenExpressionRef_val(_tru);
BinaryenExpressionRef fals = BinaryenExpressionRef_val(_fals);
BinaryenType ty = BinaryenType_val(_ty);
BinaryenExpressionRef exp = BinaryenSelect(module, cond, tru, fals, ty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_drop(value _module, value _p1) {
CAMLparam2(_module, _p1);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef p1 = BinaryenExpressionRef_val(_p1);
BinaryenExpressionRef exp = BinaryenDrop(module, p1);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_return(value _module, value _p1) {
CAMLparam2(_module, _p1);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef p1 = BinaryenExpressionRef_val(_p1);
BinaryenExpressionRef exp = BinaryenReturn(module, p1);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_memory_size(value _module) {
CAMLparam1(_module);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef exp = BinaryenMemorySize(module);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_memory_grow(value _module, value _p1) {
CAMLparam2(_module, _p1);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef p1 = BinaryenExpressionRef_val(_p1);
BinaryenExpressionRef exp = BinaryenMemoryGrow(module, p1);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_nop(value _module) {
CAMLparam1(_module);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef exp = BinaryenNop(module);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_unreachable(value _module) {
CAMLparam1(_module);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef exp = BinaryenUnreachable(module);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_memory_copy(value _module, value _dest, value _source, value _size) {
CAMLparam4(_module, _dest, _source, _size);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef dest = BinaryenExpressionRef_val(_dest);
BinaryenExpressionRef source = BinaryenExpressionRef_val(_source);
BinaryenExpressionRef size = BinaryenExpressionRef_val(_size);
BinaryenExpressionRef exp = BinaryenMemoryCopy(module, dest, source, size);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_memory_fill(value _module, value _dest, value _val, value _size) {
CAMLparam4(_module, _dest, _val, _size);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef dest = BinaryenExpressionRef_val(_dest);
BinaryenExpressionRef val = BinaryenExpressionRef_val(_val);
BinaryenExpressionRef size = BinaryenExpressionRef_val(_size);
BinaryenExpressionRef exp = BinaryenMemoryFill(module, dest, val, size);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_tuple_make(value _module, value _operands) {
CAMLparam2(_module, _operands);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
_operands = array_of_list(_operands);
int operandsLen = array_length(_operands);
BinaryenExpressionRef operands[operandsLen];
for (int i = 0; i < operandsLen; i++) {
operands[i] = BinaryenExpressionRef_val(Field(_operands, i));
}
BinaryenExpressionRef exp = BinaryenTupleMake(module, operands, operandsLen);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_tuple_extract(value _module, value _tuple, value _index) {
CAMLparam3(_module, _tuple, _index);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef tuple = BinaryenExpressionRef_val(_tuple);
int index = Int_val(_index);
BinaryenExpressionRef exp = BinaryenTupleExtract(module, tuple, index);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_pop(value _module, value _ty) {
CAMLparam2(_module, _ty);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenType ty = BinaryenType_val(_ty);
BinaryenExpressionRef exp = BinaryenPop(module, ty);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
CAMLprim value
caml_binaryen_expression_id_invalid(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenInvalidId()));
}
CAMLprim value
caml_binaryen_expression_id_nop(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenNopId()));
}
CAMLprim value
caml_binaryen_expression_id_block(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenBlockId()));
}
CAMLprim value
caml_binaryen_expression_id_if(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenIfId()));
}
CAMLprim value
caml_binaryen_expression_id_loop(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenLoopId()));
}
CAMLprim value
caml_binaryen_expression_id_break(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenBreakId()));
}
CAMLprim value
caml_binaryen_expression_id_switch(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenSwitchId()));
}
CAMLprim value
caml_binaryen_expression_id_call(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenCallId()));
}
CAMLprim value
caml_binaryen_expression_id_call_indirect(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenCallIndirectId()));
}
CAMLprim value
caml_binaryen_expression_id_local_get(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenLocalGetId()));
}
CAMLprim value
caml_binaryen_expression_id_local_set(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenLocalSetId()));
}
CAMLprim value
caml_binaryen_expression_id_global_get(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenGlobalGetId()));
}
CAMLprim value
caml_binaryen_expression_id_global_set(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenGlobalSetId()));
}
CAMLprim value
caml_binaryen_expression_id_load(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenLoadId()));
}
CAMLprim value
caml_binaryen_expression_id_store(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenStoreId()));
}
CAMLprim value
caml_binaryen_expression_id_atomic_rmw(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenAtomicRMWId()));
}
CAMLprim value
caml_binaryen_expression_id_atomic_cmpxchg(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenAtomicCmpxchgId()));
}
CAMLprim value
caml_binaryen_expression_id_atomic_wait(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenAtomicWaitId()));
}
CAMLprim value
caml_binaryen_expression_id_atomic_notify(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenAtomicNotifyId()));
}
CAMLprim value
caml_binaryen_expression_id_atomic_fence(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenAtomicFenceId()));
}
CAMLprim value
caml_binaryen_expression_id_simd_extract(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenSIMDExtractId()));
}
CAMLprim value
caml_binaryen_expression_id_simd_replace(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenSIMDReplaceId()));
}
CAMLprim value
caml_binaryen_expression_id_simd_shuffle(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenSIMDShuffleId()));
}
CAMLprim value
caml_binaryen_expression_id_simd_ternary(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenSIMDTernaryId()));
}
CAMLprim value
caml_binaryen_expression_id_simd_shift(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenSIMDShiftId()));
}
CAMLprim value
caml_binaryen_expression_id_simd_load(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenSIMDLoadId()));
}
CAMLprim value
caml_binaryen_expression_id_simd_load_store_lane(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenSIMDLoadStoreLaneId()));
}
CAMLprim value
caml_binaryen_expression_id_memory_init(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenMemoryInitId()));
}
CAMLprim value
caml_binaryen_expression_id_data_drop(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenDataDropId()));
}
CAMLprim value
caml_binaryen_expression_id_memory_copy(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenMemoryCopyId()));
}
CAMLprim value
caml_binaryen_expression_id_memory_fill(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenMemoryFillId()));
}
CAMLprim value
caml_binaryen_expression_id_const(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenConstId()));
}
CAMLprim value
caml_binaryen_expression_id_unary(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenUnaryId()));
}
CAMLprim value
caml_binaryen_expression_id_binary(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenBinaryId()));
}
CAMLprim value
caml_binaryen_expression_id_select(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenSelectId()));
}
CAMLprim value
caml_binaryen_expression_id_drop(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenDropId()));
}
CAMLprim value
caml_binaryen_expression_id_return(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenReturnId()));
}
CAMLprim value
caml_binaryen_expression_id_memory_size(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenMemorySizeId()));
}
CAMLprim value
caml_binaryen_expression_id_memory_grow(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenMemoryGrowId()));
}
CAMLprim value
caml_binaryen_expression_id_unreachable(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenUnreachableId()));
}
CAMLprim value
caml_binaryen_expression_id_pop(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenPopId()));
}
CAMLprim value
caml_binaryen_expression_id_ref_null(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRefNullId()));
}
CAMLprim value
caml_binaryen_expression_id_ref_is(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRefIsId()));
}
CAMLprim value
caml_binaryen_expression_id_ref_as(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRefAsId()));
}
CAMLprim value
caml_binaryen_expression_id_ref_func(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRefFuncId()));
}
CAMLprim value
caml_binaryen_expression_id_ref_eq(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRefEqId()));
}
CAMLprim value
caml_binaryen_expression_id_try(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenTryId()));
}
CAMLprim value
caml_binaryen_expression_id_throw(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenThrowId()));
}
CAMLprim value
caml_binaryen_expression_id_rethrow(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRethrowId()));
}
CAMLprim value
caml_binaryen_expression_id_tuple_make(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenTupleMakeId()));
}
CAMLprim value
caml_binaryen_expression_id_tuple_extract(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenTupleExtractId()));
}
CAMLprim value
caml_binaryen_expression_id_i31_new(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenI31NewId()));
}
CAMLprim value
caml_binaryen_expression_id_i31_get(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenI31GetId()));
}
CAMLprim value
caml_binaryen_expression_id_call_ref(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenCallRefId()));
}
CAMLprim value
caml_binaryen_expression_id_ref_test(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRefTestId()));
}
CAMLprim value
caml_binaryen_expression_id_ref_cast(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRefCastId()));
}
CAMLprim value
caml_binaryen_expression_id_br_on(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenBrOnId()));
}
CAMLprim value
caml_binaryen_expression_id_rtt_canon(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRttCanonId()));
}
CAMLprim value
caml_binaryen_expression_id_rtt_sub(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRttSubId()));
}
CAMLprim value
caml_binaryen_expression_id_struct_new(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenStructNewId()));
}
CAMLprim value
caml_binaryen_expression_id_struct_get(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenStructGetId()));
}
CAMLprim value
caml_binaryen_expression_id_struct_set(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenStructSetId()));
}
CAMLprim value
caml_binaryen_expression_id_array_new(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenArrayNewId()));
}
CAMLprim value
caml_binaryen_expression_id_array_get(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenArrayGetId()));
}
CAMLprim value
caml_binaryen_expression_id_array_set(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenArraySetId()));
}
CAMLprim value
caml_binaryen_expression_id_array_len(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenArrayLenId()));
}
// Expression operations
CAMLprim value
caml_binaryen_expression_print(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionPrint(exp);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_expression_finalize(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionFinalize(exp);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_expression_copy(value _exp, value _module) {
CAMLparam1(_exp);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef exp = BinaryenExpressionCopy(BinaryenExpressionRef_val(_exp), module);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}
// Block operations
CAMLprim value
caml_binaryen_block_get_name(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
const char* name = BinaryenBlockGetName(exp);
if (name == NULL) {
CAMLreturn(Val_none);
} else {
CAMLreturn(caml_alloc_some(caml_copy_string(name)));
}
}
CAMLprim value
caml_binaryen_block_set_name(value _exp, value _name) {
CAMLparam2(_exp, _name);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
char* name = Safe_String_val(_name);
BinaryenBlockSetName(exp, name);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_block_get_num_children(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
CAMLreturn(Val_int(BinaryenBlockGetNumChildren(exp)));
}
CAMLprim value
caml_binaryen_block_get_child_at(value _exp, value _index) {
CAMLparam2(_exp, _index);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenIndex index = Int_val(_index);
CAMLreturn(alloc_BinaryenExpressionRef(BinaryenBlockGetChildAt(exp, index)));
}
CAMLprim value
caml_binaryen_block_set_child_at(value _exp, value _index, value _child) {
CAMLparam3(_exp, _index, _child);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenIndex index = Int_val(_index);
BinaryenExpressionRef child = BinaryenExpressionRef_val(_child);
BinaryenBlockSetChildAt(exp, index, child);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_block_append_child(value _exp, value _child) {
CAMLparam2(_exp, _child);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef child = BinaryenExpressionRef_val(_child);
CAMLreturn(Val_int(BinaryenBlockAppendChild(exp, child)));
}
CAMLprim value
caml_binaryen_block_insert_child_at(value _exp, value _index, value _child) {
CAMLparam3(_exp, _index, _child);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenIndex index = Int_val(_index);
BinaryenExpressionRef child = BinaryenExpressionRef_val(_child);
BinaryenBlockInsertChildAt(exp, index, child);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_block_remove_child_at(value _exp, value _index) {
CAMLparam2(_exp, _index);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenIndex index = Int_val(_index);
CAMLreturn(alloc_BinaryenExpressionRef(BinaryenBlockRemoveChildAt(exp, index)));
}
// If operations
CAMLprim value
caml_binaryen_if_get_condition(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
CAMLreturn(alloc_BinaryenExpressionRef(BinaryenIfGetCondition(exp)));
}
CAMLprim value
caml_binaryen_if_set_condition(value _exp, value _cond) {
CAMLparam2(_exp, _cond);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef cond = BinaryenExpressionRef_val(_cond);
BinaryenIfSetCondition(exp, cond);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_if_get_if_true(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
CAMLreturn(alloc_BinaryenExpressionRef(BinaryenIfGetIfTrue(exp)));
}
CAMLprim value
caml_binaryen_if_set_if_true(value _exp, value _child) {
CAMLparam2(_exp, _child);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef child = BinaryenExpressionRef_val(_child);
BinaryenIfSetIfTrue(exp, child);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_if_get_if_false(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef ifFalse = BinaryenIfGetIfFalse(exp);
if (ifFalse == NULL) {
CAMLreturn(Val_none);
} else {
CAMLreturn(caml_alloc_some(alloc_BinaryenExpressionRef(ifFalse)));
}
}
CAMLprim value
caml_binaryen_if_set_if_false(value _exp, value _child) {
CAMLparam2(_exp, _child);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef child = BinaryenExpressionRef_val(_child);
BinaryenIfSetIfFalse(exp, child);
CAMLreturn(Val_unit);
}
// Loop operations
CAMLprim value
caml_binaryen_loop_get_name(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
const char* name = BinaryenLoopGetName(exp);
CAMLreturn(caml_copy_string(name));
}
CAMLprim value
caml_binaryen_loop_set_name(value _exp, value _name) {
CAMLparam2(_exp, _name);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
char* name = Safe_String_val(_name);
BinaryenLoopSetName(exp, name);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_loop_get_body(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
CAMLreturn(alloc_BinaryenExpressionRef(BinaryenLoopGetBody(exp)));
}
CAMLprim value
caml_binaryen_loop_set_body(value _exp, value _child) {
CAMLparam2(_exp, _child);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef child = BinaryenExpressionRef_val(_child);
BinaryenLoopSetBody(exp, child);
CAMLreturn(Val_unit);
}
// Break operations
CAMLprim value
caml_binaryen_break_get_name(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
const char* name = BinaryenBreakGetName(exp);
CAMLreturn(caml_copy_string(name));
}
CAMLprim value
caml_binaryen_break_set_name(value _exp, value _name) {
CAMLparam2(_exp, _name);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
char* name = Safe_String_val(_name);
BinaryenBreakSetName(exp, name);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_break_get_condition(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef cond = BinaryenBreakGetCondition(exp);
if (cond == NULL) {
CAMLreturn(Val_none);
} else {
CAMLreturn(caml_alloc_some(alloc_BinaryenExpressionRef(cond)));
}
}
CAMLprim value
caml_binaryen_break_set_condition(value _exp, value _child) {
CAMLparam2(_exp, _child);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef child = BinaryenExpressionRef_val(_child);
BinaryenBreakSetCondition(exp, child);
CAMLreturn(Val_unit);
}
CAMLprim value
caml_binaryen_break_get_value(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef val = BinaryenBreakGetValue(exp);
if (val == NULL) {
CAMLreturn(Val_none);
} else {
CAMLreturn(caml_alloc_some(alloc_BinaryenExpressionRef(val)));
}
}
CAMLprim value
caml_binaryen_break_set_value(value _exp, value _child) {
CAMLparam2(_exp, _child);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);
BinaryenExpressionRef child = BinaryenExpressionRef_val(_child);
BinaryenBreakSetValue(exp, child);
CAMLreturn(Val_unit);
}
// Switch operations
CAMLprim value
caml_binaryen_switch_get_num_names(value _exp) {
CAMLparam1(_exp);
BinaryenExpressionRef exp = BinaryenExpressionRef_val(_exp);