Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvement to tests #2

Merged
merged 6 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
472 changes: 472 additions & 0 deletions examples/Jib/duopod.ir

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/Sail-Jib-Tests/JibExamples.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Class {
#name : #JibExamples,
#superclass : #Object,
#category : #'Sail-Jib-Tests'
}

{ #category : #navigating }
JibExamples class >> / aString [
| root |

root := IceRepository gitDirectoryDefiningClass: self.
root isNil ifTrue:[
self error:'Cannot find repository root for package ', self package name.
^nil.
].
root := root / 'examples'.
root isDirectory ifFalse:[
self error:'No such directory: ', root pathString.
^self.
].

^root / aString


"
(JibExamples / 'Jib' / 'return42.ir') contents
"





]
49 changes: 41 additions & 8 deletions src/Sail-Jib-Tests/JibParsingTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,38 @@ JibParsingTest >> setUp [

{ #category : #'tests - program' }
JibParsingTest >> testParseDuopod [
(self parseFileNamed: '/home/boris/work/REMS/duopod.ir') inspect
| p |

p := self parseFileNamed: JibExamples / 'Jib' / 'duopod.ir'.

self assert: (p isKindOf: JibProgram)
]

{ #category : #'tests - program' }
JibParsingTest >> testParseReturn42 [
| p |

p := self parseFileNamed: JibExamples / 'Jib' / 'return42.ir'.

self assert: (p isKindOf: JibProgram)
]

{ #category : #'tests - program' }
JibParsingTest >> testParseUnify1_n [
| p |

p := self parseFileNamed: JibExamples / 'Jib' / 'unify1_n.ir'.

self assert: (p isKindOf: JibProgram)
]

{ #category : #'tests - program' }
JibParsingTest >> testParseUnify1_p [
| p |

p := self parseFileNamed: JibExamples / 'Jib' / 'unify1_p.ir'.

self assert: (p isKindOf: JibProgram)
]

{ #category : #'tests - program' }
Expand Down Expand Up @@ -80,28 +111,30 @@ fn zhex_bits_12_forwards(zargz3) {

'.

function := program values at: 'zhex_bits_12_forwards'.
function := program children first.

self assert: function id = 'zhex_bits_12_forwards'.

self assert: (function body instrs at: 47 + 1) isExit.
self assert: (function body instrs at: 49 + 1) isEnd.
self assert: (function instrs at: 47 + 1) isExit.
self assert: (function instrs at: 49 + 1) isEnd.

"Check that entry block has two successors..."
b0 := function body blocks detect:[:bb | bb range first == 0].
b0 := function blocks detect:[:bb | bb range first == 0].
self assert: b0 successor1 notNil.
self assert: b0 successor2 notNil.

"Check that block with exit has no successors"
b47 := function body blocks detect:[:bb | bb range last == 47"index of exit"].
b47 := function blocks detect:[:bb | bb range last == 47"index of exit"].
self assert: b47 successor1 isNil.
self assert: b47 successor2 isNil.

"Check that block with end has no successors"
b49 := function body blocks detect:[:bb | bb range last == 49"index of end"].
b49 := function blocks detect:[:bb | bb range last == 49"index of end"].
self assert: b49 successor1 isNil.
self assert: b49 successor2 isNil.

"Now, compute liveness..."
JibFnBodyBlockLiveness compute: function body.
JibFnBodyBlockLiveness compute: function.
"...and check that entry blocks' live-ins are only arguments"
self assert: (b0 liveness liveIn allSatisfy:[:id|id beginsWith:'zarg']).
"...and also that terminal blocks have no live-outs"
Expand Down
10 changes: 0 additions & 10 deletions src/Sail-Jib-Tests/JibTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ Class {
#category : #'Sail-Jib-Tests'
}

{ #category : #tests }
JibTest >> jibExamples [
^self class definingGitDirectory / 'examples' / 'Jib'
]

{ #category : #tests }
JibTest >> parseExampleFileNamed: relativeFileName [
^self parseFileNamed: self jibExamples / relativeFileName
]

{ #category : #tests }
JibTest >> parseFileNamed: fileName [
^self parseString: fileName asFileReference contents
Expand Down
5 changes: 5 additions & 0 deletions src/Sail-Jib/Def_Enum.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Def_Enum >> childrenDo: aBlock [

]

{ #category : #accessing }
Def_Enum >> id [
^ id
]

{ #category : #printing }
Def_Enum >> printOn: aStream [
aStream
Expand Down
21 changes: 20 additions & 1 deletion src/Sail-Jib/Def_Fn.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Class {
#instVars : [
'id',
'ids',
'instrs'
'instrs',
'blocks'
],
#category : #'Sail-Jib'
}
Expand All @@ -18,12 +19,30 @@ Def_Fn class >> inducedParser [
construct: #(- id ids instrs)
]

{ #category : #accessing }
Def_Fn >> blocks [
blocks isNil ifTrue:[
blocks := JibFnBodyBlock analyze: self.
].
^ blocks
]

{ #category : #enumerating }
Def_Fn >> childrenDo: aBlock [
instrs do: aBlock

]

{ #category : #accessing }
Def_Fn >> id [
^ id
]

{ #category : #accessing }
Def_Fn >> instrs [
^ instrs
]

{ #category : #printing }
Def_Fn >> printOn: aStream [
aStream
Expand Down
5 changes: 5 additions & 0 deletions src/Sail-Jib/Def_Register.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ Def_Register >> childrenDo: aBlock [

]

{ #category : #accessing }
Def_Register >> id [
^ id
]

{ #category : #printing }
Def_Register >> printOn: aStream [
aStream nextPut: (Character codePoint: 16rAE).
Expand Down
5 changes: 5 additions & 0 deletions src/Sail-Jib/Def_Struct.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Def_Struct >> childrenDo: aBlock [

]

{ #category : #accessing }
Def_Struct >> id [
^ id
]

{ #category : #printing }
Def_Struct >> printOn: aStream [
aStream
Expand Down
5 changes: 5 additions & 0 deletions src/Sail-Jib/Def_Union.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Def_Union >> childrenDo: aBlock [

]

{ #category : #accessing }
Def_Union >> id [
^ id
]

{ #category : #printing }
Def_Union >> printOn: aStream [
aStream
Expand Down
5 changes: 5 additions & 0 deletions src/Sail-Jib/Def_Val.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ Def_Val >> childrenDo: aBlock [


]

{ #category : #accessing }
Def_Val >> id [
^ id
]
36 changes: 18 additions & 18 deletions src/Sail-Jib/JibFnBodyBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Class {
#name : #JibFnBodyBlock,
#superclass : #Object,
#instVars : [
'body',
'function',
'range',
'precedessors',
'successor1',
Expand All @@ -13,8 +13,8 @@ Class {
}

{ #category : #utilities }
JibFnBodyBlock class >> analyze: aJibFnBody [
"Analyze (jib) function body, create and connect basic blocks and return
JibFnBodyBlock class >> analyze: function [
"Analyze (jib) function, create and connect basic blocks and return
them in a collection. Entry block is guaranteed to be the first one in
returned collection."

Expand All @@ -24,29 +24,29 @@ JibFnBodyBlock class >> analyze: aJibFnBody [
after each goto or end instruction."
blocks := OrderedCollection new.
curBB := self new.
aJibFnBody instrs withIndexDo:[:last :lastIplus1 |
function instrs withIndexDo:[:last :lastIplus1 |
firstI isNil ifTrue:[
firstI := lastIplus1 - 1
].
last isJump ifTrue:[
| prevBB |

curBB setBody: aJibFnBody range: (firstI to: lastIplus1 - 1).
curBB setFunction: function range: (firstI to: lastIplus1 - 1).
blocks add: curBB.
prevBB := curBB.
curBB := self new.
prevBB setSuccessor1: curBB.
firstI := nil.
] ifFalse:[
(last isGoto or:[last isEnd or:[last isExit]]) ifTrue:[
curBB setBody: aJibFnBody range: (firstI to: lastIplus1 - 1).
curBB setFunction: function range: (firstI to: lastIplus1 - 1).
blocks add: curBB.
curBB := self new.
firstI := nil.
]].
].
firstI notNil ifTrue:[
curBB setBody: aJibFnBody range: (firstI to: aJibFnBody instrs size - 1).
curBB setFunction: function range: (firstI to: function instrs size - 1).
blocks add: curBB.
].

Expand Down Expand Up @@ -103,7 +103,7 @@ JibFnBodyBlock >> addPrecedessor: aJibFnBodyBlock [

{ #category : #accessing }
JibFnBodyBlock >> body [
^ body
^ function
]

{ #category : #displaying }
Expand Down Expand Up @@ -170,29 +170,29 @@ JibFnBodyBlock >> gtLivenessIn: composite [

{ #category : #accessing }
JibFnBodyBlock >> instrs [
^body instrs copyFrom: range first + 1 to: range last + 1
^function instrs copyFrom: range first + 1 to: range last + 1
]

{ #category : #enumerating }
JibFnBodyBlock >> instrsDo: aBlock [
range first + 1 to: range last + 1 do:[:i|
aBlock value: (body instrs at: i)
aBlock value: (function instrs at: i)
].
]

{ #category : #utilities }
JibFnBodyBlock >> invalidate [
self setSuccessor1: nil.
self setSuccessor2: nil.
body := nil.
function := nil.
range := -1 to: -1.
]

{ #category : #accessing }
JibFnBodyBlock >> last [
"Return the last instruction in this block"

^body instrs at: range last + 1
^function instrs at: range last + 1
]

{ #category : #accessing }
Expand Down Expand Up @@ -238,11 +238,11 @@ JibFnBodyBlock >> removePrecedessor: aJibFnBodyBlock [
]

{ #category : #initialization }
JibFnBodyBlock >> setBody: aJibFnBody range: anInterval [
self assert: (anInterval first between: 0 and: aJibFnBody instrs size - 1).
self assert: (anInterval last between: 0 and: aJibFnBody instrs size - 1).
JibFnBodyBlock >> setFunction: aDef_Fn range: anInterval [
self assert: (anInterval first between: 0 and: aDef_Fn instrs size - 1).
self assert: (anInterval last between: 0 and: aDef_Fn instrs size - 1).

body := aJibFnBody.
function := aDef_Fn.
range := anInterval.
]

Expand Down Expand Up @@ -274,8 +274,8 @@ JibFnBodyBlock >> splitAt: target [

self assert:(range includes: target).

bb1 := self class new setBody: body range: (range first to: target - 1).
bb2 := self class new setBody: body range: (target to: range last).
bb1 := self class new setFunction: function range: (range first to: target - 1).
bb2 := self class new setFunction: function range: (target to: range last).

bb1 setSuccessor1: bb2.
bb2 setSuccessor1: successor1.
Expand Down
12 changes: 6 additions & 6 deletions src/Sail-Jib/JibProgramNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ JibProgramNode class >> inducedParser [
self subclassResponsibility
]

{ #category : #testing }
JibProgramNode class >> isAbstract [
^self == JibProgramNode
]

{ #category : #accessing }
JibProgramNode >> children [
^ OrderedCollection streamContents:[ :children | self childrenDo:[ :child | children add: child ] ].
^ OrderedCollection streamContents:[ :children | self childrenDo:[ :child | children nextPut: child ] ].
]

{ #category : #enumerating }
Expand Down Expand Up @@ -99,8 +104,3 @@ JibProgramNode >> setParent: aJibProgramNode [
parent := aJibProgramNode

]

{ #category : #testing }
JibProgramNode class >> isAbstract [
^self == JibProgramNode
]