use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class AgreeProgramToSimulationProgram method populateMetadata.
private static void populateMetadata(final SimulationProgramBuilder builder, final AgreeProgram agreeProgram, final Program lustreProgram, final AgreeRenaming agreeRenaming, final Map<String, EObject> refMap) {
// Exclude inputs that are used internally by AGREE.
for (final VarDecl vd : lustreProgram.getMainNode().inputs) {
if (vd instanceof AgreeVar) {
final AgreeVar agreeVar = (AgreeVar) vd;
if (agreeVar.compInst != null) {
final FeatureInstance featureInstance = agreeVar.featInst;
// Use the name as provided by the instance object path unless it is not available
final String variableName;
if (featureInstance != null) {
variableName = featureInstance.getFullName();
} else {
final String[] idSegs = vd.id.split("__");
variableName = idSegs[idSegs.length - 1];
}
builder.addSimulationVariable(new SimulationVariable(agreeVar.compInst, variableName, vd.id, vd.type, featureInstance, agreeVar.reference));
}
}
}
// Add mappings from component instances to agree nodes
builder.addMapping(agreeProgram.topNode.compInst, agreeProgram.topNode);
for (final AgreeNode n : agreeProgram.agreeNodes) {
builder.addMapping(n.compInst, n);
}
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class AgreeInlineLatchedConnections method addLatchedInputEqs.
private void addLatchedInputEqs(AgreeNodeBuilder builder, AgreeNode subNode) {
for (AgreeVar var : subNode.inputs) {
AgreeVar latchVar = new AgreeVar(subNode.id + "__" + var.id + LATCHED_SUFFIX, var.type, var.reference, var.compInst, var.featInst);
builder.addLocal(latchVar);
Expr clockExpr = new IdExpr(subNode.id + AgreeASTBuilder.clockIDSuffix);
String sourceVarName = subNode.id + "__" + var.id;
Equation latchEq = equation("latchVar = " + sourceVarName + " -> if (pre (not clockVar)) and clockVar then " + sourceVarName + " else pre latchVar;", to("latchVar", latchVar), to("clockVar", clockExpr));
builder.addLocalEquation(new AgreeEquation(latchEq, null));
}
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class AgreeMakeClockedLustreNodes method visit.
@Override
public Expr visit(UnaryExpr e) {
if (e.op == UnaryOp.PRE) {
IdExpr stateVarId = stateVarMap.get(e.toString());
if (stateVarId != null) {
return stateVarId;
}
stateVarId = new IdExpr(statVarPrefix + numStateVars++);
stateVarMap.put(e.toString(), stateVarId);
Expr stateVarExpr = new UnaryExpr(UnaryOp.PRE, e.expr.accept(this));
stateVarExpr = expr("if clk then stateVarExpr else (pre stateVar)", to("stateVar", stateVarId), to("stateVarExpr", stateVarExpr), to("clk", clockVarName));
stateVars.add(new AgreeVar(stateVarId.id, e.accept(typeReconstructor), null, null, null));
stateVarEqs.add(new Equation(stateVarId, stateVarExpr));
return stateVarId;
}
return new UnaryExpr(e.op, e.expr.accept(this));
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class AgreeASTMapVisitor method visit.
@Override
public AgreeNode visit(AgreeNode e) {
String id = e.id;
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) {
assertions.add(this.visit(stmt));
}
List<AgreeStatement> assumptions = new ArrayList<>();
for (AgreeStatement stmt : e.assumptions) {
assumptions.add(this.visit(stmt));
}
List<AgreeStatement> guarantees = new ArrayList<>();
for (AgreeStatement stmt : e.guarantees) {
guarantees.add(this.visit(stmt));
}
List<AgreeStatement> lemmas = new ArrayList<>();
for (AgreeStatement stmt : e.lemmas) {
lemmas.add(this.visit(stmt));
}
List<AgreeStatement> patternProps = new ArrayList<>();
for (AgreeStatement stmt : e.patternProps) {
patternProps.add(this.visit(stmt));
}
List<AgreeEquation> localEqs = new ArrayList<>();
for (AgreeEquation eq : e.localEquations) {
localEqs.add(this.visit(eq));
}
Expr clockConstraint = e.clockConstraint.accept(this);
Expr initialConstraint = e.initialConstraint.accept(this);
AgreeVar clockVar = this.visit(e.clockVar);
EObject reference = e.reference;
TimingModel timing = e.timing;
// ComponentInstance compinst = e.compInst;
AgreeNodeBuilder builder = new AgreeNodeBuilder(id);
builder.addInput(inputs);
builder.addOutput(outputs);
builder.addLocal(locals);
builder.addConnection(connections);
builder.addSubNode(subNodes);
builder.addAssertion(assertions);
builder.addAssumption(assumptions);
builder.addGuarantee(guarantees);
builder.addLemma(lemmas);
builder.addLocalEquation(localEqs);
builder.addPatternProp(patternProps);
builder.setClockConstraint(clockConstraint);
builder.setInitialConstraint(initialConstraint);
builder.setClockVar(clockVar);
builder.setReference(reference);
builder.setTiming(timing);
builder.setCompInst(e.compInst);
builder.addTimeFall(e.timeFallMap);
builder.addTimeRise(e.timeRiseMap);
builder.addTimeOf(e.timeOfMap);
AgreeNode result = builder.build();
visitedNodes.put(e.compInst, result);
return result;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class LustreAstBuilder method getLustreNode.
protected static Node getLustreNode(AgreeNode agreeNode, String nodePrefix) {
List<VarDecl> inputs = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<Equation> equations = new ArrayList<>();
List<Expr> assertions = new ArrayList<>();
List<String> ivcs = agreeNode.getivcElements();
List<String> properties = new ArrayList<>();
// add assumption history variable
IdExpr assumHist = new IdExpr(assumeHistSufix);
inputs.add(new AgreeVar(assumHist.id, NamedType.BOOL, null, agreeNode.compInst, null));
int i = 0;
for (AgreeStatement statement : agreeNode.assumptions) {
String inputName = assumeSuffix + i++;
inputs.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
IdExpr assumeId = new IdExpr(inputName);
assertions.add(new BinaryExpr(assumeId, BinaryOp.EQUAL, statement.expr));
}
int j = 0;
for (AgreeStatement statement : agreeNode.lemmas) {
String inputName = lemmaSuffix + j++;
inputs.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
properties.add(inputName);
IdExpr lemmaId = new IdExpr(inputName);
assertions.add(new BinaryExpr(lemmaId, BinaryOp.EQUAL, statement.expr));
}
int k = 0;
Expr guarConjExpr = new BoolExpr(true);
for (AgreeStatement statement : agreeNode.guarantees) {
String inputName = guarSuffix + k++;
locals.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
IdExpr guarId = new IdExpr(inputName);
equations.add(new Equation(guarId, statement.expr));
if (agreeNode.getFaultTreeFlag() == false) {
ivcs.add(guarId.id);
} else {
// check if it's leaf node
if (!agreeNode.compInst.getComponentInstances().isEmpty()) {
ivcs.add(guarId.id);
}
}
guarConjExpr = LustreExprFactory.makeANDExpr(guarId, guarConjExpr);
}
// assert that if the assumptions have held historically, then the
// gurantees hold
assertions.add(new BinaryExpr(assumHist, BinaryOp.IMPLIES, guarConjExpr));
for (AgreeStatement statement : agreeNode.assertions) {
assertions.add(statement.expr);
}
// create properties for the patterns
int l = 0;
for (AgreeStatement patternPropState : agreeNode.patternProps) {
String patternVarName = patternPropSuffix + l++;
inputs.add(new AgreeVar(patternVarName, NamedType.BOOL, patternPropState, agreeNode.compInst, null));
assertions.add(new BinaryExpr(new IdExpr(patternVarName), BinaryOp.EQUAL, patternPropState.expr));
}
Expr assertExpr = new BoolExpr(true);
for (Expr expr : assertions) {
assertExpr = LustreExprFactory.makeANDExpr(expr, assertExpr);
}
String outputName = "__ASSERT";
List<VarDecl> outputs = new ArrayList<>();
outputs.add(new VarDecl(outputName, NamedType.BOOL));
equations.add(new Equation(new IdExpr(outputName), assertExpr));
// gather the remaining inputs
for (AgreeVar var : agreeNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.outputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.locals) {
locals.add(var);
}
for (AgreeEquation equation : agreeNode.localEquations) {
equations.add(equation);
}
NodeBuilder builder = new NodeBuilder(nodePrefix + agreeNode.id);
builder.addInputs(inputs);
builder.addOutputs(outputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addIvcs(ivcs);
return builder.build();
}
Aggregations