aboutsummaryrefslogtreecommitdiff
path: root/src/comp/lib/llvm.rs
blob: da748bf377c0d7dcdab01fc24ba5fb862cc80333 (plain) (blame)
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
import std._str.rustrt.sbuf;
import std._vec.rustrt.vbuf;

type ULongLong = u64;
type LongLong = i64;
type Long = i32;
type Bool = int;

native mod llvm = "libLLVM-2.7.so" {

  type ModuleRef;
  type ContextRef;
  type TypeRef;
  type TypeHandleRef;
  type ValueRef;
  type BasicBlockRef;
  type BuilderRef;
  type ModuleProviderRef;
  type MemoryBufferRef;
  type PassManagerRef;
  type UseRef;


  /* Create and destroy contexts. */
  fn ContextCreate() -> ContextRef;
  fn GetGlobalContext() -> ContextRef;
  fn ContextDispose(ContextRef C);
  fn GetMDKindIDInContext(ContextRef C, sbuf Name, uint SLen) -> uint;
  fn GetMDKindID(sbuf Name, uint SLen) -> uint;

  /* Create and destroy modules. */
  fn ModuleCreateWithName(sbuf ModuleID) -> ModuleRef;
  fn DisposeModule(ModuleRef M);

  /** Data layout. See Module::getDataLayout. */
  fn GetDataLayout(ModuleRef M) -> sbuf;
  fn SetDataLayout(ModuleRef M, sbuf Triple);

  /** Target triple. See Module::getTargetTriple. */
  fn GetTarget(ModuleRef M) -> sbuf;
  fn SetTarget(ModuleRef M, sbuf Triple);

  /** See Module::addTypeName. */
  fn AddTypeName(ModuleRef M, sbuf Name, TypeRef Ty) -> Bool;
  fn DeleteTypeName(ModuleRef M, sbuf Name);
  fn GetTypeByName(ModuleRef M, sbuf Name) -> TypeRef;

  /** See Module::dump. */
  fn DumpModule(ModuleRef M);

  /** See Module::setModuleInlineAsm. */
  fn SetModuleInlineAsm(ModuleRef M, sbuf Asm);

  /** See llvm::LLVMType::getContext. */
  fn GetTypeContext(TypeRef Ty) -> ContextRef;

  /* Operations on integer types */
  fn Int1TypeInContext(ContextRef C) -> TypeRef;
  fn Int8TypeInContext(ContextRef C) -> TypeRef;
  fn Int16TypeInContext(ContextRef C) -> TypeRef;
  fn Int32TypeInContext(ContextRef C) -> TypeRef;
  fn Int64TypeInContext(ContextRef C) -> TypeRef;
  fn IntTypeInContext(ContextRef C, uint NumBits) -> TypeRef;

  fn Int1Type() -> TypeRef;
  fn Int8Type() -> TypeRef;
  fn Int16Type() -> TypeRef;
  fn Int32Type() -> TypeRef;
  fn Int64Type() -> TypeRef;
  fn IntType(uint NumBits) -> TypeRef;
  fn GetIntTypeWidth(TypeRef IntegerTy) -> uint;

  /* Operations on real types */
  fn FloatTypeInContext(ContextRef C) -> TypeRef;
  fn DoubleTypeInContext(ContextRef C) -> TypeRef;
  fn X86FP80TypeInContext(ContextRef C) -> TypeRef;
  fn FP128TypeInContext(ContextRef C) -> TypeRef;
  fn PPCFP128TypeInContext(ContextRef C) -> TypeRef;

  fn FloatType() -> TypeRef;
  fn DoubleType() -> TypeRef;
  fn X86FP80Type() -> TypeRef;
  fn FP128Type() -> TypeRef;
  fn PPCFP128Type() -> TypeRef;

  /* Operations on function types */
  fn FunctionType(TypeRef ReturnType, vbuf ParamTypes,
                  uint ParamCount, Bool IsVarArg) -> TypeRef;
  fn IsFunctionVarArg(TypeRef FunctionTy) -> Bool;
  fn GetReturnType(TypeRef FunctionTy) -> TypeRef;
  fn CountParamTypes(TypeRef FunctionTy) -> uint;
  fn GetParamTypes(TypeRef FunctionTy, vbuf Dest);

  /* Operations on struct types */
  fn StructTypeInContext(ContextRef C, vbuf ElementTypes,
                         uint ElementCount, Bool Packed) -> TypeRef;
  fn StructType(vbuf ElementTypes, uint ElementCount,
                Bool Packed) -> TypeRef;
  fn CountStructElementTypes(TypeRef StructTy) -> uint;
  fn GetStructElementTypes(TypeRef StructTy, vbuf Dest);
  fn IsPackedStruct(TypeRef StructTy) -> Bool;

  /* Operations on union types */
  fn UnionTypeInContext(ContextRef C, vbuf ElementTypes,
                        uint ElementCount) -> TypeRef;
  fn UnionType(vbuf ElementTypes, uint ElementCount) -> TypeRef;
  fn CountUnionElementTypes(TypeRef UnionTy) -> uint;
  fn GetUnionElementTypes(TypeRef UnionTy, vbuf Dest);

  /* Operations on array, pointer, and vector types (sequence types) */
  fn ArrayType(TypeRef ElementType, uint ElementCount) -> TypeRef;
  fn PointerType(TypeRef ElementType, uint AddressSpace) -> TypeRef;
  fn VectorType(TypeRef ElementType, uint ElementCount) -> TypeRef;

  fn GetElementType(TypeRef Ty) -> TypeRef;
  fn GetArrayLength(TypeRef ArrayTy) -> uint;
  fn GetPointerAddressSpace(TypeRef PointerTy) -> uint;
  fn GetVectorSize(TypeRef VectorTy) -> uint;

  /* Operations on other types */
  fn VoidTypeInContext(ContextRef C) -> TypeRef;
  fn LabelTypeInContext(ContextRef C) -> TypeRef;
  fn OpaqueTypeInContext(ContextRef C) -> TypeRef;

  fn VoidType() -> TypeRef;
  fn LabelType() -> TypeRef;
  fn OpaqueType() -> TypeRef;

  /* Operations on type handles */
  fn CreateTypeHandle(TypeRef PotentiallyAbstractTy) -> TypeHandleRef;
  fn RefineType(TypeRef AbstractTy, TypeRef ConcreteTy);
  fn ResolveTypeHandle(TypeHandleRef TypeHandle) -> TypeRef;
  fn DisposeTypeHandle(TypeHandleRef TypeHandle);

  /* Operations on all values */
  fn TypeOf(ValueRef Val) -> TypeRef;
  fn GetValueName(ValueRef Val) -> sbuf;
  fn SetValueName(ValueRef Val, sbuf Name);
  fn DumpValue(ValueRef Val);
  fn ReplaceAllUsesWith(ValueRef OldVal, ValueRef NewVal);
  fn HasMetadata(ValueRef Val) -> int;
  fn GetMetadata(ValueRef Val, uint KindID) -> ValueRef;
  fn SetMetadata(ValueRef Val, uint KindID, ValueRef Node);

  /* Operations on Uses */
  fn GetFirstUse(ValueRef Val) -> UseRef;
  fn GetNextUse(UseRef U) -> UseRef;
  fn GetUser(UseRef U) -> ValueRef;
  fn GetUsedValue(UseRef U) -> ValueRef;

  /* Operations on Users */
  fn GetOperand(ValueRef Val, uint Index) -> ValueRef;

  /* Operations on constants of any type */
  fn ConstNull(TypeRef Ty) -> ValueRef; /* all zeroes */
  fn ConstAllOnes(TypeRef Ty) -> ValueRef; /* only for int/vector */
  fn GetUndef(TypeRef Ty) -> ValueRef;
  fn IsConstant(ValueRef Val) -> Bool;
  fn IsNull(ValueRef Val) -> Bool;
  fn IsUndef(ValueRef Val) -> Bool;
  fn ConstPointerNull(TypeRef Ty) -> ValueRef;

  /* Operations on metadata */
  fn MDStringInContext(ContextRef C, sbuf Str, uint SLen) -> ValueRef;
  fn MDString(sbuf Str, uint SLen) -> ValueRef;
  fn MDNodeInContext(ContextRef C, vbuf Vals, uint Count) -> ValueRef;
  fn MDNode(vbuf Vals, uint Count) -> ValueRef;

  /* Operations on scalar constants */
  fn ConstInt(TypeRef IntTy, ULongLong N, Bool SignExtend) -> ValueRef;
  fn ConstIntOfString(TypeRef IntTy, sbuf Text, u8 Radix) -> ValueRef;
  fn ConstIntOfStringAndSize(TypeRef IntTy, sbuf Text,
                             uint SLen, u8 Radix) -> ValueRef;
  fn ConstReal(TypeRef RealTy, f64 N) -> ValueRef;
  fn ConstRealOfString(TypeRef RealTy, sbuf Text) -> ValueRef;
  fn ConstRealOfStringAndSize(TypeRef RealTy, sbuf Text,
                              uint SLen) -> ValueRef;
  fn ConstIntGetZExtValue(ValueRef ConstantVal) -> ULongLong;
  fn ConstIntGetSExtValue(ValueRef ConstantVal) -> LongLong;


  /* Operations on composite constants */
  fn ConstStringInContext(ContextRef C, sbuf Str,
                          uint Length, Bool DontNullTerminate) -> ValueRef;
  fn ConstStructInContext(ContextRef C, vbuf ConstantVals,
                          uint Count, Bool Packed) -> ValueRef;

  fn ConstString(sbuf Str, uint Length, Bool DontNullTerminate) -> ValueRef;
  fn ConstArray(TypeRef ElementTy,
                vbuf ConstantVals, uint Length) -> ValueRef;
  fn ConstStruct(vbuf ConstantVals, uint Count, Bool Packed) -> ValueRef;
  fn ConstVector(vbuf ScalarConstantVals, uint Size) -> ValueRef;
  fn ConstUnion(TypeRef Ty, ValueRef Val) -> ValueRef;

  /* Constant expressions */
  fn AlignOf(TypeRef Ty) -> ValueRef;
  fn SizeOf(TypeRef Ty) -> ValueRef;
  fn ConstNeg(ValueRef ConstantVal) -> ValueRef;
  fn ConstNSWNeg(ValueRef ConstantVal) -> ValueRef;
  fn ConstNUWNeg(ValueRef ConstantVal) -> ValueRef;
  fn ConstFNeg(ValueRef ConstantVal) -> ValueRef;
  fn ConstNot(ValueRef ConstantVal) -> ValueRef;
  fn ConstAdd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstNSWAdd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstNUWAdd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstFAdd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstSub(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstNSWSub(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstNUWSub(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstFSub(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstMul(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstNSWMul(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstNUWMul(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstFMul(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstUDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstSDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstExactSDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstFDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstURem(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstSRem(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstFRem(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstAnd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstOr(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstXor(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstShl(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstLShr(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstAShr(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
  fn ConstGEP(ValueRef ConstantVal,
              vbuf ConstantIndices, uint NumIndices) -> ValueRef;
  fn ConstInBoundsGEP(ValueRef ConstantVal,
                      vbuf ConstantIndices,
                      uint NumIndices) -> ValueRef;
  fn ConstTrunc(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstSExt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstZExt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstFPTrunc(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstFPExt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstUIToFP(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstSIToFP(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstFPToUI(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstFPToSI(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstPtrToInt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstIntToPtr(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstBitCast(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstZExtOrBitCast(ValueRef ConstantVal,
                        TypeRef ToType) -> ValueRef;
  fn ConstSExtOrBitCast(ValueRef ConstantVal,
                        TypeRef ToType) -> ValueRef;
  fn ConstTruncOrBitCast(ValueRef ConstantVal,
                         TypeRef ToType) -> ValueRef;
  fn ConstPointerCast(ValueRef ConstantVal,
                      TypeRef ToType) -> ValueRef;
  fn ConstIntCast(ValueRef ConstantVal, TypeRef ToType,
                  Bool isSigned) -> ValueRef;
  fn ConstFPCast(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
  fn ConstSelect(ValueRef ConstantCondition,
                 ValueRef ConstantIfTrue,
                 ValueRef ConstantIfFalse) -> ValueRef;
  fn ConstExtractElement(ValueRef VectorConstant,
                         ValueRef IndexConstant) -> ValueRef;
  fn ConstInsertElement(ValueRef VectorConstant,
                        ValueRef ElementValueConstant,
                        ValueRef IndexConstant) -> ValueRef;
  fn ConstShuffleVector(ValueRef VectorAConstant,
                        ValueRef VectorBConstant,
                        ValueRef MaskConstant) -> ValueRef;
  fn ConstExtractValue(ValueRef AggConstant, vbuf IdxList,
                       uint NumIdx) -> ValueRef;
  fn ConstInsertValue(ValueRef AggConstant,
                      ValueRef ElementValueConstant,
                      vbuf IdxList, uint NumIdx) -> ValueRef;
  fn ConstInlineAsm(TypeRef Ty,
                    sbuf AsmString, sbuf Constraints,
                    Bool HasSideEffects, Bool IsAlignStack) -> ValueRef;
  fn BlockAddress(ValueRef F, BasicBlockRef BB) -> ValueRef;

}