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;
}
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();
}
Aggregations