Search in sources :

Example 6 with Context

use of claw.tatsu.common.Context 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)

Example 7 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class XcodeMLTest method createPragmaTest.

@Test
public void createPragmaTest() {
    String shortPragma = "acc loop seq";
    String longPragma = "acc data present(var1,var2,var3,var4,var5,var6,var7," + "var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18," + "var19,var20,var21,var22,var23,var24,var25,var26,var27,var28,var29," + "var30)";
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    List<Xnode> p1 = xcodeml.createPragma(null, 80);
    assertNotNull(p1);
    assertTrue(p1.isEmpty());
    List<Xnode> p2 = xcodeml.createPragma("", 80);
    assertNotNull(p2);
    assertTrue(p2.isEmpty());
    List<Xnode> p3 = xcodeml.createPragma(shortPragma, 80);
    assertNotNull(p3);
    assertEquals(1, p3.size());
    assertEquals(shortPragma, p3.get(0).value());
    List<Xnode> p4 = xcodeml.createPragma(longPragma, 80);
    assertNotNull(p4);
    assertEquals(4, p4.size());
    assertEquals("acc data &", p4.get(0).value());
    assertEquals("acc present(var1,var2,var3,var4,var5,var6,var7,var8,var9," + "var10,var11,var12 &", p4.get(1).value());
    assertEquals("acc ,var13,var14,var15,var16,var17,var18,var19,var20," + "var21,var22,var23 &", p4.get(2).value());
    assertEquals("acc ,var24,var25,var26,var27,var28,var29,var30)", p4.get(3).value());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Example 8 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class XdeclTableTest method addRemoveTest.

@Test
public void addRemoveTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = createFromFile(context);
    List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
    assertEquals(1, functions.size());
    FfunctionDefinition fctDef = new FfunctionDefinition(functions.get(0));
    assertNotNull(fctDef);
    XdeclTable fctDecl = fctDef.getDeclarationTable();
    assertNotNull(fctDecl);
    String key1 = "key1";
    String key2 = "key2";
    String key3 = "key3";
    // Add
    Xnode varDecl1 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key1);
    fctDecl.add(varDecl1);
    assertNotNull(fctDecl.get(key1));
    // Replace existing one
    Xnode varDecl2 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key1);
    fctDecl.replace(varDecl2, key1);
    assertNotNull(fctDecl.get(key1));
    assertEquals(varDecl2.getType(), fctDecl.get(key1).getType());
    // Replace non-existing - like add
    Xnode varDecl3 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key2);
    fctDecl.replace(varDecl3, key2);
    assertNotNull(fctDecl.get(key2));
    assertEquals(varDecl3.getType(), fctDecl.get(key2).getType());
    // Add at the beginning of the table
    Xnode varDecl4 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key3);
    fctDecl.addFirst(varDecl4);
    assertEquals(varDecl4.getType(), fctDecl.firstChild().getType());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Example 9 with Context

use of claw.tatsu.common.Context 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 10 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class ConfigurationTest method readConfig.

void readConfig(Path cfgDirPath) {
    try {
        Configuration conf = new TestConfiguration();
        assertNotNull(conf);
        Context context = new TestContext();
        assertNotNull(context);
        conf = Configuration.load(cfgDirPath, null, null, null, null, Integer.valueOf(MAX_COLUMN), context, Collections.emptyList());
        assertNotNull(context.getGenerator());
        assertNotNull(conf.accelerator());
        assertEquals(MAX_COLUMN, context.getMaxColumns());
        assertFalse(conf.isForcePure());
        conf.setForcePure();
        assertTrue(conf.isForcePure());
        int[] majorMinor = conf.getMajorMinor("0.3");
        assertEquals(0, majorMinor[0]);
        assertEquals(3, majorMinor[1]);
        try {
            conf.checkVersion("0.2");
            fail();
        } catch (Exception ignored) {
        }
        try {
            conf.getMajorMinor("sdjhsajkd");
            fail();
        } catch (Exception ignored) {
        }
        try {
            conf.checkVersion(ClawVersion.VERSION);
        } catch (Exception ignored) {
            fail();
        }
        assertTrue(conf.accelerator() instanceof OpenAccConfiguration);
        assertTrue(context.getGenerator() instanceof OpenAcc);
        assertSame(Target.GPU, conf.getCurrentTarget());
        assertSame(CompilerDirective.OPENACC, conf.getCurrentDirective());
        assertEquals(Configuration.CPU_STRATEGY_FUSION, conf.getParameter(Configuration.CPU_STRATEGY));
        conf.overrideConfigurationParameter(Configuration.CPU_STRATEGY, Configuration.CPU_STRATEGY_SINGLE);
        assertEquals(Configuration.CPU_STRATEGY_SINGLE, conf.getParameter(Configuration.CPU_STRATEGY));
        assertNull(conf.getParameter(DUMMY_KEY));
        conf.overrideConfigurationParameter(DUMMY_KEY, DUMMY_VALUE);
        assertEquals(DUMMY_VALUE, conf.getParameter(DUMMY_KEY));
    } catch (Exception e) {
        fail();
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) OpenAccConfiguration(claw.tatsu.directive.configuration.OpenAccConfiguration) TestConfiguration(helper.Utils.TestConfiguration) TestContext(helper.Utils.TestContext) TestConfiguration(helper.Utils.TestConfiguration) OpenAcc(claw.tatsu.directive.generator.OpenAcc) OpenAccConfiguration(claw.tatsu.directive.configuration.OpenAccConfiguration)

Aggregations

Context (claw.tatsu.common.Context)54 TestContext (helper.Utils.TestContext)44 Test (org.junit.Test)43 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)27 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)22 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)12 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)9 Xid (claw.tatsu.xcodeml.xnode.common.Xid)4 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)4 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)3 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)3 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)3 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)3 Configuration (claw.wani.x2t.configuration.Configuration)3 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)3 ArrayList (java.util.ArrayList)3 DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)2 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 XcodeML (claw.tatsu.xcodeml.xnode.common.XcodeML)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2