Commit 7e7b0d4d authored by razvan's avatar razvan
Browse files

comments added

parent d796ff06
......@@ -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 does 0, 1 or many calls to subprograms.
* In their turn, each one of these subprogram can 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 contains 0, 1 or many subprogram subcomponents.
* In their turn, each one of these subprogram contains 0, 1 or many other subprogram subcomponents.
*/
// 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)
{
callsStackPath = callsStackPath + "." + ((SubprogramSubcomponent) path.getNamedElement()).getComponentType().getName();
callSequence = 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(callsStackPath)) {
loopBounds.get(callsStackPath).addAll(boundsList);
if (loopBounds.containsKey(callSequence)) {
loopBounds.get(callSequence).addAll(boundsList);
} else {
loopBounds.put(callsStackPath, boundsList);
loopBounds.put(callSequence, 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 calls stack
assert matcher.find(); // the first occurrence is not part of the call sequence
while (matcher.find())
{
functions.add(matcher.group(1));
}
String callsStack = String.join(".", functions);
String callSequence = String.join(".", functions);
// Look for anomalies
if (loopBounds.containsKey(callsStack)) {
line = line.replace("?", loopBounds.get(callsStack).pop().toString());
if (loopBounds.containsKey(callSequence) && !loopBounds.get(callSequence).isEmpty()) {
line = line.replace("?", loopBounds.get(callSequence).pop().toString());
} else {
System.out.println("ERROR: CALLS STACK " + callsStack + " NOT PRESENT IN MODEL");
System.out.println("ERROR: CALLS STACK " + callSequence + " 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
......@@ -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.CallPathToTransitionMap;
import fr.mem4csd.analysis.workflowanalysisotawa.util.CallSequenceToTransitionMap;
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 CallPathToTransitionMap(system.getComponentInstances().get(0).getComponentInstances().get(0));
HashMap<String, String> transitionsMap = new CallSequenceToTransitionMap(system.getComponentInstances().get(0).getComponentInstances().get(0));
Iterator<String> iterator = loopBoundsMap.keySet().iterator(); // needs a LinkedHashMap here
while (iterator.hasNext())
{
String currentCallPath = iterator.next();
String currentTransition = transitionsMap.get(currentCallPath.split("\\.")[0]);
while (!loopBoundsMap.get(currentCallPath).isEmpty())
String currentCallSequence = iterator.next();
String currentTransition = transitionsMap.get(currentCallSequence.split("\\.")[0]);
while (!loopBoundsMap.get(currentCallSequence).isEmpty())
{
modifyFlowFactsFile(outputFlowFactsFile,
loopBoundsMap.get(currentCallPath),
otawaCallsMap.get(currentCallPath),
loopBoundsMap.get(currentCallSequence),
otawaCallsMap.get(currentCallSequence),
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();
......
......@@ -13,9 +13,9 @@ import org.osate.ba.aadlba.BehaviorTransition;
import org.osate.ba.aadlba.SubprogramCallAction;
@SuppressWarnings("serial")
public class CallPathToTransitionMap extends HashMap<String, String> {
public class CallSequenceToTransitionMap extends HashMap<String, String> {
public CallPathToTransitionMap(ComponentInstance ci)
public CallSequenceToTransitionMap(ComponentInstance ci)
{
initMap(ci);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment