PageRenderTime 36ms CodeModel.GetById 21ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/extra/llvm/core/core.factor

http://github.com/abeaumont/factor
Unknown | 419 lines | 341 code | 78 blank | 0 comment | 0 complexity | b7fcbdf6e74eaa180c132d0ae582114f MD5 | raw file
  1! Copyright (C) 2009 Matthew Willis.
  2! See http://factorcode.org/license.txt for BSD license.
  3USING: alien alien.libraries alien.syntax system sequences combinators kernel alien.c-types ;
  4
  5IN: llvm.core
  6
  7<<
  8
  9: add-llvm-library ( name -- )
 10    dup
 11    {
 12        { [ os macosx? ] [ "/usr/local/lib/lib" ".dylib" surround ] }
 13        { [ os windows? ] [ ".dll" append ] }
 14        { [ os unix? ] [ "lib" ".so" surround ] }
 15    } cond cdecl add-library ;
 16
 17"LLVMSystem" add-llvm-library
 18"LLVMSupport" add-llvm-library
 19"LLVMCore" add-llvm-library
 20"LLVMBitReader" add-llvm-library
 21
 22>>
 23
 24! llvm-c/Core.h
 25
 26LIBRARY: LLVMCore
 27
 28TYPEDEF: uint unsigned
 29TYPEDEF: unsigned enum
 30
 31ENUM: LLVMAttribute
 32    { LLVMZExtAttribute         0b1 }
 33    { LLVMSExtAttribute         0b10 }
 34    { LLVMNoReturnAttribute     0b100 }
 35    { LLVMInRegAttribute        0b1000 }
 36    { LLVMStructRetAttribute    0b10000 }
 37    { LLVMNoUnwindAttribute     0b100000 }
 38    { LLVMNoAliasAttribute      0b1000000 }
 39    { LLVMByValAttribute        0b10000000 }
 40    { LLVMNestAttribute         0b100000000 }
 41    { LLVMReadNoneAttribute     0b1000000000 }
 42    { LLVMReadOnlyAttribute     0b10000000000 } ;
 43
 44ENUM: LLVMTypeKind
 45  LLVMVoidTypeKind
 46  LLVMFloatTypeKind
 47  LLVMDoubleTypeKind
 48  LLVMX86_FP80TypeKind
 49  LLVMFP128TypeKind
 50  LLVMPPC_FP128TypeKind
 51  LLVMLabelTypeKind
 52  LLVMMetadataTypeKind
 53  LLVMIntegerTypeKind
 54  LLVMFunctionTypeKind
 55  LLVMStructTypeKind
 56  LLVMArrayTypeKind
 57  LLVMPointerTypeKind
 58  LLVMOpaqueTypeKind
 59  LLVMVectorTypeKind ;
 60
 61ENUM: LLVMLinkage
 62  LLVMExternalLinkage
 63  LLVMLinkOnceLinkage
 64  LLVMWeakLinkage
 65  LLVMAppendingLinkage
 66  LLVMInternalLinkage
 67  LLVMDLLImportLinkage
 68  LLVMDLLExportLinkage
 69  LLVMExternalWeakLinkage
 70  LLVMGhostLinkage ;
 71
 72ENUM: LLVMVisibility
 73  LLVMDefaultVisibility
 74  LLVMHiddenVisibility
 75  LLVMProtectedVisibility ;
 76
 77ENUM: LLVMCallConv
 78  { LLVMCCallConv             0 }
 79  { LLVMFastCallConv          8 }
 80  { LLVMColdCallConv          9 }
 81  { LLVMX86StdcallCallConv    64 }
 82  { LLVMX86FastcallCallConv   65 } ;
 83
 84ENUM: LLVMIntPredicate
 85  { LLVMIntEQ                 32 }
 86  { LLVMIntNE                 33 }
 87  { LLVMIntUGT                34 }
 88  { LLVMIntUGE                35 }
 89  { LLVMIntULT                36 }
 90  { LLVMIntULE                37 }
 91  { LLVMIntSGT                38 }
 92  { LLVMIntSGE                39 }
 93  { LLVMIntSLT                40 }
 94  { LLVMIntSLE                41 } ;
 95
 96ENUM: LLVMRealPredicate
 97  LLVMRealPredicateFalse
 98  LLVMRealOEQ
 99  LLVMRealOGT
