Search in sources :

Example 26 with Xnode

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

the class ClawRange method compareToDoStmt.

/**
 * Compare a ClawRange with a do statement.
 *
 * @param doStmt The do statement to compare iteration range.
 * @return True if the iteration range share the same property.
 */
public boolean compareToDoStmt(Xnode doStmt) {
    if (!Xnode.isOfCode(doStmt, Xcode.F_DO_STATEMENT)) {
        return false;
    }
    Xnode inductionVar = doStmt.matchDirectDescendant(Xcode.VAR);
    Xnode indexRange = doStmt.matchDirectDescendant(Xcode.INDEX_RANGE);
    Xnode lower = indexRange.matchDirectDescendant(Xcode.LOWER_BOUND).child(0);
    Xnode upper = indexRange.matchDirectDescendant(Xcode.UPPER_BOUND).child(0);
    Xnode step = indexRange.matchDirectDescendant(Xcode.STEP).child(0);
    return !(inductionVar == null || _inductionVar == null || !inductionVar.value().equals(_inductionVar)) && !(lower == null || _lowerBound == null || !lower.value().equals(_lowerBound)) && !(upper == null || _upperBound == null || !upper.value().equals(_upperBound)) && (step == null && _step == null || !(step == null || _step == null || !_step.equals(step.value())));
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode)

Example 27 with Xnode

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

the class FieldTest method assertDimension.

/**
 * Assert information of a dimension.
 *
 * @param dimension  Node representing the dimension (indexRange node).
 * @param lowerBound Value of the lowerBound.
 * @param upperBound Value of the upperBound.
 */
private void assertDimension(Xnode dimension, int lowerBound, int upperBound) {
    assertNotNull(dimension);
    assertEquals(Xcode.INDEX_RANGE, dimension.opcode());
    Xnode lowerBoundNode = dimension.firstChild();
    assertNotNull(lowerBoundNode);
    Xnode upperBoundNode = dimension.lastChild();
    assertNotNull(upperBoundNode);
    assertEquals(Xcode.F_INT_CONSTANT, lowerBoundNode.firstChild().opcode());
    assertEquals(String.valueOf(lowerBound), lowerBoundNode.firstChild().value());
    assertEquals(Xcode.F_INT_CONSTANT, upperBoundNode.firstChild().opcode());
    assertEquals(String.valueOf(upperBound), upperBoundNode.firstChild().value());
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode)

Example 28 with Xnode

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

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

the class PragmaTest method getPragmaPrefixTest.

@Test
public void getPragmaPrefixTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p1.setValue(CompilerDirective.OPENACC.getPrefix());
    assertEquals(CompilerDirective.OPENACC.getPrefix(), Pragma.getPrefix(p1));
    Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p2.setValue(CompilerDirective.OPENMP.getPrefix());
    assertEquals(CompilerDirective.OPENMP.getPrefix(), Pragma.getPrefix(p2));
    Xnode p3 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p3.setValue("");
    assertEquals("", Pragma.getPrefix(p3));
    Xnode p4 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    assertEquals("", Pragma.getPrefix(p4));
    Xnode p5 = xcodeml.createNode(Xcode.F_DO_STATEMENT);
    p5.setValue("acc");
    assertEquals("", Pragma.getPrefix(p5));
    assertEquals("", Pragma.getPrefix(null));
    Xnode p6 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p6.setValue(CompilerDirective.OPENACC.getPrefix() + " loop private(a)");
    assertEquals(CompilerDirective.OPENACC.getPrefix(), Pragma.getPrefix(p6));
    p6.setValue(CompilerDirective.OPENMP.getPrefix() + " target");
    assertEquals(CompilerDirective.OPENMP.getPrefix(), Pragma.getPrefix(p6));
}
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 30 with Xnode

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

the class AssignStatementTest method gatherAssignmentTest1.

@Test
public void gatherAssignmentTest1() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ASSIGN_STMT, context);
    assertNotNull(xcodeml);
    List<Xnode> nodes = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
    assertEquals(1, nodes.size());
    assertEquals(Xcode.F_FUNCTION_DEFINITION, nodes.get(0).opcode());
    FfunctionDefinition fctDef = new FfunctionDefinition(nodes.get(0));
    List<AssignStatement> assignStatements = fctDef.gatherAssignStatements();
    assertEquals(2, assignStatements.size());
    assertTrue(assignStatements.get(0).isChildOf(Xcode.F_IF_STATEMENT));
    assertFalse(assignStatements.get(1).isChildOf(Xcode.F_IF_STATEMENT));
    Set<String> vars = assignStatements.get(0).getVarNames();
    assertEquals(2, vars.size());
    assertTrue(vars.contains("t"));
    assertTrue(vars.contains("q"));
}
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) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

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