Permalink
Browse files

Converted simple to safe API

  • Loading branch information...
1 parent 4b32594 commit aec892ab2d8556f7e7b36540bad26057d72a52d6 @endobson committed Sep 17, 2011
View
@@ -7,7 +7,42 @@
(require ffi/unsafe)
-(provide (all-defined-out))
+(provide
+ (except-out (all-defined-out)
+ safe:binop
+ safe:uniop
+ safe:icmp))
+
+;TODO differentiate types and ensure that types match,
+;and contexts match
+(define safe:binop
+ (_fun (builder : safe:LLVMBuilderRef)
+ safe:LLVMValueRef
+ safe:LLVMValueRef
+ _non-null-string ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr (safe:llvm-builder-ref-module builder))))
+
+(define safe:uniop
+ (_fun (builder : safe:LLVMBuilderRef)
+ safe:LLVMValueRef
+ _non-null-string ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr (safe:llvm-builder-ref-module builder))))
+
+(define safe:icmp
+ (_fun (builder : safe:LLVMBuilderRef)
+ LLVMIntPredicate
+ safe:LLVMValueRef
+ safe:LLVMValueRef
+ _non-null-string ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr (safe:llvm-builder-ref-module builder))))
+
+
+
+
+
;/* Arithmetic */
(define-llvm-multiple-unsafe
@@ -38,6 +73,36 @@
LLVMBuildXor)
(_fun LLVMBuilderRef LLVMValueRef LLVMValueRef _string -> LLVMValueRef))
+
+(define-llvm-multiple-safe
+ (LLVMBuildAdd
+ LLVMBuildNSWAdd
+ LLVMBuildNUWAdd
+ LLVMBuildFAdd
+ LLVMBuildSub
+ LLVMBuildNSWSub
+ LLVMBuildNUWSub
+ LLVMBuildFSub
+ LLVMBuildMul
+ LLVMBuildNSWMul
+ LLVMBuildNUWMul
+ LLVMBuildFMul
+ LLVMBuildUDiv
+ LLVMBuildSDiv
+ LLVMBuildExactSDiv
+ LLVMBuildFDiv
+ LLVMBuildURem
+ LLVMBuildSRem
+ LLVMBuildFRem
+ LLVMBuildShl
+ LLVMBuildLShr
+ LLVMBuildAShr
+ LLVMBuildAnd
+ LLVMBuildOr
+ LLVMBuildXor)
+ safe:binop)
+
+
(define-llvm-unsafe LLVMBuildBinOp
(_fun LLVMBuilderRef LLVMOpcode LLVMValueRef LLVMValueRef _string -> LLVMValueRef))
@@ -50,6 +115,16 @@
(_fun LLVMBuilderRef LLVMValueRef _string -> LLVMValueRef))
+(define-llvm-multiple-safe
+ (LLVMBuildNeg
+ LLVMBuildNSWNeg
+ LLVMBuildNUWNeg
+ LLVMBuildFNeg
+ LLVMBuildNot)
+ safe:uniop)
+
+
+
;/* Comparisons */
(define-llvm-unsafe LLVMBuildICmp
(_fun LLVMBuilderRef
@@ -58,6 +133,9 @@
LLVMValueRef
_string -> LLVMValueRef))
+
+(define-llvm-safe LLVMBuildICmp safe:icmp)
+
(define-llvm-unsafe LLVMBuildFCmp
(_fun LLVMBuilderRef
LLVMRealPredicate
@@ -22,6 +22,12 @@
;(define-llvm LLVMGetBasicBlockTerminator (_fun LLVMBasicBlockRef -> LLVMValueRef))
;Not yet in my dev repo of llvm
+
+(define-llvm-safe LLVMGetBasicBlockParent
+ (_fun (bb : safe:LLVMBasicBlockRef) ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr (safe:llvm-basic-block-ref-module bb))))
+
(define-llvm-unsafe LLVMCountBasicBlocks (_fun LLVMValueRef -> _uint))
(define-llvm-unsafe LLVMGetBasicBlocks
(_fun (fun) ::
@@ -44,6 +50,15 @@
(define-llvm-unsafe LLVMAppendBasicBlockInContext (_fun LLVMContextRef LLVMValueRef _string -> LLVMBasicBlockRef))
(define-llvm-unsafe LLVMInsertBasicBlockInContext (_fun LLVMContextRef LLVMBasicBlockRef _string -> LLVMBasicBlockRef))
+;TODO check that function value's context and ctx are the same
+;and that it is a function value
+(define-llvm-safe LLVMAppendBasicBlockInContext
+ (_fun (ctx fun name) ::
+ (ctx : safe:LLVMContextRef)
+ (fun : safe:LLVMValueRef)
+ (name : _non-null-string) ->
+ (bb : _pointer) ->
+ (safe:llvm-basic-block-ref bb ctx)))
(define-llvm-unsafe LLVMAppendBasicBlock
(_fun LLVMValueRef _string -> LLVMBasicBlockRef))
View
@@ -6,7 +6,20 @@
(require ffi/unsafe)
-(provide (all-defined-out))
+(provide (except-out (all-defined-out)
+ safe:position-builder-at-end))
+
+
+
+(define safe:position-builder-at-end
+ (_fun (builder bb) ::
+ (builder : safe:LLVMBuilderRef)
+ (bb : safe:LLVMBasicBlockRef) ->
+ _void ->
+ (begin
+ (set-safe:llvm-builder-ref-module! builder
+ (safe:llvm-basic-block-ref-module bb))
+ (void))))
;/*===-- Instruction builders ----------------------------------------------===*/
@@ -17,13 +30,20 @@
(define-llvm-unsafe LLVMCreateBuilderInContext (_fun LLVMContextRef -> LLVMBuilderRef))
(define-llvm-unsafe LLVMCreateBuilder (_fun -> LLVMBuilderRef))
+(define-llvm-safe LLVMCreateBuilderInContext safe:LLVMBuilderCreator)
+
(define-llvm-unsafe LLVMPositionBuilder (_fun LLVMBuilderRef LLVMBasicBlockRef LLVMValueRef -> _void))
(define-llvm-unsafe LLVMPositionBuilderBefore
(_fun LLVMBuilderRef LLVMValueRef -> _void))
(define-llvm-unsafe LLVMPositionBuilderAtEnd (_fun LLVMBuilderRef LLVMBasicBlockRef -> _void))
+(define-llvm-safe LLVMPositionBuilderAtEnd safe:position-builder-at-end)
(define-llvm-unsafe LLVMGetInsertBlock (_fun LLVMBuilderRef -> LLVMBasicBlockRef))
+(define-llvm-safe LLVMGetInsertBlock
+ (_fun (builder : safe:LLVMBuilderRef) ->
+ (ptr : _pointer) ->
+ (safe:llvm-basic-block-ref ptr (safe:llvm-builder-ref-module builder))))
(define-llvm-unsafe LLVMClearInsertionPosition
(_fun LLVMBuilderRef -> _void))
@@ -34,6 +54,7 @@
(_fun LLVMBuilderRef LLVMValueRef _string -> _void))
(define-llvm-unsafe LLVMDisposeBuilder (_fun LLVMBuilderRef -> _void))
+(define (safe:LLVMDisposeBuilder builder) (void))
View
@@ -7,7 +7,22 @@
(require ffi/unsafe)
-(provide (all-defined-out))
+
+;TODO differentiate types and ensure that types match,
+;and contexts match
+(define safe:icast
+ (_fun (builder : safe:LLVMBuilderRef)
+ safe:LLVMValueRef
+ safe:LLVMTypeRef
+ _non-null-string ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr (safe:llvm-builder-ref-module builder))))
+
+(define safe:pcast safe:icast)
+
+
+
+(provide (except-out (all-defined-out) safe:pcast safe:icast))
(define-llvm-multiple-unsafe
(LLVMBuildTrunc
@@ -33,5 +48,31 @@
LLVMBuildFPCast)
(_fun LLVMBuilderRef LLVMValueRef LLVMTypeRef _string -> LLVMValueRef))
+
+(define-llvm-multiple-safe
+ (LLVMBuildTrunc
+ LLVMBuildZExt
+ LLVMBuildSExt
+ LLVMBuildFPToUI
+ LLVMBuildFPToSI
+ LLVMBuildUIToFP
+ LLVMBuildSIToFP
+ LLVMBuildFPTrunc
+ LLVMBuildFPExt)
+ safe:icast)
+
+(define-llvm-multiple-safe
+ (LLVMBuildPtrToInt
+ LLVMBuildIntToPtr
+ LLVMBuildBitCast
+ LLVMBuildZExtOrBitCast
+ LLVMBuildSExtOrBitCast
+ LLVMBuildTruncOrBitCast
+ LLVMBuildPointerCast
+ LLVMBuildIntCast
+ LLVMBuildFPCast)
+ safe:pcast)
+
+
(define-llvm-unsafe LLVMBuildCast
(_fun LLVMBuilderRef LLVMOpcode LLVMValueRef LLVMTypeRef _string -> LLVMValueRef))
View
@@ -19,6 +19,11 @@
-> LLVMTypeRef))
+(define-llvm-safe LLVMConstInt
+ (_fun (ty : safe:LLVMTypeRef) _long LLVMBool ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr (safe:llvm-type-ref-context ty))))
+
;/* Operations on constants of any type */
(define-llvm-multiple-unsafe
(LLVMConstNull ; /* all zeroes */
@@ -28,6 +33,17 @@
(_fun LLVMTypeRef -> LLVMValueRef))
+(define-llvm-multiple-safe
+ (LLVMConstNull ; /* all zeroes */
+ LLVMConstAllOnes ; /* only for int/vector */
+ LLVMGetUndef
+ LLVMConstPointerNull)
+ (_fun (ty : safe:LLVMTypeRef) ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr (safe:llvm-type-ref-context ty))))
+
+
+
(define-llvm-unsafe LLVMConstIntOfString
(_fun LLVMTypeRef _string _uint8 -> LLVMValueRef))
(define-llvm-unsafe LLVMConstIntOfStringAndSize
@@ -50,6 +66,17 @@
(_uint = (string-length str))
(dnt : LLVMBool)
-> LLVMValueRef))
+
+
+(define-llvm-safe LLVMConstStringInContext
+ (_fun (context str dnt) ::
+ (context : safe:LLVMContextRef)
+ (str : _string)
+ (_uint = (string-length str))
+ (dnt : LLVMBool) ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr context)))
+
(define-llvm-unsafe LLVMConstStructInContext
@@ -59,6 +86,17 @@
(_uint = (length fields))
(packed : LLVMBool)
-> LLVMValueRef))
+
+
+(define-llvm-safe LLVMConstStructInContext
+ (_fun (context fields packed) ::
+ (context : safe:LLVMContextRef)
+ (fields : (_list i safe:LLVMValueRef))
+ (_uint = (length fields))
+ (packed : LLVMBool) ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr context)))
+
(define-llvm-unsafe LLVMConstString
@@ -85,13 +123,34 @@
-> LLVMValueRef))
+(define-llvm-safe LLVMConstNamedStruct
+ (_fun (type fields) ::
+ (type : safe:LLVMTypeRef)
+ (fields : (_list i safe:LLVMValueRef))
+ (_uint = (length fields)) ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr (safe:llvm-type-ref-context type))))
+
+
+
(define-llvm-unsafe LLVMConstArray
(_fun (type elements) ::
(type : LLVMTypeRef)
(elements : (_list i LLVMValueRef))
(_uint = (length elements))
-> LLVMValueRef))
+(define-llvm-safe LLVMConstArray
+ (_fun (type elements) ::
+ (type : safe:LLVMTypeRef)
+ (elements : (_list i safe:LLVMValueRef))
+ (_uint = (length elements)) ->
+ (ptr : _pointer) ->
+ (safe:llvm-value-ref ptr (safe:llvm-type-ref-context type))))
+
+
+
+
(define-llvm-unsafe LLVMConstVector
(_fun (elements) ::
Oops, something went wrong.

0 comments on commit aec892a

Please sign in to comment.