diff --git a/src/FAST-Core-Tools/FASTAbstractVariableVersionSSA.class.st b/src/FAST-Core-Tools/FASTAbstractVariableVersionSSA.class.st index 2776065..b5ce6fa 100644 --- a/src/FAST-Core-Tools/FASTAbstractVariableVersionSSA.class.st +++ b/src/FAST-Core-Tools/FASTAbstractVariableVersionSSA.class.st @@ -1,6 +1,22 @@ +" +I am the abstract representation of a version of a variable in Static Single Assignment form (SSA). A version represents a value assigned exactly once to a variable: each assignment to a variable during the SSA resolution creates a new version. + +I store the local declaration (`localDeclaration`) of the variable this version belongs to, and I provide the common behavior shared by the concrete versions: + +- `localUses` returns the accesses (reads and writes) linked to this version. +- `readAccesses` and `writeAccesses` split those accesses. +- `ssaVariables` returns the plain variable versions I represent: only myself for a `FASTVariableVersionSSA`, all my choices for a `FASTVariablePhiVersionSSA`. +- `name` returns a readable SSA name. + +I have two concrete subclasses: +- `FASTVariableVersionSSA` is a plain version with a version number. +- `FASTVariablePhiVersionSSA` merges several versions at a control-flow join point. + +I require the SSA resolution to have been run on the model before being used. +" Class { #name : 'FASTAbstractVariableVersionSSA', - #superclass : 'Object', + #superclass : 'MooseEntity', #instVars : [ 'localDeclaration' ], @@ -9,6 +25,15 @@ Class { #tag : 'SSA' } +{ #category : 'meta' } +FASTAbstractVariableVersionSSA class >> annotation [ + + + + + +] + { #category : 'instance creation' } FASTAbstractVariableVersionSSA class >> for: aFASTFortranVariable [ @@ -49,7 +74,9 @@ FASTAbstractVariableVersionSSA >> isPhi [ { #category : 'accessing' } FASTAbstractVariableVersionSSA >> localDeclaration [ - ^localDeclaration + + + ^ localDeclaration ] { #category : 'accessing' } @@ -75,6 +102,22 @@ FASTAbstractVariableVersionSSA >> name [ ^ self subclassResponsibility ] +{ #category : 'accessing' } +FASTAbstractVariableVersionSSA >> nodes [ + "Used for LocalResolver" + + + + + ^ self attributeAt: #nodes ifAbsentPut: [ FMMultivalueLink on: self opposite: #ssaVersion: ] +] + +{ #category : 'accessing' } +FASTAbstractVariableVersionSSA >> nodes: aCollectionOfFASTNodes [ + + self nodes value: aCollectionOfFASTNodes +] + { #category : 'printing' } FASTAbstractVariableVersionSSA >> printOn: aStream [ "Generate a string representation of the receiver based on its instance variables." diff --git a/src/FAST-Core-Tools/FASTLocalResolverScoping.class.st b/src/FAST-Core-Tools/FASTLocalResolverScoping.class.st index 0bffefd..895ce47 100644 --- a/src/FAST-Core-Tools/FASTLocalResolverScoping.class.st +++ b/src/FAST-Core-Tools/FASTLocalResolverScoping.class.st @@ -19,8 +19,7 @@ Class { { #category : 'api' } FASTLocalResolverScoping >> addUse: referingNode toLocalDeclaration: declarationNode [ - referingNode localDeclaration: declarationNode. - declarationNode addLocalUse: referingNode + referingNode localDeclaration: declarationNode ] { #category : 'api' } diff --git a/src/FAST-Core-Tools/FASTNonLocalDeclaration.class.st b/src/FAST-Core-Tools/FASTNonLocalDeclaration.class.st index 150d792..14bc918 100644 --- a/src/FAST-Core-Tools/FASTNonLocalDeclaration.class.st +++ b/src/FAST-Core-Tools/FASTNonLocalDeclaration.class.st @@ -3,17 +3,22 @@ A ""null-object"" signaling the declaration of a 'name' was not found " Class { #name : 'FASTNonLocalDeclaration', - #superclass : 'FASTEntity', - #traits : 'FASTTCanBeLocalDeclaration', - #classTraits : 'FASTTCanBeLocalDeclaration classTrait', - #instVars : [ - 'name' - ], + #superclass : 'MooseEntity', + #traits : 'FASTTCanBeLocalDeclaration + FamixTNamedEntity', + #classTraits : 'FASTTCanBeLocalDeclaration classTrait + FamixTNamedEntity classTrait', #category : 'FAST-Core-Tools-Resolver', #package : 'FAST-Core-Tools', #tag : 'Resolver' } +{ #category : 'meta' } +FASTNonLocalDeclaration class >> annotation [ + + + + +] + { #category : 'accessing' } FASTNonLocalDeclaration >> activeVersion [ "Used for LocalResolver" @@ -31,15 +36,3 @@ FASTNonLocalDeclaration >> isNonLocalDeclaration [ FASTNonLocalDeclaration >> localDeclarationName [ ^ self localUses anyOne localDeclarationName ] - -{ #category : 'accessing' } -FASTNonLocalDeclaration >> name [ - - ^ name -] - -{ #category : 'accessing' } -FASTNonLocalDeclaration >> name: anObject [ - - name := anObject -] diff --git a/src/FAST-Core-Tools/FASTTCanBeLocalDeclaration.extension.st b/src/FAST-Core-Tools/FASTTCanBeLocalDeclaration.extension.st index 494014a..3c7b5cc 100644 --- a/src/FAST-Core-Tools/FASTTCanBeLocalDeclaration.extension.st +++ b/src/FAST-Core-Tools/FASTTCanBeLocalDeclaration.extension.st @@ -18,7 +18,7 @@ FASTTCanBeLocalDeclaration >> activeVersion: aSSAVersion [ FASTTCanBeLocalDeclaration >> addLocalUse: aFASTNode [ "Used for LocalResolver" - (self attributeAt: #localUses ifAbsent: [ Error signal: 'missing #localUses attribute in ' , self asString ]) add: aFASTNode + self localUses add: aFASTNode ] { #category : '*FAST-Core-Tools' } @@ -69,7 +69,7 @@ FASTTCanBeLocalDeclaration >> assignedExpressionsMap [ FASTTCanBeLocalDeclaration >> clearLocalUses [ "Used for LocalResolver" - self attributeAt: #localUses put: OrderedCollection new + self localUses removeAll ] { #category : '*FAST-Core-Tools' } @@ -83,18 +83,21 @@ FASTTCanBeLocalDeclaration >> hasLocalDeclaration [ FASTTCanBeLocalDeclaration >> localDeclaration [ "Used for LocalResolver" - ^ self localDeclarationIfAbsent: [ - self error: 'Missing #localDeclaration attribute in ' , self asString , '. It can have multiple sources: -- The local resolution was not done (launch the local resolver visitor or the SSA visitor on your top module) -- The entity is not an entity with a definition -- There is a bug in the local resolver' ] + + + ^ self attributeAt: #localDeclaration ifAbsent: [ nil ] ] { #category : '*FAST-Core-Tools' } FASTTCanBeLocalDeclaration >> localDeclaration: aDeclarationNode [ "Used for LocalResolver" - self attributeAt: #localDeclaration put: aDeclarationNode + self attributeAt: #localDeclaration put: (FMMultivalueLink + on: self + update: #localUses + from: (self localDeclarationIfAbsent: [ nil ]) + to: aDeclarationNode) ] { #category : '*FAST-Core-Tools' } @@ -115,14 +118,18 @@ FASTTCanBeLocalDeclaration >> localDeclarationifPresent: aBlock ifAbsent: anothe FASTTCanBeLocalDeclaration >> localUses [ "Used for LocalResolver" - ^ self attributeAt: #localUses ifAbsent: [ Error signal: 'missing #localUses attribute in ' , self asString ] + + + + ^ self attributeAt: #localUses ifAbsentPut: [ FMMultivalueLink on: self opposite: #localDeclaration: ] ] { #category : '*FAST-Core-Tools' } FASTTCanBeLocalDeclaration >> localUses: aCollection [ "Used for LocalResolver" - self attributeAt: #localUses put: aCollection + self localUses value: aCollection ] { #category : '*FAST-Core-Tools' } @@ -143,8 +150,9 @@ FASTTCanBeLocalDeclaration >> ssaName [ { #category : '*FAST-Core-Tools' } FASTTCanBeLocalDeclaration >> ssaVersion [ - "If I represent a variable and we resolved the SSA of my FAST model, I'll return the SSA version I'm linked to." + + ^ self attributeAt: #ssaVersion ifAbsent: [ nil ] ] @@ -152,7 +160,11 @@ FASTTCanBeLocalDeclaration >> ssaVersion [ FASTTCanBeLocalDeclaration >> ssaVersion: aSSAVersion [ "Used for SSA" - self attributeAt: #ssaVersion put: aSSAVersion + self attributeAt: #ssaVersion put: (FMMultivalueLink + on: self + update: #nodes + from: self ssaVersion + to: aSSAVersion) ] { #category : '*FAST-Core-Tools' } diff --git a/src/FAST-Core-Tools/FASTVariablePhiVersionSSA.class.st b/src/FAST-Core-Tools/FASTVariablePhiVersionSSA.class.st index 74f719f..e0a3d47 100644 --- a/src/FAST-Core-Tools/FASTVariablePhiVersionSSA.class.st +++ b/src/FAST-Core-Tools/FASTVariablePhiVersionSSA.class.st @@ -1,14 +1,31 @@ +" +I am a phi version of a variable, created at a control-flow join point (for example at the end of an if statement or a loop) to merge the versions coming from the different branches. + +I hold the versions I merge (`choices`) and the local declaration (`localDeclaration`) of the variable. + +My name is built from the names of my choices, for example `phi(x_1, x_2)`. + +I require the SSA resolution to have been run on the model before being used. +" Class { #name : 'FASTVariablePhiVersionSSA', #superclass : 'FASTAbstractVariableVersionSSA', #instVars : [ - 'choices' + '#choices => FMMany type: #FASTVariableVersionSSA opposite: #phiVersionContainers' ], #category : 'FAST-Core-Tools-SSA', #package : 'FAST-Core-Tools', #tag : 'SSA' } +{ #category : 'meta' } +FASTVariablePhiVersionSSA class >> annotation [ + + + + +] + { #category : 'adding' } FASTVariablePhiVersionSSA >> addChoiceToPhi: aPhiVersion [ @@ -18,7 +35,14 @@ FASTVariablePhiVersionSSA >> addChoiceToPhi: aPhiVersion [ { #category : 'accessing' } FASTVariablePhiVersionSSA >> choices [ - ^choices + + ^ choices +] + +{ #category : 'accessing' } +FASTVariablePhiVersionSSA >> choices: anObject [ + + choices value: anObject ] { #category : 'instance creation' } @@ -26,7 +50,6 @@ FASTVariablePhiVersionSSA >> for: aCollection [ localDeclaration := aCollection anyOne localDeclaration. - choices := OrderedCollection new. aCollection do: [ :v | v addChoiceToPhi: self ] ] diff --git a/src/FAST-Core-Tools/FASTVariableVersionSSA.class.st b/src/FAST-Core-Tools/FASTVariableVersionSSA.class.st index c27bbda..8d8817c 100644 --- a/src/FAST-Core-Tools/FASTVariableVersionSSA.class.st +++ b/src/FAST-Core-Tools/FASTVariableVersionSSA.class.st @@ -1,14 +1,30 @@ +" +I am a plain SSA version of a variable, created each time the variable is assigned. I hold the version number (`version`) of the variable and the local declaration (`localDeclaration`) I belong to. + +My name is built from the name of my local declaration and my version number, for example `x_1`. + +I require the SSA resolution to have been run on the model before being used. +" Class { #name : 'FASTVariableVersionSSA', #superclass : 'FASTAbstractVariableVersionSSA', #instVars : [ - 'version' + '#version', + '#phiVersionContainers => FMMany type: #FASTVariablePhiVersionSSA opposite: #choices' ], #category : 'FAST-Core-Tools-SSA', #package : 'FAST-Core-Tools', #tag : 'SSA' } +{ #category : 'meta' } +FASTVariableVersionSSA class >> annotation [ + + + + +] + { #category : 'adding' } FASTVariableVersionSSA >> addChoiceToPhi: aPhiVersion [ @@ -45,6 +61,19 @@ FASTVariableVersionSSA >> newVersionNumber [ ^ version := version + 1 ] +{ #category : 'accessing' } +FASTVariableVersionSSA >> phiVersionContainers [ + + + ^ phiVersionContainers +] + +{ #category : 'accessing' } +FASTVariableVersionSSA >> phiVersionContainers: aCollection [ + + phiVersionContainers value: aCollection +] + { #category : 'testing' } FASTVariableVersionSSA >> sameVariableAs: otherFASTFortranVariable [ @@ -60,6 +89,8 @@ FASTVariableVersionSSA >> ssaVariables [ { #category : 'accessing' } FASTVariableVersionSSA >> version [ + + ^ version ] diff --git a/src/FAST-Core-Tools/ManifestFASTCoreTools.class.st b/src/FAST-Core-Tools/ManifestFASTCoreTools.class.st new file mode 100644 index 0000000..fd4c03f --- /dev/null +++ b/src/FAST-Core-Tools/ManifestFASTCoreTools.class.st @@ -0,0 +1,17 @@ +" +Please comment package here +" +Class { + #name : 'ManifestFASTCoreTools', + #superclass : 'PackageManifest', + #category : 'FAST-Core-Tools-Manifest', + #package : 'FAST-Core-Tools', + #tag : 'Manifest' +} + +{ #category : 'asserting' } +ManifestFASTCoreTools class >> shouldBeIncludedByDefaultInMetamodelsWith: aCollectionOfPackages [ + "Includes in MM that are based on FAST" + + ^ aCollectionOfPackages anySatisfy: [ :package | package definedClasses anySatisfy: [ :class | class = FASTTEntity ] ] +]