Search in sources :

Example 16 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class VhdlSimulatorVhdlTop method generate.

public void generate() {
    /* Do not generate if file is already valid */
    if (valid)
        return;
    String[] type = { "inout", "in", "out" };
    StringBuilder ports = new StringBuilder();
    ports.append("Autogenerated by logisim --");
    ports.append(System.getProperty("line.separator"));
    StringBuilder components = new StringBuilder();
    components.append("Autogenerated by logisim --");
    components.append(System.getProperty("line.separator"));
    StringBuilder map = new StringBuilder();
    map.append("Autogenerated by logisim --");
    map.append(System.getProperty("line.separator"));
    Boolean firstPort = true, firstComp = true, firstMap = true;
    /* For each vhdl entity */
    for (Component comp : VhdlSimulator.getVhdlComponents(vhdlSimulator.getProject().getCircuitState())) {
        if (comp.getFactory().getClass().equals(VhdlEntity.class)) {
            InstanceState state = vhdlSimulator.getProject().getCircuitState().getInstanceState(comp);
            VhdlContent content = state.getAttributeValue(VhdlEntity.CONTENT_ATTR);
            String vhdlEntityName = comp.getFactory().getHDLTopName(state.getInstance().getAttributeSet());
            /*
				 * Create ports
				 */
            for (Port port : content.getPorts()) {
                if (!firstPort) {
                    ports.append(";");
                    ports.append(System.getProperty("line.separator"));
                } else {
                    firstPort = false;
                }
                String portName = vhdlEntityName + "_" + port.getToolTip();
                ports.append("		" + portName + " : " + type[port.getType()] + " std_logic");
                int width = port.getFixedBitWidth().getWidth();
                if (width > 1) {
                    ports.append("_vector(" + (width - 1) + " downto 0)");
                }
            }
            /*
				 * Create components
				 */
            components.append("	component " + vhdlEntityName);
            components.append(System.getProperty("line.separator"));
            components.append("		port (");
            components.append(System.getProperty("line.separator"));
            firstComp = true;
            for (Port port : content.getPorts()) {
                if (!firstComp) {
                    components.append(";");
                    components.append(System.getProperty("line.separator"));
                } else
                    firstComp = false;
                components.append("			" + port.getToolTip() + " : " + type[port.getType()] + " std_logic");
                int width = port.getFixedBitWidth().getWidth();
                if (width > 1) {
                    components.append("_vector(" + (width - 1) + " downto 0)");
                }
            }
            components.append(System.getProperty("line.separator"));
            components.append("		);");
            components.append(System.getProperty("line.separator"));
            components.append("	end component ;");
            components.append(System.getProperty("line.separator"));
            components.append("	");
            components.append(System.getProperty("line.separator"));
            /*
				 * Create port map
				 */
            map.append("	" + vhdlEntityName + "_map : " + vhdlEntityName + " port map (");
            map.append(System.getProperty("line.separator"));
            firstMap = true;
            for (Port port : content.getPorts()) {
                if (!firstMap) {
                    map.append(",");
                    map.append(System.getProperty("line.separator"));
                } else
                    firstMap = false;
                map.append("		" + port.getToolTip() + " => " + vhdlEntityName + "_" + port.getToolTip());
            }
            map.append(System.getProperty("line.separator"));
            map.append("	);");
            map.append(System.getProperty("line.separator"));
            map.append("	");
            map.append(System.getProperty("line.separator"));
        }
    }
    ports.append(System.getProperty("line.separator"));
    ports.append("		---------------------------");
    ports.append(System.getProperty("line.separator"));
    components.append("	---------------------------");
    components.append(System.getProperty("line.separator"));
    map.append("	---------------------------");
    map.append(System.getProperty("line.separator"));
    /*
		 * Replace template blocks by generated datas
		 */
    String template;
    try {
        template = new String(FileUtil.getBytes(this.getClass().getResourceAsStream(VhdlSimulator.VHDL_TEMPLATES_PATH + "top_sim.templ")));
    } catch (IOException e) {
        logger.error("Could not read template : {}", e.getMessage());
        return;
    }
    template = template.replaceAll("%date%", LocaleManager.parserSDF.format(new Date()));
    template = template.replaceAll("%ports%", ports.toString());
    template = template.replaceAll("%components%", components.toString());
    template = template.replaceAll("%map%", map.toString());
    PrintWriter writer;
    try {
        writer = new PrintWriter(VhdlSimulator.SIM_SRC_PATH + VhdlSimulator.SIM_TOP_FILENAME, "UTF-8");
        writer.print(template);
        writer.close();
    } catch (FileNotFoundException e) {
        logger.error("Could not create top_sim file : {}", e.getMessage());
        e.printStackTrace();
        return;
    } catch (UnsupportedEncodingException e) {
        logger.error("Could not create top_sim file : {}", e.getMessage());
        e.printStackTrace();
        return;
    }
    valid = true;
}
Also used : Port(com.cburch.logisim.instance.Port) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Date(java.util.Date) InstanceState(com.cburch.logisim.instance.InstanceState) Component(com.cburch.logisim.comp.Component) PrintWriter(java.io.PrintWriter)

Example 17 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class VhdlContent method parseContent.

