Search in sources :

Example 6 with IllegalTransformationException

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

the class XcodeML method importVar.

/**
 * Create a copy with a new hash type of an integer variable element from one
 * XcodeML unit to the current unit.
 *
 * @param base       Base variable element to be copied.
 * @param xcodemlSrc Source XcodeML unit.
 * @return The newly created element in the current XcodeML unit.
 * @throws IllegalTransformationException If the variable element doesn't meet
 *                                        the criteria.
 */
private Xnode importVar(Xnode base, XcodeML xcodemlSrc) throws IllegalTransformationException {
    String typeValue = base.getType();
    if (!FortranType.INTEGER.isOfType(typeValue)) {
        throw new IllegalTransformationException("Only integer variable are " + "supported as lower/upper bound value for promoted arrays.");
    }
    FbasicType type = xcodemlSrc.getTypeTable().getBasicType(typeValue);
    FbasicType bType = createBasicType(FortranType.INTEGER, Intent.NONE);
    if (type != null) {
        bType.setIntent(type.getIntent());
    }
    return createVar(bType.getType(), base.value(), Xscope.fromString(base.getAttribute(Xattr.SCOPE)));
}
Also used : IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Example 7 with IllegalTransformationException

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

the class PragmaTest method splitByContTest2.

@Test
public void splitByContTest2() {
    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 p = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    fd.body().append(p);
    p.setValue("acc data copyin(a) acc      present(b)");
    try {
        Pragma.splitByCont(p, CompilerDirective.OPENACC.getPrefix(), xcodeml);
        List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
        assertEquals(previous.size() + 2, 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 8 with IllegalTransformationException

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

the class ScaGPU method transformReturnStatement.

private void transformReturnStatement(XcodeProgram xcodeml) throws IllegalTransformationException {
    List<Xnode> returns = _fctDef.matchAll(Xcode.F_RETURN_STATEMENT);
    if (returns.isEmpty()) {
        // No return statement to be transformed
        return;
    }
    if (returns.size() > 1) {
        throw new IllegalTransformationException("RETURN transformation is " + "currently limited to one per subroutine/function");
    }
    Xnode returnStmt = returns.get(0);
    if (!canTransformReturn(returnStmt)) {
        throw new IllegalTransformationException("RETURN statement cannot be " + "transformed.");
    }
    Xnode thenBody = returnStmt.ancestor();
    Xnode thenNode = thenBody.ancestor();
    Xnode ifNode = thenNode.ancestor();
    Xnode elseNode = xcodeml.createElse();
    ifNode.append(elseNode);
    returnStmt.delete();
    thenBody.append(xcodeml.createComment("CLAW: RETURN statement transformed for parallel region"));
    Body.shiftIn(ifNode.nextSibling(), _fctDef.lastChild(), elseNode.body(), true);
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException)

Example 9 with IllegalTransformationException

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

the class LoopTest method mergeFailTest.

@Test
public void mergeFailTest() {
    Context context = new TestContext();
    XcodeML xcodeml = XmlHelper.getDummyXcodeProgram(context);
    assertNotNull(xcodeml);
    Xnode n1 = xcodeml.createNode(Xcode.F_IF_STATEMENT);
    Xnode n2 = xcodeml.createNode(Xcode.F_IF_STATEMENT);
    try {
        Loop.merge(n1, null);
        fail();
    } catch (IllegalTransformationException ignored) {
    }
    try {
        Loop.merge(null, n2);
        fail();
    } catch (IllegalTransformationException ignored) {
    }
    try {
        Loop.merge(n1, n2);
        fail();
    } catch (IllegalTransformationException ignored) {
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) TestContext(helper.Utils.TestContext) XcodeML(claw.tatsu.xcodeml.xnode.common.XcodeML) Test(org.junit.Test)

Example 10 with IllegalTransformationException

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

the class ClawTranslatorDriver method transform.

/**
 * Apply all the transformation in the pipeline.
 *
 * @throws Exception
 */
public void transform() throws Exception {
    try {
        if (!_canTransform) {
            return;
        }
        for (Map.Entry<Class<?>, TransformationGroup> entry : _translator.getGroups().entrySet()) {
            Message.debug(context(), "Apply transformation: " + entry.getValue().transformationName() + " - " + entry.getValue().count());
            try {
                entry.getValue().applyTransformations(_translationUnit, _translator);
                Message.warnings(context(), _translationUnit);
            } catch (IllegalTransformationException itex) {
                _translationUnit.addError(itex.getMessage(), itex.getStartLine());
                flushErrors();
                throw itex;
            } catch (Exception ex) {
                _translationUnit.addError("Unexpected error: " + ex.getMessage(), 0);
                if (context().getXmOption().isDebugOutput()) {
                    StringWriter errors = new StringWriter();
                    ex.printStackTrace(new PrintWriter(errors));
                    _translationUnit.addError(errors.toString(), 0);
                }
                flushErrors();
                throw ex;
            }
        }
    } catch (Exception ex) {
        context().getErrorStream().println("Transformation exception: " + ex.getMessage());
        throw ex;
    }
}
Also used : StringWriter(java.io.StringWriter) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) TransformationGroup(claw.shenron.transformation.TransformationGroup) Map(java.util.Map) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException) IOException(java.io.IOException) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) PrintWriter(java.io.PrintWriter)

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