LLVMStXMethod.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 17 Sep 2015 17:17:56 +0100
changeset 42 23ae490859cd
parent 33 feabf14b6c1d
permissions -rw-r--r--
Fixed LLVMExamples>>example7_factorial_with_debug_info Pass DIFile instead of DICompileUnit to #createTypeFunctionIn:parameterTypes: Fixed #createParameterVariable: - parameters are numbered starting with 1.

"
    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 }"

LLVMFunction subclass:#LLVMStXMethod
	instanceVariableNames:''
	classVariableNames:'SelectorSpecialCharMappingTable'
	poolDictionaries:''
	category:'LLVM-S-StX'
!

!LLVMStXMethod 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.
"
! !

!LLVMStXMethod class methodsFor:'initialization'!

initialize
    "Invoked at system start or when the class is dynamically loaded."

    "/ please change as required (and remove this comment)

    SelectorSpecialCharMappingTable := Dictionary withKeysAndValues:
                #($+ 'pl'
                  $- 'mi'
                  $* 'mu'
                  $/ 'di'
                  $, 'co'
                  $@ 'at'
                  $< 'le'
                  $> 'gr'
                  $= 'eq'
                  $~ 'ne'
                  $| 'pi'
                  $\ 'mo'
                  $& 'am').

    "Modified: / 11-07-2015 / 09:24:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMStXMethod class methodsFor:'utilities'!

llvmFunctionNameForClass: class selector: selector      
    "For given class name and selector, returns the name 
     used by LLVM"

    ^ String streamContents:[ :s|
        s nextPutAll: '__M_L_'.
        s nextPutAll: (class name copyReplaceAll: $: with: $_).
        s nextPut: $_.
        selector isBinarySelector ifTrue:[ 
            selector do:[:c |     
                s nextPutAll: (SelectorSpecialCharMappingTable at: c)
            ].
        ] ifFalse:[ 
            selector do:[:c |  
                c isAlphaNumeric ifTrue:[ 
                    s nextPut: c 
                ] ifFalse:[
                    c == $: ifTrue:[ 
                        s nextPut: $_
                    ] ifFalse:[  
                        s nextPut: $_.
                        c codePoint printOn: s.
                    ]
                ].
            ]
        ].
    ].

    "
    LLVMStXMethod llvmFunctionNameForClass: LLVMStXMethod selector: #llvmFunctionNameForClass:selector: 
    LLVMStXMethod llvmFunctionNameForClass: SmallInteger selector: #+
    LLVMStXMethod llvmFunctionNameForClass: Object selector: #~=

    "

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

!LLVMStXMethod methodsFor:'accessing'!

numParams
    ^ super numParams - 4

    "Created: / 14-08-2015 / 12:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parameterAt: index
    ^ super parameterAt: 4 + index.

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

!LLVMStXMethod methodsFor:'initialization'!

initializeArgumentsNames
    "Assign human readable names to parameters"
    (super parameterAt: 1) name: 'self'.
    (super parameterAt: 2) name: 'selector'.
    (super parameterAt: 3) name: 'searchClass'.
    (super parameterAt: 4) name: 'pIlc'.
    1 to: super numArgs -  4 do:[:numArg | 
        self halt.
        (super parameterAt: 4+numArg) name: 'marg', numArg printString.
    ].

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


LLVMStXMethod initialize!