Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mbe-tools
utilities
Commits
7e7b0d4d
Commit
7e7b0d4d
authored
Mar 01, 2021
by
razvan
Browse files
comments added
parent
d796ff06
Changes
3
Hide whitespace changes
Inline
Side-by-side
analysis/fr.mem4csd.analysis.otawa/src/fr/mem4csd/analysis/workflowanalysisotawa/impl/AadlToOtawaFlowFactsImpl.java
View file @
7e7b0d4d
...
...
@@ -7,27 +7,18 @@ import de.mdelab.workflow.components.impl.WorkflowComponentImpl;
import
de.mdelab.workflow.impl.WorkflowExecutionException
;
import
fr.mem4csd.analysis.workflowanalysisotawa.AadlToOtawaFlowFacts
;
import
fr.mem4csd.analysis.workflowanalysisotawa.WorkflowanalysisotawaPackage
;
import
fr.mem4csd.analysis.workflowanalysisotawa.util.MyPair
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
javax.swing.plaf.basic.BasicRootPaneUI
;
import
org.eclipse.core.runtime.IProgressMonitor
;
import
org.eclipse.emf.common.notify.Notification
;
...
...
@@ -36,21 +27,14 @@ import org.eclipse.emf.ecore.EClass;
import
org.eclipse.emf.ecore.EObject
;
import
org.eclipse.emf.ecore.impl.ENotificationImpl
;
import
org.eclipse.emf.ecore.resource.Resource
;
import
org.osate.aadl2.BehavioredImplementation
;
import
org.osate.aadl2.ContainmentPathElement
;
import
org.osate.aadl2.IntegerLiteral
;
import
org.osate.aadl2.ListValue
;
import
org.osate.aadl2.NamedElement
;
import
org.osate.aadl2.Property
;
import
org.osate.aadl2.PropertyAssociation
;
import
org.osate.aadl2.PropertyExpression
;
import
org.osate.aadl2.SubprogramCall
;
import
org.osate.aadl2.SubprogramCallSequence
;
import
org.osate.aadl2.SubprogramSubcomponent
;
import
org.osate.aadl2.ThreadImplementation
;
import
org.osate.aadl2.instance.ComponentInstance
;
import
org.osate.aadl2.instance.SystemInstance
;
import
org.osate.utils.PropertyUtils
;
/**
* <!-- begin-user-doc -->
...
...
@@ -275,11 +259,8 @@ public class AadlToOtawaFlowFactsImpl extends WorkflowComponentImpl implements A
SystemInstance
system
=
(
SystemInstance
)
srcInstanceModel
.
getContents
().
get
(
0
);
// TODO
//String outputFlowFactsFile = this.outputFlowFactsFile;
String
outputFlowFactsFile
=
"../fr.mem4csd.analysis.otawa.tests.sources/model/output/test_flowfacts.ff"
;
String
outputFlowFactsFile
=
"../fr.mem4csd.analysis.otawa.tests.sources/model/output/test_flowfacts.ff"
;
// TODO
/*
* 0. Create output directory
...
...
@@ -314,14 +295,14 @@ public class AadlToOtawaFlowFactsImpl extends WorkflowComponentImpl implements A
}
/*
* 2. Collect all loop bounds in AADL description file
* 2. Collect all loop bounds in
the
AADL description file
*
* It is
first
assumed that the architecture is composed of only one process,
* which contains only one thread, which
doe
s 0, 1 or many
calls to
subprograms.
* In their turn, each one of these subprogram c
an call
0, 1 or many other subprograms.
* It is assumed that the architecture is composed of only one process,
* which contains only one thread, which
contain
s 0, 1 or many subprogram
subcomponent
s.
* In their turn, each one of these subprogram c
ontains
0, 1 or many other subprogram
subcomponent
s.
*/
// will contain loop bounds for function main and each call (if the Loop_Bounds property is defined)
//
loopBounds
will contain loop bounds for function main and each
function
call (if the Loop_Bounds property is defined)
HashMap
<
String
,
LinkedList
<
Integer
>>
loopBounds
=
new
HashMap
<
String
,
LinkedList
<
Integer
>>();
ThreadImplementation
main_thread
=
(
ThreadImplementation
)
system
.
getComponentInstances
().
get
(
0
)
...
...
@@ -329,21 +310,23 @@ public class AadlToOtawaFlowFactsImpl extends WorkflowComponentImpl implements A
for
(
PropertyAssociation
propertyAssociation
:
main_thread
.
getAllPropertyAssociations
())
{
// skip other properties than Loop_Bounds
if
(!
propertyAssociation
.
getProperty
().
getName
().
equals
(
"Loop_Bounds"
))
{
break
;
}
String
callsStackPath
=
main_thread
.
getTypeName
();
// "main"
// A. Build the call sequence type (e.g. main, main.f.g, main.g...)
String
callSequence
=
main_thread
.
getTypeName
();
// "main"
if
(!
propertyAssociation
.
getAppliesTos
().
isEmpty
())
{
// if loop in a subprogram
ContainmentPathElement
path
=
propertyAssociation
.
getAppliesTos
().
get
(
0
).
getPath
();
while
(
path
!=
null
)
{
call
sStackPath
=
callsStackPath
+
"."
+
((
SubprogramSubcomponent
)
path
.
getNamedElement
()).
getComponentType
().
getName
();
call
Sequence
=
callSequence
+
"."
+
((
SubprogramSubcomponent
)
path
.
getNamedElement
()).
getComponentType
().
getName
();
path
=
path
.
getPath
();
}
}
// B. Add the loop bounds to the right call sequence type
LinkedList
<
Integer
>
boundsList
=
new
LinkedList
<
Integer
>();
assert
propertyAssociation
.
getOwnedValues
().
get
(
0
).
getOwnedValue
()
instanceof
ListValue
;
ListValue
listValue
=
(
ListValue
)
propertyAssociation
.
getOwnedValues
().
get
(
0
).
getOwnedValue
();
...
...
@@ -354,10 +337,10 @@ public class AadlToOtawaFlowFactsImpl extends WorkflowComponentImpl implements A
boundsList
.
add
((
int
)
intLiteral
.
getValue
());
}
if
(
loopBounds
.
containsKey
(
call
sStackPath
))
{
loopBounds
.
get
(
call
sStackPath
).
addAll
(
boundsList
);
if
(
loopBounds
.
containsKey
(
call
Sequence
))
{
loopBounds
.
get
(
call
Sequence
).
addAll
(
boundsList
);
}
else
{
loopBounds
.
put
(
call
sStackPath
,
boundsList
);
loopBounds
.
put
(
call
Sequence
,
boundsList
);
}
}
...
...
@@ -373,24 +356,26 @@ public class AadlToOtawaFlowFactsImpl extends WorkflowComponentImpl implements A
{
fileIn
=
new
BufferedReader
(
new
FileReader
(
outputFlowFactsFile
));
StringBuffer
inputBuffer
=
new
StringBuffer
();
Pattern
pattern
=
Pattern
.
compile
(
"\"([^\"]*)\""
);
Pattern
pattern
=
Pattern
.
compile
(
"\"([^\"]*)\""
);
// matches words in quotes (call sequence)
String
line
;
// A. Read the pre-filed Flow Facts file and modify lines that need to be modified
while
((
line
=
fileIn
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"?"
))
{
List
<
String
>
functions
=
new
LinkedList
<>();
Matcher
matcher
=
pattern
.
matcher
(
line
);
assert
matcher
.
find
();
// the first occurrence is not part of the call
s
s
tack
assert
matcher
.
find
();
// the first occurrence is not part of the call s
equence
while
(
matcher
.
find
())
{
functions
.
add
(
matcher
.
group
(
1
));
}
String
call
sStack
=
String
.
join
(
"."
,
functions
);
String
call
Sequence
=
String
.
join
(
"."
,
functions
);
// Look for anomalies
if
(
loopBounds
.
containsKey
(
call
sStack
))
{
line
=
line
.
replace
(
"?"
,
loopBounds
.
get
(
call
sStack
).
pop
().
toString
());
if
(
loopBounds
.
containsKey
(
call
Sequence
)
&&
!
loopBounds
.
get
(
callSequence
).
isEmpty
(
))
{
line
=
line
.
replace
(
"?"
,
loopBounds
.
get
(
call
Sequence
).
pop
().
toString
());
}
else
{
System
.
out
.
println
(
"ERROR: CALLS STACK "
+
call
sStack
+
" NOT PRESENT IN MODEL"
);
System
.
out
.
println
(
"ERROR: CALLS STACK "
+
call
Sequence
+
" NOT PRESENT IN MODEL"
);
}
}
inputBuffer
.
append
(
line
);
...
...
@@ -398,6 +383,7 @@ public class AadlToOtawaFlowFactsImpl extends WorkflowComponentImpl implements A
}
fileIn
.
close
();
// B. Write the content of the StringBuffer in the right file
fileOut
=
new
FileOutputStream
(
outputFlowFactsFile
);
fileOut
.
write
(
inputBuffer
.
toString
().
getBytes
());
fileOut
.
close
();
...
...
@@ -420,8 +406,7 @@ public class AadlToOtawaFlowFactsImpl extends WorkflowComponentImpl implements A
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
}
}
// Look for anomalies
...
...
@@ -433,4 +418,4 @@ public class AadlToOtawaFlowFactsImpl extends WorkflowComponentImpl implements A
}
}
}
//AadlToOtawaFlowFactsImpl
}
//AadlToOtawaFlowFactsImpl
\ No newline at end of file
analysis/fr.mem4csd.analysis.otawa/src/fr/mem4csd/analysis/workflowanalysisotawa/impl/AadlToOtawaFlowFactsStateMachineImpl.java
View file @
7e7b0d4d
...
...
@@ -7,7 +7,7 @@ import de.mdelab.workflow.components.impl.WorkflowComponentImpl;
import
de.mdelab.workflow.impl.WorkflowExecutionException
;
import
fr.mem4csd.analysis.workflowanalysisotawa.AadlToOtawaFlowFactsStateMachine
;
import
fr.mem4csd.analysis.workflowanalysisotawa.WorkflowanalysisotawaPackage
;
import
fr.mem4csd.analysis.workflowanalysisotawa.util.Call
Path
ToTransitionMap
;
import
fr.mem4csd.analysis.workflowanalysisotawa.util.Call
Sequence
ToTransitionMap
;
import
fr.mem4csd.analysis.workflowanalysisotawa.util.OtawaAnalysisGraph
;
import
java.awt.Color
;
...
...
@@ -383,17 +383,17 @@ public class AadlToOtawaFlowFactsStateMachineImpl extends WorkflowComponentImpl
* 5. Flow Facts file modification
*/
HashMap
<
String
,
String
>
transitionsMap
=
new
Call
Path
ToTransitionMap
(
system
.
getComponentInstances
().
get
(
0
).
getComponentInstances
().
get
(
0
));
HashMap
<
String
,
String
>
transitionsMap
=
new
Call
Sequence
ToTransitionMap
(
system
.
getComponentInstances
().
get
(
0
).
getComponentInstances
().
get
(
0
));
Iterator
<
String
>
iterator
=
loopBoundsMap
.
keySet
().
iterator
();
// needs a LinkedHashMap here
while
(
iterator
.
hasNext
())
{
String
currentCall
Path
=
iterator
.
next
();
String
currentTransition
=
transitionsMap
.
get
(
currentCall
Path
.
split
(
"\\."
)[
0
]);
while
(!
loopBoundsMap
.
get
(
currentCall
Path
).
isEmpty
())
String
currentCall
Sequence
=
iterator
.
next
();
String
currentTransition
=
transitionsMap
.
get
(
currentCall
Sequence
.
split
(
"\\."
)[
0
]);
while
(!
loopBoundsMap
.
get
(
currentCall
Sequence
).
isEmpty
())
{
modifyFlowFactsFile
(
outputFlowFactsFile
,
loopBoundsMap
.
get
(
currentCall
Path
),
otawaCallsMap
.
get
(
currentCall
Path
),
loopBoundsMap
.
get
(
currentCall
Sequence
),
otawaCallsMap
.
get
(
currentCall
Sequence
),
addedSymbolsTable
.
get
(
"MYLABEL_transition_start_"
+
currentTransition
),
addedSymbolsTable
.
get
(
"MYLABEL_transition_end_"
+
currentTransition
));
}
...
...
@@ -408,21 +408,22 @@ public class AadlToOtawaFlowFactsStateMachineImpl extends WorkflowComponentImpl
/*
* 7. Map addresses in addedSymbolsTable to BB numbers)
*/
HashMap
<
String
,
Integer
>
addedSymbolsTableTranslated
=
new
HashMap
<
String
,
Integer
>();
initAddedSymbolsTableTranslation
(
addedSymbolsTable
,
addedSymbolsTableTranslated
);
/*
* 8. ILP equations addition (state machine behavior +
complete
states management)
* 8. ILP equations addition (
declarations +
state machine behavior +
Dummy / initial / complete / final
states management)
*/
makeILPEquationsFile
(
outputILPEquationsFile
,
system
.
getComponentInstances
().
get
(
0
).
getComponentInstances
().
get
(
0
),
otawaAnalysisGraph
,
addedSymbolsTableTranslated
,
1
,
// dummyToCompleteTotal
1
,
// completeOutgoingTotal
1
,
// completeToDummyTotal
0
,
// dummyToInitialNotComplete
1
,
// dummyToCompleteTotal
1
,
// completeOutgoingTotal
1
,
// completeToDummyTotal
0
,
// dummyToInitialNotComplete
0
);
// finalNotCompleteToDummy
}
...
...
@@ -483,10 +484,12 @@ public class AadlToOtawaFlowFactsStateMachineImpl extends WorkflowComponentImpl
for
(
PropertyAssociation
propertyAssociation
:
mainThread
.
getAllPropertyAssociations
())
{
// skip other properties than Loop_Bounds
if
(!
propertyAssociation
.
getProperty
().
getName
().
equals
(
"Loop_Bounds"
))
{
break
;
}
// A. Build the AADL call sequence (e.g. f1, f3.g0...) and the OTAWA call sequence type (e.g. main.f, main.f.g...)
String
aadlCalls
=
""
;
String
otawaCalls
=
"main"
;
if
(!
propertyAssociation
.
getAppliesTos
().
isEmpty
())
{
// always true
...
...
@@ -499,6 +502,7 @@ public class AadlToOtawaFlowFactsStateMachineImpl extends WorkflowComponentImpl
}
}
// B. Add the loop bounds to the right call sequence
LinkedList
<
Integer
>
loopBounds
=
new
LinkedList
<
Integer
>();
assert
propertyAssociation
.
getOwnedValues
().
get
(
0
).
getOwnedValue
()
instanceof
ListValue
;
ListValue
listValue
=
(
ListValue
)
propertyAssociation
.
getOwnedValues
().
get
(
0
).
getOwnedValue
();
...
...
@@ -523,7 +527,7 @@ public class AadlToOtawaFlowFactsStateMachineImpl extends WorkflowComponentImpl
{
String
inputBinary
=
"../fr.mem4csd.analysis.otawa.tests.sources/model/input/binary_statemachine.elf"
;
// TODO
String
command
=
"/opt/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-objdump"
+
" -t "
+
inputBinary
+
" | grep MYLABEL_ | awk -F' ' '{print $5 \" \" $1}'"
;
+
" -t "
+
inputBinary
+
" | grep MYLABEL_ | awk -F' ' '{print $5 \" \" $1}'"
;
// TODO
try
{
Process
p
=
Runtime
.
getRuntime
().
exec
(
new
String
[]
{
"/bin/sh"
,
"-c"
,
command
});
...
...
@@ -646,9 +650,11 @@ public class AadlToOtawaFlowFactsStateMachineImpl extends WorkflowComponentImpl
fileIn
=
new
BufferedReader
(
new
FileReader
(
outputFlowFactsFile
));
StringBuffer
outputBuffer
=
new
StringBuffer
();
String
line
;
// A. Read the edited Flow Facts file and modify the line containing the last "?"
while
((
line
=
fileIn
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"?"
))
{
if
(
line
.
contains
(
"?"
))
{
// should be entered only once
line
=
line
.
replace
(
"?"
,
""
+
loopBound
);
}
outputBuffer
.
append
(
line
);
...
...
@@ -656,6 +662,7 @@ public class AadlToOtawaFlowFactsStateMachineImpl extends WorkflowComponentImpl
}
fileIn
.
close
();
// B. Write the content of the StringBuffer in the right file
fileOut
=
new
FileOutputStream
(
outputFlowFactsFile
);
fileOut
.
write
(
outputBuffer
.
toString
().
getBytes
());
fileOut
.
close
();
...
...
@@ -740,6 +747,7 @@ public class AadlToOtawaFlowFactsStateMachineImpl extends WorkflowComponentImpl
// A.1. Declaration of DummyStart
printWriter
.
println
(
"bb DummyStart $"
+
addedSymbolsTableTranslated
.
get
(
"MYLABEL_state_start_DummyStart"
));
printWriter
.
println
();
// A.2. Declaration of DummyEnd
printWriter
.
println
(
"bb DummyEnd $"
+
addedSymbolsTableTranslated
.
get
(
"MYLABEL_state_start_DummyEnd"
));
printWriter
.
println
();
...
...
analysis/fr.mem4csd.analysis.otawa/src/fr/mem4csd/analysis/workflowanalysisotawa/util/Call
Path
ToTransitionMap.java
→
analysis/fr.mem4csd.analysis.otawa/src/fr/mem4csd/analysis/workflowanalysisotawa/util/Call
Sequence
ToTransitionMap.java
View file @
7e7b0d4d
...
...
@@ -13,9 +13,9 @@ import org.osate.ba.aadlba.BehaviorTransition;
import
org.osate.ba.aadlba.SubprogramCallAction
;
@SuppressWarnings
(
"serial"
)
public
class
Call
Path
ToTransitionMap
extends
HashMap
<
String
,
String
>
{
public
class
Call
Sequence
ToTransitionMap
extends
HashMap
<
String
,
String
>
{
public
Call
Path
ToTransitionMap
(
ComponentInstance
ci
)
public
Call
Sequence
ToTransitionMap
(
ComponentInstance
ci
)
{
initMap
(
ci
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment