Search in sources :

Example 1 with FortranDecompiler

use of cx2x.decompiler.FortranDecompiler in project claw-compiler by C2SM-RCM.

the class Cx2x method main.

/**
   * Main point of entry of the program.
   *
   * @param args Arguments of the program.
   * @throws Exception if translation failed.
   */
public static void main(String[] args) throws Exception {
    String input;
    String xcodeMlOutput = null;
    String fortranOutput = null;
    String target_option = null;
    String directive_option = null;
    String configuration_path = null;
    String schema_path = null;
    int maxColumns = 0;
    boolean forcePure = false;
    CommandLine cmd;
    try {
        cmd = processCommandArgs(args);
    } catch (ParseException pex) {
        error(pex.getMessage());
        return;
    }
    // Help option
    if (cmd.hasOption("h")) {
        usage();
        return;
    }
    // Display target list option
    if (cmd.hasOption("tl")) {
        listTarget();
        return;
    }
    // Display directive list option
    if (cmd.hasOption("dl")) {
        listDirectiveLanguage();
        return;
    }
    // Target option
    if (cmd.hasOption("t")) {
        target_option = cmd.getOptionValue("t");
    }
    // Directive option
    if (cmd.hasOption("dir")) {
        directive_option = cmd.getOptionValue("dir");
    }
    // Suppressing line directive option
    if (cmd.hasOption("l")) {
        XmOption.setIsSuppressLineDirective(true);
    }
    // Debug option
    if (cmd.hasOption("d")) {
        XmOption.setDebugOutput(true);
    }
    // XcodeML/F output file option
    if (cmd.hasOption("o")) {
        xcodeMlOutput = cmd.getOptionValue("o");
    }
    // FORTRAN output file option
    if (cmd.hasOption("f")) {
        fortranOutput = cmd.getOptionValue("f");
    }
    if (cmd.hasOption("w")) {
        maxColumns = Integer.parseInt(cmd.getOptionValue("w"));
    }
    if (cmd.hasOption("c")) {
        configuration_path = cmd.getOptionValue("c");
    }
    if (cmd.hasOption("s")) {
        schema_path = cmd.getOptionValue("s");
    }
    // Check that configuration file exists
    if (configuration_path == null) {
        error("Configuration file missing.");
        return;
    }
    File configFile = new File(configuration_path);
    if (!configFile.exists()) {
        error("Configuration file not found. " + configuration_path);
    }
    if (cmd.hasOption("sc")) {
        showConfig(configuration_path, schema_path);
        return;
    }
    if (cmd.getArgs().length == 0) {
        error("no input file");
        return;
    } else {
        input = cmd.getArgs()[0];
    }
    // Module search path options
    if (cmd.hasOption("M")) {
        for (String value : cmd.getOptionValues("M")) {
            XcodeMLtools_Fmod.addSearchPath(value);
        }
    }
    // Read the configuration file
    Configuration config;
    try {
        config = new Configuration(configuration_path, schema_path);
        config.setUserDefinedTarget(target_option);
        config.setUserDefineDirective(directive_option);
        config.setMaxColumns(maxColumns);
    } catch (Exception ex) {
        error(ex.getMessage());
        return;
    }
    // Force pure option
    if (cmd.hasOption("fp")) {
        config.setForcePure();
    }
    // Call the translator to apply transformation on XcodeML/F
    ClawXcodeMlTranslator translator = new ClawXcodeMlTranslator(input, xcodeMlOutput, config);
    translator.analyze();
    translator.transform();
    translator.flush(config);
    // Produce report
    if (cmd.hasOption("r")) {
        ClawTransformationReport report = new ClawTransformationReport(cmd.getOptionValue("r"));
        report.generate(config, args, translator);
    }
    // Decompile XcodeML/F to Fortran
    FortranDecompiler decompiler = new FortranDecompiler();
    if (!decompiler.decompile(fortranOutput, xcodeMlOutput, maxColumns, XmOption.isSuppressLineDirective())) {
        error("Unable to decompile XcodeML to Fortran");
    }
}
Also used : GroupConfiguration(cx2x.translator.config.GroupConfiguration) Configuration(cx2x.translator.config.Configuration) ClawXcodeMlTranslator(cx2x.translator.ClawXcodeMlTranslator) ClawTransformationReport(cx2x.translator.report.ClawTransformationReport) File(java.io.File) FortranDecompiler(cx2x.decompiler.FortranDecompiler)

Aggregations

FortranDecompiler (cx2x.decompiler.FortranDecompiler)1 ClawXcodeMlTranslator (cx2x.translator.ClawXcodeMlTranslator)1 Configuration (cx2x.translator.config.Configuration)1 GroupConfiguration (cx2x.translator.config.GroupConfiguration)1 ClawTransformationReport (cx2x.translator.report.ClawTransformationReport)1 File (java.io.File)1