/
llvm.rs
1601 lines (1365 loc) · 60.6 KB
/
llvm.rs
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
import std._vec;
import std._str;
import std._str.rustrt.sbuf;
import std._vec.rustrt.vbuf;
import llvm.ModuleRef;
import llvm.ContextRef;
import llvm.TypeRef;
import llvm.TypeHandleRef;
import llvm.ValueRef;
import llvm.BasicBlockRef;
import llvm.BuilderRef;
import llvm.ModuleProviderRef;
import llvm.MemoryBufferRef;
import llvm.PassManagerRef;
import llvm.UseRef;
import llvm.TargetDataRef;
import llvm.Linkage;
import llvm.Attribute;
import llvm.Visibility;
import llvm.CallConv;
import llvm.IntPredicate;
import llvm.RealPredicate;
import llvm.Opcode;
import llvm.ObjectFileRef;
import llvm.SectionIteratorRef;
type ULongLong = u64;
type LongLong = i64;
type Long = i32;
type Bool = int;
const Bool True = 1;
const Bool False = 0;
// Consts for the LLVM CallConv type, pre-cast to uint.
// FIXME: figure out a way to merge these with the native
// typedef and/or a tag type in the native module below.
const uint LLVMCCallConv = 0u;
const uint LLVMFastCallConv = 8u;
const uint LLVMColdCallConv = 9u;
const uint LLVMX86StdcallCallConv = 64u;
const uint LLVMX86FastcallCallConv = 65u;
const uint LLVMDefaultVisibility = 0u;
const uint LLVMHiddenVisibility = 1u;
const uint LLVMProtectedVisibility = 2u;
const uint LLVMExternalLinkage = 0u;
const uint LLVMAvailableExternallyLinkage = 1u;
const uint LLVMLinkOnceAnyLinkage = 2u;
const uint LLVMLinkOnceODRLinkage = 3u;
const uint LLVMWeakAnyLinkage = 4u;
const uint LLVMWeakODRLinkage = 5u;
const uint LLVMAppendingLinkage = 6u;
const uint LLVMInternalLinkage = 7u;
const uint LLVMPrivateLinkage = 8u;
const uint LLVMDLLImportLinkage = 9u;
const uint LLVMDLLExportLinkage = 10u;
const uint LLVMExternalWeakLinkage = 11u;
const uint LLVMGhostLinkage = 12u;
const uint LLVMCommonLinkage = 13u;
const uint LLVMLinkerPrivateLinkage = 14u;
const uint LLVMLinkerPrivateWeakLinkage = 15u;
const uint LLVMZExtAttribute = 1u;
const uint LLVMSExtAttribute = 2u;
const uint LLVMNoReturnAttribute = 4u;
const uint LLVMInRegAttribute = 8u;
const uint LLVMStructRetAttribute = 16u;
const uint LLVMNoUnwindAttribute = 32u;
const uint LLVMNoAliasAttribute = 64u;
const uint LLVMByValAttribute = 128u;
const uint LLVMNestAttribute = 256u;
const uint LLVMReadNoneAttribute = 512u;
const uint LLVMReadOnlyAttribute = 1024u;
const uint LLVMNoInlineAttribute = 2048u;
const uint LLVMAlwaysInlineAttribute = 4096u;
const uint LLVMOptimizeForSizeAttribute = 8192u;
const uint LLVMStackProtectAttribute = 16384u;
const uint LLVMStackProtectReqAttribute = 32768u;
const uint LLVMAlignmentAttribute = 2031616u; // 31 << 16
const uint LLVMNoCaptureAttribute = 2097152u;
const uint LLVMNoRedZoneAttribute = 4194304u;
const uint LLVMNoImplicitFloatAttribute = 8388608u;
const uint LLVMNakedAttribute = 16777216u;
const uint LLVMInlineHintAttribute = 33554432u;
const uint LLVMStackAttribute = 469762048u; // 7 << 26
// Consts for the LLVM IntPredicate type, pre-cast to uint.
// FIXME: as above.
const uint LLVMIntEQ = 32u;
const uint LLVMIntNE = 33u;
const uint LLVMIntUGT = 34u;
const uint LLVMIntUGE = 35u;
const uint LLVMIntULT = 36u;
const uint LLVMIntULE = 37u;
const uint LLVMIntSGT = 38u;
const uint LLVMIntSGE = 39u;
const uint LLVMIntSLT = 40u;
const uint LLVMIntSLE = 41u;
// Consts for the LLVM RealPredicate type, pre-case to uint.
// FIXME: as above.
const uint LLVMRealOEQ = 1u;
const uint LLVMRealOGT = 2u;
const uint LLVMRealOGE = 3u;
const uint LLVMRealOLT = 4u;
const uint LLVMRealOLE = 5u;
const uint LLVMRealONE = 6u;
const uint LLVMRealORD = 7u;
const uint LLVMRealUNO = 8u;
const uint LLVMRealUEQ = 9u;
const uint LLVMRealUGT = 10u;
const uint LLVMRealUGE = 11u;
const uint LLVMRealULT = 12u;
const uint LLVMRealULE = 13u;
const uint LLVMRealUNE = 14u;
native mod llvm = llvm_lib {
type ModuleRef;
type ContextRef;
type TypeRef;
type TypeHandleRef;
type ValueRef;
type BasicBlockRef;
type BuilderRef;
type ModuleProviderRef;
type MemoryBufferRef;
type PassManagerRef;
type UseRef;
type TargetDataRef;
/* FIXME: These are enums in the C header. Represent them how, in rust? */
type Linkage;
type Attribute;
type Visibility;
type CallConv;
type IntPredicate;
type RealPredicate;
type Opcode;
/* Create and destroy contexts. */
fn LLVMContextCreate() -> ContextRef;
fn LLVMGetGlobalContext() -> ContextRef;
fn LLVMContextDispose(ContextRef C);
fn LLVMGetMDKindIDInContext(ContextRef C, sbuf Name, uint SLen) -> uint;
fn LLVMGetMDKindID(sbuf Name, uint SLen) -> uint;
/* Create and destroy modules. */
fn LLVMModuleCreateWithNameInContext(sbuf ModuleID,
ContextRef C)-> ModuleRef;
fn LLVMDisposeModule(ModuleRef M);
/** Data layout. See Module::getDataLayout. */
fn LLVMGetDataLayout(ModuleRef M) -> sbuf;
fn LLVMSetDataLayout(ModuleRef M, sbuf Triple);
/** Target triple. See Module::getTargetTriple. */
fn LLVMGetTarget(ModuleRef M) -> sbuf;
fn LLVMSetTarget(ModuleRef M, sbuf Triple);
/** See Module::addTypeName. */
fn LLVMAddTypeName(ModuleRef M, sbuf Name, TypeRef Ty) -> Bool;
fn LLVMDeleteTypeName(ModuleRef M, sbuf Name);
fn LLVMGetTypeByName(ModuleRef M, sbuf Name) -> TypeRef;
/** See Module::dump. */
fn LLVMDumpModule(ModuleRef M);
/** See Module::setModuleInlineAsm. */
fn LLVMSetModuleInlineAsm(ModuleRef M, sbuf Asm);
/** See llvm::LLVMTypeKind::getTypeID. */
// FIXME: returning int rather than TypeKind because
// we directly inspect the values, and casting from
// a native doesn't work yet (only *to* a native).
fn LLVMGetTypeKind(TypeRef Ty) -> int;
/** See llvm::LLVMType::getContext. */
fn LLVMGetTypeContext(TypeRef Ty) -> ContextRef;
/* Operations on integer types */
fn LLVMInt1TypeInContext(ContextRef C) -> TypeRef;
fn LLVMInt8TypeInContext(ContextRef C) -> TypeRef;
fn LLVMInt16TypeInContext(ContextRef C) -> TypeRef;
fn LLVMInt32TypeInContext(ContextRef C) -> TypeRef;
fn LLVMInt64TypeInContext(ContextRef C) -> TypeRef;
fn LLVMIntTypeInContext(ContextRef C, uint NumBits) -> TypeRef;
fn LLVMInt1Type() -> TypeRef;
fn LLVMInt8Type() -> TypeRef;
fn LLVMInt16Type() -> TypeRef;
fn LLVMInt32Type() -> TypeRef;
fn LLVMInt64Type() -> TypeRef;
fn LLVMIntType(uint NumBits) -> TypeRef;
fn LLVMGetIntTypeWidth(TypeRef IntegerTy) -> uint;
/* Operations on real types */
fn LLVMFloatTypeInContext(ContextRef C) -> TypeRef;
fn LLVMDoubleTypeInContext(ContextRef C) -> TypeRef;
fn LLVMX86FP80TypeInContext(ContextRef C) -> TypeRef;
fn LLVMFP128TypeInContext(ContextRef C) -> TypeRef;
fn LLVMPPCFP128TypeInContext(ContextRef C) -> TypeRef;
fn LLVMFloatType() -> TypeRef;
fn LLVMDoubleType() -> TypeRef;
fn LLVMX86FP80Type() -> TypeRef;
fn LLVMFP128Type() -> TypeRef;
fn LLVMPPCFP128Type() -> TypeRef;
/* Operations on function types */
fn LLVMFunctionType(TypeRef ReturnType, vbuf ParamTypes,
uint ParamCount, Bool IsVarArg) -> TypeRef;
fn LLVMIsFunctionVarArg(TypeRef FunctionTy) -> Bool;
fn LLVMGetReturnType(TypeRef FunctionTy) -> TypeRef;
fn LLVMCountParamTypes(TypeRef FunctionTy) -> uint;
fn LLVMGetParamTypes(TypeRef FunctionTy, vbuf Dest);
/* Operations on struct types */
fn LLVMStructTypeInContext(ContextRef C, vbuf ElementTypes,
uint ElementCount, Bool Packed) -> TypeRef;
fn LLVMStructType(vbuf ElementTypes, uint ElementCount,
Bool Packed) -> TypeRef;
fn LLVMCountStructElementTypes(TypeRef StructTy) -> uint;
fn LLVMGetStructElementTypes(TypeRef StructTy, vbuf Dest);
fn LLVMIsPackedStruct(TypeRef StructTy) -> Bool;
/* Operations on array, pointer, and vector types (sequence types) */
fn LLVMArrayType(TypeRef ElementType, uint ElementCount) -> TypeRef;
fn LLVMPointerType(TypeRef ElementType, uint AddressSpace) -> TypeRef;
fn LLVMVectorType(TypeRef ElementType, uint ElementCount) -> TypeRef;
fn LLVMGetElementType(TypeRef Ty) -> TypeRef;
fn LLVMGetArrayLength(TypeRef ArrayTy) -> uint;
fn LLVMGetPointerAddressSpace(TypeRef PointerTy) -> uint;
fn LLVMGetVectorSize(TypeRef VectorTy) -> uint;
/* Operations on other types */
fn LLVMVoidTypeInContext(ContextRef C) -> TypeRef;
fn LLVMLabelTypeInContext(ContextRef C) -> TypeRef;
fn LLVMOpaqueTypeInContext(ContextRef C) -> TypeRef;
fn LLVMVoidType() -> TypeRef;
fn LLVMLabelType() -> TypeRef;
fn LLVMOpaqueType() -> TypeRef;
/* Operations on type handles */
fn LLVMCreateTypeHandle(TypeRef PotentiallyAbstractTy) -> TypeHandleRef;
fn LLVMRefineType(TypeRef AbstractTy, TypeRef ConcreteTy);
fn LLVMResolveTypeHandle(TypeHandleRef TypeHandle) -> TypeRef;
fn LLVMDisposeTypeHandle(TypeHandleRef TypeHandle);
/* Operations on all values */
fn LLVMTypeOf(ValueRef Val) -> TypeRef;
fn LLVMGetValueName(ValueRef Val) -> sbuf;
fn LLVMSetValueName(ValueRef Val, sbuf Name);
fn LLVMDumpValue(ValueRef Val);
fn LLVMReplaceAllUsesWith(ValueRef OldVal, ValueRef NewVal);
fn LLVMHasMetadata(ValueRef Val) -> int;
fn LLVMGetMetadata(ValueRef Val, uint KindID) -> ValueRef;
fn LLVMSetMetadata(ValueRef Val, uint KindID, ValueRef Node);
/* Operations on Uses */
fn LLVMGetFirstUse(ValueRef Val) -> UseRef;
fn LLVMGetNextUse(UseRef U) -> UseRef;
fn LLVMGetUser(UseRef U) -> ValueRef;
fn LLVMGetUsedValue(UseRef U) -> ValueRef;
/* Operations on Users */
fn LLVMGetOperand(ValueRef Val, uint Index) -> ValueRef;
/* Operations on constants of any type */
fn LLVMConstNull(TypeRef Ty) -> ValueRef; /* all zeroes */
fn LLVMConstAllOnes(TypeRef Ty) -> ValueRef; /* only for int/vector */
fn LLVMGetUndef(TypeRef Ty) -> ValueRef;
fn LLVMIsConstant(ValueRef Val) -> Bool;
fn LLVMIsNull(ValueRef Val) -> Bool;
fn LLVMIsUndef(ValueRef Val) -> Bool;
fn LLVMConstPointerNull(TypeRef Ty) -> ValueRef;
/* Operations on metadata */
fn LLVMMDStringInContext(ContextRef C, sbuf Str, uint SLen) -> ValueRef;
fn LLVMMDString(sbuf Str, uint SLen) -> ValueRef;
fn LLVMMDNodeInContext(ContextRef C, vbuf Vals, uint Count) -> ValueRef;
fn LLVMMDNode(vbuf Vals, uint Count) -> ValueRef;
/* Operations on scalar constants */
fn LLVMConstInt(TypeRef IntTy, ULongLong N, Bool SignExtend) -> ValueRef;
// FIXME: radix is actually u8, but our native layer can't handle this
// yet. lucky for us we're little-endian. Small miracles.
fn LLVMConstIntOfString(TypeRef IntTy, sbuf Text, int Radix) -> ValueRef;
fn LLVMConstIntOfStringAndSize(TypeRef IntTy, sbuf Text,
uint SLen, u8 Radix) -> ValueRef;
fn LLVMConstReal(TypeRef RealTy, f64 N) -> ValueRef;
fn LLVMConstRealOfString(TypeRef RealTy, sbuf Text) -> ValueRef;
fn LLVMConstRealOfStringAndSize(TypeRef RealTy, sbuf Text,
uint SLen) -> ValueRef;
fn LLVMConstIntGetZExtValue(ValueRef ConstantVal) -> ULongLong;
fn LLVMConstIntGetSExtValue(ValueRef ConstantVal) -> LongLong;
/* Operations on composite constants */
fn LLVMConstStringInContext(ContextRef C, sbuf Str, uint Length,
Bool DontNullTerminate) -> ValueRef;
fn LLVMConstStructInContext(ContextRef C, vbuf ConstantVals,
uint Count, Bool Packed) -> ValueRef;
fn LLVMConstString(sbuf Str, uint Length,
Bool DontNullTerminate) -> ValueRef;
fn LLVMConstArray(TypeRef ElementTy,
vbuf ConstantVals, uint Length) -> ValueRef;
fn LLVMConstStruct(vbuf ConstantVals, uint Count,
Bool Packed) -> ValueRef;
fn LLVMConstVector(vbuf ScalarConstantVals, uint Size) -> ValueRef;
/* Constant expressions */
fn LLVMAlignOf(TypeRef Ty) -> ValueRef;
fn LLVMSizeOf(TypeRef Ty) -> ValueRef;
fn LLVMConstNeg(ValueRef ConstantVal) -> ValueRef;
fn LLVMConstNSWNeg(ValueRef ConstantVal) -> ValueRef;
fn LLVMConstNUWNeg(ValueRef ConstantVal) -> ValueRef;
fn LLVMConstFNeg(ValueRef ConstantVal) -> ValueRef;
fn LLVMConstNot(ValueRef ConstantVal) -> ValueRef;
fn LLVMConstAdd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstNSWAdd(ValueRef LHSConstant,
ValueRef RHSConstant) -> ValueRef;
fn LLVMConstNUWAdd(ValueRef LHSConstant,
ValueRef RHSConstant) -> ValueRef;
fn LLVMConstFAdd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstSub(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstNSWSub(ValueRef LHSConstant,
ValueRef RHSConstant) -> ValueRef;
fn LLVMConstNUWSub(ValueRef LHSConstant,
ValueRef RHSConstant) -> ValueRef;
fn LLVMConstFSub(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstMul(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstNSWMul(ValueRef LHSConstant,
ValueRef RHSConstant) -> ValueRef;
fn LLVMConstNUWMul(ValueRef LHSConstant,
ValueRef RHSConstant) -> ValueRef;
fn LLVMConstFMul(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstUDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstSDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstExactSDiv(ValueRef LHSConstant,
ValueRef RHSConstant) -> ValueRef;
fn LLVMConstFDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstURem(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstSRem(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstFRem(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstAnd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstOr(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstXor(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstShl(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstLShr(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstAShr(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
fn LLVMConstGEP(ValueRef ConstantVal,
vbuf ConstantIndices, uint NumIndices) -> ValueRef;
fn LLVMConstInBoundsGEP(ValueRef ConstantVal,
vbuf ConstantIndices,
uint NumIndices) -> ValueRef;
fn LLVMConstTrunc(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstSExt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstZExt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstFPTrunc(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstFPExt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstUIToFP(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstSIToFP(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstFPToUI(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstFPToSI(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstPtrToInt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstIntToPtr(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstBitCast(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstZExtOrBitCast(ValueRef ConstantVal,
TypeRef ToType) -> ValueRef;
fn LLVMConstSExtOrBitCast(ValueRef ConstantVal,
TypeRef ToType) -> ValueRef;
fn LLVMConstTruncOrBitCast(ValueRef ConstantVal,
TypeRef ToType) -> ValueRef;
fn LLVMConstPointerCast(ValueRef ConstantVal,
TypeRef ToType) -> ValueRef;
fn LLVMConstIntCast(ValueRef ConstantVal, TypeRef ToType,
Bool isSigned) -> ValueRef;
fn LLVMConstFPCast(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
fn LLVMConstSelect(ValueRef ConstantCondition,
ValueRef ConstantIfTrue,
ValueRef ConstantIfFalse) -> ValueRef;
fn LLVMConstExtractElement(ValueRef VectorConstant,
ValueRef IndexConstant) -> ValueRef;
fn LLVMConstInsertElement(ValueRef VectorConstant,
ValueRef ElementValueConstant,
ValueRef IndexConstant) -> ValueRef;
fn LLVMConstShuffleVector(ValueRef VectorAConstant,
ValueRef VectorBConstant,
ValueRef MaskConstant) -> ValueRef;
fn LLVMConstExtractValue(ValueRef AggConstant, vbuf IdxList,
uint NumIdx) -> ValueRef;
fn LLVMConstInsertValue(ValueRef AggConstant,
ValueRef ElementValueConstant,
vbuf IdxList, uint NumIdx) -> ValueRef;
fn LLVMConstInlineAsm(TypeRef Ty,
sbuf AsmString, sbuf Constraints,
Bool HasSideEffects, Bool IsAlignStack) -> ValueRef;
fn LLVMBlockAddress(ValueRef F, BasicBlockRef BB) -> ValueRef;
/* Operations on global variables, functions, and aliases (globals) */
fn LLVMGetGlobalParent(ValueRef Global) -> ModuleRef;
fn LLVMIsDeclaration(ValueRef Global) -> Bool;
fn LLVMGetLinkage(ValueRef Global) -> Linkage;
fn LLVMSetLinkage(ValueRef Global, Linkage Link);
fn LLVMGetSection(ValueRef Global) -> sbuf;
fn LLVMSetSection(ValueRef Global, sbuf Section);
fn LLVMGetVisibility(ValueRef Global) -> Visibility;
fn LLVMSetVisibility(ValueRef Global, Visibility Viz);
fn LLVMGetAlignment(ValueRef Global) -> uint;
fn LLVMSetAlignment(ValueRef Global, uint Bytes);
/* Operations on global variables */
fn LLVMAddGlobal(ModuleRef M, TypeRef Ty, sbuf Name) -> ValueRef;
fn LLVMAddGlobalInAddressSpace(ModuleRef M, TypeRef Ty,
sbuf Name,
uint AddressSpace) -> ValueRef;
fn LLVMGetNamedGlobal(ModuleRef M, sbuf Name) -> ValueRef;
fn LLVMGetFirstGlobal(ModuleRef M) -> ValueRef;
fn LLVMGetLastGlobal(ModuleRef M) -> ValueRef;
fn LLVMGetNextGlobal(ValueRef GlobalVar) -> ValueRef;
fn LLVMGetPreviousGlobal(ValueRef GlobalVar) -> ValueRef;
fn LLVMDeleteGlobal(ValueRef GlobalVar);
fn LLVMGetInitializer(ValueRef GlobalVar) -> ValueRef;
fn LLVMSetInitializer(ValueRef GlobalVar, ValueRef ConstantVal);
fn LLVMIsThreadLocal(ValueRef GlobalVar) -> Bool;
fn LLVMSetThreadLocal(ValueRef GlobalVar, Bool IsThreadLocal);
fn LLVMIsGlobalConstant(ValueRef GlobalVar) -> Bool;
fn LLVMSetGlobalConstant(ValueRef GlobalVar, Bool IsConstant);
/* Operations on aliases */
fn LLVMAddAlias(ModuleRef M, TypeRef Ty, ValueRef Aliasee,
sbuf Name) -> ValueRef;
/* Operations on functions */
fn LLVMAddFunction(ModuleRef M, sbuf Name,
TypeRef FunctionTy) -> ValueRef;
fn LLVMGetNamedFunction(ModuleRef M, sbuf Name) -> ValueRef;
fn LLVMGetFirstFunction(ModuleRef M) -> ValueRef;
fn LLVMGetLastFunction(ModuleRef M) -> ValueRef;
fn LLVMGetNextFunction(ValueRef Fn) -> ValueRef;
fn LLVMGetPreviousFunction(ValueRef Fn) -> ValueRef;
fn LLVMDeleteFunction(ValueRef Fn);
fn LLVMGetIntrinsicID(ValueRef Fn) -> uint;
fn LLVMGetFunctionCallConv(ValueRef Fn) -> uint;
fn LLVMSetFunctionCallConv(ValueRef Fn, uint CC);
fn LLVMGetGC(ValueRef Fn) -> sbuf;
fn LLVMSetGC(ValueRef Fn, sbuf Name);
fn LLVMAddFunctionAttr(ValueRef Fn, Attribute PA);
fn LLVMGetFunctionAttr(ValueRef Fn) -> Attribute;
fn LLVMRemoveFunctionAttr(ValueRef Fn, Attribute PA);
/* Operations on parameters */
fn LLVMCountParams(ValueRef Fn) -> uint;
fn LLVMGetParams(ValueRef Fn, vbuf Params);
fn LLVMGetParam(ValueRef Fn, uint Index) -> ValueRef;
fn LLVMGetParamParent(ValueRef Inst) -> ValueRef;
fn LLVMGetFirstParam(ValueRef Fn) -> ValueRef;
fn LLVMGetLastParam(ValueRef Fn) -> ValueRef;
fn LLVMGetNextParam(ValueRef Arg) -> ValueRef;
fn LLVMGetPreviousParam(ValueRef Arg) -> ValueRef;
fn LLVMAddAttribute(ValueRef Arg, Attribute PA);
fn LLVMRemoveAttribute(ValueRef Arg, Attribute PA);
fn LLVMGetAttribute(ValueRef Arg) -> Attribute;
fn LLVMSetParamAlignment(ValueRef Arg, uint align);
/* Operations on basic blocks */
fn LLVMBasicBlockAsValue(BasicBlockRef BB) -> ValueRef;
fn LLVMValueIsBasicBlock(ValueRef Val) -> Bool;
fn LLVMValueAsBasicBlock(ValueRef Val) -> BasicBlockRef;
fn LLVMGetBasicBlockParent(BasicBlockRef BB) -> ValueRef;
fn LLVMCountBasicBlocks(ValueRef Fn) -> uint;
fn LLVMGetBasicBlocks(ValueRef Fn, vbuf BasicBlocks);
fn LLVMGetFirstBasicBlock(ValueRef Fn) -> BasicBlockRef;
fn LLVMGetLastBasicBlock(ValueRef Fn) -> BasicBlockRef;
fn LLVMGetNextBasicBlock(BasicBlockRef BB) -> BasicBlockRef;
fn LLVMGetPreviousBasicBlock(BasicBlockRef BB) -> BasicBlockRef;
fn LLVMGetEntryBasicBlock(ValueRef Fn) -> BasicBlockRef;
fn LLVMAppendBasicBlockInContext(ContextRef C, ValueRef Fn,
sbuf Name) -> BasicBlockRef;
fn LLVMInsertBasicBlockInContext(ContextRef C, BasicBlockRef BB,
sbuf Name) -> BasicBlockRef;
fn LLVMAppendBasicBlock(ValueRef Fn, sbuf Name) -> BasicBlockRef;
fn LLVMInsertBasicBlock(BasicBlockRef InsertBeforeBB,
sbuf Name) -> BasicBlockRef;
fn LLVMDeleteBasicBlock(BasicBlockRef BB);
/* Operations on instructions */
fn LLVMGetInstructionParent(ValueRef Inst) -> BasicBlockRef;
fn LLVMGetFirstInstruction(BasicBlockRef BB) -> ValueRef;
fn LLVMGetLastInstruction(BasicBlockRef BB) -> ValueRef;
fn LLVMGetNextInstruction(ValueRef Inst) -> ValueRef;
fn LLVMGetPreviousInstruction(ValueRef Inst) -> ValueRef;
/* Operations on call sites */
fn LLVMSetInstructionCallConv(ValueRef Instr, uint CC);
fn LLVMGetInstructionCallConv(ValueRef Instr) -> uint;
fn LLVMAddInstrAttribute(ValueRef Instr, uint index, Attribute IA);
fn LLVMRemoveInstrAttribute(ValueRef Instr, uint index, Attribute IA);
fn LLVMSetInstrParamAlignment(ValueRef Instr, uint index, uint align);
/* Operations on call instructions (only) */
fn LLVMIsTailCall(ValueRef CallInst) -> Bool;
fn LLVMSetTailCall(ValueRef CallInst, Bool IsTailCall);
/* Operations on phi nodes */
fn LLVMAddIncoming(ValueRef PhiNode, vbuf IncomingValues,
vbuf IncomingBlocks, uint Count);
fn LLVMCountIncoming(ValueRef PhiNode) -> uint;
fn LLVMGetIncomingValue(ValueRef PhiNode, uint Index) -> ValueRef;
fn LLVMGetIncomingBlock(ValueRef PhiNode, uint Index) -> BasicBlockRef;
/* Instruction builders */
fn LLVMCreateBuilderInContext(ContextRef C) -> BuilderRef;
fn LLVMCreateBuilder() -> BuilderRef;
fn LLVMPositionBuilder(BuilderRef Builder, BasicBlockRef Block,
ValueRef Instr);
fn LLVMPositionBuilderBefore(BuilderRef Builder, ValueRef Instr);
fn LLVMPositionBuilderAtEnd(BuilderRef Builder, BasicBlockRef Block);
fn LLVMGetInsertBlock(BuilderRef Builder) -> BasicBlockRef;
fn LLVMClearInsertionPosition(BuilderRef Builder);
fn LLVMInsertIntoBuilder(BuilderRef Builder, ValueRef Instr);
fn LLVMInsertIntoBuilderWithName(BuilderRef Builder, ValueRef Instr,
sbuf Name);
fn LLVMDisposeBuilder(BuilderRef Builder);
/* Metadata */
fn LLVMSetCurrentDebugLocation(BuilderRef Builder, ValueRef L);
fn LLVMGetCurrentDebugLocation(BuilderRef Builder) -> ValueRef;
fn LLVMSetInstDebugLocation(BuilderRef Builder, ValueRef Inst);
/* Terminators */
fn LLVMBuildRetVoid(BuilderRef B) -> ValueRef;
fn LLVMBuildRet(BuilderRef B, ValueRef V) -> ValueRef;
fn LLVMBuildAggregateRet(BuilderRef B, vbuf RetVals,
uint N) -> ValueRef;
fn LLVMBuildBr(BuilderRef B, BasicBlockRef Dest) -> ValueRef;
fn LLVMBuildCondBr(BuilderRef B, ValueRef If,
BasicBlockRef Then, BasicBlockRef Else) -> ValueRef;
fn LLVMBuildSwitch(BuilderRef B, ValueRef V,
BasicBlockRef Else, uint NumCases) -> ValueRef;
fn LLVMBuildIndirectBr(BuilderRef B, ValueRef Addr,
uint NumDests) -> ValueRef;
fn LLVMBuildInvoke(BuilderRef B, ValueRef Fn,
vbuf Args, uint NumArgs,
BasicBlockRef Then, BasicBlockRef Catch,
sbuf Name) -> ValueRef;
fn LLVMBuildUnwind(BuilderRef B) -> ValueRef;
fn LLVMBuildUnreachable(BuilderRef B) -> ValueRef;
/* Add a case to the switch instruction */
fn LLVMAddCase(ValueRef Switch, ValueRef OnVal,
BasicBlockRef Dest);
/* Add a destination to the indirectbr instruction */
fn LLVMAddDestination(ValueRef IndirectBr, BasicBlockRef Dest);
/* Arithmetic */
fn LLVMBuildAdd(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildNSWAdd(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildNUWAdd(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildFAdd(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildSub(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildNSWSub(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildNUWSub(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildFSub(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildMul(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildNSWMul(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildNUWMul(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildFMul(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildUDiv(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildSDiv(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildExactSDiv(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildFDiv(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildURem(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildSRem(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildFRem(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildShl(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildLShr(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildAShr(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildAnd(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildOr(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildXor(BuilderRef B, ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildBinOp(BuilderRef B, Opcode Op,
ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildNeg(BuilderRef B, ValueRef V, sbuf Name) -> ValueRef;
fn LLVMBuildNSWNeg(BuilderRef B, ValueRef V,
sbuf Name) -> ValueRef;
fn LLVMBuildNUWNeg(BuilderRef B, ValueRef V,
sbuf Name) -> ValueRef;
fn LLVMBuildFNeg(BuilderRef B, ValueRef V, sbuf Name) -> ValueRef;
fn LLVMBuildNot(BuilderRef B, ValueRef V, sbuf Name) -> ValueRef;
/* Memory */
fn LLVMBuildMalloc(BuilderRef B, TypeRef Ty, sbuf Name) -> ValueRef;
fn LLVMBuildArrayMalloc(BuilderRef B, TypeRef Ty,
ValueRef Val, sbuf Name) -> ValueRef;
fn LLVMBuildAlloca(BuilderRef B, TypeRef Ty, sbuf Name) -> ValueRef;
fn LLVMBuildArrayAlloca(BuilderRef B, TypeRef Ty,
ValueRef Val, sbuf Name) -> ValueRef;
fn LLVMBuildFree(BuilderRef B, ValueRef PointerVal) -> ValueRef;
fn LLVMBuildLoad(BuilderRef B, ValueRef PointerVal,
sbuf Name) -> ValueRef;
fn LLVMBuildStore(BuilderRef B, ValueRef Val, ValueRef Ptr) -> ValueRef;
fn LLVMBuildGEP(BuilderRef B, ValueRef Pointer,
vbuf Indices, uint NumIndices,
sbuf Name) -> ValueRef;
fn LLVMBuildInBoundsGEP(BuilderRef B, ValueRef Pointer,
vbuf Indices, uint NumIndices,
sbuf Name) -> ValueRef;
fn LLVMBuildStructGEP(BuilderRef B, ValueRef Pointer,
uint Idx, sbuf Name) -> ValueRef;
fn LLVMBuildGlobalString(BuilderRef B, sbuf Str,
sbuf Name) -> ValueRef;
fn LLVMBuildGlobalStringPtr(BuilderRef B, sbuf Str,
sbuf Name) -> ValueRef;
/* Casts */
fn LLVMBuildTrunc(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildZExt(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildSExt(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildFPToUI(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildFPToSI(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildUIToFP(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildSIToFP(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildFPTrunc(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildFPExt(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildPtrToInt(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildIntToPtr(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildBitCast(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildZExtOrBitCast(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildSExtOrBitCast(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildTruncOrBitCast(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildCast(BuilderRef B, Opcode Op, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildPointerCast(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildIntCast(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
fn LLVMBuildFPCast(BuilderRef B, ValueRef Val,
TypeRef DestTy, sbuf Name) -> ValueRef;
/* Comparisons */
fn LLVMBuildICmp(BuilderRef B, uint Op,
ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
fn LLVMBuildFCmp(BuilderRef B, uint Op,
ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
/* Miscellaneous instructions */
fn LLVMBuildPhi(BuilderRef B, TypeRef Ty, sbuf Name) -> ValueRef;
fn LLVMBuildCall(BuilderRef B, ValueRef Fn,
vbuf Args, uint NumArgs,
sbuf Name) -> ValueRef;
fn LLVMBuildSelect(BuilderRef B, ValueRef If,
ValueRef Then, ValueRef Else,
sbuf Name) -> ValueRef;
fn LLVMBuildVAArg(BuilderRef B, ValueRef List, TypeRef Ty,
sbuf Name) -> ValueRef;
fn LLVMBuildExtractElement(BuilderRef B, ValueRef VecVal,
ValueRef Index, sbuf Name) -> ValueRef;
fn LLVMBuildInsertElement(BuilderRef B, ValueRef VecVal,
ValueRef EltVal, ValueRef Index,
sbuf Name) -> ValueRef;
fn LLVMBuildShuffleVector(BuilderRef B, ValueRef V1,
ValueRef V2, ValueRef Mask,
sbuf Name) -> ValueRef;
fn LLVMBuildExtractValue(BuilderRef B, ValueRef AggVal,
uint Index, sbuf Name) -> ValueRef;
fn LLVMBuildInsertValue(BuilderRef B, ValueRef AggVal,
ValueRef EltVal, uint Index,
sbuf Name) -> ValueRef;
fn LLVMBuildIsNull(BuilderRef B, ValueRef Val,
sbuf Name) -> ValueRef;
fn LLVMBuildIsNotNull(BuilderRef B, ValueRef Val,
sbuf Name) -> ValueRef;
fn LLVMBuildPtrDiff(BuilderRef B, ValueRef LHS,
ValueRef RHS, sbuf Name) -> ValueRef;
/* Selected entries from the downcasts. */
fn LLVMIsATerminatorInst(ValueRef Inst) -> ValueRef;
/** Writes a module to the specified path. Returns 0 on success. */
fn LLVMWriteBitcodeToFile(ModuleRef M, sbuf Path) -> int;
/** Creates target data from a target layout string. */
fn LLVMCreateTargetData(sbuf StringRep) -> TargetDataRef;
/** Returns the size of a type. FIXME: rv is actually a ULongLong! */
fn LLVMStoreSizeOfType(TargetDataRef TD, TypeRef Ty) -> uint;
/** Returns the alignment of a type. */
fn LLVMPreferredAlignmentOfType(TargetDataRef TD, TypeRef Ty) -> uint;
/** Disposes target data. */
fn LLVMDisposeTargetData(TargetDataRef TD);
/** Creates a pass manager. */
fn LLVMCreatePassManager() -> PassManagerRef;
/** Disposes a pass manager. */
fn LLVMDisposePassManager(PassManagerRef PM);
/** Runs a pass manager on a module. */
fn LLVMRunPassManager(PassManagerRef PM, ModuleRef M) -> Bool;
/** Adds a verification pass. */
fn LLVMAddVerifierPass(PassManagerRef PM);
fn LLVMAddGlobalOptimizerPass(PassManagerRef PM);
fn LLVMAddIPSCCPPass(PassManagerRef PM);
fn LLVMAddDeadArgEliminationPass(PassManagerRef PM);
fn LLVMAddInstructionCombiningPass(PassManagerRef PM);
fn LLVMAddCFGSimplificationPass(PassManagerRef PM);
fn LLVMAddFunctionInliningPass(PassManagerRef PM);
fn LLVMAddFunctionAttrsPass(PassManagerRef PM);
fn LLVMAddScalarReplAggregatesPass(PassManagerRef PM);
fn LLVMAddScalarReplAggregatesPassSSA(PassManagerRef PM);
fn LLVMAddJumpThreadingPass(PassManagerRef PM);
fn LLVMAddConstantPropagationPass(PassManagerRef PM);
fn LLVMAddReassociatePass(PassManagerRef PM);
fn LLVMAddLoopRotatePass(PassManagerRef PM);
fn LLVMAddLICMPass(PassManagerRef PM);
fn LLVMAddLoopUnswitchPass(PassManagerRef PM);
fn LLVMAddLoopDeletionPass(PassManagerRef PM);
fn LLVMAddLoopUnrollPass(PassManagerRef PM);
fn LLVMAddGVNPass(PassManagerRef PM);
fn LLVMAddMemCpyOptPass(PassManagerRef PM);
fn LLVMAddSCCPPass(PassManagerRef PM);
fn LLVMAddDeadStoreEliminationPass(PassManagerRef PM);
fn LLVMAddStripDeadPrototypesPass(PassManagerRef PM);
fn LLVMAddDeadTypeEliminationPass(PassManagerRef PM);
fn LLVMAddConstantMergePass(PassManagerRef PM);
fn LLVMAddArgumentPromotionPass(PassManagerRef PM);
fn LLVMAddTailCallEliminationPass(PassManagerRef PM);
fn LLVMAddIndVarSimplifyPass(PassManagerRef PM);
fn LLVMAddAggressiveDCEPass(PassManagerRef PM);
fn LLVMAddGlobalDCEPass(PassManagerRef PM);
fn LLVMAddCorrelatedValuePropagationPass(PassManagerRef PM);
fn LLVMAddPruneEHPass(PassManagerRef PM);
fn LLVMAddSimplifyLibCallsPass(PassManagerRef PM);
fn LLVMAddLoopIdiomPass(PassManagerRef PM);
fn LLVMAddEarlyCSEPass(PassManagerRef PM);
fn LLVMAddTypeBasedAliasAnalysisPass(PassManagerRef PM);
fn LLVMAddBasicAliasAnalysisPass(PassManagerRef PM);
/** Destroys a memory buffer. */
fn LLVMDisposeMemoryBuffer(MemoryBufferRef MemBuf);
/* Stuff that's in rustllvm/ because it's not upstream yet. */
type ObjectFileRef;
type SectionIteratorRef;
/** Opens an object file. */
fn LLVMCreateObjectFile(MemoryBufferRef MemBuf) -> ObjectFileRef;
/** Closes an object file. */
fn LLVMDisposeObjectFile(ObjectFileRef ObjectFile);
/** Enumerates the sections in an object file. */
fn LLVMGetSections(ObjectFileRef ObjectFile) -> SectionIteratorRef;
/** Destroys a section iterator. */
fn LLVMDisposeSectionIterator(SectionIteratorRef SI);
/** Returns true if the section iterator is at the end of the section
list. */
fn LLVMIsSectionIteratorAtEnd(ObjectFileRef ObjectFile,
SectionIteratorRef SI) -> Bool;
/** Moves the section iterator to point to the next section. */
fn LLVMMoveToNextSection(SectionIteratorRef SI);
/** Returns the current section name. */
fn LLVMGetSectionName(SectionIteratorRef SI) -> sbuf;
/** Returns the current section size.
FIXME: The return value is actually a uint64_t! */
fn LLVMGetSectionSize(SectionIteratorRef SI) -> uint;
/** Returns the current section contents as a string buffer. */
fn LLVMGetSectionContents(SectionIteratorRef SI) -> sbuf;
/** Reads the given file and returns it as a memory buffer. Use
LLVMDisposeMemoryBuffer() to get rid of it. */
fn LLVMRustCreateMemoryBufferWithContentsOfFile(sbuf Path) ->
MemoryBufferRef;
/* FIXME: The FileType is an enum.*/
fn LLVMRustWriteOutputFile(PassManagerRef PM, ModuleRef M,
sbuf Triple, sbuf Output,
int FileType);
/** Returns a string describing the last error caused by an LLVMRust*
call. */
fn LLVMRustGetLastError() -> sbuf;
/** Returns a string describing the hosts triple */
fn LLVMRustGetHostTriple() -> sbuf;
/** Parses the bitcode in the given memory buffer. */
fn LLVMRustParseBitcode(MemoryBufferRef MemBuf) -> ModuleRef;
/** Links LLVM modules together. `Src` is destroyed by this call and
must never be referenced again. */
fn LLVMLinkModules(ModuleRef Dest, ModuleRef Src) -> Bool;
}
native mod rustllvm = llvm_lib {
}
/* Slightly more terse object-interface to LLVM's 'builder' functions. */
// FIXME: Do we want to support mutable object fields?
obj builder(BuilderRef B, @mutable bool terminated) {
/* Terminators */
fn RetVoid() -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildRetVoid(B);
}
fn Ret(ValueRef V) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildRet(B, V);
}
fn AggregateRet(vec[ValueRef] RetVals) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildAggregateRet(B,
_vec.buf[ValueRef](RetVals),
_vec.len[ValueRef](RetVals));
}
fn Br(BasicBlockRef Dest) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildBr(B, Dest);
}
fn CondBr(ValueRef If, BasicBlockRef Then,
BasicBlockRef Else) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildCondBr(B, If, Then, Else);
}
fn Switch(ValueRef V, BasicBlockRef Else, uint NumCases) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildSwitch(B, V, Else, NumCases);
}
fn IndirectBr(ValueRef Addr, uint NumDests) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildIndirectBr(B, Addr, NumDests);
}
fn Invoke(ValueRef Fn,
vec[ValueRef] Args,
BasicBlockRef Then,
BasicBlockRef Catch) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildInvoke(B, Fn,
_vec.buf[ValueRef](Args),
_vec.len[ValueRef](Args),
Then, Catch,
_str.buf(""));
}
fn Unwind() -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildUnwind(B);
}
fn Unreachable() -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm.LLVMBuildUnreachable(B);
}
/* Arithmetic */
fn Add(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildAdd(B, LHS, RHS, _str.buf(""));
}
fn NSWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildNSWAdd(B, LHS, RHS, _str.buf(""));
}
fn NUWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildNUWAdd(B, LHS, RHS, _str.buf(""));
}
fn FAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildFAdd(B, LHS, RHS, _str.buf(""));
}
fn Sub(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildSub(B, LHS, RHS, _str.buf(""));
}
fn NSWSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildNSWSub(B, LHS, RHS, _str.buf(""));
}
fn NUWSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildNUWSub(B, LHS, RHS, _str.buf(""));
}
fn FSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildFSub(B, LHS, RHS, _str.buf(""));
}
fn Mul(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildMul(B, LHS, RHS, _str.buf(""));
}
fn NSWMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildNSWMul(B, LHS, RHS, _str.buf(""));
}
fn NUWMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildNUWMul(B, LHS, RHS, _str.buf(""));
}
fn FMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
ret llvm.LLVMBuildFMul(B, LHS, RHS, _str.buf(""));
}