use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.
the class Netlist method MarkClockSourceComponents.
public boolean MarkClockSourceComponents(ArrayList<String> HierarchyNames, ArrayList<Netlist> HierarchyNetlists, ClockSourceContainer ClockSources, FPGAReport Reporter) {
/* First pass: we go down the hierarchy till the leaves */
for (NetlistComponent sub : MySubCircuits) {
ArrayList<String> NewHierarchyNames = new ArrayList<String>();
ArrayList<Netlist> NewHierarchyNetlists = new ArrayList<Netlist>();
SubcircuitFactory SubFact = (SubcircuitFactory) sub.GetComponent().getFactory();
NewHierarchyNames.addAll(HierarchyNames);
NewHierarchyNames.add(CorrectLabel.getCorrectLabel(sub.GetComponent().getAttributeSet().getValue(StdAttr.LABEL)));
NewHierarchyNetlists.addAll(HierarchyNetlists);
NewHierarchyNetlists.add(SubFact.getSubcircuit().getNetList());
if (!SubFact.getSubcircuit().getNetList().MarkClockSourceComponents(NewHierarchyNames, NewHierarchyNetlists, ClockSources, Reporter)) {
return false;
}
}
/*
* We see if some components require the Global fast FPGA
* clock
*/
for (Component comp : MyCircuit.getNonWires()) {
if (comp.getFactory().RequiresGlobalClock()) {
ClockSources.SetGloblaClockRequirement();
}
}
/* Second pass: We mark all clock sources */
for (NetlistComponent ClockSource : MyClockGenerators) {
if (ClockSource.NrOfEnds() != 1) {
Reporter.AddFatalError("BUG: Found a clock source with more than 1 connection\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return false;
}
ConnectionEnd ClockConnection = ClockSource.getEnd(0);
if (ClockConnection.NrOfBits() != 1) {
Reporter.AddFatalError("BUG: Found a clock source with a bus as output\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return false;
}
ConnectionPoint SolderPoint = ClockConnection.GetConnection((byte) 0);
/* Check if the clock source is connected */
if (SolderPoint.GetParrentNet() != null) {
/* Third pass: add this clock to the list of ClockSources */
int clockid = ClockSources.getClockId(ClockSource.GetComponent());
/* Forth pass: Add this source as clock source to the tree */
MyClockInformation.AddClockSource(HierarchyNames, clockid, SolderPoint);
/* Fifth pass: trace the clock net all the way */
if (!TraceClockNet(SolderPoint.GetParrentNet(), SolderPoint.GetParrentNetBitIndex(), clockid, HierarchyNames, HierarchyNetlists, Reporter)) {
return false;
}
/*
* Sixth pass: We have to account for the complex splitters;
* therefore we have also to trace through our own netlist to
* find the clock connections
*/
ArrayList<ConnectionPoint> HiddenSinks = GetHiddenSinkNets(SolderPoint.GetParrentNet(), SolderPoint.GetParrentNetBitIndex(), MyComplexSplitters, null, new HashSet<String>(), true);
for (ConnectionPoint thisNet : HiddenSinks) {
MarkClockNet(HierarchyNames, clockid, thisNet);
if (!TraceClockNet(thisNet.GetParrentNet(), thisNet.GetParrentNetBitIndex(), clockid, HierarchyNames, HierarchyNetlists, Reporter)) {
return false;
}
}
}
}
return true;
}
use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.
the class Netlist method GetEndIndex.
public int GetEndIndex(NetlistComponent comp, String PinLabel, boolean IsOutputPort) {
String label = CorrectLabel.getCorrectLabel(PinLabel);
SubcircuitFactory sub = (SubcircuitFactory) comp.GetComponent().getFactory();
for (int end = 0; end < comp.NrOfEnds(); end++) {
if (comp.getEnd(end).IsOutputEnd() == IsOutputPort) {
if (comp.getEnd(end).GetConnection((byte) 0).getChildsPortIndex() == sub.getSubcircuit().getNetList().GetPortInfo(label)) {
return end;
}
}
}
return -1;
}
use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.
the class Netlist method GetMappableResources.
public Map<ArrayList<String>, NetlistComponent> GetMappableResources(ArrayList<String> Hierarchy, boolean toplevel) {
Map<ArrayList<String>, NetlistComponent> Components = new HashMap<ArrayList<String>, NetlistComponent>();
/* First we search through my sub-circuits and add those IO components */
for (NetlistComponent comp : MySubCircuits) {
SubcircuitFactory sub = (SubcircuitFactory) comp.GetComponent().getFactory();
ArrayList<String> MyHierarchyName = new ArrayList<String>();
MyHierarchyName.addAll(Hierarchy);
MyHierarchyName.add(CorrectLabel.getCorrectLabel(comp.GetComponent().getAttributeSet().getValue(StdAttr.LABEL).toString()));
Components.putAll(sub.getSubcircuit().getNetList().GetMappableResources(MyHierarchyName, false));
}
/* Now we search for all local IO components */
for (NetlistComponent comp : MyComponents) {
if (comp.GetIOInformationContainer() != null) {
ArrayList<String> MyHierarchyName = new ArrayList<String>();
MyHierarchyName.addAll(Hierarchy);
MyHierarchyName.add(CorrectLabel.getCorrectLabel(comp.GetComponent().getAttributeSet().getValue(StdAttr.LABEL).toString()));
Components.put(MyHierarchyName, comp);
}
}
/* On the toplevel we have to add the pins */
if (toplevel) {
for (NetlistComponent comp : MyInputPorts) {
ArrayList<String> MyHierarchyName = new ArrayList<String>();
MyHierarchyName.addAll(Hierarchy);
MyHierarchyName.add(CorrectLabel.getCorrectLabel(comp.GetComponent().getAttributeSet().getValue(StdAttr.LABEL).toString()));
Components.put(MyHierarchyName, comp);
}
for (NetlistComponent comp : MyInOutPorts) {
ArrayList<String> MyHierarchyName = new ArrayList<String>();
MyHierarchyName.addAll(Hierarchy);
MyHierarchyName.add(CorrectLabel.getCorrectLabel(comp.GetComponent().getAttributeSet().getValue(StdAttr.LABEL).toString()));
Components.put(MyHierarchyName, comp);
}
for (NetlistComponent comp : MyOutputPorts) {
ArrayList<String> MyHierarchyName = new ArrayList<String>();
MyHierarchyName.addAll(Hierarchy);
MyHierarchyName.add(CorrectLabel.getCorrectLabel(comp.GetComponent().getAttributeSet().getValue(StdAttr.LABEL).toString()));
Components.put(MyHierarchyName, comp);
}
}
return Components;
}
use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.
the class Netlist method ConstructHierarchyTree.
public void ConstructHierarchyTree(Set<String> ProcessedCircuits, ArrayList<String> HierarchyName, Integer GlobalInputID, Integer GlobalOutputID, Integer GlobalInOutID) {
if (ProcessedCircuits == null) {
ProcessedCircuits = new HashSet<String>();
}
/*
* The first step is to go down to the leaves and visit all involved
* sub-circuits to construct the local bubble information and form the
* Mappable components tree
*/
LocalNrOfInportBubles = 0;
LocalNrOfOutportBubles = 0;
LocalNrOfInOutBubles = 0;
for (NetlistComponent comp : MySubCircuits) {
SubcircuitFactory sub = (SubcircuitFactory) comp.GetComponent().getFactory();
ArrayList<String> MyHierarchyName = new ArrayList<String>();
MyHierarchyName.addAll(HierarchyName);
MyHierarchyName.add(CorrectLabel.getCorrectLabel(comp.GetComponent().getAttributeSet().getValue(StdAttr.LABEL).toString()));
boolean FirstTime = !ProcessedCircuits.contains(sub.getName().toString());
if (FirstTime) {
ProcessedCircuits.add(sub.getName());
sub.getSubcircuit().getNetList().ConstructHierarchyTree(ProcessedCircuits, MyHierarchyName, GlobalInputID, GlobalOutputID, GlobalInOutID);
}
int subInputBubbles = sub.getSubcircuit().getNetList().NumberOfInputBubbles();
int subInOutBubbles = sub.getSubcircuit().getNetList().NumberOfInOutBubbles();
int subOutputBubbles = sub.getSubcircuit().getNetList().NumberOfOutputBubbles();
comp.SetLocalBubbleID(LocalNrOfInportBubles, subInputBubbles, LocalNrOfOutportBubles, subOutputBubbles, LocalNrOfInOutBubles, subInOutBubbles);
LocalNrOfInportBubles += subInputBubbles;
LocalNrOfInOutBubles += subInOutBubbles;
LocalNrOfOutportBubles += subOutputBubbles;
comp.AddGlobalBubbleID(MyHierarchyName, GlobalInputID, subInputBubbles, GlobalOutputID, subOutputBubbles, GlobalInOutID, subInOutBubbles);
if (!FirstTime) {
sub.getSubcircuit().getNetList().EnumerateGlobalBubbleTree(MyHierarchyName, GlobalInputID, GlobalOutputID, GlobalInOutID);
}
GlobalInputID += subInputBubbles;
GlobalInOutID += subInOutBubbles;
GlobalOutputID += subOutputBubbles;
}
/*
* Here we processed all sub-circuits of the local hierarchy level, now
* we have to process the IO components
*/
for (NetlistComponent comp : MyComponents) {
if (comp.GetIOInformationContainer() != null) {
ArrayList<String> MyHierarchyName = new ArrayList<String>();
MyHierarchyName.addAll(HierarchyName);
MyHierarchyName.add(CorrectLabel.getCorrectLabel(comp.GetComponent().getAttributeSet().getValue(StdAttr.LABEL).toString()));
int subInputBubbles = comp.GetIOInformationContainer().GetNrOfInports();
if (comp.GetComponent().getFactory() instanceof DipSwitch) {
subInputBubbles = comp.GetComponent().getAttributeSet().getValue(DipSwitch.ATTR_SIZE);
}
int subInOutBubbles = comp.GetIOInformationContainer().GetNrOfInOutports();
int subOutputBubbles = comp.GetIOInformationContainer().GetNrOfOutports();
comp.SetLocalBubbleID(LocalNrOfInportBubles, subInputBubbles, LocalNrOfOutportBubles, subOutputBubbles, LocalNrOfInOutBubles, subInOutBubbles);
LocalNrOfInportBubles += subInputBubbles;
LocalNrOfInOutBubles += subInOutBubbles;
LocalNrOfOutportBubles += subOutputBubbles;
comp.AddGlobalBubbleID(MyHierarchyName, GlobalInputID, subInputBubbles, GlobalOutputID, subOutputBubbles, GlobalInOutID, subInOutBubbles);
GlobalInputID += subInputBubbles;
GlobalInOutID += subInOutBubbles;
GlobalOutputID += subOutputBubbles;
}
}
}
use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.
the class AttrTableToolModel method setValueRequested.
@Override
public void setValueRequested(Attribute<Object> attr, Object value) {
if (tool instanceof AddTool) {
AddTool mytool = (AddTool) tool;
if (mytool.getFactory() instanceof SubcircuitFactory) {
SubcircuitFactory fac = (SubcircuitFactory) mytool.getFactory();
if (attr.equals(CircuitAttributes.NAMED_CIRCUIT_BOX) || attr.equals(CircuitAttributes.NAME_ATTR)) {
try {
CircuitMutation mutation = new CircuitMutation(fac.getSubcircuit());
mutation.setForCircuit(attr, value);
Action action = mutation.toAction(null);
proj.doAction(action);
} catch (CircuitException ex) {
JOptionPane.showMessageDialog(proj.getFrame(), ex.getMessage());
}
return;
}
}
}
proj.doAction(ToolAttributeAction.create(tool, attr, value));
}
Aggregations