Search in sources :

Example 46 with Xnode

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

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

the class DimensionTest method dimensionDefinitionTest.

@Test
public void dimensionDefinitionTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    DimensionDefinition dimDef = new DimensionDefinition("nproma", "1", "nend");
    DimensionDefinition dimDef2 = new DimensionDefinition("nproma", "nstart", "nend");
    assertEquals("nproma(nstart:nend)", dimDef2.toString());
    assertNotNull(dimDef.getLowerBound());
    assertNotNull(dimDef.getUpperBound());
    assertNotNull(dimDef.getIterationLowerBound());
    assertNotNull(dimDef.getIterationUpperBound());
    assertNotNull(dimDef.getIterationStep());
    assertFalse(dimDef.getLowerBound().isVar());
    assertEquals(1, dimDef.getLowerBound().getIntValue());
    assertFalse(dimDef.getIterationLowerBound().isVar());
    assertEquals(1, dimDef.getIterationLowerBound().getIntValue());
    assertTrue(dimDef.getUpperBound().isVar());
    assertEquals("nend", dimDef.getUpperBound().getValue());
    assertTrue(dimDef.getIterationUpperBound().isVar());
    assertEquals("nend", dimDef.getIterationUpperBound().getValue());
    assertFalse(dimDef.getIterationStep().isVar());
    assertEquals(1, dimDef.getIterationStep().getIntValue());
    assertEquals("nproma", dimDef.getIdentifier());
    assertEquals(InsertionPosition.BEFORE, dimDef.getInsertionPosition());
    dimDef.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(InsertionPosition.AFTER, dimDef.getInsertionPosition());
    assertEquals("nproma(1:nend)", dimDef.toString());
    Xnode indexRange = dimDef.generateIndexRange(xcodeml, false, false);
    assertNotNull(indexRange);
    assertEquals(Xcode.INDEX_RANGE, indexRange.opcode());
    assertEquals(2, indexRange.children().size());
    assertEquals(Xcode.LOWER_BOUND, indexRange.firstChild().opcode());
    assertEquals(Xcode.UPPER_BOUND, indexRange.lastChild().opcode());
    Xnode indexRangeStep = dimDef.generateIndexRange(xcodeml, true, false);
    assertNotNull(indexRangeStep);
    assertEquals(Xcode.INDEX_RANGE, indexRangeStep.opcode());
    assertEquals(3, indexRangeStep.children().size());
    assertEquals(Xcode.LOWER_BOUND, indexRangeStep.firstChild().opcode());
    assertEquals(Xcode.UPPER_BOUND, indexRangeStep.child(1).opcode());
    assertEquals(Xcode.STEP, indexRangeStep.lastChild().opcode());
    Xnode arrayIndex = dimDef.generateArrayIndex(xcodeml);
    assertNotNull(arrayIndex);
    assertEquals(Xcode.ARRAY_INDEX, arrayIndex.opcode());
    assertEquals(Xcode.VAR, arrayIndex.firstChild().opcode());
    assertEquals(dimDef.getIdentifier(), arrayIndex.firstChild().value());
    Xnode allocateNode = dimDef.generateAllocateNode(xcodeml);
    assertEquals(Xcode.ARRAY_INDEX, allocateNode.opcode());
    assertEquals(Xcode.VAR, allocateNode.firstChild().opcode());
    assertEquals(dimDef.getUpperBound().getValue(), allocateNode.firstChild().value());
}
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 48 with Xnode

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

the class TransformationAndGroupTest method basicTransformationTest.

@Test
public void basicTransformationTest() {
    Transformation t1 = new T1();
    assertTrue(t1.abortOnFailedAnalysis());
    assertEquals(0, t1.getStartLine());
    t1.setStartLine(10);
    assertEquals(10, t1.getStartLine());
    assertNull(t1.getDirective());
    assertFalse(t1.isTransformed());
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    Xnode pragma = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    pragma.setLine(10);
    t1 = new T1(new AnalyzedPragma(pragma));
    assertNotNull(t1.getDirective());
    assertNotNull(t1.getDirective().getPragma());
    assertEquals(10, t1.getStartLine());
}
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) AnalyzedPragma(claw.shenron.translator.AnalyzedPragma) Test(org.junit.Test)

Example 49 with Xnode

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

the class XmlHelper method createXtypeTableFromString.

public static XtypeTable createXtypeTableFromString(String xml) {
    Xnode n = XmlHelper.getElementFromString(xml);
    assertNotNull(n);
    return new XtypeTable(n);
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) XtypeTable(claw.tatsu.xcodeml.xnode.common.XtypeTable)

Example 50 with Xnode

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

the class Loop method compareIndexRanges.

/**
 * Compare the iteration range of two do statements.
 *
 * @param l1             First do statement.
 * @param l2             Second do statement.
 * @param withLowerBound Compare lower bound or not.
 * @return True if the iteration range are identical.
 */
private static boolean compareIndexRanges(Xnode l1, Xnode l2, boolean withLowerBound) {
    // The two nodes must be do statement
    if (!Xnode.isOfCode(l1, Xcode.F_DO_STATEMENT) || !Xnode.isOfCode(l2, Xcode.F_DO_STATEMENT)) {
        return false;
    }
    Xnode inductionVar1 = l1.matchDirectDescendant(Xcode.VAR);
    Xnode inductionVar2 = l2.matchDirectDescendant(Xcode.VAR);
    Xnode indexRange1 = l1.matchDirectDescendant(Xcode.INDEX_RANGE);
    Xnode indexRange2 = l2.matchDirectDescendant(Xcode.INDEX_RANGE);
    return inductionVar1.compareValues(inductionVar2) && Range.compare(indexRange1, indexRange2, withLowerBound);
}
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