Search in sources :

Example 6 with MATLABType

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) {
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType) Entry(java.util.Map.Entry) SortedMap(java.util.SortedMap) BufferedReader(java.io.BufferedReader)

Aggregations

MATLABType (com.rockwellcollins.atc.agree.codegen.ast.MATLABType)6 MATLABExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr)5 MATLABIdExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr)4 MATLABLocalBusVarInit (com.rockwellcollins.atc.agree.codegen.ast.MATLABLocalBusVarInit)3 MATLABBinaryExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryExpr)3 MATLABBoolExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBoolExpr)3 MATLABTypeCastExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeCastExpr)3 MATLABTypeInitExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeInitExpr)3 MATLABUnaryExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABUnaryExpr)3 Entry (java.util.Map.Entry)3 TreeMap (java.util.TreeMap)3 MATLABArrayAccessExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABArrayAccessExpr)2 MATLABBusElementExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBusElementExpr)2 MATLABDoubleExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABDoubleExpr)2 MATLABIntExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIntExpr)2 SortedMap (java.util.SortedMap)2 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)2 ArrayExpr (jkind.lustre.ArrayExpr)2 ArrayUpdateExpr (jkind.lustre.ArrayUpdateExpr)2 BinaryExpr (jkind.lustre.BinaryExpr)2