100  LLVMRealOGE
101  LLVMRealOLT
102  LLVMRealOLE
103  LLVMRealONE
104  LLVMRealORD
105  LLVMRealUNO
106  LLVMRealUEQ
107  LLVMRealUGT
108  LLVMRealUGE
109  LLVMRealULT
110  LLVMRealULE
111  LLVMRealUNE
112  LLVMRealPredicateTrue ;
113
114! Opaque Types
115
116TYPEDEF: void* LLVMModuleRef
117
118TYPEDEF: void* LLVMPassManagerRef
119
120TYPEDEF: void* LLVMModuleProviderRef
121
122TYPEDEF: void* LLVMTypeRef
123
124TYPEDEF: void* LLVMTypeHandleRef
125
126TYPEDEF: void* LLVMValueRef
127
128TYPEDEF: void* LLVMBasicBlockRef
129
130TYPEDEF: void* LLVMBuilderRef
131
132TYPEDEF: void* LLVMMemoryBufferRef
133
134! Functions
135
136FUNCTION: void LLVMDisposeMessage ( c-string Message ) ;
137
138FUNCTION: LLVMModuleRef LLVMModuleCreateWithName ( c-string ModuleID ) ;
139
140FUNCTION: int LLVMAddTypeName ( LLVMModuleRef M, c-string Name, LLVMTypeRef Ty ) ;
141
142FUNCTION: void LLVMDisposeModule ( LLVMModuleRef M ) ;
143
144FUNCTION: void LLVMDumpModule ( LLVMModuleRef M ) ;
145
146FUNCTION: LLVMModuleProviderRef
147LLVMCreateModuleProviderForExistingModule ( LLVMModuleRef M ) ;
148
149FUNCTION: void LLVMDisposeModuleProvider ( LLVMModuleProviderRef MP ) ;
150
151! Types
152
153! LLVM types conform to the following hierarchy:
154!  
155!    types:
156!      integer type
157!      real type
158!      function type
159!      sequence types:
160!        array type
161!        pointer type
162!        vector type
163!      void type
164!      label type
165!      opaque type
166
167! See llvm::LLVMTypeKind::getTypeID.
168FUNCTION: LLVMTypeKind LLVMGetTypeKind ( LLVMTypeRef Ty ) ;
169
170! Operations on integer types
171FUNCTION: LLVMTypeRef LLVMInt1Type ( ) ;
172FUNCTION: LLVMTypeRef LLVMInt8Type ( ) ;
173FUNCTION: LLVMTypeRef LLVMInt16Type ( ) ;
174FUNCTION: LLVMTypeRef LLVMInt32Type ( ) ;
175FUNCTION: LLVMTypeRef LLVMInt64Type ( ) ;
176FUNCTION: LLVMTypeRef LLVMIntType ( unsigned NumBits ) ;
177FUNCTION: unsigned LLVMGetIntTypeWidth ( LLVMTypeRef IntegerTy ) ;
178
179! Operations on real types
180FUNCTION: LLVMTypeRef LLVMFloatType ( ) ;
181FUNCTION: LLVMTypeRef LLVMDoubleType ( ) ;
182FUNCTION: LLVMTypeRef LLVMX86FP80Type ( ) ;
183FUNCTION: LLVMTypeRef LLVMFP128Type ( ) ;
184FUNCTION: LLVMTypeRef LLVMPPCFP128Type ( ) ;
185
186! Operations on function types
187FUNCTION: LLVMTypeRef
188LLVMFunctionType ( LLVMTypeRef ReturnType, LLVMTypeRef* ParamTypes, unsigned ParamCount, int IsVarArg ) ;
189FUNCTION: int LLVMIsFunctionVarArg ( LLVMTypeRef FunctionTy ) ;
190FUNCTION: LLVMTypeRef LLVMGetReturnType ( LLVMTypeRef FunctionTy ) ;
191FUNCTION: unsigned LLVMCountParamTypes ( LLVMTypeRef FunctionTy ) ;
192FUNCTION: void LLVMGetParamTypes ( LLVMTypeRef FunctionTy, LLVMTypeRef* Dest ) ;
193
194! Operations on struct types
195FUNCTION: LLVMTypeRef
196LLVMStructType ( LLVMTypeRef* ElementTypes, unsigned ElementCount, int Packed ) ;
197FUNCTION: unsigned LLVMCountStructElementTypes ( LLVMTypeRef StructTy ) ;
198FUNCTION: void LLVMGetStructElementTypes ( LLVMTypeRef StructTy, LLVMTypeRef* Dest ) ;
199FUNCTION: int LLVMIsPackedStruct ( LLVMTypeRef StructTy ) ;
200
201! Operations on array, pointer, and vector types (sequence types)
202FUNCTION: LLVMTypeRef LLVMArrayType ( LLVMTypeRef ElementType, unsigned ElementCount ) ;
203FUNCTION: LLVMTypeRef LLVMPointerType ( LLVMTypeRef ElementType, unsigned AddressSpace ) ;
204FUNCTION: LLVMTypeRef LLVMVectorType ( LLVMTypeRef ElementType, unsigned ElementCount ) ;
205
206FUNCTION: LLVMTypeRef LLVMGetElementType ( LLVMTypeRef Ty ) ;
207FUNCTION: unsigned LLVMGetArrayLength ( LLVMTypeRef ArrayTy ) ;
208FUNCTION: unsigned LLVMGetPointerAddressSpace ( LLVMTypeRef PointerTy ) ;
209FUNCTION: unsigned LLVMGetVectorSize ( LLVMTypeRef VectorTy ) ;
210
211! Operations on other types
212FUNCTION: LLVMTypeRef LLVMVoidType ( ) ;
213FUNCTION: LLVMTypeRef LLVMLabelType ( ) ;
214FUNCTION: LLVMTypeRef LLVMOpaqueType ( ) ;
215
216! Operations on type handles
217FUNCTION: LLVMTypeHandleRef LLVMCreateTypeHandle ( LLVMTypeRef PotentiallyAbstractTy ) ;
218FUNCTION: void LLVMRefineType ( LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy ) ;
219FUNCTION: LLVMTypeRef LLVMResolveTypeHandle ( LLVMTypeHandleRef TypeHandle ) ;
220FUNCTION: void LLVMDisposeTypeHandle ( LLVMTypeHandleRef TypeHandle ) ;
221
222! Types end
223
224FUNCTION: unsigned LLVMCountParams ( LLVMValueRef Fn ) ;
225
226FUNCTION: void LLVMGetParams ( LLVMValueRef Fn, LLVMValueRef* Params ) ;
227
228FUNCTION: LLVMValueRef
229LLVMAddFunction ( LLVMModuleRef M, c-string Name, LLVMTypeRef FunctionTy ) ;
230
231FUNCTION: LLVMValueRef LLVMGetFirstFunction ( LLVMModuleRef M ) ;
232
233FUNCTION: LLVMValueRef LLVMGetNextFunction ( LLVMValueRef Fn ) ;
234
235FUNCTION: unsigned LLVMGetFunctionCallConv ( LLVMValueRef Fn ) ;
236
237FUNCTION: void LLVMSetFunctionCallConv ( LLVMValueRef Fn, unsigned CC ) ;
238
239FUNCTION: LLVMBasicBlockRef
240LLVMAppendBasicBlock ( LLVMValueRef Fn, c-string Name ) ;
241
242FUNCTION: LLVMValueRef LLVMGetBasicBlockParent ( LLVMBasicBlockRef BB ) ;
243
244! Values
245
246FUNCTION: LLVMTypeRef LLVMTypeOf ( LLVMValueRef Val ) ;
247FUNCTION: c-string LLVMGetValueName ( LLVMValueRef Val ) ;
248FUNCTION: void LLVMSetValueName ( LLVMValueRef Val, c-string Name ) ;
249FUNCTION: void LLVMDumpValue ( LLVMValueRef Val ) ;
250
251! Instruction Builders
252
253FUNCTION: LLVMBuilderRef LLVMCreateBuilder ( ) ;
254FUNCTION: void LLVMPositionBuilder
255( LLVMBuilderRef Builder, LLVMBasicBlockRef Block, LLVMValueRef Instr ) ;
256FUNCTION: void LLVMPositionBuilderBefore
257( LLVMBuilderRef Builder, LLVMValueRef Instr ) ;
258FUNCTION: void LLVMPositionBuilderAtEnd
259( LLVMBuilderRef Builder, LLVMBasicBlockRef Block ) ;
260FUNCTION: LLVMBasicBlockRef LLVMGetInsertBlock
261( LLVMBuilderRef Builder ) ;
262FUNCTION: void LLVMClearInsertionPosition
263( LLVMBuilderRef Builder ) ;
264FUNCTION: void LLVMInsertIntoBuilder
265( LLVMBuilderRef Builder, LLVMValueRef Instr ) ;
266FUNCTION: void LLVMDisposeBuilder
267( LLVMBuilderRef Builder ) ;
268
269! IB Terminators
270
271FUNCTION: LLVMValueRef LLVMBuildRetVoid
272( LLVMBuilderRef Builder ) ;
273FUNCTION: LLVMValueRef LLVMBuildRet
274( LLVMBuilderRef Builder, LLVMValueRef V ) ;
275FUNCTION: LLVMValueRef LLVMBuildBr
276( LLVMBuilderRef Builder, LLVMBasicBlockRef Dest ) ;
277FUNCTION: LLVMValueRef LLVMBuildCondBr
278( LLVMBuilderRef Builder, LLVMValueRef If, LLVMBasicBlockRef Then, LLVMBasicBlockRef Else ) ;
279FUNCTION: LLVMValueRef LLVMBuildSwitch
280( LLVMBuilderRef Builder, LLVMValueRef V, LLVMBasicBlockRef Else, unsigned NumCases ) ;
281FUNCTION: LLVMValueRef LLVMBuildInvoke
282( LLVMBuilderRef Builder, LLVMValueRef Fn, LLVMValueRef* Args, unsigned NumArgs,
283  LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, c-string Name ) ;
284FUNCTION: LLVMValueRef LLVMBuildUnwind
285( LLVMBuilderRef Builder ) ;
286FUNCTION: LLVMValueRef LLVMBuildUnreachable
287( LLVMBuilderRef Builder ) ;
288
289! IB Add Case to Switch
290
291FUNCTION: void LLVMAddCase
292( LLVMValueRef Switch, LLVMValueRef OnVal, LLVMBasicBlockRef Dest ) ;
293
294! IB Arithmetic
295
296FUNCTION: LLVMValueRef LLVMBuildAdd
297( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
298FUNCTION: LLVMValueRef LLVMBuildSub
299( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
300FUNCTION: LLVMValueRef LLVMBuildMul
301( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
302FUNCTION: LLVMValueRef LLVMBuildUDiv
303( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
304FUNCTION: LLVMValueRef LLVMBuildSDiv
305( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
306FUNCTION: LLVMValueRef LLVMBuildFDiv
307( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
308FUNCTION: LLVMValueRef LLVMBuildURem
309( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
310FUNCTION: LLVMValueRef LLVMBuildSRem
311( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
312FUNCTION: LLVMValueRef LLVMBuildFRem
313( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
314FUNCTION: LLVMValueRef LLVMBuildShl
315( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
316FUNCTION: LLVMValueRef LLVMBuildLShr
317( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
318FUNCTION: LLVMValueRef LLVMBuildAShr
319( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
320FUNCTION: LLVMValueRef LLVMBuildAnd
321( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
322FUNCTION: LLVMValueRef LLVMBuildOr
323( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
324FUNCTION: LLVMValueRef LLVMBuildXor
325( LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
326FUNCTION: LLVMValueRef LLVMBuildNeg
327( LLVMBuilderRef Builder, LLVMValueRef V, c-string Name ) ;
328FUNCTION: LLVMValueRef LLVMBuildNot
329( LLVMBuilderRef Builder, LLVMValueRef V, c-string Name ) ;
330
331! IB Memory
332
333FUNCTION: LLVMValueRef LLVMBuildMalloc
334( LLVMBuilderRef Builder, LLVMTypeRef Ty, c-string Name ) ;
335FUNCTION: LLVMValueRef LLVMBuildArrayMalloc
336( LLVMBuilderRef Builder, LLVMTypeRef Ty, LLVMValueRef Val, c-string Name ) ;
337FUNCTION: LLVMValueRef LLVMBuildAlloca
338( LLVMBuilderRef Builder, LLVMTypeRef Ty, c-string Name ) ;
339FUNCTION: LLVMValueRef LLVMBuildArrayAlloca
340( LLVMBuilderRef Builder, LLVMTypeRef Ty, LLVMValueRef Val, c-string Name ) ;
341FUNCTION: LLVMValueRef LLVMBuildFree
342( LLVMBuilderRef Builder, LLVMValueRef PointerVal ) ;
343FUNCTION: LLVMValueRef LLVMBuildLoad
344( LLVMBuilderRef Builder, LLVMValueRef PointerVal, c-string Name ) ;
345FUNCTION: LLVMValueRef LLVMBuildStore
346( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMValueRef Ptr ) ;
347FUNCTION: LLVMValueRef LLVMBuildGEP
348( LLVMBuilderRef B, LLVMValueRef Pointer, LLVMValueRef* Indices,
349  unsigned NumIndices, c-string Name ) ;
350
351! IB Casts
352
353FUNCTION: LLVMValueRef LLVMBuildTrunc
354( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
355FUNCTION: LLVMValueRef LLVMBuildZExt
356( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
357FUNCTION: LLVMValueRef LLVMBuildSExt
358( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
359FUNCTION: LLVMValueRef LLVMBuildFPToUI
360( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
361FUNCTION: LLVMValueRef LLVMBuildFPToSI
362( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
363FUNCTION: LLVMValueRef LLVMBuildUIToFP
364( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
365FUNCTION: LLVMValueRef LLVMBuildSIToFP
366( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
367FUNCTION: LLVMValueRef LLVMBuildFPTrunc
368( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
369FUNCTION: LLVMValueRef LLVMBuildFPExt
370( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
371FUNCTION: LLVMValueRef LLVMBuildPtrToInt
372( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
373FUNCTION: LLVMValueRef LLVMBuildIntToPtr
374( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
375FUNCTION: LLVMValueRef LLVMBuildBitCast
376( LLVMBuilderRef Builder, LLVMValueRef Val, LLVMTypeRef DestTy, c-string Name ) ;
377
378! IB Comparisons
379
380FUNCTION: LLVMValueRef LLVMBuildICmp
381( LLVMBuilderRef Builder, LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
382FUNCTION: LLVMValueRef LLVMBuildFCmp
383( LLVMBuilderRef Builder, LLVMRealPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, c-string Name ) ;
384
385! IB Misc Instructions
386
387FUNCTION: LLVMValueRef LLVMBuildPhi
388( LLVMBuilderRef Builder, LLVMTypeRef Ty, c-string Name ) ;
389FUNCTION: LLVMValueRef LLVMBuildCall
390( LLVMBuilderRef Builder, LLVMValueRef Fn, LLVMValueRef* Args, unsigned NumArgs, c-string Name ) ;
391FUNCTION: LLVMValueRef LLVMBuildSelect
392( LLVMBuilderRef Builder, LLVMValueRef If, LLVMValueRef Then, LLVMValueRef Else, c-string Name ) ;
393FUNCTION: LLVMValueRef LLVMBuildVAArg
394( LLVMBuilderRef Builder, LLVMValueRef List, LLVMTypeRef Ty, c-string Name ) ;
395FUNCTION: LLVMValueRef LLVMBuildExtractElement
396( LLVMBuilderRef Builder, LLVMValueRef VecVal, LLVMValueRef Index, c-string Name ) ;
397FUNCTION: LLVMValueRef LLVMBuildInsertElement
398( LLVMBuilderRef Builder, LLVMValueRef VecVal, LLVMValueRef EltVal, LLVMValueRef Index, c-string Name ) ;
399FUNCTION: LLVMValueRef LLVMBuildShuffleVector
400( LLVMBuilderRef Builder, LLVMValueRef V1, LLVMValueRef V2, LLVMValueRef Mask, c-string Name ) ;
401FUNCTION: LLVMValueRef LLVMBuildExtractValue
402( LLVMBuilderRef Builder, LLVMValueRef AggVal, unsigned Index, c-string Name ) ;
403FUNCTION: LLVMValueRef LLVMBuildInsertValue
404( LLVMBuilderRef Builder, LLVMValueRef AggVal, LLVMValueRef EltVal, unsigned Index, c-string Name ) ;
405
406! Memory Buffers/Bit Reader
407
408FUNCTION: int LLVMCreateMemoryBufferWithContentsOfFile
409( c-string Path, LLVMMemoryBufferRef* OutMemBuf, c-string* OutMessage ) ;
410
411FUNCTION: void LLVMDisposeMemoryBuffer ( LLVMMemoryBufferRef MemBuf ) ;
412
413LIBRARY: LLVMBitReader
414
415FUNCTION: int LLVMParseBitcode
416( LLVMMemoryBufferRef MemBuf, LLVMModuleRef* OutModule, c-string* OutMessage ) ;
417 
418FUNCTION: int LLVMGetBitcodeModuleProvider
419( LLVMMemoryBufferRef MemBuf, LLVMModuleProviderRef* OutMP, c-string* OutMessage ) ;