Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

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

Prototype

public List<Element> getChildren(final String cname) 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element with the given local name and belonging to no namespace, returned as Element objects.

Usage

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  a2s .  c o 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);
        }/*w  ww  .  j  a v a 2  s  . co  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

/**
 * Creates the templates for the primitive sites with information from the
 * primitive defs and device information file.
 *//*from   w w w  .jav a 2s.c  om*/
private Map<SiteType, SiteTemplate> createSiteTemplates() {
    Map<SiteType, SiteTemplate> siteTemplates = new HashMap<>();
    FamilyType family = device.getFamily();

    // Create a template for each primitive type
    for (PrimitiveDef def : device.getPrimitiveDefs()) {
        Element ptEl = getSiteTypeEl(def.getType());

        SiteTemplate template = new SiteTemplate();
        template.setType(def.getType());
        template.setBelTemplates(createBelTemplates(def, ptEl));
        createAndSetIntrasiteRouting(def, template, ptEl);
        createAndSetSitePins(def, template);

        Element compatTypesEl = ptEl.getChild("compatible_types");
        if (compatTypesEl != null) {
            template.setCompatibleTypes(compatTypesEl.getChildren("compatible_type").stream()
                    .map(it -> SiteType.valueOf(family, it.getText())).toArray(SiteType[]::new));
        }

        siteTemplates.put(def.getType(), template);
    }

    return siteTemplates;
}

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/* w  ww  . j a v  a2  s .  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.DeviceGenerator.java

License:Open Source License

/**
 * Searches the device info file for the primitive type element of the
 * specified type./*from   w  ww .ja va2 s.com*/
 *
 * @param type the type of the element to retrieve
 * @return the JDOM element for the requested primitive type
 */
private Element getSiteTypeEl(SiteType type) {
    Element siteTypesEl = familyInfo.getRootElement().getChild("site_types");
    for (Element siteTypeEl : siteTypesEl.getChildren("site_type")) {
        if (siteTypeEl.getChild("name").getText().equals(type.name()))
            return siteTypeEl;
    }
    throw new FileFormatException("no site type " + type.name() + " in familyInfo.xml");
}

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

License:Open Source License

/**
 * Creates a map from pad bel name -> corresponding package pin. This
 * information is needed when generating Tincr Checkpoints from
 * RS to be loaded into Vivado./*  ww w .j  a va2  s . co  m*/
 */
private static void createPackagePins(Device device, Document deviceInfo) {
    Element pinMapRootEl = deviceInfo.getRootElement().getChild("package_pins");

    if (pinMapRootEl == null) {
        throw new Exceptions.ParseException("No package pin information found in device info file: "
                + deviceInfo.getBaseURI() + ".\n"
                + "Either add the package pin mappings, or remove the device info file and regenerate.");
    }

    // Add the package pins to the device
    pinMapRootEl
            .getChildren("package_pin").stream().map(ppEl -> new PackagePin(ppEl.getChildText("name"),
                    ppEl.getChildText("bel"), ppEl.getChild("is_clock") != null))
            .forEach(packagePin -> device.addPackagePin(packagePin));

    if (device.getPackagePins().isEmpty()) {
        throw new Exceptions.ParseException("No package pin information found in device info file: "
                + deviceInfo.getBaseURI() + ".\n"
                + "Either add the package pin mappings, or remove the device info file and regenerate.");
    }
}

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

License:Open Source License

public static void makeCorrections(PrimitiveDefList defs, Document deviceInfo) {
    for (PrimitiveDef def : defs) {
        Element ptEl = getSiteTypeEl(deviceInfo, def.getType());
        Element correctionsEl = ptEl.getChild("corrections");
        if (correctionsEl == null) // no corrections for this primitive type
            continue;
        for (Element creationEl : correctionsEl.getChildren("new_element")) {
            createPrimitiveElement(def, creationEl);
        }//from  ww w. ja  va2  s .com
        for (Element modificationEl : correctionsEl.getChildren("modify_element")) {
            modifyPrimitiveElement(def, modificationEl);
        }
        for (Element psEl : correctionsEl.getChildren("polarity_selector")) {
            fixPolarityMux(def, psEl);
        }
        for (Element pinEl : correctionsEl.getChildren("pin_direction")) {
            modifyPinDirection(def, pinEl);
        }
    }
}