use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AGREE by loonwerks.
the class AgreeProgramToSimulationProgram method transform.
public static SimulationProgram transform(final AgreeProgram agreeProgram, final SimulationProgramType type) {
Objects.requireNonNull(agreeProgram, "agreeProgram must not be null");
// Build a Component Instance to AgreeNode map
final Program lustreProgram = LustreAstBuilder.getAssumeGuaranteeLustreProgram(agreeProgram);
final AgreeRenaming agreeRenaming = new AgreeRenaming();
final AgreeLayout layout = new AgreeLayout();
RenamingVisitor.addRenamings(lustreProgram, agreeRenaming, agreeProgram.topNode.compInst, layout);
SimulationProgram program;
try {
final SimulationProgramBuilder builder = new SimulationProgramBuilder(type, agreeProgram.topNode.compInst, lustreProgram, agreeRenaming);
populateMetadata(builder, agreeProgram, lustreProgram, agreeRenaming, agreeRenaming.getRefMap());
program = builder.build();
} catch (final Exception ex) {
throw new AGREESimulatorException(lustreProgram, ex);
}
try {
program = CreateLocalVariablesForPropertyExpressions.transform(program);
program = RemovePropertySatisficationRequirements.transform(program);
program = RemoveCondacts.transform(program);
program = InlineNodeCalls.transform(program);
program = ReplaceFollowedByOperator.transform(program);
program = ReplacePreOperator.transform(program);
program = CreateSimulationProperties.transform(program);
program = RemoveProperties.transform(program);
program = CreateSimulationGuarantee.transform(program);
} catch (final Exception ex) {
throw new AGREESimulatorException(program.getLustreProgram(), ex);
}
return program;
}
use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AGREE by loonwerks.
the class TcgLinkerFactory method createVerification.
protected AnalysisResult createVerification(String resultName, ComponentInstance compInst, Program lustreProgram, AgreeProgram agreeProgram) {
AgreeRenaming agreeRenaming = new AgreeRenaming();
AgreeLayout layout = new AgreeLayout();
RenamingVisitor.addRenamings(lustreProgram, agreeRenaming, compInst, layout);
TcgRenaming renaming = new TcgRenaming(agreeRenaming, agreeRenaming.getRefMap());
Node mainNode = lustreProgram.getMainNode();
if (mainNode == null) {
throw new AgreeException("Could not find main lustre node after translation");
}
List<String> properties = new ArrayList<>();
JKindResult result;
result = new JKindResult(resultName, properties, renaming);
queue.add(result);
ComponentImplementation compImpl = AgreeUtils.getInstanceImplementation(compInst);
linker.setAgreeProgram(result, agreeProgram);
linker.setProgram(result, lustreProgram);
linker.setComponent(result, compImpl);
linker.setContract(result, getContract(compImpl));
linker.setLayout(result, layout);
// linker.setReferenceMap(result, renaming.getRefMap());
linker.setLog(result, AgreeLogger.getLog());
linker.setRenaming(result, renaming);
// System.out.println(program);
return result;
}
use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AMASE by loonwerks.
the class FaultsVerifyAllHandler method doFaultPropagationInjection.
protected Program doFaultPropagationInjection(JKindResult result, Program program) {
List<JKindResult> childVerifications = getChildContractResults(result);
// com.rockwellcollins.atc.agree.analysis.VerifyHandler#wrapVerificationResult(ComponentInstance, CompositeAnalysisResult)
if ("Contract Guarantees".equals(result.getName())) {
for (JKindResult childResult : childVerifications) {
AgreeRenaming childRenaming = (AgreeRenaming) linker.getRenaming(childResult);
for (PropertyResult propertyResult : childResult.getPropertyResults()) {
// where it is protected and we need to duplicate the literal here.
if (propertyResult.getProperty() instanceof InvalidProperty && childRenaming.getRefMap().get(propertyResult.getProperty().getName()) instanceof GuaranteeStatement) {
String guaranteeName = propertyResult.getProperty().getName();
String lustreVarName = childRenaming.getLustreNameFromAgreeVar(guaranteeName);
// WARNING: Here we assume that the subnode id of interest is named as given below.
// We need to introduce this literal "_TOP__" here because the computation is hidden in AGREE
// literals in com.rockwellcollins.atc.agree.analysis.LustreAstBuilder#getAssumeGuaranteeLustreProgram(AgreeProgram)
// WARNING: the string literal "Verification for " in the line below needs to match that in
// com.rockwellcollins.atc.agree.analysis.handlers.VerifyHandler#runJob(Element, IProgressMonitor) and
// com.rockwellcollins.atc.agree.analysis.handlers.VerifyHandler#buildAnalysisResult(String, ComponentInstance)
String subnodeName = "_TOP__" + childResult.getParent().getName().replaceFirst("Verification for ", "");
// TODO: The string concatenation is also done in the AddFaultDriverVisitor; unify them
program = new AddFaultDriverVisitor(subnodeName, lustreVarName).visit(program);
} else if (propertyResult.getProperty() instanceof ValidProperty && propertyResult.getProperty().getName().contains(childRenaming.forceRename(AddPairwiseFaultDriverWitnesses.FAULT_DRIVER_PAIR_WITNESS_BASENAME)) && pairwiseFaultDriverProperties.containsKey(childResult) && pairwiseFaultDriverProperties.get(childResult).containsKey(propertyResult.getName()) && // invalidated and have corresponding fault drivers that are present in this verification
pairwiseFaultDriverProperties.get(childResult).get(propertyResult.getName()).entrySet().stream().allMatch(e -> {
PropertyResult p = childResult.getPropertyResult(childRenaming.rename(e.getKey()));
return (p != null) ? p.getProperty() instanceof InvalidProperty : false;
})) {
program = new AddFaultDriverGuardAssertionVisitor(program.main, pairwiseFaultDriverProperties.get(childResult).get(propertyResult.getName()).values().stream().collect(Collectors.toList())).visit(program);
}
}
}
/* If not the top analysis, that is the parent of the composite parent of the composite parent of this result is not null */
if (result.getParent().getParent().getParent() != null) {
Map<PropertyResult, String> accumulatedGuarantees = Maps.newLinkedHashMap();
for (PropertyResult propertyResult : result.getPropertyResults()) {
AgreeRenaming renaming = (AgreeRenaming) linker.getRenaming(result);
if (renaming.getRefMap().get(propertyResult.getName()) instanceof GuaranteeStatement) {
String guaranteeName = propertyResult.getName();
String lustreVarName = renaming.getLustreNameFromAgreeVar(guaranteeName);
accumulatedGuarantees.put(propertyResult, lustreVarName);
}
}
AddPairwiseFaultDriverWitnesses pairwiseFaultVisitor = new AddPairwiseFaultDriverWitnesses(Lists.newArrayList(accumulatedGuarantees.values()));
program = pairwiseFaultVisitor.visit(program);
result.addProperties(pairwiseFaultVisitor.getProperties());
// WARNING: the string literal "Verification for " in the line below needs to match that in
// com.rockwellcollins.atc.agree.analysis.handlers.VerifyHandler#runJob(Element, IProgressMonitor) and
// com.rockwellcollins.atc.agree.analysis.handlers.VerifyHandler#buildAnalysisResult(String, ComponentInstance)
// TODO: the concatenation of nodeName with fault driver is done elsewhere too, unify
String nodeName = "_TOP__" + result.getParent().getName().replaceFirst("Verification for ", "");
pairwiseFaultDriverProperties.put(result, pairwiseFaultVisitor.getPairwiseWitnesses().entrySet().stream().collect(Collectors.toMap(e -> ((AgreeRenaming) linker.getRenaming(result)).forceRename(e.getKey()), e -> e.getValue().stream().collect(Collectors.toMap(id -> id, id -> nodeName + AddFaultDriverVisitor.getFaultDriverId(id))))));
}
}
return program;
}
use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AMASE by loonwerks.
the class SafetyLinkerFactory method createVerification.
protected AnalysisResult createVerification(String resultName, ComponentInstance compInst, Program lustreProgram, AgreeProgram agreeProgram) {
// Renaming: organizes things between jkind and agree results?
AgreeRenaming agreeRenaming = new AgreeRenaming();
AgreeLayout layout = new AgreeLayout();
RenamingVisitor.addRenamings(lustreProgram, agreeRenaming, compInst, layout);
SafetyRenaming renaming = new SafetyRenaming(agreeRenaming, agreeRenaming.getRefMap());
Node mainNode = lustreProgram.getMainNode();
if (mainNode == null) {
throw new AgreeException("Could not find main lustre node after translation");
}
List<String> properties = new ArrayList<>();
JKindResult result;
result = new JKindResult(resultName, properties, renaming);
queue.add(result);
// Set the program, component, contract, layout, log, and renaming
ComponentImplementation compImpl = AgreeUtils.getInstanceImplementation(compInst);
linker.setAgreeProgram(result, agreeProgram);
linker.setProgram(result, lustreProgram);
linker.setComponent(result, compImpl);
linker.setContract(result, getContract(compImpl));
linker.setLayout(result, layout);
linker.setReferenceMap(result, renaming.getRefMap());
linker.setLog(result, AgreeLogger.getLog());
linker.setRenaming(result, renaming);
return result;
}
use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AMASE by loonwerks.
the class FaultsVerifyAllHandler method createVerification.
private AnalysisResult createVerification(String resultName, ComponentInstance compInst, Program lustreProgram, AgreeProgram agreeProgram, AnalysisType analysisType) {
AgreeAutomaterRegistry aAReg = (AgreeAutomaterRegistry) ExtensionRegistry.getRegistry(ExtensionRegistry.AGREE_AUTOMATER_EXT_ID);
List<AgreeAutomater> automaters = aAReg.getAgreeAutomaters();
AgreeRenaming renaming = new AgreeRenaming();
AgreeLayout layout = new AgreeLayout();
Node mainNode = null;
for (Node node : lustreProgram.nodes) {
if (node.id.equals(lustreProgram.main)) {
mainNode = node;
break;
}
}
if (mainNode == null) {
throw new AgreeException("Could not find main lustre node after translation");
}
List<String> properties = new ArrayList<>();
RenamingVisitor.addRenamings(lustreProgram, renaming, compInst, layout);
addProperties(renaming, properties, mainNode, agreeProgram);
for (AgreeAutomater aa : automaters) {
renaming = aa.rename(renaming);
layout = aa.transformLayout(layout);
}
JKindResult result;
switch(analysisType) {
case Consistency:
result = new ConsistencyResult(resultName, mainNode.properties, Collections.singletonList(true), renaming);
break;
case Realizability:
result = new JRealizabilityResult(resultName, renaming);
break;
case AssumeGuarantee:
result = new SafetyJKindResult(resultName, properties, renaming);
break;
default:
throw new AgreeException("Unhandled Analysis Type");
}
queue.add(result);
ComponentImplementation compImpl = AgreeUtils.getInstanceImplementation(compInst);
linker.setProgram(result, lustreProgram);
linker.setComponent(result, compImpl);
linker.setContract(result, getContract(compImpl));
linker.setLayout(result, layout);
linker.setReferenceMap(result, renaming.getRefMap());
linker.setLog(result, AgreeLogger.getLog());
linker.setRenaming(result, renaming);
// System.out.println(program);
return result;
}
Aggregations