Search in sources :

Example 31 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class NestedDoStatementTest method ctorTest.

@Test
public void ctorTest() {
    // One do statement
    Xnode do1 = XmlHelper.createXnode(group1);
    assertNotNull(do1);
    NestedDoStatement ndo1 = new NestedDoStatement(do1);
    assertNotNull(ndo1);
    assertEquals(1, ndo1.size());
    assertEquals(ndo1.getOuterStatement(), ndo1.getInnerStatement());
    // Two do statements
    Xnode do2 = XmlHelper.createXnode(group2);
    assertNotNull(do2);
    NestedDoStatement ndo2 = new NestedDoStatement(do2);
    assertNotNull(ndo2);
    assertEquals(2, ndo2.size());
    assertEquals(ndo2.get(0), ndo2.getOuterStatement());
    assertEquals(ndo2.get(1), ndo2.getInnerStatement());
    assertNotEquals(ndo2.getOuterStatement(), ndo2.getInnerStatement());
    // Two do statements
    Xnode do3 = XmlHelper.createXnode(group3);
    assertNotNull(do3);
    NestedDoStatement ndo3 = new NestedDoStatement(do3);
    assertNotNull(ndo3);
    assertEquals(3, ndo3.size());
    assertEquals(ndo3.get(0), ndo3.getOuterStatement());
    assertEquals(ndo3.get(2), ndo3.getInnerStatement());
    assertNotEquals(ndo3.getOuterStatement(), ndo3.getInnerStatement());
    // Only two do statements in a potential 3 nested group one
    NestedDoStatement ndo3Only2 = new NestedDoStatement(do3, 2);
    assertNotNull(ndo3Only2);
    assertEquals(2, ndo3Only2.size());
    assertEquals(ndo3Only2.get(0), ndo3Only2.getOuterStatement());
    assertEquals(ndo3Only2.get(1), ndo3Only2.getInnerStatement());
    List<Xnode> doStmts = do3.matchAll(Xcode.F_DO_STATEMENT);
    assertEquals(2, doStmts.size());
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) Test(org.junit.Test)

Example 32 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class AddPrint method transform.

/**
 * Insert a print statement with the function name after each function calls.
 *
 * @param xcodeml        The XcodeML on which the transformations are applied.
 * @param translator     The translator used to applied the transformations.
 * @param transformation Not used in this transformation
 */
@Override
public void transform(XcodeProgram xcodeml, Translator translator, Transformation transformation) {
    for (Xnode fctDef : xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION)) {
        Xnode printStatement = xcodeml.createPrintStatement("*", new String[] { "Call function", fctDef.matchDescendant(Xcode.NAME).value() });
        fctDef.body().insert(printStatement, false);
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode)

Example 33 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class AnalyzedPragmaTest method ctorTest.

@Test
public void ctorTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p1.setValue("acc parallel");
    Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p2.setValue("acc end parallel");
    AnalyzedPragma ap1 = new AnalyzedPragma(p1);
    assertFalse(ap1.isEndPragma());
    assertNotNull(ap1.getPragma());
    assertEquals("acc parallel", ap1.getPragma().value());
    ap1.setEndPragma();
    assertTrue(ap1.isEndPragma());
    AnalyzedPragma ap2 = new AnalyzedPragma();
    assertFalse(ap2.isEndPragma());
    assertNull(ap2.getPragma());
    ap2.setPragma(p2);
    ap2.setEndPragma();
    assertTrue(ap2.isEndPragma());
    assertNotNull(ap2.getPragma());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 34 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode 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 35 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class VectorBlock method gatherUsedVariables.

/**
 * Collect all variables names used within the block.
 */
private void gatherUsedVariables() {
    if (_readAndWrittenVariables == null) {
        _readAndWrittenVariables = new HashSet<>();
    }
    if (isSingleStatement()) {
        _readAndWrittenVariables.addAll(_startStmt.matchAll(Xcode.VAR).stream().map(Xnode::value).collect(Collectors.toList()));
    } else {
        Xnode crt = getStartStmt();
        while (!crt.equals(getEndStmt())) {
            _readAndWrittenVariables.addAll(crt.matchAll(Xcode.VAR).stream().map(Xnode::value).collect(Collectors.toList()));
            crt = crt.nextSibling();
        }
        if (crt.equals(getEndStmt())) {
            _readAndWrittenVariables.addAll(crt.matchAll(Xcode.VAR).stream().map(Xnode::value).collect(Collectors.toList()));
        }
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode)

Aggregations

Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)124 Context (claw.tatsu.common.Context)29 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)24 Test (org.junit.Test)24 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)20 TestContext (helper.Utils.TestContext)20 ArrayList (java.util.ArrayList)18 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)17 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)9 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)8 Xid (claw.tatsu.xcodeml.xnode.common.Xid)8 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)8 HashSet (java.util.HashSet)7 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)6 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)6 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)5 ClawPragma (claw.wani.language.ClawPragma)5 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)5 NodeList (org.w3c.dom.NodeList)5 DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)4