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());
}
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());
}
}
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());
}
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());
}
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);
}
Aggregations