use of com.rockwellcollins.atc.agree.codegen.ast.MATLABType in project AGREE by loonwerks.
the class MdlScriptCreator method createScript.
@Override
protected void createScript() throws Exception {
boolean firstPort = true;
boolean firstBusObj = true;
boolean firstSignal = true;
writeline("%% This script generates an implementation or verification model for the given component");
writeline("%% Initialize variables that come from the dialog in OSATE%%");
writeline("% 'Output Directory'");
writeline("dir_path = " + "'" + outputDir + "';");
writeline("% 'Model to Insert Observer'");
writeline("implMdlPath = '" + implMdl + "';");
writeline("% 'Subsystem to verify'");
writeline("subsysName = " + "'" + subSysName + "';");
newline();
writeline("%% Initialize varables based on generation parameters and AADL elements");
writeline("% name of verification script (contians AGREE contract scripting)");
writeline("scriptName = " + "'" + scriptName + "';");
writeline("% type of model to generate: 1 = implementation model, 2 = verification model");
write("generate_mode = ");
if (createImplModel) {
writeline("1");
} else {
writeline("2");
}
writeline("%% the I/O from AADL");
firstPort = true;
write("inportnames = {");
for (String inName : inportnames) {
if (!firstPort) {
write(", ");
}
write("'" + inName + "'");
firstPort = false;
}
write("};");
newline();
firstPort = true;
write("inporttypes = {");
for (String inType : inporttypes) {
if (!firstPort) {
write(", ");
}
write("'" + inType + "'");
firstPort = false;
}
write("};");
newline();
newline();
firstPort = true;
write("outportnames = {");
for (String outName : outportnames) {
if (!firstPort) {
write(", ");
}
write("'" + outName + "'");
firstPort = false;
}
write("};");
newline();
firstPort = true;
write("outporttypes = {");
for (String outType : outporttypes) {
if (!firstPort) {
write(", ");
}
write("'" + outType + "'");
firstPort = false;
}
writeline("};");
firstBusObj = true;
write("busdefs = {");
Iterator<Entry<String, SortedMap<String, MATLABType>>> busIterator = busdefs.entrySet().iterator();
while (busIterator.hasNext()) {
if (!firstBusObj) {
writeline(",';'...");
write(" ");
}
Entry<String, SortedMap<String, MATLABType>> busEntry = busIterator.next();
// print bus type
write("'" + busEntry.getKey() + "',");
firstSignal = true;
Iterator<Entry<String, MATLABType>> elemIterator = busEntry.getValue().entrySet().iterator();
while (elemIterator.hasNext()) {
if (!firstSignal) {
write(",");
}
Entry<String, MATLABType> elemEntry = elemIterator.next();
// print bus element type followed by element ID
write("'" + portTypeNameUpdate(elemEntry.getValue()) + "','" + elemEntry.getKey() + "'");
firstSignal = false;
}
firstBusObj = false;
}
writeline(",';'};");
newline();
writeline("%% Initialize varables based on general settings, not set by the exporter script");
newline();
writeline("% these are computed from variables above");
writeline("[~,implMdlNameNoExtension,~] = fileparts(implMdlPath);");
writeline("[~,verifMdlNameNoExtension,~] = fileparts('" + verifMdlName + "');");
InputStream stream = getClass().getResourceAsStream("/resources/FixedScript.txt");
String str = "";
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
try {
if (stream != null) {
while ((str = reader.readLine()) != null) {
writeline(str);
}
}
} finally {
reader.close();
}
} finally {
try {
stream.close();
} catch (Throwable ignore) {
}
}
}
Aggregations