Search in sources :

Example 1 with Option

use of org.sireum.Option in project osate-plugin by sireum.

the class LaunchHAMR method runJob.

@Override
public IStatus runJob(Element elem, IProgressMonitor monitor) {
    prompt = null;
    MessageConsole console = displayConsole();
    console.clearConsole();
    if (// 
    !Util.emitSireumVersion(console) || !(ApiUtil.hamrCliApiCompatible(new PrintStream(console.newMessageStream())))) {
        displayPopup("HAMR code generation was unsuccessful");
        return Status.CANCEL_STATUS;
    }
    SystemInstance si = getSystemInstance(elem);
    if (si == null) {
        Dialog.showError(getToolName(), "Please select a system implementation or a system instance");
        return Status.CANCEL_STATUS;
    }
    writeToConsole("Generating AIR ...");
    Aadl model = Util.getAir(si, true, console);
    if (model != null) {
        final int bit_width = HAMRPropertyProvider.getDefaultBitWidthFromElement(si);
        if (!HAMRPropertyProvider.bitWidths.contains(bit_width)) {
            String options = HAMRPropertyProvider.bitWidths.stream().map(Object::toString).collect(Collectors.joining(", "));
            displayPopup("Invalid bit width: " + bit_width + ".  Valid options are " + options);
            return Status.CANCEL_STATUS;
        }
        final int max_seq_size = HAMRPropertyProvider.getDefaultMaxSequenceSizeFromElement(si);
        if (max_seq_size < 0) {
            displayPopup("Max sequence size must be greater than or equal to 0");
            return Status.CANCEL_STATUS;
        }
        final int max_string_size = HAMRPropertyProvider.getDefaultMaxStringSizeFromElement(si);
        if (max_string_size < 0) {
            displayPopup("Max string size must be greater than or equal to 0");
            return Status.CANCEL_STATUS;
        }
        List<Platform> platforms = HAMRPropertyProvider.getPlatformsFromElement(si);
        List<HW> hardwares = HAMRPropertyProvider.getHWsFromElement(si);
        if (PreferenceValues.HAMR_SERIALIZE_AIR_OPT.getValue()) {
            File f = serializeToFile(model, PreferenceValues.HAMR_AIR_OUTPUT_FOLDER_OPT.getValue(), si);
            writeToConsole("Wrote: " + f.getAbsolutePath());
        }
        Display.getDefault().syncExec(() -> {
            prompt = new HAMRPrompt(getProject(si), getShell(), si.getComponentImplementation().getFullName(), platforms, hardwares, bit_width, max_seq_size, max_string_size);
            prompt.open();
        });
        if (prompt.getReturnCode() == Window.OK) {
            try {
                int toolRet = 0;
                List<Report> report = HAMRUtil.checkModel(si, prompt);
                for (Report r : report) {
                    writeToConsole(r.toString());
                    if (r instanceof ErrorReport) {
                        toolRet = 1;
                    }
                }
                if (toolRet == 0) {
                    writeToConsole("Generating " + getToolName() + " artifacts...");
                    final File workspaceRoot = getProjectPath(si).toFile();
                    final org.sireum.String _slangOutputDir = // 
                    prompt.getSlangOptionOutputDirectory().equals("") ? new org.sireum.String(workspaceRoot.getAbsolutePath()) : new org.sireum.String(prompt.getSlangOptionOutputDirectory());
                    final org.sireum.String _base = // 
                    prompt.getOptionBasePackageName().equals("") ? new org.sireum.String(HAMRUtil.cleanupPackageName(new File(_slangOutputDir.string()).getName())) : new org.sireum.String(HAMRUtil.cleanupPackageName(prompt.getOptionBasePackageName()));
                    final org.sireum.String _cOutputDirectory = // 
                    prompt.getOptionCOutputDirectory().equals("") ? null : new org.sireum.String(prompt.getOptionCOutputDirectory());
                    org.sireum.String _camkesOutputDir = // 
                    prompt.getOptionCamkesOptionOutputDirectory().equals("") ? null : new org.sireum.String(prompt.getOptionCamkesOptionOutputDirectory());
                    toolRet = Util.callWrapper(getToolName(), console, () -> {
                        boolean verbose = PreferenceValues.HAMR_VERBOSE_OPT.getValue();
                        String platform = prompt.getOptionPlatform().hamrName();
                        Option<org.sireum.String> slangOutputDir = ArsitBridge.sireumOption(_slangOutputDir);
                        Option<org.sireum.String> slangPackageName = ArsitBridge.sireumOption(_base);
                        boolean noProyekIve = !PreferenceValues.HAMR_RUN_PROYEK_IVE_OPT.getValue();
                        boolean noEmbedArt = !PreferenceValues.HAMR_EMBED_ART_OPT.getValue();
                        boolean devicesAsThreads = PreferenceValues.HAMR_DEVICES_AS_THREADS_OPT.getValue();
                        boolean genSbtMill = PreferenceValues.HAMR_GEN_SBT_MILL_OPT.getValue();
                        IS<Z, org.sireum.String> slangAuxCodeDirs = prompt.getOptionCAuxSourceDirectory().equals("") ? VisitorUtil.toISZ() : VisitorUtil.toISZ(new org.sireum.String(prompt.getOptionCAuxSourceDirectory()));
                        Option<org.sireum.String> slangOutputCDirectory = ArsitBridge.sireumOption(_cOutputDirectory);
                        boolean excludeComponentImpl = prompt.getOptionExcludesSlangImplementations();
                        Z bitWidth = SlangUtils.toZ(prompt.getOptionBitWidth());
                        Z maxStringSize = SlangUtils.toZ(prompt.getOptionMaxStringSize());
                        Z maxArraySize = SlangUtils.toZ(prompt.getOptionMaxSequenceSize());
                        boolean runTranspiler = PreferenceValues.HAMR_RUN_TRANSPILER_OPT.getValue();
                        Option<org.sireum.String> camkesOutputDirectory = ArsitBridge.sireumOption(_camkesOutputDir);
                        IS<Z, org.sireum.String> camkesAuxCodeDirs = prompt.getOptionCamkesAuxSrcDir().equals("") ? VisitorUtil.toISZ() : VisitorUtil.toISZ(new org.sireum.String(prompt.getOptionCamkesAuxSrcDir()));
                        Option<org.sireum.String> aadlRootDir = ArsitBridge.sireumOption(new org.sireum.String(workspaceRoot.getAbsolutePath()));
                        List<org.sireum.String> exOptions = new ArrayList<>();
                        if (org.sireum.aadl.osate.PreferenceValues.getPROCESS_BA_OPT()) {
                            exOptions.add(new org.sireum.String("PROCESS_BTS_NODES"));
                        }
                        if (PreferenceValues.HAMR_PROOF_GENERATE.getValue()) {
                            exOptions.add(new org.sireum.String("GENERATE_REFINEMENT_PROOF"));
                        }
                        IS<Z, org.sireum.String> experimentalOptions = VisitorUtil.toISZ(exOptions);
                        Reporter reporter = org.sireum.message.Reporter$.MODULE$.create();
                        Z codegenRet = // 
                        org.sireum.cli.HAMR.codeGenR(// 
                        model, // 
                        verbose, // 
                        org.sireum.Cli.SireumHamrCodegenHamrPlatform$.MODULE$.byName(platform).get(), // 
                        slangOutputDir, // 
                        slangPackageName, // 
                        noProyekIve, // 
                        noEmbedArt, // 
                        devicesAsThreads, // 
                        genSbtMill, // 
                        slangAuxCodeDirs, // 
                        slangOutputCDirectory, // 
                        excludeComponentImpl, // 
                        bitWidth, // 
                        maxStringSize, // 
                        maxArraySize, // 
                        runTranspiler, // 
                        camkesOutputDirectory, // 
                        camkesAuxCodeDirs, // 
                        aadlRootDir, // 
                        experimentalOptions, reporter);
                        // For now just making HAMR markers an opt-in feature
                        if (PreferenceValues.HAMR_PROPOGATE_MARKERS.getValue()) {
                            report(reporter, si);
                        }
                        return codegenRet.toInt();
                    });
                    if (toolRet == 0 && PreferenceValues.HAMR_PROOF_GENERATE.getValue() && (prompt.getOptionPlatform() == Platform.seL4 || prompt.getOptionPlatform() == Platform.seL4_Only)) {
                        String sep = File.separator;
                        File smt2FileLocation = new File(new File(_slangOutputDir.string()), "src" + sep + "c" + sep + "camkes" + sep + "proof" + sep + "smt2_case.smt2");
                        if (_camkesOutputDir != null) {
                            smt2FileLocation = new File(new File(_camkesOutputDir.string()), "proof" + sep + "smt2_case.smt2");
                        }
                        // or perhaps store the path in the eclipse store
                        ProofUtil.lastSMT2Proof = smt2FileLocation;
                        if (PreferenceValues.HAMR_PROOF_CHECK.getValue()) {
                            PrintStream out = new PrintStream(console.newMessageStream());
                            toolRet = ProofUtil.checkProof(smt2FileLocation, out);
                            out.close();
                        }
                    }
                }
                String msg = "HAMR code " + (toolRet == 0 ? "successfully generated" : "generation was unsuccessful");
                displayPopup(msg);
                refreshWorkspace();
            } catch (Throwable ex) {
                ex.printStackTrace();
                displayPopup("Error encountered while running HAMR.\n\n" + ex.getLocalizedMessage());
                return Status.CANCEL_STATUS;
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : Platform(org.sireum.aadl.osate.hamr.handlers.HAMRPropertyProvider.Platform) HW(org.sireum.aadl.osate.hamr.handlers.HAMRPropertyProvider.HW) ErrorReport(org.sireum.aadl.osate.hamr.handlers.HAMRUtil.ErrorReport) SystemInstance(org.osate.aadl2.instance.SystemInstance) Aadl(org.sireum.hamr.ir.Aadl) Z(org.sireum.Z) ArrayList(java.util.ArrayList) List(java.util.List) PrintStream(java.io.PrintStream) MessageConsole(org.eclipse.ui.console.MessageConsole) Report(org.sireum.aadl.osate.hamr.handlers.HAMRUtil.Report) ErrorReport(org.sireum.aadl.osate.hamr.handlers.HAMRUtil.ErrorReport) Reporter(org.sireum.message.Reporter) IS(org.sireum.IS) Option(org.sireum.Option) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

File (java.io.File)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 MessageConsole (org.eclipse.ui.console.MessageConsole)1 SystemInstance (org.osate.aadl2.instance.SystemInstance)1 IS (org.sireum.IS)1 Option (org.sireum.Option)1 Z (org.sireum.Z)1 HW (org.sireum.aadl.osate.hamr.handlers.HAMRPropertyProvider.HW)1 Platform (org.sireum.aadl.osate.hamr.handlers.HAMRPropertyProvider.Platform)1 ErrorReport (org.sireum.aadl.osate.hamr.handlers.HAMRUtil.ErrorReport)1 Report (org.sireum.aadl.osate.hamr.handlers.HAMRUtil.Report)1 Aadl (org.sireum.hamr.ir.Aadl)1 Reporter (org.sireum.message.Reporter)1