From fa67379c0152885096595b144829545b61be16e0 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 10 Jun 2024 14:16:29 +0100 Subject: [PATCH 1/5] Remove unused methods from `TRRegisterDependencies` This commit removes unused `#addPreDependencyOf:on:` and `#addPostDependencyOf:on:` from `TRRegisterDependencies` --- src/Tinyrossa/TRRegisterDependencies.class.st | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/Tinyrossa/TRRegisterDependencies.class.st b/src/Tinyrossa/TRRegisterDependencies.class.st index 5e70cae..5a71770 100644 --- a/src/Tinyrossa/TRRegisterDependencies.class.st +++ b/src/Tinyrossa/TRRegisterDependencies.class.st @@ -73,22 +73,6 @@ TRRegisterDependencies class >> pre: pre post: post [ ^ self basicNew initializeWithPre: pre post: post. ] -{ #category : #'adding & removing' } -TRRegisterDependencies >> addPostDependencyOf: vreg on: rreg [ - "Add register dependency ensuring that *after execution* - of an instruction, value of *vreg* is kept in *rreg*." - - post add: (TRRegisterDependency virtual: vreg real: rreg) -] - -{ #category : #'adding & removing' } -TRRegisterDependencies >> addPreDependencyOf: vreg on: rreg [ - "Add register dependency ensuring that *prior execution* - of an instruction, value of *vreg* is stored in *rreg*." - - pre add: (TRRegisterDependency virtual: vreg real: rreg) -] - { #category : #initialization } TRRegisterDependencies >> initializeWithPre: preDependencyGroup post: postDependencyGroup [ pre := preDependencyGroup. From bf24dc918bc4358904bd7b2ed820b873692d0bbf Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Wed, 12 Jun 2024 15:39:40 +0100 Subject: [PATCH 2/5] Move compilation test shell to category "Tinyrossa-Tests-Shells" This commit moves `TRCompilationTestShell` and subclasses to category "Tinyrossa-Tests-Shells", removing "-SmalltalkX". These classes are no longer Smalltalk/X specific. --- src/Tinyrossa-Tests/TRCompilationTestShell.class.st | 2 +- src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st | 2 +- src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st | 2 +- .../TRCompilationTestShellRemoteUsingSSH.class.st | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Tinyrossa-Tests/TRCompilationTestShell.class.st b/src/Tinyrossa-Tests/TRCompilationTestShell.class.st index 0d00ecc..ade445f 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShell.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShell.class.st @@ -12,7 +12,7 @@ Class { #pools : [ 'TRRegisterKinds' ], - #category : #'Tinyrossa-Tests-Shells-SmalltalkX' + #category : #'Tinyrossa-Tests-Shells' } { #category : #accessing } diff --git a/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st b/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st index d71d41f..0a812e4 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st @@ -7,7 +7,7 @@ Class { #classVars : [ 'Host' ], - #category : #'Tinyrossa-Tests-Shells-SmalltalkX' + #category : #'Tinyrossa-Tests-Shells' } { #category : #accessing } diff --git a/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st b/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st index 18f8050..b8bcddf 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st @@ -4,7 +4,7 @@ Class { #instVars : [ 'qemu' ], - #category : #'Tinyrossa-Tests-Shells-SmalltalkX' + #category : #'Tinyrossa-Tests-Shells' } { #category : #running } diff --git a/src/Tinyrossa-Tests/TRCompilationTestShellRemoteUsingSSH.class.st b/src/Tinyrossa-Tests/TRCompilationTestShellRemoteUsingSSH.class.st index cccdcc8..41f72cf 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShellRemoteUsingSSH.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShellRemoteUsingSSH.class.st @@ -4,7 +4,7 @@ Class { #classVars : [ 'Host' ], - #category : #'Tinyrossa-Tests-Shells-SmalltalkX' + #category : #'Tinyrossa-Tests-Shells' } { #category : #accessing } From 2898b51b49b1972bbf857b79c916945adf45f403 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Wed, 12 Jun 2024 16:06:03 +0100 Subject: [PATCH 3/5] Remove `compilation` instvar from test shell This commit removes `compilation` instvar introduced in commit 84b2519 "Implement `TRCompilationTestShell >> #call` and `#call:`". In a hindsight, this does not seem proper. We need to be able to test compilation of multiple functions calling each other, so the there'll be "multiple compilations". Removing `compilation` from shell prompted refactoring of `call`, `call:` and `call:_:` utility methods - they need to take `compilation` as a first parameter. While at it, split code injection and call to actual function into two method to facilitate tests with multiple functions. --- .../TRCompilationTestCase.class.st | 29 ++--- .../TRCompilationTestShell.class.st | 108 +++++++++--------- .../TRCompilationTestShellGem5.class.st | 6 +- .../TRCompilationTestShellQEMU.class.st | 2 +- 4 files changed, 73 insertions(+), 72 deletions(-) diff --git a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st index 7fb0185..bd414b2 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st @@ -69,7 +69,8 @@ TRCompilationTestCase >> setUp [ compilation := TRCompilation forTarget: target. compilation config stressRA: (testParameters at: #stressRA). - shell := TRCompilationTestShell forCompilation: compilation. + + shell := TRCompilationTestShell forTarget: target. ] { #category : #accessing } @@ -200,7 +201,7 @@ TRCompilationTestCase >> test01_bytecode_abs [ compilation compile. - self assert: (shell call: 2) equals: 2 abs. + self assert: (shell inject: compilation andInvokeWith: { 2 }) equals: 2 abs. ] { #category : #tests } @@ -218,7 +219,7 @@ TRCompilationTestCase >> test02_iconst [ compilation optimize. compilation compile. - self assert: (shell call) equals: x. + self assert: (shell inject: compilation andInvokeWith: #()) equals: x. " TRRV64GCompilationTests debug: #test02_iconst_p @@ -244,7 +245,7 @@ TRCompilationTestCase >> test03_lconst [ compilation optimize. compilation compile. - self assert: (shell call) equals: x. + self assert: (shell inject: compilation andInvokeWith: #()) equals: x. " TRRV64GCompilationTests debug: #test03_lconst_n @@ -273,7 +274,7 @@ TRCompilationTestCase >> test06_iadd_discarding_value [ compilation optimize. compilation compile. - self assert: (shell call: x ) equals: -1. + self assert: (shell inject: compilation andInvokeWith: { x }) equals: -1. " TRRV64GCompilationTests debug: #test06_iadd_discarding_value @@ -316,7 +317,7 @@ TRCompilationTestCase >> test07_call_discarding_value [ compilation compile. - self assert: (shell call: x) equals: ((x == 0) ifTrue:[ -1 ] ifFalse:[ x ]). + self assert: (shell inject: compilation andInvokeWith: {x }) equals: ((x == 0) ifTrue:[ -1 ] ifFalse:[ x ]). " TRRV64GCompilationTests debug: #test07_call_discarding_value @@ -330,7 +331,7 @@ TRCompilationTestCase >> test_example01_meaningOfLife [ compilation: compilation; example01_meaningOfLife. - self assert: (shell call) equals: 42. + self assert: (shell inject: compilation andInvokeWith: #()) equals: 42. ] { #category : #'tests - examples' } @@ -339,7 +340,7 @@ TRCompilationTestCase >> test_example03_signum [ compilation: compilation; example03_signum. - self assert: (shell call:-5) equals: -5 sign. + self assert: (shell inject: compilation andInvokeWith: { -5 }) equals: -5 sign. ] { #category : #'tests - examples' } @@ -348,7 +349,7 @@ TRCompilationTestCase >> test_example04_factorial_i [ compilation: compilation; example04_factorial_i. - self assert: (shell call:5) equals: 5 factorial. + self assert: (shell inject: compilation andInvokeWith: { 5 }) equals: 5 factorial. ] { #category : #'tests - examples' } @@ -360,7 +361,7 @@ TRCompilationTestCase >> test_example05_factorial_r [ compilation: compilation; example05_factorial_r. - self assert: (shell call:5) equals: 5 factorial. + self assert: (shell inject: compilation andInvokeWith: { 5 }) equals: 5 factorial. ] { #category : #'tests - examples' } @@ -368,7 +369,7 @@ TRCompilationTestCase >> test_example08_bytecode_compiler [ TRCompilationExamples new compilation: compilation; example08_bytecode_compiler. - self assert: (shell call:2) equals: 2 factorial. + self assert: (shell inject: compilation andInvokeWith: { 2 }) equals: 2 factorial. ] { #category : #'tests - examples' } @@ -381,7 +382,7 @@ TRCompilationTestCase >> test_example09_signum_2 [ compilation: compilation; example09_signum_2. - self assert: (shell call:-1) equals: -1 sign. + self assert: (shell inject: compilation andInvokeWith: { -1 }) equals: -1 sign. ] { #category : #'tests - examples' } @@ -393,7 +394,7 @@ TRCompilationTestCase >> test_example15_add_with_overflow_check [ TRCompilationExamples new compilation: compilation; example15_add_with_overflow_check. - self assert: (shell call: 16r7FFFFFFE _: 2 ) equals: 0. + self assert: (shell inject: compilation andInvokeWith: { 16r7FFFFFFE . 2 }) equals: 0. ] { #category : #'tests - examples' } @@ -405,7 +406,7 @@ TRCompilationTestCase >> test_example16_factorial_i_with_overflow [ TRCompilationExamples new compilation: compilation; example16_factorial_i_with_overflow. - self assert: (shell call:13)equals: -1. + self assert: (shell inject: compilation andInvokeWith: { 13 })equals: -1. " diff --git a/src/Tinyrossa-Tests/TRCompilationTestShell.class.st b/src/Tinyrossa-Tests/TRCompilationTestShell.class.st index ade445f..a7579ce 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShell.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShell.class.st @@ -2,7 +2,7 @@ Class { #name : #TRCompilationTestShell, #superclass : #TestAsserter, #instVars : [ - 'compilation', + 'target', 'binary', 'debugger' ], @@ -30,11 +30,11 @@ TRCompilationTestShell class >> defaultImpl: aClass [ ] { #category : #'instance creation' } -TRCompilationTestShell class >> forCompilation: aTRCompilation [ +TRCompilationTestShell class >> forTarget: aTRCompilationTarget [ self == TRCompilationTestShell ifTrue: [ - ^ self defaultImpl forCompilation: aTRCompilation + ^ self defaultImpl forTarget: aTRCompilationTarget ] ifFalse: [ - ^ self new initializeWithCompilation: aTRCompilation + ^ self new initializeWithTarget: aTRCompilationTarget ]. ] @@ -76,48 +76,63 @@ TRCompilationTestShell class >> shellDirectory [ " ] -{ #category : #utilities } -TRCompilationTestShell >> call [ - ^ self callWithArguments: #() +{ #category : #accessing } +TRCompilationTestShell >> debugger [ + self assert: debugger notNil. + ^ debugger +] + +{ #category : #initialization } +TRCompilationTestShell >> initializeWithTarget: aTRCompilationTarget [ + target := aTRCompilationTarget. + self setUp. ] { #category : #utilities } -TRCompilationTestShell >> call: arg1 [ - ^ self callWithArguments: { arg1 } +TRCompilationTestShell >> inject: compilation [ + "Utility: inject compiled code into the shell" + + debugger memoryAt: self nzone put: compilation codeBuffer bytes ] { #category : #utilities } -TRCompilationTestShell >> call: arg1 _:arg2 [ - ^ self callWithArguments: { arg1 . arg2 } +TRCompilationTestShell >> inject: compilation andInvokeWith: arguments [ + | argumentTypes | + + self inject: compilation. + + argumentTypes := ((compilation symbolManager lookupSymbolsByType: TRParameterSymbol) + sorted: [ :a :b | a index < b index ]) + collect:[ :e | e type ]. + + ^ self invoke: compilation functionSymbol with: arguments types: argumentTypes. ] -{ #category : #'utilities-private' } -TRCompilationTestShell >> callWithArguments: values [ - | params | +{ #category : #utilities } +TRCompilationTestShell >> invoke: symbol with: arguments types: argumentTypes [ + | linkage | - "Inject compiled code into shell" - debugger memoryAt: self nzone put: compilation codeBuffer bytes. + linkage := symbol linkageClass basicNew. - "Prepare parameters" - params := (compilation symbolManager lookupSymbolsByType: TRParameterSymbol) sorted: [ :a :b | a index < b index ]. - self assert: values size == params size description: 'Number of formal paramerers does not match actual'. - 1 to: values size do: [:i | - | param value | + self assert: arguments size == argumentTypes size description: 'Number of formal paramerers does not match actual'. + 1 to: arguments size do: [:i | + | typ arg | - param := params at: i. - value := values at: i. + typ := argumentTypes at: i. + arg := arguments at: i. - param type validateConstant: value. + typ validateConstant: arg. - param type isIntegerType ifTrue: [ + typ isIntegerType ifTrue: [ | argReg | - argReg := (compilation codegen linkage parameterRegisters: GPR) at: i. - debugger setRegister: argReg nameInGDB to: value. + argReg := (linkage parameterRegisters: GPR) at: i. + debugger setRegister: argReg nameInGDB to: arg. ] ifFalse: [ - self error: 'Parameter type not supported yet: ' , param type name + self error: 'Parameter type not supported yet: ' , typ name ]. ]. + self debugger setRegister: 'pc' to: self nzone. "Call injected function" " @@ -126,28 +141,16 @@ TRCompilationTestShell >> callWithArguments: values [ debugger c. "Retrieve return value" - compilation functionSymbol type isIntegerType ifTrue: [ + symbol type isIntegerType ifTrue: [ | retReg | - retReg := (compilation codegen linkage returnRegisters: GPR) at: 1. + retReg := (linkage returnRegisters: GPR) at: 1. ^ debugger getRegister: retReg nameInGDB ] ifFalse: [ - self error: 'Return type not supported yet: ' , compilation functionSymbol type name + self error: 'Return type not supported yet: ' , symbol type name ]. ] -{ #category : #accessing } -TRCompilationTestShell >> debugger [ - self assert: debugger notNil. - ^ debugger -] - -{ #category : #initialization } -TRCompilationTestShell >> initializeWithCompilation: aTRCompilation [ - compilation := aTRCompilation. - self setUp; reset. -] - { #category : #accessing } TRCompilationTestShell >> nzone [ "Return the address of nzone. See shell.link linker script." @@ -155,11 +158,6 @@ TRCompilationTestShell >> nzone [ ^ 16r00080000 ] -{ #category : #running } -TRCompilationTestShell >> reset [ - self debugger setRegister: 'pc' to: self nzone -] - { #category : #running } TRCompilationTestShell >> setUp [ | shellDir | @@ -167,7 +165,7 @@ TRCompilationTestShell >> setUp [ shellDir := self class shellDirectory. self assert: shellDir notNil description:'Could not determine directory with test shells!'. - binary := shellDir / ('shell-' , (compilation config target name readStream upTo: $-)). + binary := shellDir / ('shell-' , (target name readStream upTo: $-)). self assert: binary isExecutable. ] @@ -202,18 +200,20 @@ TRCompilationTestShell >> tearDownDebugger [ (debugger notNil and: [ debugger isConnected ]) ifTrue: [ | shouldQuitDebugger | - - debugger send: 'kill'. + + (debugger inferiors anySatisfy: [:e | e isRunning ]) ifTrue: [ + debugger send: 'kill' + ]. shouldQuitDebugger := (Smalltalk includesKey: #VDBDebuggerApplication) not or:[(Smalltalk at: #VDBDebuggerApplication) allInstances allSatisfy:[:vdbApp | vdbApp debugger ~~ debugger]]. shouldQuitDebugger ifTrue: [ - debugger send: 'quit' andWait: false. + debugger send: 'quit' andWait: false. ]. - ]. + ]. ] ifFalse:[ "debugger is either nil or SmallRSP's RemoteGDB" - debugger notNil ifTrue:[ + debugger notNil ifTrue:[ debugger disconnect. ]. ]. diff --git a/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st b/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st index 0a812e4..73cc327 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st @@ -37,13 +37,13 @@ TRCompilationTestShellGem5 >> setUp [ gem5exe := gem5dir asFileReference / 'build' / 'ALL' / 'gem5.debug'. ]. gem5exe exists ifFalse: [ - gem5exe := gem5dir asFileReference / 'build' / compilation config target gem5 / 'gem5.opt'. + gem5exe := gem5dir asFileReference / 'build' / target gem5 / 'gem5.opt'. ]. gem5exe exists ifFalse: [ - gem5exe := gem5dir asFileReference / 'build' / compilation config target gem5 / 'gem5.opt'. + gem5exe := gem5dir asFileReference / 'build' / target gem5 / 'gem5.opt'. ]. - self assert: gem5exe exists description: 'No gem5.debug nor gem5.opt found in GEM5_DIR/build/ALL nor GEM5_DIR/build/',compilation config target gem5. + self assert: gem5exe exists description: 'No gem5.debug nor gem5.opt found in GEM5_DIR/build/ALL nor GEM5_DIR/build/',target gem5. gem5cmd := '<1s> --listener-mode on "--debug-flags=Decode" <2s>/shell-gem5.py -c <3s> --wait-gdb --param ''system.shared_backstore = "/gem5"''' expandMacrosWith: gem5exe pathString with: shellDir pathString with: binary pathString. diff --git a/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st b/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st index b8bcddf..5db8750 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st @@ -13,7 +13,7 @@ TRCompilationTestShellQEMU >> setUp [ super setUp. - qemuCmd := compilation config target qemu, ' -g 1234 ', binary pathString. + qemuCmd := target qemu, ' -g 1234 ', binary pathString. "First, start QEMU... " qemu := OSProcess new command: qemuCmd. From 78933de84dcd5e46ba96e6f4a8e7d2e5f94f8557 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Thu, 13 Jun 2024 10:36:05 +0100 Subject: [PATCH 4/5] Remove unused instvar `parameters` from `TRFunctionSymbol` --- src/Tinyrossa/TRFunctionSymbol.class.st | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Tinyrossa/TRFunctionSymbol.class.st b/src/Tinyrossa/TRFunctionSymbol.class.st index 18ba997..c9d18f6 100644 --- a/src/Tinyrossa/TRFunctionSymbol.class.st +++ b/src/Tinyrossa/TRFunctionSymbol.class.st @@ -3,7 +3,6 @@ Class { #superclass : #TRSymbol, #instVars : [ 'linkageClass', - 'parameters', 'address' ], #pools : [ @@ -40,7 +39,6 @@ TRFunctionSymbol >> initializeWithName:nameArg type:typeArg linkage: linkageClas name := nameArg. type := typeArg. linkageClass := linkageClassArg. - parameters := OrderedCollection new. ] { #category : #testing } From 111c438b8882e53205bbff5eb6d579e75abaae1a Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Thu, 15 Aug 2024 18:14:54 +0100 Subject: [PATCH 5/5] Add `TRRegisterMappedSymbol >> asAcDSLOperand` --- src/Tinyrossa/TRRegisterMappedSymbol.class.st | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Tinyrossa/TRRegisterMappedSymbol.class.st b/src/Tinyrossa/TRRegisterMappedSymbol.class.st index c89a0dd..d3ff160 100644 --- a/src/Tinyrossa/TRRegisterMappedSymbol.class.st +++ b/src/Tinyrossa/TRRegisterMappedSymbol.class.st @@ -19,6 +19,11 @@ TRRegisterMappedSymbol class >> name:name type:type index: index [ ^ self basicNew initializeWithName:name type:type index: index ] +{ #category : #conversion } +TRRegisterMappedSymbol >> asAcDSLOperand [ + ^ AcDSLSymbol value: name +] + { #category : #accessing } TRRegisterMappedSymbol >> index [ "Return (sequential) index of symbol.