IRTransformTest.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 29 Mar 2012 18:03:58 +0000
changeset 37 be8c2dd09dff
parent 34 4c372f8296b9
child 41 f3898a3b378d
permissions -rw-r--r--
Build files regenerated

"{ Package: 'cvut:stx/goodies/newcompiler' }"

TestCase subclass:#IRTransformTest
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'NewCompiler-IR-Tests'
!


!IRTransformTest methodsFor:'testing'!

testAdd
    |iRMethod aCompiledMethod|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                returnTop;
                ir.
    (iRMethod allSequences last) last delete.
    (iRMethod allSequences last) last delete.
    (iRMethod allSequences last) add:(IRInstruction pushLiteral:2).
    (iRMethod allSequences last) add:(IRInstruction returnTop).
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ].
!

testAddBefore
    |iRMethod aCompiledMethod ret|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                returnTop;
                ir.
    (iRMethod allSequences last) last delete.
    (iRMethod allSequences last) last delete.
    ret := (IRInstruction returnTop).
    (iRMethod allSequences last) add:ret.
    (iRMethod allSequences last) add:(IRInstruction pushLiteral:2) before:ret.
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ].
!

testAddIntructions
        
        | iRMethod aCompiledMethod |

        iRMethod := IRBuilder new
                numRargs: 1;
                addTemps: #(self);              "receiver and args declarations"
                pushLiteral: 1;                                 
                returnTop;
                ir.

        (iRMethod allSequences last) last delete.
        (iRMethod allSequences last) last delete.

        (iRMethod allSequences last)
                        addInstructions: {(IRInstruction pushLiteral: 2). (IRInstruction returnTop)}.

        aCompiledMethod := iRMethod compiledCode.
        self should: [(aCompiledMethod valueWithReceiver: nil arguments: #() ) = 2].

    "Modified: / 30-03-2009 / 19:40:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

testAddIntructionsBefore
        
        | iRMethod aCompiledMethod push |

        iRMethod := IRBuilder new
                numRargs: 1;
                addTemps: #(self);              "receiver and args declarations"
                pushLiteral: 1;                                 
                returnTop;
                ir.

        push := (iRMethod allSequences last) at: (iRMethod allSequences size - 1) .

        (iRMethod allSequences last)
                        addInstructions: {(IRInstruction pushLiteral: 2). (IRInstruction returnTop)} before: push.

        aCompiledMethod := iRMethod compiledCode.
        self should: [(aCompiledMethod valueWithReceiver: nil arguments: #() ) = 2].

    "Modified: / 30-03-2009 / 19:40:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

testAddIntructionsBeforeFromLList
    |iRMethod aCompiledMethod push llist col|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                returnTop;
                ir.
    push := (iRMethod allSequences last) at:(iRMethod allSequences size - 1).
    llist := LinkedList new.
    llist add:(IRInstruction pushLiteral:2).
    llist add:(IRInstruction returnTop).
    col := llist asOrderedCollection.
    (iRMethod allSequences last) addInstructions:col before:push.
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ].
!

testDelete
    |iRMethod aCompiledMethod|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                pushLiteral:2;
                returnTop;
                ir.
    ((iRMethod allSequences last) 
        detect:[:each | each isConstant:[:c | c == 2 ] ]) delete.
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 1 ].
!

testReplace
    |iRMethod aCompiledMethod|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                returnTop;
                ir.
    (iRMethod allSequences last at:1) 
        replaceWith:(IRInstruction pushLiteral:2).
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ].
!

testReplaceInstr
        
        | iRMethod aCompiledMethod |

        iRMethod := IRBuilder new
                numRargs: 1;
                addTemps: #(self);              "receiver and args declarations"
                pushLiteral: 1;                                 
                returnTop;
                ir.
        
        (iRMethod allSequences last at: 1) 
                        replaceWithInstructions: {(IRInstruction pushLiteral: 2)}.

        aCompiledMethod := iRMethod compiledCode.
        self should: [(aCompiledMethod valueWithReceiver: nil arguments: #() ) = 2].

    "Modified: / 30-03-2009 / 19:40:30 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!IRTransformTest class methodsFor:'documentation'!

version
    ^ '$Id$'
!

version_CVS
    ^ '§Header: /cvs/stx/cvut/stx/goodies/newcompiler/IRTransformTest.st,v 1.3 2009/10/08 11:56:52 fm Exp §'
!

version_SVN
    ^ '$Id::                                                                                                                        $'
! !