public boolean parseContent(String content) {
    VhdlParser parser = new VhdlParser(content.toString());
    try {
        parser.parse();
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), Strings.get("validationParseError"), JOptionPane.ERROR_MESSAGE);
        return false;
    }
    name = parser.getName();
    libraries = parser.getLibraries();
    architecture = parser.getArchitecture();
    List<VhdlParser.PortDescription> inputsDesc = parser.getInputs();
    List<VhdlParser.PortDescription> outputsDesc = parser.getOutputs();
    inputs = new Port[inputsDesc.size()];
    outputs = new Port[outputsDesc.size()];
    for (int i = 0; i < inputsDesc.size(); i++) {
        VhdlParser.PortDescription desc = inputsDesc.get(i);
        inputs[i] = new Port(0, (i * VhdlEntity.PORT_GAP) + VhdlEntity.HEIGHT, desc.getType(), desc.getWidth());
        inputs[i].setToolTip(Strings.getter(desc.getName()));
    }
    for (int i = 0; i < outputsDesc.size(); i++) {
        VhdlParser.PortDescription desc = outputsDesc.get(i);
        outputs[i] = new Port(VhdlEntity.WIDTH, (i * VhdlEntity.PORT_GAP) + VhdlEntity.HEIGHT, desc.getType(), desc.getWidth());
        outputs[i].setToolTip(Strings.getter(desc.getName()));
    }
    this.content = new StringBuffer(content);
    fireContentSet();
    return true;
}
Also used : Port(com.cburch.logisim.instance.Port) IOException(java.io.IOException)

Example 18 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class NotGate method configurePorts.

private void configurePorts(Instance instance) {
    Object size = instance.getAttributeValue(ATTR_SIZE);
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    int dx = size == SIZE_NARROW ? -20 : -30;
    Port[] ports = new Port[2];
    ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
    Location out = Location.create(0, 0).translate(facing, dx);
    ports[1] = new Port(out.getX(), out.getY(), Port.INPUT, StdAttr.WIDTH);
    instance.setPorts(ports);
}
Also used : Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 19 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class BitAdder method configurePorts.

private void configurePorts(Instance instance) {
    BitWidth inWidth = instance.getAttributeValue(StdAttr.WIDTH);
    int inputs = instance.getAttributeValue(NUM_INPUTS).intValue();
    int outWidth = computeOutputBits(inWidth.getWidth(), inputs);
    int y;
    int dy = 10;
    switch(inputs) {
        case 1:
            y = 0;
            break;
        case 2:
            y = -10;
            dy = 20;
            break;
        case 3:
            y = -10;
            break;
        default:
            y = ((inputs - 1) / 2) * -10;
    }
    Port[] ps = new Port[inputs + 1];
    ps[0] = new Port(0, 0, Port.OUTPUT, BitWidth.create(outWidth));
    ps[0].setToolTip(Strings.getter("bitAdderOutputManyTip"));
    for (int i = 0; i < inputs; i++) {
        ps[i + 1] = new Port(-40, y + i * dy, Port.INPUT, inWidth);
        ps[i + 1].setToolTip(Strings.getter("bitAdderInputTip"));
    }
    instance.setPorts(ps);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port)

Example 20 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class BitFinder method configurePorts.

private void configurePorts(Instance instance) {
    BitWidth inWidth = instance.getAttributeValue(StdAttr.WIDTH);
    int outWidth = computeOutputBits(inWidth.getWidth() - 1);
    Port[] ps = new Port[3];
    ps[0] = new Port(-20, 20, Port.OUTPUT, BitWidth.ONE);
    ps[1] = new Port(0, 0, Port.OUTPUT, BitWidth.create(outWidth));
    ps[2] = new Port(-40, 0, Port.INPUT, inWidth);
    Object type = instance.getAttributeValue(TYPE);
    if (type == HIGH_ZERO) {
        ps[0].setToolTip(Strings.getter("bitFinderPresentTip", "0"));
        ps[1].setToolTip(Strings.getter("bitFinderIndexHighTip", "0"));
    } else if (type == LOW_ZERO) {
        ps[0].setToolTip(Strings.getter("bitFinderPresentTip", "0"));
        ps[1].setToolTip(Strings.getter("bitFinderIndexLowTip", "0"));
    } else if (type == HIGH_ONE) {
        ps[0].setToolTip(Strings.getter("bitFinderPresentTip", "1"));
        ps[1].setToolTip(Strings.getter("bitFinderIndexHighTip", "1"));
    } else {
        ps[0].setToolTip(Strings.getter("bitFinderPresentTip", "1"));
        ps[1].setToolTip(Strings.getter("bitFinderIndexLowTip", "1"));
    }
    ps[2].setToolTip(Strings.getter("bitFinderInputTip"));
    instance.setPorts(ps);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port)

Aggregations

Port (com.cburch.logisim.instance.Port)40 BitWidth (com.cburch.logisim.data.BitWidth)12 Direction (com.cburch.logisim.data.Direction)10 Location (com.cburch.logisim.data.Location)9 Bounds (com.cburch.logisim.data.Bounds)6 Value (com.cburch.logisim.data.Value)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 Graphics (java.awt.Graphics)3 IOException (java.io.IOException)2 Component (com.cburch.logisim.comp.Component)1 AttributeSet (com.cburch.logisim.data.AttributeSet)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 VhdlContent (com.cburch.logisim.std.hdl.VhdlContent)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1