Search in sources :

Example 96 with Component

use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.

the class ToplevelHDLGeneratorFactory method GetModuleFunctionality.

@Override
public ArrayList<String> GetModuleFunctionality(Netlist TheNetlist, AttributeSet attrs, FPGAReport Reporter, String HDLType) {
    ArrayList<String> Contents = new ArrayList<String>();
    int NrOfClockTrees = TheNetlist.NumberOfClockTrees();
    String Preamble = (HDLType.equals(VHDL)) ? "" : "assign ";
    String BracketOpen = (HDLType.equals(VHDL)) ? "(" : "[";
    String BracketClose = (HDLType.equals(VHDL)) ? ")" : "]";
    String AssignOperator = (HDLType.equals(VHDL)) ? " <= " : " = ";
    String NotOperator = (HDLType.equals(VHDL)) ? "NOT " : "~";
    StringBuffer Temp = new StringBuffer();
    /* First we process all pins */
    Contents.addAll(MakeRemarkBlock("Here all signal adaptations are performed", 3, HDLType));
    for (ArrayList<String> CompId : MyIOComponents.GetComponents()) {
        if (MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof Pin) {
            Component ThisPin = MyIOComponents.GetComponent(CompId).GetComponent();
            ArrayList<String> MyMaps = MyIOComponents.GetMapNamesList(CompId);
            if (MyMaps == null) {
                Reporter.AddFatalError("Component has no map information, bizar! " + CompId.toString());
                return Contents;
            }
            int PinPinId = 0;
            for (int MapOffset = 0; MapOffset < MyMaps.size(); MapOffset++) {
                String map = MyMaps.get(MapOffset);
                int InputId = MyIOComponents.GetFPGAInputPinId(map);
                int OutputId = MyIOComponents.GetFPGAOutputPinId(map);
                int NrOfPins = MyIOComponents.GetNrOfPins(map);
                boolean Invert = MyIOComponents.RequiresToplevelInversion(CompId, map);
                for (int PinId = 0; PinId < NrOfPins; PinId++) {
                    Temp.setLength(0);
                    Temp.append("   " + Preamble);
                    if (InputId >= 0) {
                        Temp.append("s_" + CorrectLabel.getCorrectLabel(ThisPin.getAttributeSet().getValue(StdAttr.LABEL)));
                        if (ThisPin.getEnd(0).getWidth().getWidth() > 1) {
                            Temp.append(BracketOpen + PinPinId + BracketClose);
                        }
                        PinPinId++;
                        Temp.append(AssignOperator);
                        if (Invert) {
                            Temp.append(NotOperator);
                        }
                        Temp.append(HDLGeneratorFactory.FPGAInputPinName);
                        Temp.append("_" + Integer.toString(InputId + PinId));
                        Temp.append(";");
                        Contents.add(Temp.toString());
                    }
                    if (OutputId >= 0) {
                        Temp.append(HDLGeneratorFactory.FPGAOutputPinName);
                        Temp.append("_" + Integer.toString(OutputId + PinId));
                        Temp.append(AssignOperator);
                        if (Invert) {
                            Temp.append(NotOperator);
                        }
                        Temp.append("s_" + CorrectLabel.getCorrectLabel(ThisPin.getAttributeSet().getValue(StdAttr.LABEL)));
                        if (ThisPin.getEnd(0).getWidth().getWidth() > 1) {
                            Temp.append(BracketOpen + PinPinId + BracketClose);
                        }
                        PinPinId++;
                        Temp.append(";");
                        Contents.add(Temp.toString());
                    }
                }
            }
        }
    }
    /* Now we process the bubbles */
    Contents.addAll(MakeRemarkBlock("Here all inlined adaptations are performed", 3, HDLType));
    for (ArrayList<String> CompId : MyIOComponents.GetComponents()) {
        if (!(MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof Pin) && !(MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof PortIO) && !(MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof ReptarLocalBus)) {
            HDLGeneratorFactory Generator = MyIOComponents.GetComponent(CompId).GetComponent().getFactory().getHDLGenerator(HDLType, MyIOComponents.GetComponent(CompId).GetComponent().getAttributeSet());
            if (Generator == null) {
                Reporter.AddError("No generator for component " + CompId.toString());
            } else {
                Contents.addAll(Generator.GetInlinedCode(HDLType, CompId, Reporter, MyIOComponents));
            }
        } else if (MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof ReptarLocalBus) {
            ((ReptarLocalBus) MyIOComponents.GetComponent(CompId).GetComponent().getFactory()).setMapInfo(MyIOComponents);
        } else if (MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof PortIO) {
            ((PortIO) MyIOComponents.GetComponent(CompId).GetComponent().getFactory()).setMapInfo(MyIOComponents);
        }
    }
    if (NrOfClockTrees > 0) {
        Contents.addAll(MakeRemarkBlock("Here the clock tree components are defined", 3, HDLType));
        TickComponentHDLGeneratorFactory Ticker = new TickComponentHDLGeneratorFactory(FpgaClockFrequency, TickFrequency);
        Contents.addAll(Ticker.GetComponentMap(null, (long) 0, null, Reporter, "", HDLType));
        long index = 0;
        for (Component Clockgen : TheNetlist.GetAllClockSources()) {
            NetlistComponent ThisClock = new NetlistComponent(Clockgen);
            Contents.addAll(Clockgen.getFactory().getHDLGenerator(HDLType, ThisClock.GetComponent().getAttributeSet()).GetComponentMap(TheNetlist, index++, ThisClock, Reporter, "Bla", HDLType));
        }
    }
    Contents.add("");
    /* Here the map is performed */
    Contents.addAll(MakeRemarkBlock("Here the toplevel component is connected", 3, HDLType));
    CircuitHDLGeneratorFactory DUT = new CircuitHDLGeneratorFactory(MyCircuit);
    Contents.addAll(DUT.GetComponentMap(TheNetlist, (long) 0, null, Reporter, CorrectLabel.getCorrectLabel(MyCircuit.getName()), HDLType));
    return Contents;
}
Also used : ArrayList(java.util.ArrayList) NetlistComponent(com.bfh.logisim.designrulecheck.NetlistComponent) PortIO(com.cburch.logisim.std.io.PortIO) Pin(com.cburch.logisim.std.wiring.Pin) ReptarLocalBus(com.cburch.logisim.std.io.ReptarLocalBus) ClockHDLGeneratorFactory(com.cburch.logisim.std.wiring.ClockHDLGeneratorFactory) NetlistComponent(com.bfh.logisim.designrulecheck.NetlistComponent) Component(com.cburch.logisim.comp.Component)

