Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Design Rule Check: no multiple drivers #130

Merged
merged 6 commits into from
Jul 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/java/org/manifold/compiler/back/digital/Check.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.manifold.compiler.back.digital;

import org.manifold.compiler.UndefinedBehaviourError;

public abstract class Check {
protected abstract void verify();

protected Boolean result = null;

public boolean run() {
if (result == null) {
verify();
// ensure that the check set a result
if (result == null) {
throw new UndefinedBehaviourError(
"Design rule check run produced no result");
}
}
return result;
}
// TODO(murphy) get list of failures
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.manifold.compiler.back.digital;

import java.util.Map;

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 NoMultipleDriversCheck extends Check {

private Schematic schematic;
private Netlist netlist;
private PortTypeValue digitalOutType;

public NoMultipleDriversCheck(Schematic schematic, Netlist netlist) {
this.schematic = schematic;
this.netlist = netlist;
try {
this.digitalOutType = schematic.getPortType("digitalOut");
} catch (UndeclaredIdentifierException e) {
throw new UndefinedBehaviourError(
"schematic does not define digitalOut port type");
}
}

@Override
protected void verify() {
System.err.println("expected digital out type = "
+ digitalOutType.toString());
Map<String, Net> allNets = netlist.getNets();
boolean noMultipleDrivers = true;
for (Net net : allNets.values()) {
int nDrivers = 0;
// a driver is any Port of type `digitalOutType`
for (PortValue port : net.getConnectedPorts()) {
System.err.println("port type = "
+ port.getType().toString());
if (port.getType() == digitalOutType) {
nDrivers += 1;
}
}
/*
* after checking all ports on this net, if there are at least 2 drivers
* then this net is multiply-driven and DRC fails
*/
if (nDrivers >= 2) {
noMultipleDrivers = false;
}
/*
* TODO(murphy) If all we care about is the decision, we can break here.
* However, we should keep processing in order to collect a list of which
* 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;
}

}
193 changes: 25 additions & 168 deletions src/test/java/org/manifold/compiler/back/TestNetlist.java
Original file line number Diff line number Diff line change
@@ -1,199 +1,56 @@
package org.manifold.compiler.back;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.HashMap;
import java.util.Map;

import org.junit.BeforeClass;
import org.junit.Test;
import org.manifold.compiler.BooleanTypeValue;
import org.manifold.compiler.BooleanValue;
import org.manifold.compiler.ConnectionType;
import org.manifold.compiler.ConnectionValue;
import org.manifold.compiler.InvalidAttributeException;
import org.manifold.compiler.MultipleDefinitionException;
import org.manifold.compiler.NodeTypeValue;
import org.manifold.compiler.NodeValue;
import org.manifold.compiler.PortTypeValue;
import org.manifold.compiler.PortValue;
import org.manifold.compiler.TypeValue;
import org.manifold.compiler.UndeclaredAttributeException;
import org.manifold.compiler.Value;
import org.manifold.compiler.back.digital.Net;
import org.manifold.compiler.back.digital.Netlist;
import org.manifold.compiler.middle.Schematic;
import org.manifold.compiler.middle.SchematicException;

public class TestNetlist {

private static PortTypeValue digitalInPortType;
private static PortTypeValue digitalOutPortType;

private static final Map<String, TypeValue> noTypeAttributes
= new HashMap<>();
private static final Map<String, Value> noAttributes
= new HashMap<>();

private static Map<String, TypeValue> registerTypeAttributes
= new HashMap<>();
private static Map<String, PortTypeValue> registerTypePorts
= new HashMap<>();
private static NodeTypeValue registerType;

private static Map<String, PortTypeValue> inputPinTypePorts
= new HashMap<>();
private static NodeTypeValue inputPinType;

private static Map<String, PortTypeValue> outputPinTypePorts
= new HashMap<>();
private static NodeTypeValue outputPinType;

private static ConnectionType digitalWireType;


@BeforeClass
public static void setupIntermediateTypes(){

digitalInPortType = new PortTypeValue(noTypeAttributes);
digitalOutPortType = new PortTypeValue(noTypeAttributes);

registerTypeAttributes.put("initialValue",
BooleanTypeValue.getInstance());
registerTypeAttributes.put("resetActiveHigh",
BooleanTypeValue.getInstance());
registerTypeAttributes.put("resetAsynchronous",
BooleanTypeValue.getInstance());
registerTypeAttributes.put("clockActiveHigh",
BooleanTypeValue.getInstance());
registerTypePorts.put("in", digitalInPortType);
registerTypePorts.put("out", digitalOutPortType);
registerTypePorts.put("clock", digitalInPortType);
registerTypePorts.put("reset", digitalInPortType);
registerType = new NodeTypeValue(registerTypeAttributes, registerTypePorts);

inputPinTypePorts.put("out", digitalOutPortType);
inputPinType = new NodeTypeValue(noTypeAttributes, inputPinTypePorts);

outputPinTypePorts.put("in", digitalInPortType);
outputPinType = new NodeTypeValue(noTypeAttributes, outputPinTypePorts);

digitalWireType = new ConnectionType(noTypeAttributes);
public static void setupClass() {
UtilSchematicConstruction.setupIntermediateTypes();
}

/**
* Instantiate a Schematic, but with varying degrees of "completeness"
* in terms of what object types are included. If types are missing,
* it will not be possible to construct a Netlist.
* @throws MultipleDefinitionException
*/
public static Schematic instantiateSchematic(String name,
boolean includePortTypes, boolean includeNodeTypes,
boolean includeConnectionTypes)
throws MultipleDefinitionException {
Schematic s = new Schematic(name);
if (includePortTypes) {
s.addPortType("digitalIn", digitalInPortType);
s.addPortType("digitalOut", digitalOutPortType);
}

if (includeNodeTypes) {
s.addNodeType("register", registerType);
s.addNodeType("inputPin", inputPinType);
s.addNodeType("outputPin", outputPinType);
}

if (includeConnectionTypes) {
s.addConnectionType("digitalWire", digitalWireType);
}

return s;
}

/**
* Instantiate a Schematic and include all object types.
*/
public static Schematic instantiateSchematic(String name)
throws MultipleDefinitionException {
return instantiateSchematic(name, true, true, true);
}

public static NodeValue instantiateRegister(boolean initialValue,
boolean resetActiveHigh, boolean resetAsynchronous,
boolean clockActiveHigh)
throws SchematicException {
Map<String, Value> registerAttrs = new HashMap<>();
registerAttrs.put("initialValue",
BooleanValue.getInstance(initialValue));
registerAttrs.put("resetActiveHigh",
BooleanValue.getInstance(resetActiveHigh));
registerAttrs.put("resetAsynchronous",
BooleanValue.getInstance(resetAsynchronous));
registerAttrs.put("clockActiveHigh",
BooleanValue.getInstance(clockActiveHigh));
Map<String, Map<String, Value>> registerPortAttrs = new HashMap<>();
registerPortAttrs.put("in", noAttributes);
registerPortAttrs.put("out", noAttributes);
registerPortAttrs.put("clock", noAttributes);
registerPortAttrs.put("reset", noAttributes);
NodeValue register = new NodeValue(
registerType, registerAttrs, registerPortAttrs);
return register;
}

public static NodeValue instantiateInputPin() throws SchematicException {
Map<String, Map<String, Value>> inputPinPortAttrs = new HashMap<>();
inputPinPortAttrs.put("out", noAttributes);
NodeValue inputPin = new NodeValue(
inputPinType, noAttributes, inputPinPortAttrs);
return inputPin;
}

public static NodeValue instantiateOutputPin() throws SchematicException {
Map<String, Map<String, Value>> outputPinPortAttrs = new HashMap<>();
outputPinPortAttrs.put("in", noAttributes);
NodeValue outputPin = new NodeValue(
outputPinType, noAttributes, outputPinPortAttrs);
return outputPin;
}

public static ConnectionValue instantiateWire(
PortValue from, PortValue to)
throws UndeclaredAttributeException, InvalidAttributeException{
ConnectionValue wire = new ConnectionValue(
digitalWireType, from, to, noAttributes);
return wire;
}


@Test
public void testConstruction() throws SchematicException {
// [digitalIn] -> [digitalOut]
Schematic sch = instantiateSchematic("case0");
NodeValue in = instantiateInputPin();
NodeValue out = instantiateOutputPin();
ConnectionValue in_to_out = instantiateWire(
Schematic sch = UtilSchematicConstruction.instantiateSchematic("case0");
NodeValue in = UtilSchematicConstruction.instantiateInputPin();
NodeValue out = UtilSchematicConstruction.instantiateOutputPin();
ConnectionValue in_to_out = UtilSchematicConstruction.instantiateWire(
in.getPort("out"), out.getPort("in"));
sch.addNode("in", in);
sch.addNode("out", out);
sch.addConnection("in_to_out", in_to_out);

Netlist netlist = new Netlist(sch);
}

@Test
public void testGetNets() throws SchematicException {
// [digitalIn] -> [digitalOut]
Schematic sch = instantiateSchematic("case0");
NodeValue in = instantiateInputPin();
NodeValue out = instantiateOutputPin();
ConnectionValue in_to_out = instantiateWire(
Schematic sch = UtilSchematicConstruction.instantiateSchematic("case0");
NodeValue in = UtilSchematicConstruction.instantiateInputPin();
NodeValue out = UtilSchematicConstruction.instantiateOutputPin();
ConnectionValue in_to_out = UtilSchematicConstruction.instantiateWire(
in.getPort("out"), out.getPort("in"));
sch.addNode("in", in);
sch.addNode("out", out);
sch.addConnection("in_to_out", in_to_out);

Netlist netlist = new Netlist(sch);

Map<String, Net> nets = netlist.getNets();
// there should be exactly one net
assertEquals(1, nets.values().size());
Expand All @@ -202,21 +59,21 @@ public void testGetNets() throws SchematicException {
assertTrue(n_in_to_out.getConnectedPorts().contains(in.getPort("out")));
assertTrue(n_in_to_out.getConnectedPorts().contains(out.getPort("in")));
}

@Test
public void testGetConnectedNet() throws SchematicException {
// [digitalIn] -> [digitalOut]
Schematic sch = instantiateSchematic("case0");
NodeValue in = instantiateInputPin();
NodeValue out = instantiateOutputPin();
ConnectionValue in_to_out = instantiateWire(
Schematic sch = UtilSchematicConstruction.instantiateSchematic("case0");
NodeValue in = UtilSchematicConstruction.instantiateInputPin();
NodeValue out = UtilSchematicConstruction.instantiateOutputPin();
ConnectionValue in_to_out = UtilSchematicConstruction.instantiateWire(
in.getPort("out"), out.getPort("in"));
sch.addNode("in", in);
sch.addNode("out", out);
sch.addConnection("in_to_out", in_to_out);

Netlist netlist = new Netlist(sch);

// `in` and `out` should both be connected to the same net
Net n_in = netlist.getConnectedNet(in.getPort("out"));
assertNotNull(n_in);
Expand Down
Loading