LLVMConstant.st
changeset 16 23e82cf19788
child 50 dbda820d4d24
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LLVMConstant.st	Mon Aug 03 18:08:14 2015 +0100
@@ -0,0 +1,162 @@
+"
+    Copyright (C) 2015-now Jan Vrany
+
+    This code is not an open-source (yet). You may use this code
+    for your own experiments and projects, given that:
+
+    * all modification to the code will be sent to the
+      original author for inclusion in future releases
+    * this is not used in any commercial software
+
+    This license is provisional and may (will) change in
+    a future.
+"
+"{ Package: 'jv:llvm_s' }"
+
+"{ NameSpace: Smalltalk }"
+
+Object subclass:#LLVMConstant
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'LLVM-S-Core'
+!
+
+!LLVMConstant class methodsFor:'documentation'!
+
+copyright
+"
+    Copyright (C) 2015-now Jan Vrany
+
+    This code is not an open-source (yet). You may use this code
+    for your own experiments and projects, given that:
+
+    * all modification to the code will be sent to the
+      original author for inclusion in future releases
+    * this is not used in any commercial software
+
+    This license is provisional and may (will) change in
+    a future.
+"
+!
+
+documentation
+"
+    A simple factory for creating constant values.
+
+    LLVMConstant sint16: 10.
+    LLVMConstant string: 'Hello World!!'.
+
+    [author:]
+        Jan Vrany <jan.vrany@fit.cvut.cz>
+
+    [instance variables:]
+
+    [class variables:]
+
+    [see also:]
+
+"
+! !
+
+!LLVMConstant class methodsFor:'constants - int - signed'!
+
+sint16:value 
+    ^ self sint:value type:LLVMType int16
+
+    "Created: / 11-07-2015 / 16:43:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sint1:value 
+    ^ self sint:value type:LLVMType int1
+
+    "Created: / 11-07-2015 / 16:44:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sint32:value 
+    ^ self sint:value type:LLVMType int32
+
+    "Created: / 03-08-2015 / 15:59:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sint64:value 
+    ^ self sint:value type:LLVMType int64
+
+    "Created: / 03-08-2015 / 15:59:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sint:value type:type 
+    self assert:type isIntegerType.
+    self assert:value isInteger.
+    ^ LLVM ConstInt:type _:value _:1
+
+    "Created: / 11-07-2015 / 16:41:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 03-08-2015 / 17:08:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sintptr:value 
+    ^ self sint:value type:LLVMType intptr
+
+    "Created: / 03-08-2015 / 15:59:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!LLVMConstant class methodsFor:'constants - int - unsigned'!
+
+uint16:value 
+    ^ self uint:value type:LLVMType int16
+
+    "Created: / 03-08-2015 / 16:00:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+uint1:value 
+    ^ self uint:value type:LLVMType int1
+
+    "Created: / 03-08-2015 / 16:01:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+uint32:value 
+    ^ self uint:value type:LLVMType int32
+
+    "Created: / 03-08-2015 / 16:01:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+uint64:value 
+    ^ self uint:value type:LLVMType int64
+
+    "Created: / 03-08-2015 / 16:01:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+uint:value type:type 
+    self assert:type isIntegerType.
+    self assert:value isInteger.
+    ^ LLVM 
+        ConstInt:type
+        _:value
+        _:0
+
+    "Created: / 11-07-2015 / 16:41:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+uintptr:value 
+    ^ self uint:value type:LLVMType intptr
+
+    "Created: / 03-08-2015 / 16:01:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!LLVMConstant class methodsFor:'constants - strings'!
+
+string:aString 
+    ^ self string:aString nullTerminate:true
+
+    "Created: / 03-08-2015 / 16:18:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+string:aString nullTerminate:nullTerminate 
+    self assert:aString isSingleByteString.
+    ^ LLVM 
+        ConstString:aString
+        _:aString size
+        _:((nullTerminate == true) ifTrue:[ 1 ] ifFalse:[ 0 ])
+             "Created: / 03-08-2015 / 16:17:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+