use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class Gal22v10JEDECExporterTest method testPin13.
public void testPin13() throws Exception {
Variable Q0 = new Variable("Q0");
Variable Q1 = new Variable("Q1");
Variable Q2 = new Variable("Q2");
Expression Y = and(Q0, Q1, Q2);
Gal22v10JEDECExporter gal = new Gal22v10JEDECExporter();
gal.getPinMapping().assignPin("Q0", 10).assignPin("Q1", 11).assignPin("Q2", 13).assignPin("Y", 23);
gal.getBuilder().addCombinatorial("Y", Y);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
gal.writeTo(baos);
assertEquals("\u0002Digital GAL22v10 assembler*\r\n" + "QF5892*\r\n" + "G0*\r\n" + "F0*\r\n" + // fuses generated with WinCupl
"L32 00000000000011111111111111111111*\r\n" + "L64 11111111111111111111111111111111*\r\n" + "L96 11111111111111111111111111110111*\r\n" + "L128 01010000000000000000000000000000*\r\n" + "L5792 00000000000000001100000000000000*\r\n" + // "L5824 00000011000000110000001000000000*\r\n" + // CUPL writes data to the signature bytes, don't know why
"C0AE3*\r\n" + "\u00033205", baos.toString());
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class CircuitBuilderTest method testBuilderSequentialJK.
public void testBuilderSequentialJK() throws Exception {
Variable y0 = new Variable("Y_0");
Variable y1 = new Variable("Y_1");
// counter
Expression y0s = not(y0);
Expression y1s = or(not(y0), not(y1));
ElementLibrary library = new ElementLibrary();
Circuit circuit = new CircuitBuilder(new ShapeFactory(library), true).addSequential("Y_0", y0s).addSequential("Y_1", y1s).createCircuit();
ModelCreator m = new ModelCreator(circuit, library);
TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
te.check(0, 0);
te.checkC(1, 1);
te.checkC(0, 0);
te.checkC(1, 1);
te.checkC(0, 0);
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class FuseMapFiller method fillExpression.
/**
* Fills an expression to the fuse map
*
* @param offs number of first fuse of first product term to use
* @param exp the expression
* @param productTerms the number of product terms available
* @throws FuseMapFillerException EquationHandlerException
*/
public void fillExpression(int offs, Expression exp, int productTerms) throws FuseMapFillerException {
ArrayList<Expression> terms;
if (exp instanceof Operation.Or) {
Operation.Or or = (Operation.Or) exp;
terms = or.getExpressions();
} else {
terms = new ArrayList<>();
terms.add(exp);
}
if (terms.size() > productTerms)
throw new FuseMapFillerException("only " + productTerms + " product terms supported but " + terms.size() + " needed!");
int fusesInTerm = varsConnectedToMap * 2;
for (Expression e : terms) {
for (int i = 0; i < fusesInTerm; i++) fuseMap.setFuse(offs + i, true);
ArrayList<Expression> ands;
if (e instanceof Operation.And) {
ands = ((Operation.And) e).getExpressions();
} else {
ands = new ArrayList<>();
ands.add(e);
}
for (Expression v : ands) {
Variable var;
boolean invert = false;
if (v instanceof Variable)
var = (Variable) v;
else if (v instanceof Not) {
Expression n = ((Not) v).getExpression();
if (n instanceof Variable) {
var = (Variable) n;
invert = true;
} else {
throw new FuseMapFillerException("NOT does not contain a variable!");
}
} else
throw new FuseMapFillerException("only VAR or NOT VAR allowed!");
MapEntry entry = varMap.get(var);
if (entry == null)
throw new FuseMapFillerException("VAR " + var + " not found in term list!");
int fuse = entry.getFuse(invert);
fuseMap.setFuse(offs + fuse, false);
}
offs += fusesInTerm;
}
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class BuilderExpressionCreator method create.
/**
* Fills the builder
*
* @param expressions the expressions to use
* @throws ExpressionException ExpressionException
* @throws FormatterException FormatterException
*/
public void create(ExpressionListenerStore expressions) throws ExpressionException, FormatterException {
if (expressions == null)
throw new ExpressionException(Lang.get("err_noExpressionsAvailable"));
ExpressionListener el = new ExpressionListener() {
@Override
public void resultFound(String name, Expression expression) throws FormatterException, ExpressionException {
if (!contained.contains(name)) {
contained.add(name);
try {
if (name.endsWith("n+1")) {
name = name.substring(0, name.length() - 2);
builder.addSequential(name, ExpressionModifier.modifyExpression(expression, modifier));
} else
builder.addCombinatorial(name, ExpressionModifier.modifyExpression(expression, modifier));
} catch (BuilderException e) {
throw new RuntimeException(e);
}
}
}
@Override
public void close() {
}
};
if (useJKOptimizer)
el = new ExpressionListenerOptimizeJK(el);
expressions.replayTo(el);
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class ExpressionListenerJK method resultFound.
@Override
public void resultFound(String name, Expression expression) throws FormatterException, ExpressionException {
parent.resultFound(name, expression);
if (name.endsWith("n+1")) {
String detName = name.substring(0, name.length() - 2);
DetermineJKStateMachine jk = new DetermineJKStateMachine(detName, expression);
Expression j = jk.getJ();
parent.resultFound("J_" + detName, j);
Expression s = jk.getSimplifiedJ();
if (!s.toString().equals(j.toString())) {
parent.resultFound("", s);
}
Expression k = jk.getK();
parent.resultFound("K_" + detName, k);
s = jk.getSimplifiedK();
if (!s.toString().equals(k.toString())) {
parent.resultFound("", s);
}
}
}
Aggregations