Search in sources :

Example 26 with Context

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

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

the class XcodeProgTest method createUnvalidXcodeProgram.

@Test
public void createUnvalidXcodeProgram() throws IOException {
    Context context = new TestContext();
    final String d1 = "<XcodeProgram source=\"original_code.f90\"\n" + "language=\"Fortran\"\n" + "time=\"2015-11-25 14:47:59\"\n" + "compiler-info=\"XcodeML/Fortran-FrontEnd\"\n" + "version=\"1.5\"></XcodeProgram>";
    final String d2 = "<XcodeProgram source=\"original_code.f90\"\n" + "language=\"C\"\n" + "time=\"2015-11-25 14:47:59\"\n" + "compiler-info=\"XcodeML/Fortran-FrontEnd\"\n" + "version=\"1.0\"></XcodeProgram>";
    // Simulate STDIN
    try (ByteArrayInputStream in = new ByteArrayInputStream(d1.getBytes())) {
        // Version not valid
        XcodeProgram xc1 = XcodeProgram.createFromStream(in, context);
        assertNotNull(xc1);
        assertTrue(xc1.hasErrors());
    }
    try (ByteArrayInputStream in = new ByteArrayInputStream(d2.getBytes())) {
        // Language not valid
        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)

Example 28 with Context

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

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

the class TransformationAndGroupTest method transformationGroupBaseTest.

@Test
public void transformationGroupBaseTest() {
    TransformationGroup ig = new IndependentTransformationGroup("loop-hoist");
    TransformationGroup dg = new DependentTransformationGroup("loop-fusion");
    groupTest(dg, "loop-fusion");
    groupTest(ig, "loop-hoist");
    Transformation t1 = new T1();
    ig.add(t1);
    assertEquals(1, ig.count());
    assertFalse(t1.isTransformed());
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    assertNotNull(xcodeml);
    try {
        ig.applyTransformations(xcodeml, null);
    } catch (Exception e) {
        fail();
    }
    assertTrue(t1.isTransformed());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 30 with Context

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

the class ExpandNotation method generateSavepoint.

/**
 * Generate serialization savepoints before and after the expand block.
 *
 * @param xcodeml Current XcodeML translation unit.
 * @param hook    Block around which serialization are generated
 */
private Xblock generateSavepoint(Configuration cfg, XcodeProgram xcodeml, Xblock hook, List<String> readArrays, List<String> writtenArrays) {
    final Context context = xcodeml.context();
    Serialization.insertImports(cfg, xcodeml, hook.getStart().findParentFunction());
    Xnode start = null;
    Xnode end;
    if (context.isTarget(Target.GPU)) {
        // Read inputs
        start = Serialization.generateReadSavepoint(cfg, xcodeml, hook.getStart(), _clawStart.getMetadataMap(), readArrays, _clawStart.value(ClawClause.SAVEPOINT), SerializationStep.SER_IN);
    } else if (context.isTarget(Target.CPU)) {
        // Write inputs
        start = Serialization.generateWriteSavepoint(cfg, xcodeml, hook.getStart(), _clawStart.getMetadataMap(), readArrays, _clawStart.value(ClawClause.SAVEPOINT), SerializationStep.SER_IN);
    }
    // Write outputs
    end = Serialization.generateWriteSavepoint(cfg, xcodeml, hook.getEnd(), _clawStart.getMetadataMap(), writtenArrays, _clawStart.value(ClawClause.SAVEPOINT), SerializationStep.SER_OUT);
    return new Xblock(start, end);
}
Also used : Context(claw.tatsu.common.Context) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) Xblock(claw.tatsu.xcodeml.abstraction.Xblock)

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