Search in sources :

Example 41 with TestContext

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

the class XsymbolsTest method addToTableTest.

@Test
public void addToTableTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    assertNotNull(xcodeml);
    XsymbolTable table = xcodeml.getGlobalSymbolsTable();
    assertNotNull(table);
    Xid id1 = xcodeml.createId(FortranType.INTEGER, XstorageClass.F_LOCAL, "id1");
    table.add(id1);
    assertTrue(table.contains("id1"));
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Example 42 with TestContext

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

the class ConditionTest method dependsOnTest.

@Test
public void dependsOnTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ASSIGN_STMT, context);
    assertNotNull(xcodeml);
    List<Xnode> nodes = xcodeml.matchAll(Xcode.F_IF_STATEMENT);
    assertEquals(1, nodes.size());
    Xnode ifStmt = nodes.get(0);
    assertEquals(Xcode.F_IF_STATEMENT, ifStmt.opcode());
    Xnode condition = ifStmt.matchDirectDescendant(Xcode.CONDITION);
    assertNotNull(condition);
    assertFalse(Condition.dependsOn(condition, Collections.emptySet()));
    assertFalse(Condition.dependsOn(null, Collections.singleton("t")));
    assertFalse(Condition.dependsOn(ifStmt, Collections.singleton("t")));
    assertTrue(Condition.dependsOn(condition, Collections.singleton("t")));
    assertFalse(Condition.dependsOn(condition, Collections.singleton("k")));
}
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 43 with TestContext

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

the class LoopTest method mergeTest.

@Test
public void mergeTest() {
    Context context = new TestContext();
    XcodeML xcodeml = XmlHelper.getDummyXcodeProgram(context);
    assertNotNull(xcodeml);
    DimensionDefinition d1 = new DimensionDefinition("i", "1", "10");
    Xnode inductionI = xcodeml.createVar(FortranType.INTEGER, "i", Xscope.LOCAL);
    Xnode l1 = xcodeml.createDoStmt(inductionI, d1.generateIndexRange(xcodeml, true, false));
    Xnode l2 = xcodeml.createDoStmt(inductionI, d1.generateIndexRange(xcodeml, true, false));
    List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
    assertFalse(fctDefs.isEmpty());
    FfunctionDefinition f1 = fctDefs.get(0);
    int doStmtCnt1 = f1.matchAll(Xcode.F_DO_STATEMENT).size();
    f1.body().append(l1);
    f1.body().append(l2);
    int doStmtCnt2 = f1.matchAll(Xcode.F_DO_STATEMENT).size();
    assertEquals(doStmtCnt1 + 2, doStmtCnt2);
    try {
        Loop.merge(l1, l2);
    } catch (IllegalTransformationException e) {
        fail();
    }
    int doStmtCnt3 = f1.matchAll(Xcode.F_DO_STATEMENT).size();
    assertEquals(doStmtCnt1 + 1, doStmtCnt3);
}
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) XcodeML(claw.tatsu.xcodeml.xnode.common.XcodeML) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) Test(org.junit.Test)

Example 44 with TestContext

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

the class DimensionTest method boundDefinitionTest.

@Test
public void boundDefinitionTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    BoundDefinition lowerBound = new BoundDefinition("1", BoundDefinition.BoundType.LOWER);
    BoundDefinition upperBound = new BoundDefinition("nend", BoundDefinition.BoundType.LOWER);
    BoundDefinition step = new BoundDefinition("1", BoundDefinition.BoundType.STEP);
    assertFalse(lowerBound.isVar());
    assertTrue(upperBound.isVar());
    assertFalse(step.isVar());
    assertEquals(1, lowerBound.getIntValue());
    assertEquals("nend", upperBound.getValue());
    assertEquals(1, step.getIntValue());
    Xnode lowerNode = lowerBound.generate(xcodeml);
    assertNotNull(lowerNode);
    assertNotNull(lowerNode.firstChild());
    assertEquals(Xcode.F_INT_CONSTANT, lowerNode.firstChild().opcode());
    assertEquals("1", lowerNode.firstChild().value());
    Xnode upperNode = upperBound.generate(xcodeml);
    assertNotNull(upperNode);
    assertNotNull(upperNode.firstChild());
    assertEquals(Xcode.VAR, upperNode.firstChild().opcode());
    assertEquals("nend", upperNode.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 45 with TestContext

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

the class XcodeProgTest method creationFailingTest.

@Test
public void creationFailingTest() throws IOException {
    Context context = new TestContext();
    XcodeProgram xc1 = XcodeProgram.createFromDocument(null, context);
    assertNotNull(xc1);
    assertTrue(xc1.hasErrors());
    // Simulate STDIN
    try (ByteArrayInputStream in = new ByteArrayInputStream("<dummy></dummy>".getBytes())) {
        XcodeProgram xc2 = XcodeProgram.createFromStream(in, context);
        assertNotNull(xc2);
        assertTrue(xc2.hasErrors());
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) ByteArrayInputStream(java.io.ByteArrayInputStream) 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