use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.
the class LinearizationAgreeASTVisitor method visit.
@Override
public AgreeNode visit(AgreeNode e) {
List<AgreeVar> inputs = new ArrayList<>();
for (AgreeVar input : e.inputs) {
inputs.add(this.visit(input));
}
List<AgreeVar> outputs = new ArrayList<>();
for (AgreeVar output : e.outputs) {
outputs.add(this.visit(output));
}
List<AgreeVar> locals = new ArrayList<>();
for (AgreeVar local : e.locals) {
locals.add(this.visit(local));
}
// Note that nodes and connections contain cross-references to each
// other. But, valid model structure requires that connections
// refer only to features on the this node and the sub-nodes. Thus,
// we may visit the sub-nodes first, and then use the result of that
// in visiting the connections.
//
List<AgreeNode> subNodes = new ArrayList<>();
for (AgreeNode subnode : e.subNodes) {
subNodes.add(this.visit(subnode));
}
List<AgreeConnection> connections = new ArrayList<>();
for (AgreeConnection conn : e.connections) {
connections.add(this.visit(conn));
}
List<AgreeStatement> assertions = new ArrayList<>();
for (AgreeStatement stmt : e.assertions) {
if (stmt.expr != null) {
LinearizationResult linResult = linearizeStatement(e, stmt, jkind.lustre.BinaryOp.AND);
outputs.addAll(linResult.addedLocals);
assertions.addAll(linResult.liftedConstraints);
assertions.add(linResult.linearizedStatement);
} else {
assertions.add(stmt);
}
}
List<AgreeStatement> assumptions = new ArrayList<>();
for (AgreeStatement stmt : e.assumptions) {
if (stmt.expr != null) {
LinearizationResult linResult = linearizeStatement(e, stmt, jkind.lustre.BinaryOp.AND);
outputs.addAll(linResult.addedLocals);
assertions.addAll(linResult.liftedConstraints);
assumptions.add(linResult.linearizedStatement);
} else {
assumptions.add(stmt);
}
}
List<AgreeStatement> guarantees = new ArrayList<>();
for (AgreeStatement stmt : e.guarantees) {
if (stmt.expr != null) {
LinearizationResult linResult = linearizeStatement(e, stmt, jkind.lustre.BinaryOp.IMPLIES);
outputs.addAll(linResult.addedLocals);
guarantees.addAll(linResult.liftedConstraints);
guarantees.add(linResult.linearizedStatement);
} else {
guarantees.add(stmt);
}
}
List<AgreeStatement> lemmas = new ArrayList<>();
for (AgreeStatement stmt : e.lemmas) {
if (stmt.expr != null) {
LinearizationResult linResult = linearizeStatement(e, stmt, jkind.lustre.BinaryOp.IMPLIES);
outputs.addAll(linResult.addedLocals);
assertions.addAll(linResult.liftedConstraints);
lemmas.add(linResult.linearizedStatement);
} else {
lemmas.add(stmt);
}
}
Expr clockConstraint = e.clockConstraint.accept(this);
Expr initialConstraint = e.initialConstraint.accept(this);
AgreeVar clockVar = this.visit(e.clockVar);
AgreeNodeBuilder builder = new AgreeNodeBuilder(e);
builder.clearInputs();
builder.addInput(inputs);
builder.clearOutputs();
builder.addOutput(outputs);
builder.clearLocals();
builder.addLocal(locals);
builder.clearConnections();
builder.addConnection(connections);
builder.clearSubNodes();
builder.addSubNode(subNodes);
builder.clearAssertions();
builder.addAssertion(assertions);
builder.clearAssumptions();
builder.addAssumption(assumptions);
builder.clearGuarantees();
builder.addGuarantee(guarantees);
builder.clearLemmas();
builder.addLemma(lemmas);
builder.setClockConstraint(clockConstraint);
builder.setInitialConstraint(initialConstraint);
builder.setClockVar(clockVar);
AgreeNode result = builder.build();
visitedNodes.put(e.compInst, result);
return result;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.
the class AsymFaultASTBuilder method addSafetyEqStmts.
/**
* Add any safety eq stmts to the main assert for this node.
*
* @param node NodeBuilder for this lustre node
* @param fault Fault associated with the sender component
* @param assertExpr The main assert stmt linking the output to the fault val out
*/
private Expr addSafetyEqStmts(NodeBuilder node, List<Fault> faults, Expr assertExpr) {
List<AgreeStatement> safetyEqList = new ArrayList<AgreeStatement>();
// Collect all safetyEq stmts in one list
for (Fault f : faults) {
safetyEqList.addAll(f.safetyEqAsserts);
}
if (!safetyEqList.isEmpty()) {
// Build and expression with all expr in list
Expr safetyEqExpr = super.buildBigAndExpr(safetyEqList, 0);
BinaryExpr finalExpr2 = new BinaryExpr(safetyEqExpr, BinaryOp.AND, assertExpr);
return finalExpr2;
} else {
return assertExpr;
}
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method mapFaultActiveToNodeInterface.
/**
* Method links trigger with indep/dep active stmt.
*
* Ex: assert (Sender__fault__trigger__Sender__fault_1 =
* (__fault__independently__active__Sender__Sender__fault_1 or
* __fault__dependently__active__Sender__Sender__fault_1));
*
* @param f Fault
* @param path path of fault (where in program it is located)
* @param base
* @param builder Node builder that will have these assertions added
*/
public void mapFaultActiveToNodeInterface(Fault f, List<String> path, String base, AgreeNodeBuilder builder) {
String interfaceVarId = addPathDelimiters(path, this.createFaultNodeTriggerId(f.id));
String indepentlyActiveVarId = this.createFaultIndependentActiveId(base);
String depentlyActiveVarId = this.createFaultDependentActiveId(base);
// for the counterexample layout
for (String str : path) {
mapFaultToPath.put(f, str);
}
Expr equate = new BinaryExpr(new IdExpr(interfaceVarId), BinaryOp.EQUAL, new BinaryExpr(new IdExpr(indepentlyActiveVarId), BinaryOp.OR, new IdExpr(depentlyActiveVarId)));
builder.addAssertion(new AgreeStatement("", equate, f.faultStatement));
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method constrainFaultActive.
/**
* Method constrains hardware faults to be permanent.
*
* @param hwf HardwareFault to be constrained.
* @param nameBase Name of fault.
* @param builder AgreeNodeBuilder will have assertions added.
*/
public void constrainFaultActive(HWFault hwf, String nameBase, AgreeNodeBuilder builder) {
IdExpr independentlyActiveExpr = new IdExpr(this.createFaultIndependentActiveId(nameBase));
IdExpr dependentlyActiveExpr = new IdExpr(this.createFaultDependentActiveId(nameBase));
IdExpr independentEventExpr = new IdExpr(this.createFaultEventId(nameBase));
List<Expr> faultExprs = new ArrayList<>();
// collect the list of source faults in the propagations
// whose target fault is the current fault
// the names of those source faults are created through
// createFaultIndependentActiveId
getSrcFaultExprList(hwf, faultExprs);
// create a disjunction of the source faults as the triggering event
// for the dependent fault
Expr dependentEventExpr = buildFaultDisjunctionExpr(faultExprs, 0);
Expr assertIndependentExpr;
Expr assertDependentExpr;
TemporalConstraint tc = hwf.duration.getTc();
if (tc instanceof PermanentConstraint) {
assertIndependentExpr = createPermanentExpr(independentlyActiveExpr, independentEventExpr);
assertDependentExpr = createPermanentExpr(dependentlyActiveExpr, dependentEventExpr);
} else if (tc instanceof TransientConstraint) {
System.out.println("WARNING: ignoring duration on transient faults");
assertIndependentExpr = createTransientExpr(independentlyActiveExpr, independentEventExpr);
assertDependentExpr = createTransientExpr(dependentlyActiveExpr, dependentEventExpr);
} else {
throw new SafetyException("Unknown constraint type during translation of fault " + hwf.id + ". Constraint must be 'permanent'.");
}
builder.addAssertion(new AgreeStatement("", assertIndependentExpr, hwf.hwFaultStatement));
builder.addAssertion(new AgreeStatement("", assertDependentExpr, hwf.hwFaultStatement));
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method addTopLevelMaxFaultOccurrenceConstraint.
/**
* Method adds count constraints to top level assertions.
*
* @param maxFaults No. of faults allowed in count.
* @param topNode This node (main)
* @param builder node builder will have constraints added.
*/
public void addTopLevelMaxFaultOccurrenceConstraint(int maxFaults, AgreeNode topNode, AgreeNodeBuilder builder) {
// add a global fault count
String id = "__fault__global_count";
builder.addInput(new AgreeVar(id, NamedType.INT, topNode.reference));
// assign it.
List<Expr> sumExprs = new ArrayList<>();
// getFaultCountExprList(topNode, new ArrayList<>(), sumExprs);
getFaultCountExprList(topNode, sumExprs);
Expr faultCountExpr = buildFaultCountExpr(sumExprs, 0);
Expr equate = new BinaryExpr(new IdExpr(id), BinaryOp.EQUAL, faultCountExpr);
builder.addAssertion(new AgreeStatement("", equate, topNode.reference));
// add assertions that the mutually exclusive fault activations
for (FaultPair curPair : mutualExclusiveFaults) {
// assert that the pair cannot both be true
// get fault triggers
String ft1Trigger = this.getMainNodeFaultIndepStr(curPair.ft1);
String ft2Trigger = this.getMainNodeFaultIndepStr(curPair.ft2);
Expr ft1False = new UnaryExpr(UnaryOp.NOT, new IdExpr(ft1Trigger));
Expr ft2False = new UnaryExpr(UnaryOp.NOT, new IdExpr(ft2Trigger));
Expr ft1FalseOrft2False = new BinaryExpr(ft1False, BinaryOp.OR, ft2False);
builder.addAssertion(new AgreeStatement("", ft1FalseOrft2False, topNode.reference));
}
// assert that the value is <= maxFaults
Expr lessEqual = new BinaryExpr(new IdExpr(id), BinaryOp.LESSEQUAL, new IntExpr(maxFaults));
builder.addAssertion(new AgreeStatement("", lessEqual, topNode.reference));
}
Aggregations