Example 97 with Component

use of com.cburch.logisim.comp.Component 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;
}
Also used : EndData(com.cburch.logisim.comp.EndData) Splitter(com.cburch.logisim.circuit.Splitter) NetlistComponent(com.bfh.logisim.designrulecheck.NetlistComponent) ArrayList(java.util.ArrayList) Point(java.awt.Point) Point(java.awt.Point) NetlistComponent(com.bfh.logisim.designrulecheck.NetlistComponent) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Aggregations

Component (com.cburch.logisim.comp.Component)97 Location (com.cburch.logisim.data.Location)26 ArrayList (java.util.ArrayList)20 Circuit (com.cburch.logisim.circuit.Circuit)19 AttributeSet (com.cburch.logisim.data.AttributeSet)13 Wire (com.cburch.logisim.circuit.Wire)12 Bounds (com.cburch.logisim.data.Bounds)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)8 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 EndData (com.cburch.logisim.comp.EndData)8 InstanceComponent (com.cburch.logisim.instance.InstanceComponent)8 Project (com.cburch.logisim.proj.Project)7 Pin (com.cburch.logisim.std.wiring.Pin)7 Graphics (java.awt.Graphics)7 CircuitState (com.cburch.logisim.circuit.CircuitState)6 Splitter (com.cburch.logisim.circuit.Splitter)6 Selection (com.cburch.logisim.gui.main.Selection)6 InstanceState (com.cburch.logisim.instance.InstanceState)5