use of com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram in project AGREE by loonwerks.
the class AgreePatternTranslator method translate.
public static AgreeProgram translate(AgreeProgram program) {
List<Node> patternLustreNodes = new ArrayList<>();
// reset the static variable before refreshing its values in translateNode call
containsRealTimePatterns = false;
AgreeNode topNode = new AgreePatternTranslator().translateNode(program.topNode, true);
List<AgreeNode> agreeNodes = gatherNodes(topNode);
patternLustreNodes.addAll(program.globalLustreNodes);
return new AgreeProgram(agreeNodes, patternLustreNodes, program.uninterpretedFunctions, program.globalTypes, topNode, containsRealTimePatterns);
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram in project AGREE by loonwerks.
the class AgreeMakeClockedLustreNodes method translate.
public static AgreeProgram translate(AgreeProgram program) {
AgreeMakeClockedLustreNodes visitor = new AgreeMakeClockedLustreNodes(program);
List<Node> nodeList = new ArrayList<>();
for (Node node : program.globalLustreNodes) {
nodeList.add(node);
nodeList.add(visitor.getClockedNode(node.id));
}
return new AgreeProgram(program.agreeNodes, nodeList, program.uninterpretedFunctions, program.globalTypes, program.topNode);
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram in project AGREE by loonwerks.
the class LustreAstBuilder method getAssumeGuaranteeLustreProgram.
public static Program getAssumeGuaranteeLustreProgram(AgreeProgram agreeProgram) {
nodes = new ArrayList<>();
uninterpretedFcns = new ArrayList<>();
AgreeNode flatNode = flattenAgreeNode(agreeProgram, agreeProgram.topNode, "_TOP__");
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<>();
List<String> ivcs = new ArrayList<>();
int j = 0;
for (AgreeStatement assumption : flatNode.assumptions) {
String assumName = assumeSuffix + j++;
locals.add(new AgreeVar(assumName, NamedType.BOOL, assumption.reference, flatNode.compInst, null));
IdExpr assumId = new IdExpr(assumName);
equations.add(new Equation(assumId, assumption.expr));
assertions.add(assumId);
// Else add the defined ivc list.
if (flatNode.getFaultTreeFlag() == false) {
ivcs.add(assumId.id);
}
}
for (AgreeStatement assertion : flatNode.assertions) {
assertions.add(assertion.expr);
}
// add assumption and monolithic lemmas first (helps with proving)
for (AgreeVar var : flatNode.outputs) {
if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
properties.add(var.id);
}
inputs.add(var);
}
// add property that all assumption history is true
Expr assumeConj = new BoolExpr(true);
for (AgreeNode subNode : agreeProgram.topNode.subNodes) {
assumeConj = new BinaryExpr(new IdExpr(subNode.id + "__" + assumeHistSufix), BinaryOp.AND, assumeConj);
}
AgreeVar assumeHistVar = new AgreeVar(assumeHistSufix, NamedType.BOOL, agreeProgram.topNode.compInst.getComponentClassifier(), agreeProgram.topNode.compInst, null);
locals.add(assumeHistVar);
equations.add(new Equation(new IdExpr(assumeHistVar.id), assumeConj));
properties.add(assumeHistVar.id);
int k = 0;
for (AgreeStatement patternPropState : flatNode.patternProps) {
String patternVarName = patternPropSuffix + k++;
locals.add(new AgreeVar(patternVarName, NamedType.BOOL, patternPropState, flatNode.compInst, null));
equations.add(new Equation(new IdExpr(patternVarName), patternPropState.expr));
properties.add(patternVarName);
}
int lemmaCount = 0;
for (AgreeStatement lemma : flatNode.lemmas) {
String lemmaName = lemmaSuffix + lemmaCount++;
locals.add(new AgreeVar(lemmaName, NamedType.BOOL, lemma.reference, flatNode.compInst, null));
equations.add(new Equation(new IdExpr(lemmaName), lemma.expr));
properties.add(lemmaName);
}
int i = 0;
for (AgreeStatement guarantee : flatNode.guarantees) {
String guarName = guarSuffix + i++;
locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, flatNode.compInst, null));
equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
properties.add(guarName);
}
if (flatNode.getFaultTreeFlag()) {
ivcs.addAll(agreeProgram.topNode.getivcElements());
}
for (AgreeVar var : flatNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : flatNode.locals) {
locals.add(var);
}
equations.addAll(flatNode.localEquations);
assertions.add(AgreeRealtimeCalendarBuilder.getTimeConstraint(flatNode.eventTimes));
NodeBuilder builder = new NodeBuilder("main");
builder.addInputs(inputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addAssertions(assertions);
builder.addIvcs(ivcs);
Node main = builder.build();
nodes.add(main);
nodes.addAll(agreeProgram.globalLustreNodes);
nodes.add(getHistNode());
// add realtime constraint nodes
nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
uninterpretedFcns.addAll(agreeProgram.uninterpretedFunctions);
Program program = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(main.id).build();
return program;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram in project AGREE by loonwerks.
the class LustreAstBuilder method getConsistencyChecks.
public static List<Pair<String, Program>> getConsistencyChecks(AgreeProgram agreeProgram) {
List<Pair<String, Program>> programs = new ArrayList<>();
List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
nodes = new ArrayList<>();
uninterpretedFcns = new ArrayList<>();
Node topConsist = getConsistencyLustreNode(agreeProgram.topNode, false);
// we don't want node lemmas to show up in the consistency check
for (Node node : agreeProgram.globalLustreNodes) {
nodes.add(removeProperties(node));
}
nodes.add(topConsist);
nodes.add(getHistNode());
nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
uninterpretedFcns.addAll(agreeProgram.uninterpretedFunctions);
Program topConsistProg = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(topConsist.id).build();
// String topComponentName = agreeProgram.topNode.id.replace("_Instance", "");
// programs.add(Tuples.create(topComponentName + " consistent", topConsistProg));
programs.add(Tuples.create("This component consistent", topConsistProg));
for (AgreeNode subNode : agreeProgram.topNode.subNodes) {
nodes = new ArrayList<>();
subNode = flattenAgreeNode(agreeProgram, subNode, "_TOP__");
Node subConsistNode = getConsistencyLustreNode(subNode, true);
for (Node node : agreeProgram.globalLustreNodes) {
nodes.add(removeProperties(node));
}
nodes.add(subConsistNode);
nodes.add(getHistNode());
nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
Program subConsistProg = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(subConsistNode.id).build();
programs.add(Tuples.create(subNode.id + " consistent", subConsistProg));
}
nodes = new ArrayList<>();
// agreeProgram = translate(agreeProgram);
AgreeNode compositionNode = flattenAgreeNode(agreeProgram, agreeProgram.topNode, "_TOP__");
Node topCompositionConsist = getConsistencyLustreNode(compositionNode, true);
for (Node node : agreeProgram.globalLustreNodes) {
nodes.add(removeProperties(node));
}
// nodes.addAll(agreeProgram.globalLustreNodes);
nodes.add(topCompositionConsist);
nodes.add(getHistNode());
nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
Program topCompositConsistProg = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(topCompositionConsist.id).build();
programs.add(Tuples.create("Component composition consistent", topCompositConsistProg));
return programs;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram in project AGREE by loonwerks.
the class AGREESimulationEngineFactoryHelper method createSimulationEngine.
public static SimulationEngine createSimulationEngine(final SystemInstance systemInstance, final ExceptionHandler exceptionHandler, final SimulationProgramType type) {
Objects.requireNonNull(systemInstance, "systemInstance must not be null");
Objects.requireNonNull(exceptionHandler, "exceptionHandler must not be null");
// Check that the component type is compatible
if (!isCompatible(systemInstance.getComponentImplementation())) {
final ComponentType componentType = systemInstance.getComponentClassifier().getType();
throw new RuntimeException(componentType.getName() + " does not contain an AGREE annex subclause.");
}
final AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(systemInstance, type.isMonolithic());
final SimulationProgram simulationProgram = AgreeProgramToSimulationProgram.transform(agreeProgram, type);
final Simulation simulation = new Simulation(simulationProgram);
return new AGREESimulationEngine(simulation, systemInstance, exceptionHandler);
}
Aggregations