IRPrinter.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 Oct 2014 22:23:12 +0000
changeset 43 c8afb8e4c3cc
parent 42 acdc3ec6d152
permissions -rw-r--r--
Removed obsolete #version method

"{ Package: 'ctu:ircompiler' }"

IRInterpreter subclass:#IRPrinter
	instanceVariableNames:'stream indent'
	classVariableNames:''
	poolDictionaries:''
	category:'IR Compiler-IR'
!

IRPrinter comment:'I interpret IRMethod instructions and write them out to a print stream.'
!


!IRPrinter methodsFor:'initialize'!

indent: tabs

	indent _ tabs
!

stream: stringWriteStream

	stream _ stringWriteStream
! !

!IRPrinter methodsFor:'instructions'!

blockReturnTop

	stream nextPutAll: 'blockReturnTop'.
!

goto: seqNum

	stream nextPutAll: 'goto: '.
	seqNum printOn: stream.
!

if: bool goto: seqNum1 otherwise: seqNum2

	stream nextPutAll: 'if: '.
	bool printOn: stream.
	stream nextPutAll: ' goto: '.
	seqNum1 printOn: stream.
	stream nextPutAll: ' else: '.
	seqNum2 printOn: stream.
!

jumpOverBlock: blockSeq to: dest

	stream nextPutAll: 'jumpOverBlock: '.
	stream nextPutAll: ' block '.
	blockSeq  printOn: stream.
	stream nextPutAll: ' cont: '.
	dest  printOn: stream.
!

label: seqNum

	"add tab and cr since this does not get called within interpretInstruction:"
	stream cr.  "extra cr just to space out sequences"
	indent timesRepeat: [stream tab].
	stream nextPutAll: 'label: '.
	seqNum printOn: stream.
	stream cr.
!

line: line

    stream nextPutAll: 'line: '.
    line printOn: stream

    "Created: / 02-12-2008 / 09:00:40 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

popTop

	stream nextPutAll: 'popTop'
!

pushBlock: irClosure

        stream nextPutAll: 'pushBlock:'.
        IRPrinter new
                indent: indent + 1;
                stream: stream;
                interpret: irClosure removeEmptyStart.

    "Modified: / 30-03-2009 / 16:51:49 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

pushDup

	stream nextPutAll: 'pushDup'
!

pushLiteral: object

        stream nextPutAll: 'pushLiteral: '.
        object isVariableBinding ifTrue: [^ stream nextPutAll: object key].
        object printOn: stream.


        ((object isKindOf: BlockClosure) or: [object isKindOf: CompiledMethod])
                ifTrue: [
                        IRPrinter new
                                indent: indent + 1;
                                stream: stream;
                                interpret: object method ir removeEmptyStart].

    "Modified: / 03-11-2008 / 17:59:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

pushLiteralVariable: object

	stream nextPutAll: 'pushLiteralVariable: '.
	object isVariableBinding ifTrue: [^ stream nextPutAll: object key].
	object printOn: stream.
!

pushTemp: index kind: kind level: level

        stream 
            nextPutAll: 'push ';
            nextPutAll: kind;
            nextPutAll: ': '.
        index printOn: stream.
        level == 0 ifFalse:
            [stream
                nextPutAll:' level: '.
            level printOn: stream].                
            
        index = 0 ifTrue: [stream nextPutAll: ' "receiver"'].
        index = -1 ifTrue: [stream nextPutAll: ' "thisEnv"'].
        index = -2 ifTrue: [stream nextPutAll: ' "thisContext"'].

    "Created: / 30-03-2009 / 14:04:20 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

remoteReturn

	stream nextPutAll: 'remoteReturn'.
!

returnTop

	stream nextPutAll: 'returnTop'.
!

send: selector numArgs: numArgs

        stream 
            nextPutAll: 'send: ';
            nextPutAll: selector storeString.
        stream nextPutAll: ' numArgs: '.
        numArgs printOn: stream.

    "Created: / 01-12-2008 / 19:41:52 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 30-03-2009 / 18:43:26 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

send: selector numArgs: numArgs toSuperOf: behavior

        stream 
            nextPutAll: 'send: ';
            nextPutAll: selector storeString.
        stream nextPutAll: ' numArgs: '.
        numArgs printOn: stream.
        stream nextPutAll: ' toSuperOf: '.
        behavior printOn: stream.

    "Created: / 01-12-2008 / 19:46:28 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 30-03-2009 / 18:44:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

storeIntoLiteralVariable: name
        stream 
            nextPutAll: 'storeLiteralVariable: ';
            nextPutAll: name

    "Created: / 11-05-2009 / 22:39:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

storeTemp: index kind: kind level: level

        stream 
            nextPutAll: 'store ';
            nextPutAll: kind;
            nextPutAll: ': '.
        index printOn: stream.
        level == 0 ifFalse:
            [stream
                nextPutAll:' level: '.
            level printOn: stream].  

        index = -1 ifTrue: [stream nextPutAll: ' "thisEnv"'].

    "Created: / 30-03-2009 / 14:05:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!IRPrinter methodsFor:'interpret'!

interpretInstruction: irInstruction

	indent timesRepeat: [stream tab].
	super interpretInstruction: irInstruction.
	stream cr.
! !

!IRPrinter class methodsFor:'documentation'!

version_CVS
    ^ 'Header: /cvs/stx/cvut/stx/goodies/newcompiler/IRPrinter.st,v 1.3 2009/10/08 12:00:24 fm Exp '
!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '$Id::                                                                                                                        $'
! !