compiler/PPCConfiguration.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 }"

Object subclass:#PPCConfiguration
	instanceVariableNames:'arguments ir history'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Core'
!

!PPCConfiguration class methodsFor:'as yet unclassified'!

default
	^ PPCFirstPrototype new
!

new
	^ self basicNew
		initialize;
		yourself
! !

!PPCConfiguration methodsFor:'accessing'!

arguments: args
	arguments := args
!

input: whatever
	ir := whatever.
	self remember: #input.
!

ir
	^ ir
!

ir: whatever
	ir := whatever
! !

!PPCConfiguration methodsFor:'as yet unclassified'!

compile: whatever
	self input: whatever.
	self invokePhases.
	^ ir
!

compile: whatever arguments: args
	self arguments: args.
	^ self compile: whatever.
!

remember: key
	arguments debug ifTrue: [ 
		history add: key -> (ir copy).
	]
! !

!PPCConfiguration methodsFor:'initialization'!

initialize
	history := OrderedCollection new
! !

!PPCConfiguration methodsFor:'phases'!

check
	ir checkTree 
!

generate
	| compiler rootMethod compiledParser |
	arguments generate ifFalse: [ ^ self ].
	
	compiler := PPCCompiler on: arguments.
	
	rootMethod := (PPCCodeGenerator on: compiler)
		arguments: arguments;
		visit: ir.
	
	compiler compileParser.
	compiler compiledParser startSymbol: rootMethod methodName.
	compiledParser := compiler compiledParser new.
	
	ir := compiledParser.
!

inline
	arguments inline ifFalse: [ ^ self ].
	
	ir := PPCInliningVisitor new
		arguments: arguments;
		visit: ir.
	self remember: #inline.
!

merge
	arguments merge ifFalse: [ ^ self ].
	
	ir :=  PPCMergingVisitor new
		arguments: arguments;
		visit: ir.
	self remember: #merge
!

specialize
	arguments specialize ifFalse: [ ^ self ].

	" 
		Invokes a visitor that creates specialized nodes
		for some patterns of PPCNodes
	"
	ir :=  (PPCOptimizingVisitor new
		arguments: arguments;
		visit: ir).
	self remember: #specialize
!

toPPCIr
	ir := ir asCompilerTree.
	self remember: #ppcNodes
!

tokenize
	arguments tokenize ifFalse: [ ^ self ] .
	
	ir :=  PPCTokenDetector new
		arguments: arguments;
		visit: ir.
	self remember: #tokenize
! !