compiler/PPCInliningVisitor.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 Apr 2015 23:43:14 +0200
changeset 438 20598d7ce9fa
child 452 9f4558b3be66
permissions -rw-r--r--
Updated to PetitCompiler-JanKurs.100, PetitCompiler-Tests-JanKurs.44 and PetitCompiler-Benchmarks-JanKurs.4 Name: PetitCompiler-JanKurs.100 Author: JanKurs Time: 30-04-2015, 10:48:52.165 AM UUID: 80196870-5921-46d9-ac20-a43bf5c2f3c2 Name: PetitCompiler-Tests-JanKurs.44 Author: JanKurs Time: 30-04-2015, 10:49:22.489 AM UUID: 348c02e8-18ce-48f6-885d-fcff4516a298 Name: PetitCompiler-Benchmarks-JanKurs.4 Author: JanKurs Time: 30-04-2015, 10:58:44.890 AM UUID: 18cadb42-f9ef-45fb-82e9-8469ade56c8b

"{ Package: 'stx:goodies/petitparser/compiler' }"

"{ NameSpace: Smalltalk }"

PPCNodeVisitor subclass:#PPCInliningVisitor
	instanceVariableNames:'acceptedNodes'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Visitors'
!

!PPCInliningVisitor methodsFor:'initialization'!

initialize
	super 	initialize.
		
	acceptedNodes := 0
! !

!PPCInliningVisitor methodsFor:'testing'!

canInline
	^ acceptedNodes > 1
! !

!PPCInliningVisitor methodsFor:'visiting'!

beforeAccept: node
	acceptedNodes := acceptedNodes + 1.
	super beforeAccept: node
!

markForInline: node
	self canInline ifTrue: [ 
		node markForInline.
	].
	^ node
!

visitCharSetPredicateNode: node
	^ self markForInline: node
!

visitCharacterNode: node
	^ self markForInline: node
!

visitLiteralNode: node
	^ self markForInline: node
!

visitMessagePredicateNode: node
	^ self markForInline: node
!

visitNilNode: node
	^ self markForInline: node
!

visitNotCharSetPredicateNode: node
	^ self markForInline: node
!

visitNotLiteralNode: node
	^ self markForInline: node
!

visitNotMessagePredicateNode: node
	^ self markForInline: node
!

visitPluggableNode: node
    "Sadly, on Smalltalk/X blocks cannot be inlined because
     the VM does not provide enough information to map
     it back to source code. Very bad indeed!!"
    ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifFalse:[
			^ self markForInline: node
    ].
    ^ super visitPluggableNode: node.

    "Modified: / 23-04-2015 / 12:15:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

visitTokenStarMessagePredicateNode: node
	^ self markForInline: node
!

visitTokenStarSeparatorNode: node
	^ self markForInline: node
! !