diff --git a/src/main/java/org/manifold/compiler/back/digital/DesignRuleCheck.java b/src/main/java/org/manifold/compiler/back/digital/Check.java similarity index 78% rename from src/main/java/org/manifold/compiler/back/digital/DesignRuleCheck.java rename to src/main/java/org/manifold/compiler/back/digital/Check.java index 737e539..f028ad4 100644 --- a/src/main/java/org/manifold/compiler/back/digital/DesignRuleCheck.java +++ b/src/main/java/org/manifold/compiler/back/digital/Check.java @@ -2,14 +2,14 @@ import org.manifold.compiler.UndefinedBehaviourError; -public abstract class DesignRuleCheck { - public abstract void check(); +public abstract class Check { + protected abstract void verify(); protected Boolean result = null; - public boolean passed() { + public boolean run() { if (result == null) { - check(); + verify(); // ensure that the check set a result if (result == null) { throw new UndefinedBehaviourError( diff --git a/src/main/java/org/manifold/compiler/back/digital/Netlist.java b/src/main/java/org/manifold/compiler/back/digital/Netlist.java index c79ba16..7f0076f 100644 --- a/src/main/java/org/manifold/compiler/back/digital/Netlist.java +++ b/src/main/java/org/manifold/compiler/back/digital/Netlist.java @@ -17,19 +17,9 @@ public class Netlist { private ConnectionType digitalWireType; - public ConnectionType getDigitalWireType() { - return digitalWireType; - } private PortTypeValue digitalInType; - public PortTypeValue getDigitalInType() { - return digitalInType; - } private PortTypeValue digitalOutType; - public PortTypeValue getDigitalOutType() { - return digitalOutType; - } - private Map nets = new HashMap<>(); public Map getNets() { diff --git a/src/main/java/org/manifold/compiler/back/digital/DRC_NoMultipleDrivers.java b/src/main/java/org/manifold/compiler/back/digital/NoMultipleDriversCheck.java similarity index 68% rename from src/main/java/org/manifold/compiler/back/digital/DRC_NoMultipleDrivers.java rename to src/main/java/org/manifold/compiler/back/digital/NoMultipleDriversCheck.java index 02f0428..2332d8b 100644 --- a/src/main/java/org/manifold/compiler/back/digital/DRC_NoMultipleDrivers.java +++ b/src/main/java/org/manifold/compiler/back/digital/NoMultipleDriversCheck.java @@ -4,22 +4,30 @@ import org.manifold.compiler.PortTypeValue; import org.manifold.compiler.PortValue; +import org.manifold.compiler.UndeclaredIdentifierException; +import org.manifold.compiler.UndefinedBehaviourError; +import org.manifold.compiler.middle.Schematic; -public class DRC_NoMultipleDrivers extends DesignRuleCheck { +public class NoMultipleDriversCheck extends Check { + private Schematic schematic; private Netlist netlist; - private PortTypeValue digitalInType; private PortTypeValue digitalOutType; - public DRC_NoMultipleDrivers(Netlist netlist) { + public NoMultipleDriversCheck(Schematic schematic, Netlist netlist) { + this.schematic = schematic; this.netlist = netlist; - this.digitalInType = netlist.getDigitalInType(); - this.digitalOutType = netlist.getDigitalOutType(); + try { + this.digitalOutType = schematic.getPortType("digitalOut"); + } catch (UndeclaredIdentifierException e) { + throw new UndefinedBehaviourError( + "schematic does not define digitalOut port type"); + } } @Override - public void check() { + protected void verify() { System.err.println("expected digital out type = " + digitalOutType.toString()); Map allNets = netlist.getNets(); @@ -47,6 +55,7 @@ public void check() { * nets are multiply driven, and the ports that are driving them. This * will be useful when showing the user the results of DRC so they can * correct the design. + * This is described in Issue #131. */ } this.result = noMultipleDrivers; diff --git a/src/test/java/org/manifold/compiler/back/TestDRC_NoMultipleDrivers.java b/src/test/java/org/manifold/compiler/back/TestNoMultipleDriversCheck.java similarity index 83% rename from src/test/java/org/manifold/compiler/back/TestDRC_NoMultipleDrivers.java rename to src/test/java/org/manifold/compiler/back/TestNoMultipleDriversCheck.java index ef427c5..e9913ab 100644 --- a/src/test/java/org/manifold/compiler/back/TestDRC_NoMultipleDrivers.java +++ b/src/test/java/org/manifold/compiler/back/TestNoMultipleDriversCheck.java @@ -13,14 +13,14 @@ import org.junit.runners.Parameterized.Parameters; import org.manifold.compiler.ConnectionValue; import org.manifold.compiler.NodeValue; -import org.manifold.compiler.back.digital.DRC_NoMultipleDrivers; -import org.manifold.compiler.back.digital.DesignRuleCheck; +import org.manifold.compiler.back.digital.Check; import org.manifold.compiler.back.digital.Netlist; +import org.manifold.compiler.back.digital.NoMultipleDriversCheck; import org.manifold.compiler.middle.Schematic; import org.manifold.compiler.middle.SchematicException; @RunWith(Parameterized.class) -public class TestDRC_NoMultipleDrivers { +public class TestNoMultipleDriversCheck { @BeforeClass public static void setupClass() { @@ -45,7 +45,7 @@ public static Collection data() throws SchematicException { case0.addConnection("in0_to_out0", in0_to_out0); Netlist netlist_case0 = new Netlist(case0); - Object[] case0_data = new Object[] { netlist_case0, true }; + Object[] case0_data = new Object[] { case0, netlist_case0, true }; testData.add(case0_data); } // END CASE 0 @@ -70,7 +70,7 @@ public static Collection data() throws SchematicException { case1.addConnection("in1_to_out0", in1_to_out0); Netlist netlist_case1 = new Netlist(case1); - Object[] case1_data = new Object[] { netlist_case1, false }; + Object[] case1_data = new Object[] { case1, netlist_case1, false }; testData.add(case1_data); } // END CASE 1 @@ -78,20 +78,21 @@ public static Collection data() throws SchematicException { } // test inputs + private Schematic schematic; private Netlist netlist; private boolean expectedCheckResult; - public TestDRC_NoMultipleDrivers(Netlist netlist, + public TestNoMultipleDriversCheck(Schematic schematic, Netlist netlist, Boolean expectedCheckResult) { + this.schematic = schematic; this.netlist = netlist; this.expectedCheckResult = expectedCheckResult; } @Test public void testDRC() { - DesignRuleCheck drc = new DRC_NoMultipleDrivers(netlist); - drc.check(); - boolean actualCheckResult = drc.passed(); + Check drc = new NoMultipleDriversCheck(schematic, netlist); + boolean actualCheckResult = drc.run(); assertEquals(expectedCheckResult, actualCheckResult); }