use of com.cburch.logisim.comp.EndData in project logisim-evolution by reds-heig.
the class Netlist method GetHiddenSinks.
private ArrayList<ConnectionPoint> GetHiddenSinks(Net thisNet, Byte bitIndex, ArrayList<Component> SplitterList, Component ActiveSplitter, Set<String> HandledNets, Boolean isSourceNet) {
ArrayList<ConnectionPoint> result = new ArrayList<ConnectionPoint>();
/*
* to prevent deadlock situations we check if we already looked at this
* net
*/
String NetId = Integer.toString(MyNets.indexOf(thisNet)) + "-" + Byte.toString(bitIndex);
if (HandledNets.contains(NetId)) {
return result;
} else {
HandledNets.add(NetId);
}
if (thisNet.hasBitSinks(bitIndex) && !isSourceNet) {
result.addAll(thisNet.GetBitSinks(bitIndex));
}
/* Check if we have a connection to another splitter */
for (Component currentSplitter : SplitterList) {
if (ActiveSplitter != null) {
if (currentSplitter.equals(ActiveSplitter)) {
continue;
}
}
List<EndData> ends = currentSplitter.getEnds();
for (byte end = 0; end < ends.size(); end++) {
if (thisNet.contains(ends.get(end).getLocation())) {
/* Here we have to process the inherited bits of the parent */
byte[] BusBitConnection = ((Splitter) currentSplitter).GetEndpoints();
if (end == 0) {
/* this is a main net, find the connected end */
Byte SplitterEnd = BusBitConnection[bitIndex];
/* Find the corresponding Net index */
Byte Netindex = 0;
for (int index = 0; index < bitIndex; index++) {
if (BusBitConnection[index] == SplitterEnd) {
Netindex++;
}
}
/* Find the connected Net */
Net SlaveNet = null;
for (Net thisnet : MyNets) {
if (thisnet.contains(ends.get(SplitterEnd).getLocation())) {
SlaveNet = thisnet;
}
}
if (SlaveNet != null) {
if (SlaveNet.IsRootNet()) {
/* Trace down the slavenet */
result.addAll(GetHiddenSinks(SlaveNet, Netindex, SplitterList, currentSplitter, HandledNets, false));
} else {
result.addAll(GetHiddenSinks(SlaveNet.getParent(), SlaveNet.getBit(Netindex), SplitterList, currentSplitter, HandledNets, false));
}
}
} else {
ArrayList<Byte> Rootindices = new ArrayList<Byte>();
for (byte b = 0; b < BusBitConnection.length; b++) {
if (BusBitConnection[b] == end) {
Rootindices.add(b);
}
}
Net RootNet = null;
for (Net thisnet : MyNets) {
if (thisnet.contains(currentSplitter.getEnd(0).getLocation())) {
RootNet = thisnet;
}
}
if (RootNet != null) {
if (RootNet.IsRootNet()) {
result.addAll(GetHiddenSinks(RootNet, Rootindices.get(bitIndex), SplitterList, currentSplitter, HandledNets, false));
} else {
result.addAll(GetHiddenSinks(RootNet.getParent(), RootNet.getBit(Rootindices.get(bitIndex)), SplitterList, currentSplitter, HandledNets, false));
}
}
}
}
}
}
return result;
}
use of com.cburch.logisim.comp.EndData in project logisim-evolution by reds-heig.
the class Netlist method GenerateNetlist.
private boolean GenerateNetlist(FPGAReport Reporter, String HDLIdentifier) {
ArrayList<SimpleDRCContainer> drc = new ArrayList<SimpleDRCContainer>();
boolean errors = false;
GridBagConstraints gbc = new GridBagConstraints();
JFrame panel = new JFrame("Netlist: " + MyCircuit.getName());
panel.setResizable(false);
panel.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
GridBagLayout thisLayout = new GridBagLayout();
panel.setLayout(thisLayout);
JLabel LocText = new JLabel("Generating Netlist for Circuit: " + MyCircuit.getName());
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel.add(LocText, gbc);
JProgressBar progres = new JProgressBar(0, 7);
progres.setValue(0);
progres.setStringPainted(true);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel.add(progres, gbc);
panel.pack();
panel.setLocation(Projects.getCenteredLoc(panel.getWidth(), panel.getHeight()));
panel.setVisible(true);
CircuitName = MyCircuit.getName();
wires.clear();
wires.addAll(MyCircuit.getWires());
/*
* FIRST PASS: In this pass we take all wire segments and see if they
* are connected to other segments. If they are connected we build a
* net.
*/
while (wires.size() != 0) {
Net NewNet = new Net();
GetNet(null, NewNet);
if (!NewNet.isEmpty()) {
MyNets.add(NewNet);
}
}
/*
* Here we start to detect direct input-output component connections,
* read we detect "hidden" nets
*/
Set<Component> components = MyCircuit.getNonWires();
/* we Start with the creation of an outputs list */
Set<Location> OutputsList = new HashSet<Location>();
Set<Location> InputsList = new HashSet<Location>();
Set<Component> TunnelList = new HashSet<Component>();
MyComplexSplitters.clear();
drc.clear();
drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetList_IOError"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_INSTANCE));
drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetList_BitwidthError"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_WIRE));
for (Component com : components) {
/*
* We do not process the splitter and tunnel, they are processed
* later on
*/
boolean Ignore = false;
/* In this case, the probe should not be synthetised:
* We could set the Probe as non-HDL element. But If we set the Probe
* as non HDL element, logisim will not allow user to download the design.
*
* In some case we need to use Logisim Simulation before running the design on the hardware.
* During simulation, probes are very helpful to see signals values. And when simulation is ok,
* the user does not want to delete all probes.
* Thus, here we remove it form the netlist so it is transparent.
*/
if (com.getFactory() instanceof Probe) {
continue;
}
if (com.getFactory() instanceof SplitterFactory) {
MyComplexSplitters.add(com);
Ignore = true;
}
if (com.getFactory() instanceof Tunnel) {
TunnelList.add(com);
Ignore = true;
}
List<EndData> ends = com.getEnds();
for (EndData end : ends) {
if (!Ignore) {
if (end.isInput() && end.isOutput()) {
drc.get(0).AddMarkComponent(com);
}
if (end.isOutput()) {
OutputsList.add(end.getLocation());
} else {
InputsList.add(end.getLocation());
}
}
/* Here we are going to mark the bitwidths on the nets */
int width = end.getWidth().getWidth();
Location loc = end.getLocation();
for (Net ThisNet : MyNets) {
if (ThisNet.contains(loc)) {
if (!ThisNet.setWidth(width)) {
drc.get(1).AddMarkComponents(ThisNet.getWires());
}
}
}
}
}
for (int i = 0; i < drc.size(); i++) {
if (drc.get(i).DRCInfoPresent()) {
errors = true;
Reporter.AddError(drc.get(i));
}
}
if (errors) {
panel.dispose();
return false;
}
progres.setValue(1);
Rectangle ProgRect = progres.getBounds();
ProgRect.x = 0;
ProgRect.y = 0;
progres.paintImmediately(ProgRect);
/*
* Now we check if an input pin is connected to an output and in case of
* a Splitter if it is connected to either of them
*/
drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetAdd_ComponentWidthMismatch"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_INSTANCE));
Map<Location, Integer> Points = new HashMap<Location, Integer>();
for (Component comp : components) {
for (EndData end : comp.getEnds()) {
Location loc = end.getLocation();
if (Points.containsKey(loc)) {
/* Found a connection already used */
boolean newNet = true;
for (Net net : MyNets) {
if (net.contains(loc))
newNet = false;
}
if (newNet) {
int BitWidth = Points.get(loc);
if (BitWidth == end.getWidth().getWidth()) {
MyNets.add(new Net(loc, BitWidth));
} else {
drc.get(0).AddMarkComponent(comp);
}
}
} else
Points.put(loc, end.getWidth().getWidth());
}
}
if (drc.get(0).DRCInfoPresent()) {
Reporter.AddError(drc.get(0));
panel.dispose();
return false;
}
progres.setValue(2);
ProgRect = progres.getBounds();
ProgRect.x = 0;
ProgRect.y = 0;
progres.paintImmediately(ProgRect);
/*
* Here we are going to process the tunnels and possible merging of the
* tunneled nets
*/
boolean TunnelsPresent = false;
for (Component com : TunnelList) {
List<EndData> ends = com.getEnds();
for (EndData end : ends) {
for (Net ThisNet : MyNets) {
if (ThisNet.contains(end.getLocation())) {
ThisNet.addTunnel(com.getAttributeSet().getValue(StdAttr.LABEL));
TunnelsPresent = true;
}
}
}
}
drc.clear();
drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetMerge_BitWidthError"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_WIRE));
if (TunnelsPresent) {
Iterator<Net> NetIterator = MyNets.listIterator();
while (NetIterator.hasNext()) {
Net ThisNet = NetIterator.next();
if (ThisNet.HasTunnel() && (MyNets.indexOf(ThisNet) < (MyNets.size() - 1))) {
boolean merged = false;
Iterator<Net> SearchIterator = MyNets.listIterator(MyNets.indexOf(ThisNet) + 1);
while (SearchIterator.hasNext() && !merged) {
Net SearchNet = SearchIterator.next();
for (String name : ThisNet.TunnelNames()) {
if (SearchNet.ContainsTunnel(name) && !merged) {
merged = true;
if (!SearchNet.merge(ThisNet)) {
drc.get(0).AddMarkComponents(SearchNet.getWires());
drc.get(0).AddMarkComponents(ThisNet.getWires());
}
}
}
}
if (merged) {
NetIterator.remove();
}
}
}
}
if (drc.get(0).DRCInfoPresent()) {
Reporter.AddError(drc.get(0));
panel.dispose();
return false;
}
progres.setValue(3);
ProgRect = progres.getBounds();
ProgRect.x = 0;
ProgRect.y = 0;
progres.paintImmediately(ProgRect);
/* At this point all net segments are build. All tunnels have been removed. There is still the processing of
* the splitters and the determination of the direction of the nets.
*/
/* First we are going to check on duplicated splitters and remove them */
Iterator<Component> MySplitIterator = MyComplexSplitters.listIterator();
while (MySplitIterator.hasNext()) {
Component ThisSplitter = MySplitIterator.next();
if (MyComplexSplitters.indexOf(ThisSplitter) < (MyComplexSplitters.size() - 1)) {
boolean FoundDuplicate = false;
Iterator<Component> SearchIterator = MyComplexSplitters.listIterator(MyComplexSplitters.indexOf(ThisSplitter) + 1);
while (SearchIterator.hasNext() && !FoundDuplicate) {
Component SearchSplitter = SearchIterator.next();
if (SearchSplitter.getLocation().equals(ThisSplitter.getLocation())) {
FoundDuplicate = true;
for (int i = 0; i < SearchSplitter.getEnds().size(); i++) {
if (!SearchSplitter.getEnd(i).getLocation().equals(ThisSplitter.getEnd(i).getLocation()))
FoundDuplicate = false;
}
}
}
if (FoundDuplicate) {
SimpleDRCContainer warn = new SimpleDRCContainer(MyCircuit, Strings.get("NetList_duplicatedSplitter"), SimpleDRCContainer.LEVEL_SEVERE, SimpleDRCContainer.MARK_INSTANCE);
warn.AddMarkComponent(ThisSplitter);
Reporter.AddWarning(warn);
MySplitIterator.remove();
}
}
}
/* In this round we are going to detect the unconnected nets meaning those having a width of 0 and remove them */
drc.clear();
Iterator<Net> NetIterator = MyNets.listIterator();
drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetList_emptynets"), SimpleDRCContainer.LEVEL_NORMAL, SimpleDRCContainer.MARK_WIRE));
while (NetIterator.hasNext()) {
Net wire = NetIterator.next();
if (wire.BitWidth() == 0) {
drc.get(0).AddMarkComponents(wire.getWires());
NetIterator.remove();
}
}
if (drc.get(0).DRCInfoPresent()) {
Reporter.AddWarning(drc.get(0));
}
MySplitIterator = MyComplexSplitters.iterator();
/* We also check quickly the splitters and remove the ones where input-bus is output-bus. We mark those who are not
* correctly connected and remove both versions from the set.
*/
drc.clear();
drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetList_ShortCircuit"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_WIRE));
errors = false;
while (MySplitIterator.hasNext()) {
Component mySplitter = MySplitIterator.next();
int BusWidth = mySplitter.getEnd(0).getWidth().getWidth();
List<EndData> myEnds = mySplitter.getEnds();
int MaxFanoutWidth = 0;
int index = -1;
for (int i = 1; i < myEnds.size(); i++) {
int width = mySplitter.getEnd(i).getWidth().getWidth();
if (width > MaxFanoutWidth) {
MaxFanoutWidth = width;
index = i;
}
}
/* stupid situation first: the splitters bus connection is a single fanout */
if (BusWidth == MaxFanoutWidth) {
Net busnet = null;
Net connectedNet = null;
Location BusLoc = mySplitter.getEnd(0).getLocation();
Location ConnectedLoc = mySplitter.getEnd(index).getLocation();
boolean issueWarning = false;
/* here we search for the nets */
for (Net CurrentNet : MyNets) {
if (CurrentNet.contains(BusLoc)) {
if (busnet != null) {
Reporter.AddFatalError("BUG: Multiple bus nets found for a single splitter\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
panel.dispose();
return false;
} else {
busnet = CurrentNet;
}
}
if (CurrentNet.contains(ConnectedLoc)) {
if (connectedNet != null) {
Reporter.AddFatalError("BUG: Multiple nets found for a single splitter split connection\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
panel.dispose();
return false;
} else {
connectedNet = CurrentNet;
}
}
}
if (connectedNet != null) {
if (busnet != null) {
/* we can merge both nets */
if (!busnet.merge(connectedNet)) {
Reporter.AddFatalError("BUG: Splitter bus merge error\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
panel.dispose();
return false;
} else {
MyNets.remove(MyNets.indexOf(connectedNet));
}
} else {
issueWarning = true;
}
} else {
issueWarning = true;
}
if (issueWarning) {
SimpleDRCContainer warn = new SimpleDRCContainer(MyCircuit, Strings.get("NetList_NoSplitterConnection"), SimpleDRCContainer.LEVEL_SEVERE, SimpleDRCContainer.MARK_INSTANCE);
warn.AddMarkComponent(mySplitter);
Reporter.AddWarning(warn);
}
MySplitIterator.remove();
/* Does not exist anymore */
}
}
progres.setValue(4);
ProgRect = progres.getBounds();
ProgRect.x = 0;
ProgRect.y = 0;
progres.paintImmediately(ProgRect);
/*
* Finally we have to process the splitters to determine the bus
* hierarchy (if any)
*/
/*
* In this round we only process the evident splitters and remove them
* from the list
*/
Iterator<Component> MySplitters = MyComplexSplitters.iterator();
while (MySplitters.hasNext()) {
Component com = MySplitters.next();
/*
* Currently by definition end(0) is the combined end of the
* splitter
*/
List<EndData> ends = com.getEnds();
EndData CombinedEnd = ends.get(0);
int RootNet = -1;
/* We search for the root net in the list of nets */
for (int i = 0; i < MyNets.size() && RootNet < 0; i++) {
if (MyNets.get(i).contains(CombinedEnd.getLocation())) {
RootNet = i;
}
}
if (RootNet < 0) {
Reporter.AddFatalError("BUG: Splitter without a bus connection\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
this.clear();
panel.dispose();
return false;
}
/*
* Now we process all the other ends to find the child busses/nets
* of this root bus
*/
ArrayList<Integer> Connections = new ArrayList<Integer>();
for (int i = 1; i < ends.size(); i++) {
EndData ThisEnd = ends.get(i);
/* Find the connected net */
int ConnectedNet = -1;
for (int j = 0; j < MyNets.size() && ConnectedNet < 1; j++) {
if (MyNets.get(j).contains(ThisEnd.getLocation())) {
ConnectedNet = j;
}
}
Connections.add(ConnectedNet);
}
boolean unconnectedEnds = false;
for (int i = 1; i < ends.size(); i++) {
int ConnectedNet = Connections.get(i - 1);
if (ConnectedNet >= 0) {
/* There is a net connected to this splitter's end point */
if (!MyNets.get(ConnectedNet).setParent(MyNets.get(RootNet))) {
MyNets.get(ConnectedNet).ForceRootNet();
}
/* Here we have to process the inherited bits of the parent */
byte[] BusBitConnection = ((Splitter) com).GetEndpoints();
for (byte b = 0; b < BusBitConnection.length; b++) {
if (BusBitConnection[b] == i) {
MyNets.get(ConnectedNet).AddParrentBit(b);
}
}
} else {
unconnectedEnds = true;
}
}
if (unconnectedEnds) {
SimpleDRCContainer warn = new SimpleDRCContainer(MyCircuit, Strings.get("NetList_NoSplitterEndConnections"), SimpleDRCContainer.LEVEL_NORMAL, SimpleDRCContainer.MARK_INSTANCE);
warn.AddMarkComponent(com);
Reporter.AddWarning(warn);
}
}
progres.setValue(5);
ProgRect = progres.getBounds();
ProgRect.x = 0;
ProgRect.y = 0;
progres.paintImmediately(ProgRect);
/*
* Now the complete netlist is created, we have to check that each
* net/bus entry has only 1 source and 1 or more sinks. If there exist
* more than 1 source we have a short circuit! We keep track of the
* sources and sinks at the root nets/buses
*/
for (Net ThisNet : MyNets) {
if (ThisNet.IsRootNet()) {
ThisNet.InitializeSourceSinks();
}
}
for (Component comp : components) {
if (comp.getFactory() instanceof SubcircuitFactory) {
if (!ProcessSubcircuit(comp, Reporter)) {
this.clear();
panel.dispose();
return false;
}
} else if ((comp.getFactory() instanceof Pin) || (comp.getFactory().getIOInformation() != null) || (comp.getFactory().getHDLGenerator(HDLIdentifier, comp.getAttributeSet()) != null)) {
if (!ProcessNormalComponent(comp, Reporter)) {
this.clear();
panel.dispose();
return false;
}
}
}
progres.setValue(6);
ProgRect = progres.getBounds();
ProgRect.x = 0;
ProgRect.y = 0;
progres.paintImmediately(ProgRect);
/*
* Here we are going to process the complex splitters, note that in the
* previous handling of the splitters we marked all nets connected to a
* complex splitter with a forcerootnet annotation; we are going to
* cycle trough all these nets
*/
for (Net thisnet : MyNets) {
if (thisnet.IsForcedRootNet()) {
/* Cycle through all the bits of this net */
for (int bit = 0; bit < thisnet.BitWidth(); bit++) {
for (Component comp : MyComplexSplitters) {
/*
* Currently by definition end(0) is the combined end of
* the splitter
*/
List<EndData> ends = comp.getEnds();
EndData CombinedEnd = ends.get(0);
int ConnectedBus = -1;
/* We search for the root net in the list of nets */
for (int i = 0; i < MyNets.size() && ConnectedBus < 0; i++) {
if (MyNets.get(i).contains(CombinedEnd.getLocation())) {
ConnectedBus = i;
}
}
if (ConnectedBus < 0) {
/*
* This should never happen as we already checked in
* the first pass
*/
Reporter.AddFatalError("BUG: This is embarasing as this should never happen\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
this.clear();
panel.dispose();
return false;
}
for (int endid = 1; endid < ends.size(); endid++) {
/*
* we iterate through all bits to see if the current
* net is connected to this splitter
*/
if (thisnet.contains(ends.get(endid).getLocation())) {
/*
* first we have to get the bitindices of the
* rootbus
*/
/*
* Here we have to process the inherited bits of
* the parent
*/
byte[] BusBitConnection = ((Splitter) comp).GetEndpoints();
ArrayList<Byte> IndexBits = new ArrayList<Byte>();
for (byte b = 0; b < BusBitConnection.length; b++) {
if (BusBitConnection[b] == endid) {
IndexBits.add(b);
}
}
byte ConnectedBusIndex = IndexBits.get(bit);
/* Figure out the rootbusid and rootbusindex */
Net Rootbus = MyNets.get(ConnectedBus);
while (!Rootbus.IsRootNet()) {
ConnectedBusIndex = Rootbus.getBit(ConnectedBusIndex);
Rootbus = Rootbus.getParent();
}
ConnectionPoint SolderPoint = new ConnectionPoint(comp);
SolderPoint.SetParrentNet(Rootbus, ConnectedBusIndex);
Boolean IsSink = true;
if (!thisnet.hasBitSource(bit)) {
if (HasHiddenSource(Rootbus, ConnectedBusIndex, MyComplexSplitters, comp, new HashSet<String>())) {
IsSink = false;
}
}
if (IsSink) {
thisnet.addSinkNet(bit, SolderPoint);
} else {
thisnet.addSourceNet(bit, SolderPoint);
}
}
}
}
}
}
}
progres.setValue(7);
ProgRect = progres.getBounds();
ProgRect.x = 0;
ProgRect.y = 0;
progres.paintImmediately(ProgRect);
panel.dispose();
/* So now we have all information we need! */
return true;
}
use of com.cburch.logisim.comp.EndData in project logisim-evolution by reds-heig.
the class Netlist method GetHiddenSource.
private SourceInfo GetHiddenSource(Net thisNet, Byte bitIndex, List<Component> SplitterList, Component ActiveSplitter, Set<String> HandledNets, Set<Wire> Segments, FPGAReport Reporter) {
/*
* to prevent deadlock situations we check if we already looked at this
* net
*/
String NetId = Integer.toString(MyNets.indexOf(thisNet)) + "-" + Byte.toString(bitIndex);
if (HandledNets.contains(NetId)) {
return null;
} else {
HandledNets.add(NetId);
Segments.addAll(thisNet.getWires());
}
if (thisNet.hasBitSource(bitIndex)) {
List<ConnectionPoint> sources = thisNet.GetBitSources(bitIndex);
if (sources.size() != 1) {
Reporter.AddFatalError("BUG: Found multiple sources\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return null;
}
return new SourceInfo(sources.get(0), bitIndex);
}
/* Check if we have a connection to another splitter */
for (Component currentSplitter : SplitterList) {
if (currentSplitter.equals(ActiveSplitter)) {
continue;
}
List<EndData> ends = currentSplitter.getEnds();
for (byte end = 0; end < ends.size(); end++) {
if (thisNet.contains(ends.get(end).getLocation())) {
/* Here we have to process the inherited bits of the parent */
byte[] BusBitConnection = ((Splitter) currentSplitter).GetEndpoints();
if (end == 0) {
/* this is a main net, find the connected end */
Byte SplitterEnd = BusBitConnection[bitIndex];
/* Find the corresponding Net index */
Byte Netindex = 0;
for (int index = 0; index < bitIndex; index++) {
if (BusBitConnection[index] == SplitterEnd) {
Netindex++;
}
}
/* Find the connected Net */
Net SlaveNet = null;
for (Net thisnet : MyNets) {
if (thisnet.contains(ends.get(SplitterEnd).getLocation())) {
SlaveNet = thisnet;
}
}
if (SlaveNet != null) {
if (SlaveNet.IsRootNet()) {
/* Trace down the slavenet */
SourceInfo ret = GetHiddenSource(SlaveNet, Netindex, SplitterList, currentSplitter, HandledNets, Segments, Reporter);
if (ret != null)
return ret;
} else {
SourceInfo ret = GetHiddenSource(SlaveNet.getParent(), SlaveNet.getBit(Netindex), SplitterList, currentSplitter, HandledNets, Segments, Reporter);
if (ret != null)
return ret;
}
}
} else {
ArrayList<Byte> Rootindices = new ArrayList<Byte>();
for (byte b = 0; b < BusBitConnection.length; b++) {
if (BusBitConnection[b] == end) {
Rootindices.add(b);
}
}
Net RootNet = null;
for (Net thisnet : MyNets) {
if (thisnet.contains(currentSplitter.getEnd(0).getLocation())) {
RootNet = thisnet;
}
}
if (RootNet != null) {
if (RootNet.IsRootNet()) {
SourceInfo ret = GetHiddenSource(RootNet, Rootindices.get(bitIndex), SplitterList, currentSplitter, HandledNets, Segments, Reporter);
if (ret != null)
return ret;
} else {
SourceInfo ret = GetHiddenSource(RootNet.getParent(), RootNet.getBit(Rootindices.get(bitIndex)), SplitterList, currentSplitter, HandledNets, Segments, Reporter);
if (ret != null)
return ret;
}
}
}
}
}
}
return null;
}
use of com.cburch.logisim.comp.EndData in project logisim-evolution by reds-heig.
the class MoveGesture method computeConnections.
private static Set<ConnectionData> computeConnections(Circuit circuit, Set<Component> selected) {
if (selected == null || selected.isEmpty())
return Collections.emptySet();
// first identify locations that might be connected
Set<Location> locs = new HashSet<Location>();
for (Component comp : selected) {
for (EndData end : comp.getEnds()) {
locs.add(end.getLocation());
}
}
// now see which of them require connection
Set<ConnectionData> conns = new HashSet<ConnectionData>();
for (Location loc : locs) {
boolean found = false;
for (Component comp : circuit.getComponents(loc)) {
if (!selected.contains(comp)) {
found = true;
break;
}
}
if (found) {
List<Wire> wirePath;
Location wirePathStart;
Wire lastOnPath = findWire(circuit, loc, selected, null);
if (lastOnPath == null) {
wirePath = Collections.emptyList();
wirePathStart = loc;
} else {
wirePath = new ArrayList<Wire>();
Location cur = loc;
for (Wire w = lastOnPath; w != null; w = findWire(circuit, cur, selected, w)) {
wirePath.add(w);
cur = w.getOtherEnd(cur);
}
Collections.reverse(wirePath);
wirePathStart = cur;
}
Direction dir = null;
if (lastOnPath != null) {
Location other = lastOnPath.getOtherEnd(loc);
int dx = loc.getX() - other.getX();
int dy = loc.getY() - other.getY();
if (Math.abs(dx) > Math.abs(dy)) {
dir = dx > 0 ? Direction.EAST : Direction.WEST;
} else {
dir = dy > 0 ? Direction.SOUTH : Direction.NORTH;
}
}
conns.add(new ConnectionData(loc, dir, wirePath, wirePathStart));
}
}
return conns;
}
use of com.cburch.logisim.comp.EndData in project logisim-evolution by reds-heig.
the class PortHDLGeneratorFactory method GetEntity.
// #2
@Override
public ArrayList<String> GetEntity(Netlist TheNetlist, AttributeSet attrs, String ComponentName, FPGAReport Reporter, String HDLType) {
NetlistComponent ComponentInfo = null;
compMap.put(ComponentName, new HashMap<Integer, InOutMap>());
for (NetlistComponent comp : TheNetlist.GetNormalComponents()) {
if (comp.GetComponent().getAttributeSet().equals(attrs)) {
ComponentInfo = comp;
break;
}
}
int mapIdx = 0;
for (int portNr = 0; portNr < ComponentInfo.GetComponent().getEnds().size(); portNr++) {
Location splitterLoc = findEndConnection(ComponentInfo.GetComponent().getEnd(portNr).getLocation(), TheNetlist.getCircuit());
if (splitterLoc == null) {
Reporter.AddFatalError("Found 0, 2 or more connections on PortIO's splitter (" + ComponentName + ")");
return null;
}
for (Splitter split : TheNetlist.getSplitters()) {
if (split.getLocation().equals(splitterLoc)) {
// trouve le
// premier
// splitter du
// Port
compMap.get(ComponentName).put(mapIdx, new InOutMap(Type.INOUT, new Point(0, split.GetEndpoints().length - 1), portNr));
int splitPortNr = 0;
for (EndData end : split.getEnds()) {
if (!end.getLocation().equals(splitterLoc)) {
// parcours
// les
// sortie
// du
// splitter
Location compLoc = findEndConnection(end.getLocation(), TheNetlist.getCircuit());
if (compLoc == null) {
Reporter.AddFatalError("Found 0, 2 or more connections on PortIO's splitter (" + ComponentName + ")");
return null;
}
for (Component comp : TheNetlist.getCircuit().getNonWires(compLoc)) {
// splitter
for (EndData port : comp.getEnds()) {
if (port.getLocation().equals(compLoc)) {
// splitter
if (!(comp instanceof Splitter) && !(comp instanceof PortIO)) {
if (port.isInput()) {
compMap.get(ComponentName).put(mapIdx, new InOutMap(Type.OUT, getBitRange(split.GetEndpoints(), splitPortNr), portNr));
} else if (port.isOutput()) {
compMap.get(ComponentName).put(mapIdx, new InOutMap(Type.IN, getBitRange(split.GetEndpoints(), splitPortNr), portNr));
}
} else {
Reporter.AddFatalError("Cannot connect PortIO's splitter to other splitter or PortIO (" + ComponentName + ")");
return null;
}
}
}
}
}
mapIdx++;
splitPortNr++;
}
}
}
}
ArrayList<String> Contents = new ArrayList<String>();
Contents.addAll(FileWriter.getGenerateRemark(ComponentName, VHDL, TheNetlist.projName()));
Contents.addAll(FileWriter.getExtendedLibrary());
Contents.add("ENTITY " + ComponentName + " IS");
Contents.add(" PORT ( ");
for (int i = 0; i < compMap.get(ComponentName).size(); i++) {
String line = " ";
switch(compMap.get(ComponentName).get(i).getType()) {
case IN:
line += inBusName + "_" + i + " : IN ";
break;
case OUT:
line += outBusName + "_" + i + " : OUT ";
break;
case INOUT:
line += inOutBusName + "_" + i + " : INOUT ";
break;
default:
Reporter.AddFatalError("Found component of unknown type (" + compMap.get(ComponentName).get(i).toString() + ")");
}
if (compMap.get(ComponentName).get(i).getSize() == 1) {
line += "std_logic";
} else {
line += "std_logic_vector (" + (compMap.get(ComponentName).get(i).getSize() - 1) + " DOWNTO 0)";
}
if (i == (compMap.get(ComponentName).size() - 1)) {
line += ")";
}
line += ";";
Contents.add(line);
}
Contents.add("END " + ComponentName + ";");
Contents.add("");
return Contents;
}
Aggregations