Search in sources :

Example 31 with IllegalTransformationException

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

the class PragmaTest method splitByContTest.

@Test
public void splitByContTest() {
    Context context = new TestContext();
    context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
    assertFalse(fctDefs.isEmpty());
    FfunctionDefinition fd = fctDefs.get(0);
    assertNotNull(fd.body());
    List<Xnode> previous = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
    Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    fd.body().append(p1);
    p1.setValue("acc data present(q,acc& p,acc& h)acc& create(pt)");
    try {
        Pragma.splitByCont(p1, CompilerDirective.OPENACC.getPrefix(), xcodeml);
        List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
        assertEquals(previous.size() + 4, splittedPragma.size());
    } catch (IllegalTransformationException e) {
        fail();
    }
    Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    fd.body().append(p2);
    p2.setValue("omp target teams omp& distribute simd");
    try {
        Pragma.splitByCont(p2, CompilerDirective.OPENMP.getPrefix(), xcodeml);
        List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
        assertEquals(previous.size() + 6, splittedPragma.size());
    } catch (IllegalTransformationException e) {
        fail();
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 32 with IllegalTransformationException

use of claw.tatsu.xcodeml.exception.IllegalTransformationException 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)

Example 33 with IllegalTransformationException

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

the class LoopTest method mergeTest.

@Test
public void mergeTest() {
    Context context = new TestContext();
    XcodeML xcodeml = XmlHelper.getDummyXcodeProgram(context);
    assertNotNull(xcodeml);
    DimensionDefinition d1 = new DimensionDefinition("i", "1", "10");
    Xnode inductionI = xcodeml.createVar(FortranType.INTEGER, "i", Xscope.LOCAL);
    Xnode l1 = xcodeml.createDoStmt(inductionI, d1.generateIndexRange(xcodeml, true, false));
    Xnode l2 = xcodeml.createDoStmt(inductionI, d1.generateIndexRange(xcodeml, true, false));
    List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
    assertFalse(fctDefs.isEmpty());
    FfunctionDefinition f1 = fctDefs.get(0);
    int doStmtCnt1 = f1.matchAll(Xcode.F_DO_STATEMENT).size();
    f1.body().append(l1);
    f1.body().append(l2);
    int doStmtCnt2 = f1.matchAll(Xcode.F_DO_STATEMENT).size();
    assertEquals(doStmtCnt1 + 2, doStmtCnt2);
    try {
        Loop.merge(l1, l2);
    } catch (IllegalTransformationException e) {
        fail();
    }
    int doStmtCnt3 = f1.matchAll(Xcode.F_DO_STATEMENT).size();
    assertEquals(doStmtCnt1 + 1, doStmtCnt3);
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) TestContext(helper.Utils.TestContext) XcodeML(claw.tatsu.xcodeml.xnode.common.XcodeML) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) Test(org.junit.Test)

Aggregations

IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)33 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)23 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)11 Context (claw.tatsu.common.Context)10 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)7 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)6 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)6 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)4 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)4 Xid (claw.tatsu.xcodeml.xnode.common.Xid)4 TestContext (helper.Utils.TestContext)4 Test (org.junit.Test)4 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)3 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)3 Configuration (claw.wani.x2t.configuration.Configuration)3 ArrayList (java.util.ArrayList)3 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)2 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)2 IllegalDirectiveException (claw.tatsu.xcodeml.exception.IllegalDirectiveException)2 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)2