Search in sources :

Example 1 with Export

use of com.ibm.uma.om.Export in project openj9 by eclipse.

the class ExportParser method parse.

public static Export parse(Node node, String containingFile) {
    Export export = new Export(containingFile);
    NamedNodeMap attributes = node.getAttributes();
    NodeList nodeList = node.getChildNodes();
    if (attributes.getNamedItem("name") != null) {
        export.setExport(attributes.getNamedItem("name").getNodeValue());
        export.setType(Export.TYPE_FUNCTION);
    } else {
        export.setExport(attributes.getNamedItem("group").getNodeValue());
        export.setType(Export.TYPE_GROUP);
    }
    Parser.populatePredicateList(nodeList, export);
    return export;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Export(com.ibm.uma.om.Export)

Example 2 with Export

use of com.ibm.uma.om.Export in project openj9 by eclipse.

the class PlatformWindows method writeExportFile.

// TODO: convert to template
@Override
protected void writeExportFile(Artifact artifact) throws UMAException {
    if (artifact.getType() != Artifact.TYPE_SHARED && artifact.getType() != Artifact.TYPE_BUNDLE) {
        return;
    }
    String filename = UMA.getUma().getRootDirectory() + artifact.getContainingModule().getFullName() + "/" + artifact.getTargetNameWithScope() + ".def";
    FileAssistant fa = new FileAssistant(filename);
    StringBuffer buffer = fa.getStringBuffer();
    buffer.append("LIBRARY " + getTargetNameWithRelease(artifact).toUpperCase() + "\n");
    if (!isProcessor("amd64") && !isType("ce")) {
        buffer.append("\n\nSECTIONS\n\t.data\tREAD WRITE\n\t.text\tEXECUTE READ\n\n");
    }
    Vector<Export> exports = artifact.getArtifactExportedFunctions();
    StringBuffer exportsBuffer = new StringBuffer();
    exportsBuffer.append("EXPORTS\n");
    boolean exportDefined = false;
    for (Export export : exports) {
        if (!export.evaluate())
            continue;
        exportDefined = true;
        String exportString = export.getExport();
        if (isProcessor("amd64")) {
            exportString = stripExportName(exportString);
        }
        exportsBuffer.append("\t" + exportString + "\n");
    }
    if (exportDefined) {
        buffer.append(exportsBuffer.toString() + "\n");
    }
    fa.writeToDisk();
}
Also used : FileAssistant(com.ibm.uma.util.FileAssistant) Export(com.ibm.uma.om.Export)

Example 3 with Export

use of com.ibm.uma.om.Export in project openj9 by eclipse.

the class PlatformImplementation method writePlatformSpecificFiles.

/* (non-Javadoc)
	 * @see com.ibm.uma.platform.IPlatform#writePlatformSpecificFiles(com.ibm.uma.Artifact)
	 */
public void writePlatformSpecificFiles(Artifact artifact) throws UMAException {
    writeExportFile(artifact);
    if (!artifact.flagSet("requiresPrimitiveTable") && !artifact.flagSet("dumpMasterPrimitiveTable")) {
        return;
    }
    String filename = UMA.getUma().getRootDirectory() + artifact.getContainingModule().getFullName() + "/" + artifact.getTargetName() + "exp.c";
    Vector<Export> exports = artifact.getExportedFunctions();
    FileAssistant fa = new FileAssistant(filename);
    StringBuffer buffer = fa.getStringBuffer();
    buffer.append(configuration.getcCopyrightNotice());
    buffer.append("#include \"j9comp.h\"\n#include \"j9static.h\"\n\n");
    buffer.append("#if !defined(J9VM_SHARED_LIBRARIES_SUPPORTED) || defined(J9VM_OPT_BUNDLE_CORE_MODULES)\n");
    if (artifact.flagSet("requiresPrimitiveTable")) {
        if (artifact.flagSet("dumpGenericProtosForPrimTable")) {
            for (Export export : exports) {
                buffer.append("extern void VMCALL " + export.getExport() + "(void);\n");
            }
        } else {
            // "We ask the the module to give us a header file name to include with the public prototypes"
            String[] prototypeHeaderFileNames = artifact.getData("prototypeHeaderFileNames");
            if (prototypeHeaderFileNames != null) {
                for (String fnm : prototypeHeaderFileNames) {
                    buffer.append("#include \"" + fnm + "\"\n");
                }
            }
            if (artifact.flagSet("extraPrototypesForExportFile")) {
                String[] extraProtos = artifact.getData("extraPrototypesForExportFile");
                for (String proto : extraProtos) {
                    buffer.append("extern void VMCALL " + proto + "(void);\n");
                }
            }
        }
        buffer.append("\nEsDefinePrimitiveTable(" + artifact.getTargetName().toUpperCase() + "PrimitiveTable)\n");
        for (Export export : exports) {
            String strippedExportName = stripExportName(export.getExport());
            buffer.append("\tEsPrimitiveTableEntry(\"" + strippedExportName + "\"," + strippedExportName + ")\n");
        }
        buffer.append("EsEndPrimitiveTable\n");
    }
    if (artifact.flagSet("dumpMasterPrimitiveTable")) {
        buffer.append("\n");
        Vector<Library> libs = artifact.getStaticLinkLibraries();
        if (artifact.getType() == Artifact.TYPE_BUNDLE) {
            libs.addAll(artifact.getLibraries());
        }
        Vector<Artifact> artifacts = new Vector<Artifact>();
        for (Library lib : libs) {
            switch(lib.getType()) {
                case Library.TYPE_BUILD:
                    Artifact artifact2 = UMA.getUma().getArtifact(lib.getName());
                    if (artifact2 != null && artifact2.evaluate()) {
                        artifacts.add(artifact2);
                    }
                    break;
            }
        }
        for (Artifact oa : artifacts) {
            if (oa.evaluate() && oa.flagSet("requiresPrimitiveTable")) {
                buffer.append("extern EsPrimitiveTable " + oa.getTargetName().toUpperCase() + "PrimitiveTable;\n");
            }
        }
        buffer.append("\nEsDefinePrimitiveTable(J9LinkedNatives)\n");
        for (Artifact oa : artifacts) {
            if (oa.evaluate() && oa.flagSet("requiresPrimitiveTable")) {
                String startComment = "";
                String endComment = "";
                if (!oa.flagSet("isRequired") && !oa.flagSet("isRequiredFor" + artifact.getTargetNameWithScope())) {
                    startComment = "/* ";
                    endComment = " */";
                }
                buffer.append("\t" + startComment + "EsPrimitiveTableEntry(\"" + getTargetNameWithRelease(oa) + "\", " + oa.getTargetName().toUpperCase() + "PrimitiveTable)" + endComment + "\n");
            }
        }
        buffer.append("EsEndPrimitiveTable\n");
    }
    buffer.append("\n#endif\n");
    fa.writeToDisk();
}
Also used : FileAssistant(com.ibm.uma.util.FileAssistant) Export(com.ibm.uma.om.Export) Library(com.ibm.uma.om.Library) Vector(java.util.Vector) Artifact(com.ibm.uma.om.Artifact)

Example 4 with Export

use of com.ibm.uma.om.Export in project openj9 by eclipse.

the class PlatformUnix method writeExportFile.

@Override
protected void writeExportFile(Artifact artifact) throws UMAException {
    if (!(artifact.getType() == Artifact.TYPE_BUNDLE) && !(artifact.getType() == Artifact.TYPE_SHARED))
        return;
    if (!isType("linux") && !isType("aix"))
        return;
    String filename = UMA.getUma().getRootDirectory() + artifact.getContainingModule().getFullName() + "/" + artifact.getTargetNameWithScope() + ".exp";
    FileAssistant fa = new FileAssistant(filename);
    StringBuffer buffer = fa.getStringBuffer();
    Vector<Export> exports = artifact.getExportedFunctions();
    if (isType("linux")) {
        buffer.append(" {\n");
        /*
			 * The linker doesn't like .exp files that has no exports after the 'global:' label.
			 * 
			 * This can happen when someone is creating a new shared library, but has yet to define any exports for it.
			 */
        if (exports.size() > 0)
            buffer.append("\tglobal :");
    }
    for (Export export : exports) {
        if (!export.evaluate())
            continue;
        if (isType("aix")) {
            buffer.append(stripExportName(export.getExport()) + "\n");
        } else if (isType("linux")) {
            buffer.append("\n\t\t" + stripExportName(export.getExport()) + ";");
        }
    }
    if (isType("linux")) {
        buffer.append("\n\tlocal : *;\n};\n");
    }
    fa.writeToDisk();
}
Also used : FileAssistant(com.ibm.uma.util.FileAssistant) Export(com.ibm.uma.om.Export)

Example 5 with Export

use of com.ibm.uma.om.Export in project openj9 by eclipse.

the class ArtifactParser method parse.

public static Artifact parse(Node artifactNode, Module module) throws UMAException {
    Artifact artifact = new Artifact(module);
    NodeList nodeList = artifactNode.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        String nodeName = node.getLocalName();
        if (nodeName == null)
            continue;
        if (nodeName.equalsIgnoreCase("description")) {
            NodeList descChildren = node.getChildNodes();
            Node descChild = descChildren.item(0);
            artifact.setDescription(descChild.getNodeValue());
        } else if (nodeName.equalsIgnoreCase("options")) {
            NodeList optionsNodeList = node.getChildNodes();
            for (int j = 0; j < optionsNodeList.getLength(); j++) {
                Node optionItem = optionsNodeList.item(j);
                NamedNodeMap attributes = optionItem.getAttributes();
                if (attributes == null)
                    continue;
                Option option = OptionParser.parse(optionItem, artifact.getContainingFile());
                artifact.addOption(option);
            }
        } else if (nodeName.equalsIgnoreCase("phase")) {
            NodeList phaseChildren = node.getChildNodes();
            for (int j = 0; j < phaseChildren.getLength(); j++) {
                Node phasesNode = phaseChildren.item(j);
                String phaselist = phasesNode.getNodeValue();
                String[] phases = phaselist.split("\\s");
                for (int k = 0; k < phases.length; k++) {
                    try {
                        artifact.setPhase(UMA.getUma().getConfiguration().phaseFromString(phases[k]), true);
                    } catch (UMABadPhaseNameException e) {
                        throw new UMAException("in file: " + artifact.getContainingFile(), e);
                    }
                }
            }
        } else if (nodeName.equalsIgnoreCase("includes")) {
            NodeList includesNodeList = node.getChildNodes();
            for (int j = 0; j < includesNodeList.getLength(); j++) {
                Node includeItem = includesNodeList.item(j);
                NamedNodeMap attributes = includeItem.getAttributes();
                if (attributes == null)
                    continue;
                Include include = new Include(artifact.getContainingFile());
                include.setPath(attributes.getNamedItem("path").getNodeValue());
                include.setType(attributes.getNamedItem("type").getNodeValue());
                artifact.addInclude(include);
                Parser.populatePredicateList(includeItem.getChildNodes(), include);
            }
        } else if (nodeName.equalsIgnoreCase("commands")) {
            NodeList commandsNodeList = node.getChildNodes();
            for (int j = 0; j < commandsNodeList.getLength(); j++) {
                Node commandItem = commandsNodeList.item(j);
                NamedNodeMap attributes = commandItem.getAttributes();
                if (attributes == null)
                    continue;
                Command command = new Command(artifact.getContainingFile());
                command.setCommand(attributes.getNamedItem("line").getNodeValue());
                command.setType(attributes.getNamedItem("type").getNodeValue());
                artifact.addCommand(command);
                Parser.populatePredicateList(commandItem.getChildNodes(), command);
            }
        } else if (nodeName.equalsIgnoreCase("dependencies")) {
            NodeList dependenciesNodeList = node.getChildNodes();
            for (int j = 0; j < dependenciesNodeList.getLength(); j++) {
                Node dependencyItem = dependenciesNodeList.item(j);
                NamedNodeMap attributes = dependencyItem.getAttributes();
                if (attributes == null)
                    continue;
                Dependency dependency = new Dependency(artifact.getContainingFile());
                dependency.setDependency(attributes.getNamedItem("name").getNodeValue());
                artifact.addDependency(dependency);
                Parser.populatePredicateList(dependencyItem.getChildNodes(), dependency);
            }
        } else if (nodeName.equalsIgnoreCase("libraries")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("library")) {
                    Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());
                    artifact.addLibrary(library);
                }
            }
        } else if (nodeName.equalsIgnoreCase("static-link-libraries")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("library")) {
                    Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());
                    artifact.addStaticLinkLibrary(library);
                }
            }
        } else if (nodeName.equalsIgnoreCase("objects")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("group") || linkItem.getNodeName().equalsIgnoreCase("object")) {
                    Object object = ObjectParser.parse(linkNodeList.item(j), artifact.getContainingFile());
                    artifact.addObject(object);
                }
            }
        } else if (nodeName.equalsIgnoreCase("vpaths")) {
            NodeList vpathsNodeList = node.getChildNodes();
            for (int j = 0; j < vpathsNodeList.getLength(); j++) {
                Node vpathItem = vpathsNodeList.item(j);
                if (vpathItem.getNodeName().equalsIgnoreCase("vpath")) {
                    VPath vpath = VPathParser.parse(vpathItem, artifact.getContainingFile());
                    artifact.addVPath(vpath);
                }
            }
        } else if (nodeName.equalsIgnoreCase("makefilestubs")) {
            NodeList mfsNodeList = node.getChildNodes();
            for (int j = 0; j < mfsNodeList.getLength(); j++) {
                Node mfsItem = mfsNodeList.item(j);
                if (mfsItem.getNodeName().equalsIgnoreCase("makefilestub")) {
                    NamedNodeMap attributes = mfsItem.getAttributes();
                    Node dataNode = attributes.getNamedItem("data");
                    MakefileStub makefileStub = new MakefileStub(dataNode.getNodeValue(), artifact.getContainingFile());
                    artifact.addMakefileStub(makefileStub);
                    Parser.populatePredicateList(mfsItem.getChildNodes(), makefileStub);
                }
            }
        } else if (nodeName.equalsIgnoreCase("exports")) {
            NodeList exportsNodeList = node.getChildNodes();
            for (int j = 0; j < exportsNodeList.getLength(); j++) {
                Node exportNode = exportsNodeList.item(j);
                if (exportNode.getNodeName().equalsIgnoreCase("group")) {
                    Export group = ExportParser.parse(exportNode, artifact.getContainingFile());
                    artifact.addExport(group);
                    group.setType(Export.TYPE_GROUP);
                } else if (exportNode.getNodeName().equalsIgnoreCase("export")) {
                    Export group = ExportParser.parse(exportNode, artifact.getContainingFile());
                    artifact.addExport(group);
                    group.setType(Export.TYPE_FUNCTION);
                }
            }
        } else if (nodeName.equalsIgnoreCase("flags")) {
            NodeList flagsNodeList = node.getChildNodes();
            for (int j = 0; j < flagsNodeList.getLength(); j++) {
                Node item = flagsNodeList.item(j);
                Flag f = FlagParser.parse(item, artifact.getContainingFile());
                if (f != null) {
                    artifact.addFlag(f);
                }
            }
        }
    }
    NamedNodeMap attributes = artifactNode.getAttributes();
    Node nameNode = attributes.getNamedItem("name");
    artifact.setName(nameNode.getNodeValue());
    Node typeNode = attributes.getNamedItem("type");
    artifact.setType(typeNode.getNodeValue());
    Node bundleNode = attributes.getNamedItem("bundle");
    if (bundleNode != null) {
        artifact.setBundle(bundleNode.getNodeValue());
    }
    Node scopeNode = attributes.getNamedItem("scope");
    if (scopeNode != null) {
        artifact.setScope(scopeNode.getNodeValue());
    }
    Node includeInAllTargetNode = attributes.getNamedItem("all");
    if (includeInAllTargetNode.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setIncludeInAllTarget(true);
    } else {
        artifact.setIncludeInAllTarget(false);
    }
    Node loadgroupNode = attributes.getNamedItem("loadgroup");
    if (loadgroupNode != null) {
        artifact.setLoadgroup(loadgroupNode.getNodeValue());
    }
    Node buildLocal = attributes.getNamedItem("buildlocal");
    if (buildLocal.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setBuildLocal(true);
    }
    Node appendReleaseNode = attributes.getNamedItem("appendrelease");
    if (appendReleaseNode.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setAppendRelease(true);
    }
    Node consoleNode = attributes.getNamedItem("console");
    if (consoleNode.getNodeValue().equalsIgnoreCase("false")) {
        artifact.setConsoleApplication(false);
    } else {
        artifact.setConsoleApplication(true);
    }
    Parser.populatePredicateList(nodeList, artifact);
    return artifact;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) MakefileStub(com.ibm.uma.om.MakefileStub) Include(com.ibm.uma.om.Include) UMAException(com.ibm.uma.UMAException) Dependency(com.ibm.uma.om.Dependency) Flag(com.ibm.uma.om.Flag) Artifact(com.ibm.uma.om.Artifact) Command(com.ibm.uma.om.Command) Export(com.ibm.uma.om.Export) Option(com.ibm.uma.om.Option) Object(com.ibm.uma.om.Object) VPath(com.ibm.uma.om.VPath) Library(com.ibm.uma.om.Library) UMABadPhaseNameException(com.ibm.uma.UMABadPhaseNameException)

Aggregations

Export (com.ibm.uma.om.Export)6 FileAssistant (com.ibm.uma.util.FileAssistant)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 NodeList (org.w3c.dom.NodeList)3 Artifact (com.ibm.uma.om.Artifact)2 Library (com.ibm.uma.om.Library)2 Node (org.w3c.dom.Node)2 UMABadPhaseNameException (com.ibm.uma.UMABadPhaseNameException)1 UMAException (com.ibm.uma.UMAException)1 Command (com.ibm.uma.om.Command)1 Dependency (com.ibm.uma.om.Dependency)1 Exports (com.ibm.uma.om.Exports)1 Flag (com.ibm.uma.om.Flag)1 Include (com.ibm.uma.om.Include)1 MakefileStub (com.ibm.uma.om.MakefileStub)1 Object (com.ibm.uma.om.Object)1 Option (com.ibm.uma.om.Option)1 VPath (com.ibm.uma.om.VPath)1 Vector (java.util.Vector)1