LLVMModule.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 31 Jul 2015 16:21:29 +0100
changeset 12 f98e97fd02ef
parent 4 d33c64726c86
child 13 fa967c0e1827
permissions -rw-r--r--
Package renamed from jv:libllvms to jv:llvm_s

"{ Package: 'jv:llvm_s' }"

"{ NameSpace: Smalltalk }"

LLVMDisposableObject subclass:#LLVMModule
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:'LLVMTypeKind'
	category:'LLVM-Core'
!

!LLVMModule class methodsFor:'instance creation'!

newWithName: name
    ^ LLVM ModuleCreateWithName: name

    "Created: / 07-07-2015 / 20:22:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMModule methodsFor:'accessing'!

dataLayoutString
    ^ LLVM GetDataLayout: self.

    "Created: / 11-07-2015 / 06:57:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMModule methodsFor:'adding & removing'!

addFunctionNamed: name type: type
    self assert: name isSingleByteString.
    self assert: type kind == LLVMFunctionTypeKind.
    ^ LLVM AddFunction: self _: name _: type.

    "Created: / 07-07-2015 / 21:59:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addMethodForClass: class selector: selector
    | name type typeObj typeIlcPtr argTypes|

    name := LLVMStXMethod llvmFunctionNameForClass: class selector: selector.
    typeObj := LLVMType intptr.
    typeIlcPtr := LLVMType intptr.
    argTypes := LLVMObjectArray new: 4"receiver, selector, clsOrNil, pIlc" + selector numArgs.
    1 to: argTypes size do:[:i | 
        argTypes at: i put: typeObj.
    ].
    argTypes at: 4 put: typeIlcPtr.
    type := LLVMType function: argTypes  returning: typeObj.
    ^ LLVM AddMethod: self _: name _: type.

    "Created: / 11-07-2015 / 09:37:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMModule methodsFor:'debugging'!

inspectorExtraAttributes 
    | d |

    d := super inspectorExtraAttributes.      
    d add: '-dump' -> [ self dumpString ].
    ^ d

    "Created: / 10-07-2015 / 14:37:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMModule methodsFor:'debugging-dumping'!

dumpOn: aStream
    aStream nextPutAll: self dumpString

    "Created: / 10-07-2015 / 14:32:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

dumpString
    | cstr str|

    cstr := LLVM PrintModuleToString: self.
    str := cstr copyCStringFromHeap.
    LLVM DisposeMessage: cstr.
    ^ str

    "Created: / 10-07-2015 / 14:31:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMModule methodsFor:'initialization & release'!

dispose
    ^ LLVM DisposeModule: self

    "Modified: / 08-07-2015 / 22:40:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMModule methodsFor:'inspecting'!

inspector2TabCode
    <inspector2Tab>

    ^ (self newInspector2Tab)
        label:'Code';
        priority:50;
        text: [ self dumpString ];
        yourself

    "Modified: / 10-07-2015 / 14:37:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !