Search in sources :

Example 6 with IllegalDirectiveException

use of claw.tatsu.xcodeml.exception.IllegalDirectiveException in project claw-compiler by C2SM-RCM.

the class ClawTranslatorDriver method analyze.

/**
 * Analysis the XcodeML/F directives and categorized them in corresponding
 * transformation with the help of the translator.
 *
 * @throws Exception
 */
public void analyze(InputStream inStrm) throws Exception {
    _translationUnit = XcodeProgram.createFromStream(inStrm, context());
    if (_translationUnit.hasErrors()) {
        flushErrors();
        throw new Exception("Translation unit has errors");
    }
    if (cfg().getCurrentDirective() == CompilerDirective.OPENMP && cfg().getCurrentTarget() == Target.CPU) {
        _translationUnit.addWarning("Fine grain OpenMP directive generation " + "is not advised for CPU target.", 0);
    }
    try {
        // Check all pragma found in the translation unit
        for (Xnode pragma : _translationUnit.matchAll(Xcode.F_PRAGMA_STATEMENT)) {
            // Pragma can be handled by the translator so let it do its job.
            if (_translator.isHandledPragma(pragma)) {
                _translator.generateTransformation(_translationUnit, pragma);
            } else {
                // Check if the pragma is a compile guard
                if (context().getGenerator().isCompileGuard(pragma.value())) {
                    pragma.delete();
                } else {
                    // Handle special transformation of OpenACC line continuation
                    for (GroupConfiguration gc : cfg().getGroups()) {
                        if (gc.getTriggerType() == GroupConfiguration.TriggerType.DIRECTIVE && Pragma.getPrefix(pragma).equals(gc.getDirective())) {
                            generateTransformation(gc, new ClawPragma(pragma));
                        }
                    }
                }
            }
        }
        _translator.finalizeTranslation(_translationUnit);
    } catch (IllegalDirectiveException e) {
        _translationUnit.addError(e.getMessage(), e.getDirectiveLine());
        flushErrors();
        throw e;
    } catch (IllegalTransformationException e) {
        _translationUnit.addError(e.getMessage(), e.getStartLine());
        flushErrors();
        throw e;
    }
    // Generate transformation for translation_unit trigger type
    for (GroupConfiguration gc : cfg().getGroups()) {
        if (gc.getTriggerType() == GroupConfiguration.TriggerType.TRANSLATION_UNIT) {
            generateTransformation(gc, null);
        }
    }
    // Analysis done, the transformation can be performed.
    _canTransform = true;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) GroupConfiguration(claw.wani.x2t.configuration.GroupConfiguration) ClawPragma(claw.wani.language.ClawPragma) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException) IOException(java.io.IOException) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException)

Aggregations

IllegalDirectiveException (claw.tatsu.xcodeml.exception.IllegalDirectiveException)6 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)4 ClawPragma (claw.wani.language.ClawPragma)3 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)1 ClawLexer (claw.wani.language.parser.ClawLexer)1 ClawParser (claw.wani.language.parser.ClawParser)1 GroupConfiguration (claw.wani.x2t.configuration.GroupConfiguration)1 IOException (java.io.IOException)1 BailErrorStrategy (org.antlr.v4.runtime.BailErrorStrategy)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 InputMismatchException (org.antlr.v4.runtime.InputMismatchException)1 NoViableAltException (org.antlr.v4.runtime.NoViableAltException)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1