use of org.osate.aadl2.instance.SystemInstance 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;
}
use of org.osate.aadl2.instance.SystemInstance in project AMASE by loonwerks.
the class GenMCSHandler method runJob.
@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
// this flag is set by the rerun handler to prevent clearing the advice map
if (!calledFromRerun) {
rerunAdviceMap.clear();
}
calledFromRerun = false;
disableRerunHandler();
handlerService = getWindow().getService(IHandlerService.class);
try {
// Make sure the user selected a component implementation
ComponentImplementation ci = getComponentImplementation(root, implUtil);
SystemInstance si = getSysInstance(ci, implUtil);
AnalysisResult result;
CompositeAnalysisResult wrapper = new CompositeAnalysisResult("");
// SystemType sysType = si.getSystemImplementation().getType();
ComponentType sysType = AgreeUtils.getInstanceType(si);
EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (annexSubClauses.size() == 0) {
throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
}
if (isRecursive()) {
if (AgreeUtils.usingKind2()) {
throw new AgreeException("Kind2 only supports monolithic verification");
}
result = buildAnalysisResult(((NamedElement) root).getName(), si);
wrapper.addChild(result);
result = wrapper;
} else if (isRealizability()) {
AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
Program program = LustreAstBuilder.getRealizabilityLustreProgram(agreeProgram);
wrapper.addChild(createVerification("Realizability Check", si, program, agreeProgram, AnalysisType.Realizability));
result = wrapper;
} else {
wrapVerificationResult(si, wrapper);
result = wrapper;
}
showView(result, linker);
return doAnalysis(root, monitor, result, linker);
} catch (Throwable e) {
String messages = getNestedMessages(e);
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
} finally {
implUtil.cleanup();
}
}
use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.
the class AwasServerHandler method highlightInstanceDiagram.
@SuppressWarnings("restriction")
public static void highlightInstanceDiagram(Map<URI, String> uris, SystemInstance root) {
display.syncExec(() -> {
Set<DiagramElement> des = new HashSet<DiagramElement>();
AwasUtil.getAllDiagramElements(ade.getDiagram()).forEach(de -> des.add(de));
des.forEach(de -> {
URI hUri = new EObjectURIWrapper((EObject) de.getBusinessObject()).getUri();
if (de.getBusinessObject() instanceof EObject && uris.containsKey(hUri)) {
de.setStyle(StyleBuilder.create(de.getStyle()).backgroundColor(AwasUtil.hex2Rgb(uris.get(hUri))).outlineColor(AwasUtil.hex2Rgb(uris.get(hUri))).build());
}
});
ade.getActionExecutor().execute("highlight diagram", ExecutionMode.NORMAL, () -> {
ade.updateNowIfModelHasChanged();
ade.updateDiagram();
ade.getGefDiagram().refreshDiagramStyles();
ade.doSave(new NullProgressMonitor());
return null;
});
//
// ade.forceDiagramUpdateOnNextModelChange();
// ade.updateDiagram();
// ade.setFocus();
// ade.clearSelection();
// ade.updateNowIfModelHasChanged();
// ade.doSave(new NullProgressMonitor());
});
}
use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.
the class ReachForwardHandler method execute.
@SuppressWarnings("restriction")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Boolean isImplDiagram = false;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
List<DiagramElement> des = SelectionUtil.getSelectedDiagramElements(SelectionHelper.getDiagramSelection(), // getSelectedDiagramElem(event)
true);
List<InstanceObject> ios = des.stream().flatMap(de -> {
Object bo = de.getBusinessObject();
List<InstanceObject> io = new ArrayList();
if (bo != null && bo instanceof InstanceObject) {
io.add(((InstanceObject) bo));
}
return io.stream();
}).collect(Collectors.toList());
List<String> criterions = ios.stream().map(io -> io.getInstanceObjectPath()).collect(Collectors.toList());
if (!ios.isEmpty()) {
MessageConsole console = displayConsole("Awas Console");
try {
Aadl model = Util.getAir(ios.get(0).getSystemInstance(), true, console);
Model awasModel = org.sireum.awas.slang.Aadl2Awas$.MODULE$.apply(model);
SymbolTable st = org.sireum.awas.symbol.SymbolTable$.MODULE$.apply(awasModel, new ConsoleTagReporter());
FlowGraph<FlowNode, FlowEdge<FlowNode>> graph = org.sireum.awas.flow.FlowGraph$.MODULE$.apply(awasModel, st, false);
AwasGraph awasgraph = new AwasGraphImpl(graph, st);
String query = "t = reach forward " + "{" + String.join(",", criterions) + "}";
Map<String, Collector> qres = awasgraph.queryEvaluator(query);
if (qres.isEmpty()) {
MessageDialog.openError(window.getShell(), "Sireum", "Empty result");
} else {
final DiagramService diagramService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(DiagramService.class);
SystemInstance si = ios.get(0).getSystemInstance();
Resource resource = si.eResource();
ComponentImplementation cii = InstanceUtil.getComponentImplementation(si, 0, null);
// cii.eResource().getResourceSet().get
List<Collector> lc = new ArrayList<Collector>(qres.values());
Set<AgeEditor> ads = AwasUtil.awasGraphUri2AgeDiagramEditor(lc.get(0).getGraph(), isImplDiagram, st, resource, diagramService);
AwasUtil.highlightDiagrams(ads, lc.get(0), isImplDiagram, st, resource);
}
} catch (URISyntaxException e1) {
// // TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e3) {
e3.printStackTrace();
String m2 = "Could not invoke visualizer. Please make sure Awas is configured correctly.\n\n" + e3.getLocalizedMessage();
MessageDialog.openError(window.getShell(), "Sireum", m2);
}
} else {
String m3 = "Please select a component or port from the instance diagram";
MessageDialog.openError(window.getShell(), "Sireum", m3);
}
return null;
}
use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.
the class Phantom method hamrCodegen.
int hamrCodegen(SireumHamrCodegenOption ho, ResourceSet rs) {
if (ho.args().size().toInt() != 1) {
addError("Expecting exactly one argument");
return 1;
}
String s = ho.args().apply(z(0)).string();
File f = new File(s).getAbsoluteFile();
if (!f.exists() || !f.isFile()) {
addError("Either point to a serialized AIR file, or to a .project or .system file");
return 1;
}
addInfo("Sireum Version: " + SireumApi.version());
Reporter reporter = org.sireum.message.Reporter$.MODULE$.create();
int ret = 0;
if (f.getName().equals(".project") || f.getName().startsWith(".system")) {
List<AadlSystem> systems = AadlProjectUtil.findSystems(f);
if (systems.size() != 1) {
addError("Found " + systems.size() + " AADL projects. " + "Point to a single .project file " + "or a .system file\n");
// printUsage();
return 1;
}
AadlSystem system = systems.get(0);
SystemInstance si = getSystemInstance(system, rs);
if (si == null) {
ret = 1;
} else {
Aadl model = Util.getAir(si, true);
org.sireum.cli.HAMR.codeGenReporter(model, ho, reporter);
ret = reporter.hasError() ? 1 : 0;
}
} else {
// assume it's a serialized AIR file
ret = org.sireum.cli.HAMR.codeGen(ho, reporter).toInt();
}
addInfo("HAMR Codegen was " + ((ret != 0) ? "un" : "") + "succesful");
return ret;
}
Aggregations