Search in sources :

Example 21 with ClawPragma

use of claw.wani.language.ClawPragma 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

ClawPragma (claw.wani.language.ClawPragma)21 ClawConstraint (claw.wani.language.ClawConstraint)5 IllegalDirectiveException (claw.tatsu.xcodeml.exception.IllegalDirectiveException)3 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)3 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 Test (org.junit.Test)2 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)1 ClawMapping (claw.wani.language.ClawMapping)1 OpenAccContinuation (claw.wani.transformation.internal.OpenAccContinuation)1 LoopFusion (claw.wani.transformation.ll.loop.LoopFusion)1 LoopInterchange (claw.wani.transformation.ll.loop.LoopInterchange)1 GroupConfiguration (claw.wani.x2t.configuration.GroupConfiguration)1 IOException (java.io.IOException)1