use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class LoopTest method mergeFailTest.
@Test
public void mergeFailTest() {
Context context = new TestContext();
XcodeML xcodeml = XmlHelper.getDummyXcodeProgram(context);
assertNotNull(xcodeml);
Xnode n1 = xcodeml.createNode(Xcode.F_IF_STATEMENT);
Xnode n2 = xcodeml.createNode(Xcode.F_IF_STATEMENT);
try {
Loop.merge(n1, null);
fail();
} catch (IllegalTransformationException ignored) {
}
try {
Loop.merge(null, n2);
fail();
} catch (IllegalTransformationException ignored) {
}
try {
Loop.merge(n1, n2);
fail();
} catch (IllegalTransformationException ignored) {
}
}
use of claw.tatsu.xcodeml.xnode.common.Xnode 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.xcodeml.xnode.common.Xnode 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.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class XmlHelper method createXtypeTableFromString.
public static XtypeTable createXtypeTableFromString(String xml) {
Xnode n = XmlHelper.getElementFromString(xml);
assertNotNull(n);
return new XtypeTable(n);
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class Loop method compareIndexRanges.
/**
* Compare the iteration range of two do statements.
*
* @param l1 First do statement.
* @param l2 Second do statement.
* @param withLowerBound Compare lower bound or not.
* @return True if the iteration range are identical.
*/
private static boolean compareIndexRanges(Xnode l1, Xnode l2, boolean withLowerBound) {
// The two nodes must be do statement
if (!Xnode.isOfCode(l1, Xcode.F_DO_STATEMENT) || !Xnode.isOfCode(l2, Xcode.F_DO_STATEMENT)) {
return false;
}
Xnode inductionVar1 = l1.matchDirectDescendant(Xcode.VAR);
Xnode inductionVar2 = l2.matchDirectDescendant(Xcode.VAR);
Xnode indexRange1 = l1.matchDirectDescendant(Xcode.INDEX_RANGE);
Xnode indexRange2 = l2.matchDirectDescendant(Xcode.INDEX_RANGE);
return inductionVar1.compareValues(inductionVar2) && Range.compare(indexRange1, indexRange2, withLowerBound);
}
Aggregations