Search in sources :

Example 11 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class XnodeUtilTest method xpathIntersectTest.

@Test
public void xpathIntersectTest() {
    Context context = new TestContext();
    assertTrue(Files.exists(TestConstant.TEST_PROGRAM));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PROGRAM, context);
    assertNotNull(xcodeml);
    List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
    assertEquals(4, pragmas.size());
    Xnode loopHoistStart = new Xnode(pragmas.get(1).element());
    assertNotNull(loopHoistStart);
    assertTrue(loopHoistStart.value().contains("loop-hoist"));
    Xnode loopHoistEnd = new Xnode(pragmas.get(2).element());
    assertNotNull(loopHoistEnd);
    assertTrue(loopHoistEnd.value().contains("end loop-hoist"));
    List<HoistedNestedDoStatement> stmts = XnodeUtil.findDoStatementForHoisting(loopHoistStart, loopHoistEnd, Arrays.asList("j", "i"));
    assertEquals(3, stmts.size());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) HoistedNestedDoStatement(claw.tatsu.xcodeml.abstraction.HoistedNestedDoStatement) Test(org.junit.Test)

Example 12 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class FbasicTypeTest method addDimensionTest.

@Test
public void addDimensionTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    FbasicType bt = xcodeml.createBasicType(FortranType.INTEGER, Intent.NONE);
    assertEquals(0, bt.getDimensions());
    assertFalse(bt.isArray());
    assertFalse(bt.isAllAssumedShape());
    Xnode d1 = xcodeml.createEmptyAssumedShaped();
    bt.addDimension(d1);
    assertEquals(1, bt.getDimensions());
    Xnode d2 = xcodeml.createEmptyAssumedShaped();
    bt.addDimension(d2);
    assertEquals(2, bt.getDimensions());
    assertTrue(bt.isAllAssumedShape());
    Xnode arrayIndex = xcodeml.createNode(Xcode.ARRAY_INDEX);
    arrayIndex.append(xcodeml.createIntConstant(10));
    bt.addDimension(arrayIndex, 0);
    assertEquals(3, bt.getDimensions());
    assertEquals(Xcode.ARRAY_INDEX, bt.getDimensions(0).opcode());
    assertEquals(Xcode.INDEX_RANGE, bt.getDimensions(1).opcode());
    assertEquals(Xcode.INDEX_RANGE, bt.getDimensions(2).opcode());
    assertTrue(bt.getDimensions(1).getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE));
    assertTrue(bt.getDimensions(2).getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE));
    assertFalse(bt.isAllAssumedShape());
    assertTrue(bt.isArray());
}
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 13 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class FfunctionTypeTest method simpleFctTypeTest.

/**
 * Test simple fct type
 *
 * function foo(a,b) integer a, b
 */
@Test
public void simpleFctTypeTest() {
    Context context = new TestContext();
    FfunctionType f = XmlHelper.createXfctTypeFromString(fctType1);
    assertFunctionType(f);
    FfunctionType clone = f.cloneNode();
    assertNotEquals(clone.element(), f.element());
    assertFunctionType(clone);
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    FfunctionType emptyFctType = xcodeml.createFunctionType(null);
    assertFalse(emptyFctType.hasParam("a"));
    Xnode paramA = xcodeml.createName("a", FortranType.INTEGER.toString());
    Xnode paramB = xcodeml.createName("b", FortranType.INTEGER.toString());
    Xnode paramC = xcodeml.createName("c", FortranType.INTEGER.toString());
    Xnode paramD = xcodeml.createName("d", FortranType.INTEGER.toString());
    emptyFctType.addParameters(paramB);
    assertEquals(1, emptyFctType.getParameters().size());
    emptyFctType.addParameters(paramB, paramA);
    assertEquals(2, emptyFctType.getParameters().size());
    emptyFctType.addParameters(paramD, paramC);
    assertEquals(3, emptyFctType.getParameters().size());
    emptyFctType.addParameters(null);
    assertEquals(3, emptyFctType.getParameters().size());
    emptyFctType.addParameters(null, null);
    assertEquals(3, emptyFctType.getParameters().size());
    assertEquals("a", emptyFctType.getParameters().get(0).value());
    assertEquals("b", emptyFctType.getParameters().get(1).value());
    assertEquals("c", emptyFctType.getParameters().get(2).value());
    emptyFctType.addParameters(null, paramD);
    assertEquals(4, emptyFctType.getParameters().size());
    assertEquals("d", emptyFctType.getParameters().get(3).value());
    List<String> names = emptyFctType.getParamsNames();
    assertEquals(4, names.size());
    assertEquals("a", names.get(0));
    assertEquals("b", names.get(1));
    assertEquals("c", names.get(2));
    assertEquals("d", names.get(3));
}
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 14 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class XnodeTest method hasBodyTest.

@Test
public void hasBodyTest() {
    Context context = new TestContext();
    List<Xcode> expectedNodeWithBody = new ArrayList<>(Arrays.asList(Xcode.ASSOCIATE_STATEMENT, Xcode.BLOCK_STATEMENT, Xcode.CRITICAL_STATEMENT, Xcode.ELSE, Xcode.F_CASE_LABEL, Xcode.F_DO_CONCURRENT_STATEMENT, Xcode.F_DO_STATEMENT, Xcode.F_DO_WHILE_STATEMENT, Xcode.F_FUNCTION_DEFINITION, Xcode.FOR_ALL_STATEMENT, Xcode.THEN, Xcode.TYPE_GUARD));
    for (Xcode x : expectedNodeWithBody) {
        assertTrue(x.hasBody());
    }
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    for (Xcode opcode : Xcode.values()) {
        Xnode n = xcodeml.createNode(opcode);
        if (expectedNodeWithBody.contains(n.opcode())) {
            assertTrue(n.opcode().hasBody());
            assertTrue(n.hasBody());
        } else {
            assertFalse(n.opcode().hasBody());
            assertFalse(n.hasBody());
        }
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class XnodeTest method deletedTest.

@Test
public void deletedTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    Xnode n1 = xcodeml.createNode(Xcode.F_BASIC_TYPE);
    assertFalse(n1.isDeleted());
    n1.delete();
    assertTrue(n1.isDeleted());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Aggregations

TestContext (helper.Utils.TestContext)45 Context (claw.tatsu.common.Context)44 Test (org.junit.Test)43 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)22 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)20 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)9 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)4 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 XcodeML (claw.tatsu.xcodeml.xnode.common.XcodeML)2 TestConfiguration (helper.Utils.TestConfiguration)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 AnalyzedPragma (claw.shenron.translator.AnalyzedPragma)1 OpenAccConfiguration (claw.tatsu.directive.configuration.OpenAccConfiguration)1 OpenAcc (claw.tatsu.directive.generator.OpenAcc)1 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)1 HoistedNestedDoStatement (claw.tatsu.xcodeml.abstraction.HoistedNestedDoStatement)1 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)1 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)1 Before (org.junit.Before)1