Search in sources :

Example 1 with XmDecompilerContext

use of xcodeml.util.XmDecompilerContext in project claw-compiler by C2SM-RCM.

the class FortranDecompiler method decompile.

/**
   * Decompile the XcodeML file into Fortran code.
   *
   * @param outputFilepath Fortran output file path.
   * @param inputFilepath  XcodeML input file path.
   * @param maxColumns     Maximum number of column for the output file.
   * @param lineDirectives If true, preprocessor line directives are added.
   * @return True if the decompilation succeeded. False otherwise.
   */
public boolean decompile(String outputFilepath, String inputFilepath, int maxColumns, boolean lineDirectives) {
    if (!lineDirectives) {
        XmOption.setIsSuppressLineDirective(true);
    }
    XmOption.setCoarrayNoUseStatement(true);
    XmOption.setDebugOutput(false);
    if (!openXcodeMLFile(inputFilepath)) {
        return false;
    }
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFilepath)));
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        XmDecompiler decompiler = _toolFactory.createDecompiler();
        XmDecompilerContext context = _toolFactory.createDecompilerContext();
        if (maxColumns > 0) {
            context.setProperty(XmDecompilerContext.KEY_MAX_COLUMNS, "" + maxColumns);
        }
        try {
            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = docFactory.newDocumentBuilder();
            Document xcodeDoc;
            xcodeDoc = builder.parse(inputFilepath);
            decompiler.decompile(context, xcodeDoc, writer);
        } catch (ParserConfigurationException | SAXException | IOException e) {
            return false;
        }
        if (writer != null) {
            writer.flush();
        } else {
            return false;
        }
        return true;
    } catch (Exception ex) {
        if (_reader != null) {
            try {
                _reader.close();
            } catch (IOException ignored) {
            }
        }
        if (writer != null) {
            writer.close();
        }
    }
    return false;
}
Also used : XmDecompiler(xcodeml.util.XmDecompiler) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XmDecompilerContext(xcodeml.util.XmDecompilerContext) Document(org.w3c.dom.Document) XmException(xcodeml.XmException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with XmDecompilerContext

use of xcodeml.util.XmDecompilerContext in project claw-compiler by C2SM-RCM.

the class OmniBackendDriver method decompile.

/**
 * Decompile the XcodeML file into Fortran code.
 *
 * @param outputFilepath Fortran output file path.
 * @param xcodeml        XcodeML document.
 * @param maxColumns     Maximum number of column for the output file.
 * @param lineDirectives If true, preprocessor line directives are added.
 * @throws XmException
 */
public void decompile(OutputStream output, Document xcodeml, int maxColumns, boolean lineDirectives, IXmOption xmOption) throws XmException {
    if (!lineDirectives) {
        xmOption.setIsSuppressLineDirective(true);
    }
    xmOption.setDebugOutput(false);
    PrintWriter writer = new PrintWriter(output);
    XmDecompiler decompiler = _toolFactory.createDecompiler();
    XmDecompilerContext context = _toolFactory.createDecompilerContext(xmOption);
    if (maxColumns > 0) {
        context.setProperty(XmDecompilerContext.KEY_MAX_COLUMNS, "" + maxColumns);
    }
    decompiler.decompile(context, xcodeml, writer);
    writer.flush();
}
Also used : XmDecompiler(xcodeml.util.XmDecompiler) XmDecompilerContext(xcodeml.util.XmDecompilerContext) PrintWriter(java.io.PrintWriter)

Aggregations

XmDecompiler (xcodeml.util.XmDecompiler)2 XmDecompilerContext (xcodeml.util.XmDecompilerContext)2 PrintWriter (java.io.PrintWriter)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1 XmException (xcodeml.XmException)1