From 15094afeaa3fdf20626d3ac8fd5538012bcd94a1 Mon Sep 17 00:00:00 2001 From: "helmut.neemann" Date: Mon, 6 Jun 2016 15:20:57 +0200 Subject: [PATCH] added test for GAL22v10 JEDEC compiler --- .../Gal22v10/Gal22v10JEDECExporter.java | 7 +- .../digital/builder/jedec/FuseMapFiller.java | 43 +++++- .../Gal22v10/Gal22v10JEDECExporterTest.java | 146 ++++++++++++++++++ 3 files changed, 186 insertions(+), 10 deletions(-) create mode 100644 src/test/java/de/neemann/digital/builder/Gal22v10/Gal22v10JEDECExporterTest.java diff --git a/src/main/java/de/neemann/digital/builder/Gal22v10/Gal22v10JEDECExporter.java b/src/main/java/de/neemann/digital/builder/Gal22v10/Gal22v10JEDECExporter.java index 3b79d297f..b522f4bdc 100644 --- a/src/main/java/de/neemann/digital/builder/Gal22v10/Gal22v10JEDECExporter.java +++ b/src/main/java/de/neemann/digital/builder/Gal22v10/Gal22v10JEDECExporter.java @@ -30,7 +30,7 @@ public class Gal22v10JEDECExporter implements ExpressionExporter varMap; + private final HashMap varMap; /** * Creates a new instance @@ -43,7 +43,21 @@ public class FuseMapFiller { * @return this for chained calls */ public FuseMapFiller addVariable(int index, Variable var) { - varMap.put(var, index); + varMap.put(var, new MapEntry(index, false)); + return this; + } + + /** + * Adds a variable to the matrix + * In difference to addVariable() the inverted column comes first and the non inverted column follows. + * So the both columns are in reverse order compared to addVariable() + * + * @param index number in matrix + * @param var the variable + * @return this for chained calls + */ + public FuseMapFiller addVariableReverse(int index, Variable var) { + varMap.put(var, new MapEntry(index, true)); return this; } @@ -104,13 +118,12 @@ public class FuseMapFiller { } else throw new FuseMapFillerException("only VAR or NOT VAR allowed!"); - Integer i = varMap.get(var); + MapEntry entry = varMap.get(var); - if (i == null) + if (entry == null) throw new FuseMapFillerException("VAR " + var + " not found in term list!"); - int fuse = i * 2; - if (invert) fuse++; + int fuse = entry.getFuse(invert); fuseMap.setFuse(offs + fuse, false); } @@ -120,4 +133,22 @@ public class FuseMapFiller { } + private class MapEntry { + private final int index; + private final boolean swap; + + public MapEntry(int index, boolean swap) { + this.index = index; + this.swap = swap; + } + + public int getFuse(boolean invert) { + int fuse=index*2; + if (swap) { + if (!invert) fuse++; + } else + if (invert) fuse++; + return fuse; + } + } } diff --git a/src/test/java/de/neemann/digital/builder/Gal22v10/Gal22v10JEDECExporterTest.java b/src/test/java/de/neemann/digital/builder/Gal22v10/Gal22v10JEDECExporterTest.java new file mode 100644 index 000000000..c96acf8fe --- /dev/null +++ b/src/test/java/de/neemann/digital/builder/Gal22v10/Gal22v10JEDECExporterTest.java @@ -0,0 +1,146 @@ +package de.neemann.digital.builder.Gal22v10; + +import de.neemann.digital.analyse.expression.Expression; +import de.neemann.digital.analyse.expression.Variable; +import junit.framework.TestCase; + +import java.io.ByteArrayOutputStream; + +import static de.neemann.digital.analyse.expression.Not.not; +import static de.neemann.digital.analyse.expression.Operation.and; +import static de.neemann.digital.analyse.expression.Operation.or; + +/** + * Created by helmut.neemann on 06.06.2016. + */ +public class Gal22v10JEDECExporterTest extends TestCase { + + // stepper control; sequential and combinatorial + public void testSequential() throws Exception { + Variable D = new Variable("D"); + + Variable Q0 = new Variable("Q0"); + Variable Q1 = new Variable("Q1"); + Variable Q2 = new Variable("Q2"); + + //Q0.d = !Q0; + Expression Q0d = not(Q0); + //Q1.d = !D & !Q1 & Q0 # !D & Q1 & !Q0 # D & !Q1 & !Q0 # D & Q1 & Q0; + Expression Q1d = or(and(not(D), not(Q1), Q0), and(not(D), Q1, not(Q0)), and(D, not(Q1), not(Q0)), and(D, Q1, Q0)); + //Q2.d = !D & !Q2 & Q1 & Q0 # + // !D & Q2 & !Q1 # + // Q2 & Q1 & !Q0 # + // D & !Q2 & !Q1 & !Q0 # + // D & Q2 & Q0; + Expression Q2d = or( + and(not(D), not(Q2), Q1, Q0), + and(not(D), Q2, not(Q1)), + and(Q2, Q1, not(Q0)), + and(D, not(Q2), not(Q1), not(Q0)), + and(D, Q2, Q0)); + + //P0 = !Q2 & !Q1 # Q2 & Q1 & Q0; + Expression P0 = or( + and(not(Q2), not(Q1)), + and(Q2, Q1, Q0)); + //P1 = !Q2 & Q0 # !Q2 & Q1; + Expression P1 = or( + and(not(Q2), Q0), + and(not(Q2), Q1)); + //P2 = !Q2 & Q1 & Q0 # Q2 & !Q1; + Expression P2 = or( + and(not(Q2), Q1, Q0), + and(Q2, not(Q1))); + //P3 = Q2 & Q0 # Q2 & Q1; + Expression P3 = or( + and(Q2, Q0), + and(Q2, Q1)); + + + Gal22v10JEDECExporter gal = new Gal22v10JEDECExporter(); + + gal.getBuilder() + .addSequential("Q0", Q0d) + .addSequential("Q1", Q1d) + .addSequential("Q2", Q2d) + .addCombinatorial("P0", P0) + .addCombinatorial("P1", P1) + .addCombinatorial("P2", P2) + .addCombinatorial("P3", P3); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + gal.writeTo(baos); + + assertEquals("\u0002Digital GAL22v10 assembler*\r\n" + + "QF5892*\r\n" + + "G0*\r\n" + + "F0*\r\n" + + "L1472 00000000000000000000000011111111*\r\n" + // CUPL output + "L1504 11111111111111111111111111111111*\r\n" + + "L1536 11111111111111111111111111111111*\r\n" + + "L1568 11101111111011111111111111111111*\r\n" + + "L1600 11111111111111101110111111110000*\r\n" + + "L2144 00000000000011111111111111111111*\r\n" + + "L2176 11111111111111111111111111111111*\r\n" + + "L2208 11111111111111111111110111101110*\r\n" + + "L2240 11111111111111111111111111111111*\r\n" + + "L2272 11101101111111110000000000000000*\r\n" + + "L2880 00000000000000000000000011111111*\r\n" + + "L2912 11111111111111111111111111111111*\r\n" + + "L2944 11111111111111111111111111111111*\r\n" + + "L2976 11011111111011111111111111111111*\r\n" + + "L3008 11111111111111011110111111110000*\r\n" + + "L3648 00001111111111111111111111111111*\r\n" + + "L3680 11111111111111111111111111111111*\r\n" + + "L3712 11111111111111101110111011111111*\r\n" + + "L3744 11111111111111111111111111011101*\r\n" + + "L3776 11111111000000000000000000000000*\r\n" + + "L4288 00000000000000000000000011111111*\r\n" + + "L4320 11111111111111111111111111111111*\r\n" + + "L4352 11111111101111111111111111111111*\r\n" + + + "L4384 11011110111011111111101111111111*\r\n" + + "L4416 11111111111111101101111111111111*\r\n" + + "L4448 01111111111111111111111111011101*\r\n" + + "L4480 11011111111101111111111111111111*\r\n" + + "L4512 11111110111111101111111111111111*\r\n" + + "L4544 11111111111111111110111011011111*\r\n" + + + /* CUPL uses other product term ordering + "L4384 11011110111011111111011111111111*\r\n" + + "L4416 11111111111111011101110111111111*\r\n" + + "L4448 01111111111111111111111111101110*\r\n" + + "L4480 11111111111110111111111111111111*\r\n" + + "L4512 11111110111111011111111111111111*\r\n" + + "L4544 11111111111111111110110111101111*\r\n" +*/ + + "L4864 00000000000000000000111111111111*\r\n" + + "L4896 11111111111111111111111111111111*\r\n" + + "L4928 11111011111111111111111111111111*\r\n" + + + "L4960 11011110111111111011111111111111*\r\n" + + "L4992 11111111111111101101111111110111*\r\n"+ + + /* CUPL uses other product term ordering + "L4960 11101101111111111011111111111111*\r\n" + + "L4992 11111111111111011110111111110111*\r\n" +*/ + + "L5024 11111111111111111111111111011101*\r\n" + + "L5056 11111111011111111111111111111111*\r\n" + + "L5088 11111110111011110000000000000000*\r\n" + + "L5344 00000000000000000000000011111111*\r\n" + + "L5376 11111111111111111111111111111111*\r\n" + + "L5408 11111111111111111111111111111111*\r\n" + + "L5440 11111111110111110000000000000000*\r\n" + + "L5792 00000000000000000000001111111110*\r\n" + + "L5824 10100000000000000000000000000000*\r\n" + + /* CUPL writes some data to the signature + "L5824 10100011000000110000001000000000*\r\n" + + */ + "C8241*\r\n" + + "\u000353C9", baos.toString()); + + } + + +} \ No newline at end of file