use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class CuplExporter method writeTo.
/**
* Writes code to given writer
*
* @param out the stream to write to
* @throws IOException IOException
* @throws PinMapException PinMapException
*/
public void writeTo(Writer out) throws IOException, PinMapException {
out.append("Name ").append(projectName).append(" ;\r\n").append("PartNo 00 ;\r\n").append("Date ").append(formatDate(date)).append(" ;\r\n").append("Revision 01 ;\r\n").append("Designer ").append(username).append(" ;\r\n").append("Company unknown ;\r\n").append("Assembly None ;\r\n").append("Location unknown ;\r\n").append("Device ").append(devName).append(" ;\r\n");
headerWritten(out);
out.append("\r\n/* inputs */\r\n");
if (!builder.getRegistered().isEmpty())
out.append("PIN ").append(String.valueOf(clockPin)).append(" = CLK;\r\n");
for (String in : builder.getInputs()) out.append("PIN ").append(Integer.toString(pinMap.getInputFor(in))).append(" = ").append(in).append(";\r\n");
out.append("\r\n/* outputs */\r\n");
for (String var : builder.getOutputs()) {
if (createNodes) {
int p = pinMap.isOutputAssigned(var);
if (p >= 0)
out.append("PIN ").append(Integer.toString(p)).append(" = ").append(var).append(";\r\n");
else
out.append("NODE ").append(var).append(";\r\n");
} else {
out.append("PIN ").append(Integer.toString(pinMap.getOutputFor(var))).append(" = ").append(var).append(";\r\n");
}
}
try {
if (!builder.getRegistered().isEmpty()) {
out.append("\r\n/* sequential logic */\r\n");
for (Map.Entry<String, Expression> c : builder.getRegistered().entrySet()) {
out.append(c.getKey()).append(".D = ");
breakLines(out, FormatToExpression.FORMATTER_CUPL.format(c.getValue()));
out.append(";\r\n");
sequentialWritten(out, c.getKey());
}
}
if (!builder.getCombinatorial().isEmpty()) {
out.append("\r\n/* combinatorial logic */\r\n");
for (Map.Entry<String, Expression> c : builder.getCombinatorial().entrySet()) {
out.append(c.getKey()).append(" = ");
breakLines(out, FormatToExpression.FORMATTER_CUPL.format(c.getValue()));
out.append(";\r\n");
}
}
} catch (FormatterException e) {
throw new IOException(e);
}
out.flush();
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class KarnaughMapTest method testSimple2_singleAnd.
public void testSimple2_singleAnd() throws IOException, ParseException, KarnaughException {
Expression exp = new Parser("A B").parse().get(0);
KarnaughMap c = new KarnaughMap(Variable.vars(2), exp);
assertEquals(1, c.size());
for (KarnaughMap.Cover co : c) assertEquals(1, co.getSize());
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class KarnaughMapTest method testSimple3.
public void testSimple3() throws IOException, ParseException, KarnaughException {
Expression exp = new Parser("(A ¬C) ∨ (¬A ¬B) ∨ (B C)").parse().get(0);
KarnaughMap c = new KarnaughMap(Variable.vars(3), exp);
assertEquals(3, c.size());
for (KarnaughMap.Cover co : c) assertEquals(2, co.getSize());
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class KarnaughMapTest method testSimple2.
public void testSimple2() throws IOException, ParseException, KarnaughException {
Expression exp = new Parser("(A ¬B) ∨ (¬A B)").parse().get(0);
KarnaughMap c = new KarnaughMap(Variable.vars(2), exp);
assertEquals(2, c.size());
for (KarnaughMap.Cover co : c) assertEquals(1, co.getSize());
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class ExpressionListenerJKTest method testSimple.
public void testSimple() throws IOException, ParseException, FormatterException, ExpressionException {
ExpressionListenerOptimizeJKTest.TestEL exp = new ExpressionListenerOptimizeJKTest.TestEL();
ExpressionListener elojk = new ExpressionListenerJK(exp);
Expression e1 = new Parser("(Sn*A)+(!Sn*B)").parse().get(0);
elojk.resultFound("Sn+1", e1);
elojk.close();
assertEquals(3, exp.getList().size());
assertEquals(e1, exp.getList().get(0));
assertEquals("B", exp.getList().get(1).toString());
assertEquals("not(A)", exp.getList().get(2).toString());
}
Aggregations