Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

In this page you can find the example usage for org.jdom2 Element getChildText.

Prototype

public String getChildText(final String cname) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadConfigurationPropertiesFromXml(Element cellEl, LibraryCell libCell) {
    Element properties = cellEl.getChild("libcellproperties");

    if (properties != null) {
        for (Element propertyEl : properties.getChildren("libcellproperty")) {

            boolean isReadonly = propertyEl.getChild("readonly") != null;
            // for now, skip read only properties
            // TODO: revisit this
            if (isReadonly) {
                continue;
            }/*from w w w . j ava 2  s.c  om*/

            String name = propertyEl.getChildText("name");
            String deflt = propertyEl.getChildText("default");
            // TODO: integrate the min and max properties
            // String max = propertyEl.getChildText("max");
            // String min = propertyEl.getChildText("min");
            String type = propertyEl.getChildText("type");
            String valueString = propertyEl.getChildText("values");
            String[] values = valueString.isEmpty() ? new String[0] : valueString.split(", ");

            // add the configuration to the library cell
            libCell.addDefaultProperty(new Property(name, PropertyType.EDIF, deflt, isReadonly, true));
            libCell.addConfigurableProperty(new LibraryCellProperty(name, type, values, isReadonly));
        }
    }
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadMacroFromXml(Element macroEl) {

    String type = macroEl.getChildText("type");
    LibraryMacro macroCell = new LibraryMacro(type);

    loadInternalCellsFromXml(macroEl, macroCell);
    loadPinsFromXml(macroEl, macroCell);
    loadInternalNetsFromXml(macroEl, macroCell);
    add(macroCell);//from   w  ww . j a v a2 s.c  o m
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadPinsFromXml(Element cellEl, LibraryCell libCell) {
    List<LibraryPin> pins = new ArrayList<>();
    Element pinsEl = cellEl.getChild("pins");

    Pattern pinNamePattern = Pattern.compile("(.*)\\[(.*)\\]");

    for (Element pinEl : pinsEl.getChildren("pin")) {
        LibraryPin pin = new LibraryPin();
        pin.setLibraryCell(libCell);/*w  w w . ja  v a 2  s .co m*/
        pin.setName(pinEl.getChildText("name"));
        String pinDirection = pinEl.getChildText("direction");
        switch (pinDirection) {
        case "input":
            pin.setDirection(PinDirection.IN);
            break;
        case "output":
            pin.setDirection(PinDirection.OUT);
            break;
        case "inout":
            pin.setDirection(PinDirection.INOUT);
            break;
        default:
            throw new Exceptions.ParseException(
                    "Unrecognized pin direction while parsing the CellLibrary.xml file: " + pinDirection);
        }
        String pinType = pinEl.getChildText("type");
        pin.setPinType(pinType == null ? CellPinType.DATA : CellPinType.valueOf(pinType));
        pins.add(pin);

        // for macro cells, add the internal connection information
        if (libCell.isMacro()) {
            Matcher m = pinNamePattern.matcher(pin.getName());

            if (m.matches()) {
                ((LibraryMacro) libCell).addPinOffset(m.group(1), Integer.parseInt(m.group(2)));
            }

            List<String> internalPinNames = pinEl.getChild("internalConnections").getChildren("pinname")
                    .stream().map(el -> el.getText()).collect(Collectors.toList());
            ((LibraryMacro) libCell).addInternalPinConnections(pin, internalPinNames);
        }
    }
    libCell.setLibraryPins(pins);
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadInternalCellsFromXml(Element macroEl, LibraryMacro macroCell) {

    Element cellsEl = macroEl.getChild("cells");

    for (Element internalEl : cellsEl.getChildren("internal")) {
        LibraryCell libCell = library.get(internalEl.getChildText("type"));

        if (libCell == null) {
            throw new Exceptions.ParseException(
                    "Unable to find leaf library cell \"" + internalEl.getChildText("type")
                            + "\" in macro cell: \"" + macroEl.getChildText("type") + "\"");
        } else if (libCell.isMacro()) {
            throw new Exceptions.ParseException(
                    "Nested hierarchy is not supported. Cell: \"" + macroEl.getChildText("type") + "\"");
        }//from  w  w  w . j a v  a  2 s  . c o m

        macroCell.addInternalCell(internalEl.getChildText("name"), (SimpleLibraryCell) libCell);
    }
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadInternalNetsFromXml(Element macroEl, LibraryMacro macroCell) {
    Element internalNetsEl = macroEl.getChild("internalNets");

    // only add internal nets to the macro if they exist
    if (internalNetsEl != null) {

        for (Element internalNetEl : internalNetsEl.getChildren("internalNet")) {
            String name = internalNetEl.getChildText("name");
            List<String> pinNames = internalNetEl.getChild("pins").getChildren("pinname").stream()
                    .map(el -> el.getText()).collect(Collectors.toList());
            String type = internalNetEl.getChildText("type");
            if (type == null) {
                type = "WIRE";
            }/* w  w  w.  j a v  a  2 s .  c o m*/

            macroCell.addInternalNet(name, type, pinNames);
        }
    }
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadPossibleBelsFromXml(SimpleLibraryCell libCell, Element cellEl,
        Map<SiteType, Map<String, SiteProperty>> sitePropertiesMap) {
    List<BelId> compatibleBels = new ArrayList<>();
    Map<BelId, Map<String, SiteProperty>> sharedSitePropertiesMap = new HashMap<>();
    Element belsEl = cellEl.getChild("bels");
    for (Element belEl : belsEl.getChildren("bel")) {
        Element id = belEl.getChild("id");

        String site_type = id.getChildText("site_type");
        BelId belId = new BelId(SiteType.valueOf(familyType, site_type), id.getChildText("name"));
        compatibleBels.add(belId);/*from  ww w  . j a v a  2s  .  co m*/

        loadPinMapFromXml(libCell, belEl, belId);

        Map<String, SiteProperty> siteProperties = sitePropertiesMap.computeIfAbsent(belId.getSiteType(),
                k -> new HashMap<>());
        Map<String, SiteProperty> sharedSiteProperties = new HashMap<>();
        sharedSitePropertiesMap.put(belId, sharedSiteProperties);
        Element attrsEl = belEl.getChild("attributes");
        if (attrsEl != null) {
            for (Element attrEl : attrsEl.getChildren("attribute")) {
                if (attrEl.getChild("is_site_property") != null) {
                    String attrName = attrEl.getChildText("name");
                    String rename = attrEl.getChildText("rename");
                    if (rename == null)
                        rename = attrName;
                    SiteProperty siteProperty = siteProperties.computeIfAbsent(rename,
                            k -> new SiteProperty(belId.getSiteType(), k));
                    sharedSiteProperties.put(attrName, siteProperty);
                }
            }
        }
    }
    libCell.setPossibleBels(compatibleBels);
    libCell.setSharedSiteProperties(sharedSitePropertiesMap);
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadPinMapFromXml(SimpleLibraryCell libCell, Element belEl, BelId belId) {
    Element belPinsEl = belEl.getChild("pins");
    if (belPinsEl == null) {
        for (LibraryPin pin : libCell.getLibraryPins()) {
            ArrayList<String> possPins = new ArrayList<>(1);
            possPins.add(pin.getName());
            pin.getPossibleBelPins().put(belId, possPins);
        }/*from  w ww  . j a  v  a2  s  .  c o  m*/
    } else {
        Set<LibraryPin> unmappedPins = new HashSet<>();

        // Create the bel pin mappings for each cell pin
        for (Element belPinEl : belPinsEl.getChildren("pin")) {

            String pinName = belPinEl.getChildText("name");
            LibraryPin pin = libCell.getLibraryPin(pinName);

            // skip pins that have no default mapping
            if (belPinEl.getChild("no_map") != null) {
                unmappedPins.add(pin);
                continue;
            }

            ArrayList<String> possibles = new ArrayList<>();
            for (Element possibleEl : belPinEl.getChildren("possible")) {
                possibles.add(possibleEl.getText());
            }
            possibles.trimToSize();
            pin.getPossibleBelPins().put(belId, possibles);
        }

        // Look for cell pins without a bel pin mapping. For these
        // pins, assume a bel pin name that is identical to the cell pin name
        for (LibraryPin pin : libCell.getLibraryPins()) {
            if (pin.getPossibleBelPins(belId) != null || unmappedPins.contains(pin)) {
                continue;
            }
            ArrayList<String> possPins = new ArrayList<>(1);
            possPins.add(pin.getName());
            pin.getPossibleBelPins().put(belId, possPins);
        }
    }
}

From source file:edu.byu.ece.rapidSmith.device.creation.DeviceGenerator.java

License:Open Source License

/**
 * Find the XML element specifying the type for the desired BEL
 *
 * @param belName   name of the BEL to find the type for
 * @param ptElement XML element detailing the primitive type
 * @return the BEL type/*  ww w . ja  v  a 2 s.c o  m*/
 */
private String getTypeOfBel(String belName, Element ptElement) {
    for (Element belEl : ptElement.getChild("bels").getChildren("bel")) {
        if (belEl.getChildText("name").equals(belName))
            return belEl.getChildText("type");
    }
    assert false : "No type found for the specified BEL " + belName + " " + ptElement.getChildText("name");
    return null;
}

From source file:edu.byu.ece.rapidSmith.device.creation.DeviceGenerator.java

License:Open Source License

/**
 * Creates a BEL routethrough map for the site template.  
 * @param template Site Template to generate routethroughs for
 * @param siteElement XML document element of the site in the familyinfo.xml file
 * @param wireMap WireHashMap of the site template
 * @return A Map of BEL routethroughs//from www  . j a v a2s .c  o  m
 */
private Map<Integer, Set<Integer>> createBelRoutethroughs(SiteTemplate template, Element siteElement,
        WireHashMap wireMap, WireHashMap reverseWireMap) {

    Map<Integer, Set<Integer>> belRoutethroughMap = new HashMap<>();

    for (Element belEl : siteElement.getChild("bels").getChildren("bel")) {
        String belName = belEl.getChildText("name");

        Element routethroughs = belEl.getChild("routethroughs");

        // bel has routethroughs
        if (routethroughs != null) {

            for (Element routethrough : routethroughs.getChildren("routethrough")) {

                String inputPin = routethrough.getChildText("input");
                String outputPin = routethrough.getChildText("output");

                String inputWireName = getIntrasiteWireName(template.getType(), belName, inputPin);
                String outputWireName = getIntrasiteWireName(template.getType(), belName, outputPin);

                Integer startEnum = we.getWireEnum(inputWireName);
                Integer endEnum = we.getWireEnum(outputWireName);

                // If the wire names for the routethrough do not exist, throw a parse exception telling the user 
                if (startEnum == null) {
                    throw new Exceptions.ParseException(String.format(
                            "Cannot find intrasite wire \"%s\" for bel routethrough \"%s:%s:%s\". "
                                    + "Check the familyInfo.xml file for this routethrough and make sure the connections are correct.",
                            inputWireName, template.getType(), inputPin, outputPin));
                } else if (endEnum == null) {
                    throw new Exceptions.ParseException(String.format(
                            "Cannot find intrasite wire \"%s\" for bel routethrough \"%s:%s:%s\". "
                                    + "Check the familyInfo.xml file for this routethrough and make sure the connections are correct.",
                            outputWireName, template.getType(), inputPin, outputPin));
                }

                // add the routethrough to the routethrough map; 
                Set<Integer> sinkWires = belRoutethroughMap.computeIfAbsent(startEnum, k -> new HashSet<>());
                sinkWires.add(endEnum);
            }
        }
    }

    // create a new wire connection for each routethrough and adds them to the wire map
    for (Integer startWire : belRoutethroughMap.keySet()) {

        Set<Integer> sinkWires = belRoutethroughMap.get(startWire);
        WireConnection[] wireConnections = new WireConnection[sinkWires.size()];

        int index = 0;
        for (Integer sink : sinkWires) {
            // routethroughs will be considered as pips in rapidSmith
            WireConnection wc = new WireConnection(sink, 0, 0, true);
            wireConnections[index] = wirePool.add(wc);
            index++;

            addSiteConnection(reverseWireMap, sink, startWire, true);
        }

        wireMap.put(startWire, wireConnections);
    }

    // return null if the belRoutethroughMap is empty
    return belRoutethroughMap.isEmpty() ? null : belRoutethroughMap;
}

From source file:edu.byu.ece.rapidSmith.device.creation.PrimitiveDefsCorrector.java

License:Open Source License

/**
 * Converts the polarity mux element from a mux to a configuration.  The
 * polarity muxes take a single input, and provides an option to either pass
 * the signal or invert it.// w w  w  .  ja  v  a  2  s.c  o  m
 *
 *     |---- A  /-|   |-- O1
 * S --|       |PS|---|-- O2
 *     |-- A_B  \_|   |-- ...
 *
 * To convert this mux, we will change the polarity selector mux (PS) to a
 * configuration, and then connect the source (S) to each output(O1, O2, ...).
 * @param def the primitive def the polarity mux is in
 * @param polarityMuxEl the corrections element describing the change to be made
 */
private static void fixPolarityMux(PrimitiveDef def, Element polarityMuxEl) {
    // get the polarity mux element
    PrimitiveElement muxElement = def.getElement(polarityMuxEl.getChildText("name"));
    assert muxElement != null;

    // find the source pin and all of the sinks of the polarity mux
    Pin sourcePin = null;
    Set<Pin> sinks = new HashSet<>();
    for (PrimitiveConnection c : muxElement.getConnections()) {
        if (c.isForwardConnection()) {
            PrimitiveElement sinkEl = def.getElement(c.getElement1());
            String sinkPin = c.getPin1();
            sinks.add(new Pin(sinkEl, sinkPin));
        } else {
            PrimitiveElement sourceEl = def.getElement(c.getElement1());
            sourcePin = new Pin(sourceEl, c.getPin1());
        }
    }
    // make sure we found something
    assert sinks.size() > 0;
    assert sourcePin != null;

    // disconnect the polarity mux and configure it as a configuration
    muxElement.getPins().clear();
    muxElement.setMux(false);
    muxElement.setConfiguration(true);
    muxElement.getConnections().clear();

    // remove all connections from the source to the polarity mux
    Iterator<PrimitiveConnection> it = sourcePin.element.getConnections().iterator();
    while (it.hasNext()) {
        PrimitiveConnection c = it.next();
        if (c.isForwardConnection()) {
            if (c.getElement1().equals(muxElement.getName())) {
                it.remove();
            }
        }
    }

    // remove all connections from the sinks to the polarity mux
    for (Pin sinkPin : sinks) {
        it = sinkPin.element.getConnections().iterator();
        while (it.hasNext()) {
            PrimitiveConnection c = it.next();
            if (!c.isForwardConnection()) {
                if (c.getElement1().equals(muxElement.getName())) {
                    it.remove();
                }
            }
        }
    }

    // create connections from the source to every sink
    for (Pin sinkPin : sinks) {
        // create a forward connection from the source to the sink
        PrimitiveConnection sourceConn = new PrimitiveConnection();
        sourceConn.setElement0(sourcePin.element.getName());
        sourceConn.setPin0(sourcePin.pin);
        sourceConn.setForwardConnection(true);
        sourceConn.setElement1(sinkPin.element.getName());
        sourceConn.setPin1(sinkPin.pin);
        sourcePin.element.addConnection(sourceConn);

        // create a backward connection from the sink to the source
        PrimitiveConnection sinkConn = new PrimitiveConnection();
        sinkConn.setElement0(sinkPin.element.getName());
        sinkConn.setPin0(sinkPin.pin);
        sinkConn.setForwardConnection(false);
        sinkConn.setElement1(sourcePin.element.getName());
        sinkConn.setPin1(sourcePin.pin);
        sinkPin.element.addConnection(sinkConn);
    }
}