use of com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram 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.ast.AgreeProgram in project AGREE by loonwerks.
the class AgreeASTMapVisitor method visit.
@Override
public AgreeProgram visit(AgreeProgram e) {
List<AgreeNode> agreeNodes = new ArrayList<>();
for (AgreeNode node : e.agreeNodes) {
AgreeNode visitedNode = visitedNodes.get(node.compInst);
if (visitedNode == null) {
visitedNode = this.visit(node);
}
agreeNodes.add(visitedNode);
}
List<Node> globalLustreNodes = new ArrayList<>();
for (Node node : e.globalLustreNodes) {
globalLustreNodes.add(this.visit(node));
}
List<Function> uninterpretedFunctions = new ArrayList<>();
for (Function function : e.uninterpretedFunctions) {
uninterpretedFunctions.add(this.visit(function));
}
List<jkind.lustre.Type> globalTypes = new ArrayList<>();
for (Type ty : e.globalTypes) {
globalTypes.add(ty.accept(lustreTypeMapVisitor));
}
AgreeNode topNode = this.visit(e.topNode);
return new AgreeProgram(agreeNodes, globalLustreNodes, uninterpretedFunctions, globalTypes, topNode);
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram in project AGREE by loonwerks.
the class VerifyHandler 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("");
if (isRecursive()) {
if (AgreeUtils.usingKind2()) {
throw new AgreeException("Kind2 only supports monolithic verification");
}
result = buildAnalysisResult(ci.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 {
CompositeAnalysisResult wrapperTop = new CompositeAnalysisResult("Verification for " + ci.getName());
wrapVerificationResult(si, wrapperTop);
wrapper.addChild(wrapperTop);
result = wrapper;
}
showView(result, linker);
return doAnalysis(ci, monitor);
} catch (Throwable e) {
String messages = getNestedMessages(e);
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
} finally {
implUtil.cleanup();
}
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram in project AGREE by loonwerks.
the class AgreeNodeToLustreContract method translate.
public static Node translate(AgreeNode agreeNode, AgreeProgram agreeProgram) {
List<Node> nodes = new ArrayList<>();
nodes.addAll(agreeProgram.globalLustreNodes);
// this node needs to be the last in the list
// so that it is set as the main node in the program
nodes.add(translateNode(agreeNode));
List<TypeDef> types = new ArrayList<>();
for (Type type : agreeProgram.globalTypes) {
RecordType recType = (RecordType) type;
types.add(new TypeDef(recType.id, type));
}
Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).build();
program = InlineNodeCalls.program(program);
program = FlattenPres.program(program);
Node main = DistributePres.node(program.getMainNode());
main = OrderEquations.node(main);
return main;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram in project AGREE by loonwerks.
the class LustreAstBuilder method getRealizabilityLustreProgram.
// private static AgreeProgram translate(AgreeProgram program){
// return AgreeInlineLatchedConnections.translate(program);
// }
public static Program getRealizabilityLustreProgram(AgreeProgram agreeProgram) {
List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
List<Expr> assertions = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<VarDecl> inputs = new ArrayList<>();
List<Equation> equations = new ArrayList<>();
List<String> properties = new ArrayList<>();
AgreeNode topNode = agreeProgram.topNode;
for (AgreeStatement assumption : topNode.assumptions) {
assertions.add(assumption.expr);
}
int i = 0;
for (AgreeStatement guarantee : topNode.guarantees) {
String guarName = guarSuffix + i++;
locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, topNode.compInst, null));
equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
properties.add(guarName);
}
List<String> inputStrs = new ArrayList<>();
for (AgreeVar var : topNode.inputs) {
inputs.add(var);
inputStrs.add(var.id);
}
for (AgreeVar var : topNode.outputs) {
inputs.add(var);
}
// and type equations. This would clear this up
for (AgreeStatement statement : topNode.assertions) {
if (AgreeUtils.referenceIsInContract(statement, topNode.compInst)) {
// this is a strange hack we have to do. we have to make
// equation and property
// statements not assertions. They should all be binary
// expressions with an
// equals operator. We will need to removing their corresponding
// variable
// from the inputs and add them to the local variables
BinaryExpr binExpr;
IdExpr varId;
try {
binExpr = (BinaryExpr) statement.expr;
varId = (IdExpr) binExpr.left;
} catch (ClassCastException e) {
// some equation variables are assertions for
// subrange types. do not translate these to
// local equations. Just add them to assertions
assertions.add(statement.expr);
continue;
}
boolean found = false;
int index;
for (index = 0; index < inputs.size(); index++) {
VarDecl var = inputs.get(index);
if (var.id.equals(varId.id)) {
found = true;
break;
}
}
if (!found || binExpr.op != BinaryOp.EQUAL) {
throw new AgreeException("Something went very wrong with the lustre generation in the realizability analysis");
}
locals.add(inputs.remove(index));
equations.add(new Equation(varId, binExpr.right));
}
}
NodeBuilder builder = new NodeBuilder("main");
builder.addInputs(inputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addAssertions(assertions);
builder.setRealizabilityInputs(inputStrs);
Node main = builder.build();
List<Node> nodes = new ArrayList<>();
nodes.add(main);
nodes.addAll(agreeProgram.globalLustreNodes);
List<Function> uFunctions = new ArrayList<>();
uFunctions.addAll(agreeProgram.uninterpretedFunctions);
Program program = new ProgramBuilder().addTypes(types).addFunctions(uFunctions).addNodes(nodes).setMain(main.id).build();
return program;
}
Aggregations