use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class ClawRange method compareToDoStmt.
/**
* Compare a ClawRange with a do statement.
*
* @param doStmt The do statement to compare iteration range.
* @return True if the iteration range share the same property.
*/
public boolean compareToDoStmt(Xnode doStmt) {
if (!Xnode.isOfCode(doStmt, Xcode.F_DO_STATEMENT)) {
return false;
}
Xnode inductionVar = doStmt.matchDirectDescendant(Xcode.VAR);
Xnode indexRange = doStmt.matchDirectDescendant(Xcode.INDEX_RANGE);
Xnode lower = indexRange.matchDirectDescendant(Xcode.LOWER_BOUND).child(0);
Xnode upper = indexRange.matchDirectDescendant(Xcode.UPPER_BOUND).child(0);
Xnode step = indexRange.matchDirectDescendant(Xcode.STEP).child(0);
return !(inductionVar == null || _inductionVar == null || !inductionVar.value().equals(_inductionVar)) && !(lower == null || _lowerBound == null || !lower.value().equals(_lowerBound)) && !(upper == null || _upperBound == null || !upper.value().equals(_upperBound)) && (step == null && _step == null || !(step == null || _step == null || !_step.equals(step.value())));
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class FieldTest method assertDimension.
/**
* Assert information of a dimension.
*
* @param dimension Node representing the dimension (indexRange node).
* @param lowerBound Value of the lowerBound.
* @param upperBound Value of the upperBound.
*/
private void assertDimension(Xnode dimension, int lowerBound, int upperBound) {
assertNotNull(dimension);
assertEquals(Xcode.INDEX_RANGE, dimension.opcode());
Xnode lowerBoundNode = dimension.firstChild();
assertNotNull(lowerBoundNode);
Xnode upperBoundNode = dimension.lastChild();
assertNotNull(upperBoundNode);
assertEquals(Xcode.F_INT_CONSTANT, lowerBoundNode.firstChild().opcode());
assertEquals(String.valueOf(lowerBound), lowerBoundNode.firstChild().value());
assertEquals(Xcode.F_INT_CONSTANT, upperBoundNode.firstChild().opcode());
assertEquals(String.valueOf(upperBound), upperBoundNode.firstChild().value());
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class PragmaTest method splitByContTest2.
@Test
public void splitByContTest2() {
Context context = new TestContext();
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
assertFalse(fctDefs.isEmpty());
FfunctionDefinition fd = fctDefs.get(0);
assertNotNull(fd.body());
List<Xnode> previous = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
Xnode p = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
fd.body().append(p);
p.setValue("acc data copyin(a) acc present(b)");
try {
Pragma.splitByCont(p, CompilerDirective.OPENACC.getPrefix(), xcodeml);
List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(previous.size() + 2, splittedPragma.size());
} catch (IllegalTransformationException e) {
fail();
}
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class PragmaTest method getPragmaPrefixTest.
@Test
public void getPragmaPrefixTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p1.setValue(CompilerDirective.OPENACC.getPrefix());
assertEquals(CompilerDirective.OPENACC.getPrefix(), Pragma.getPrefix(p1));
Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p2.setValue(CompilerDirective.OPENMP.getPrefix());
assertEquals(CompilerDirective.OPENMP.getPrefix(), Pragma.getPrefix(p2));
Xnode p3 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p3.setValue("");
assertEquals("", Pragma.getPrefix(p3));
Xnode p4 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
assertEquals("", Pragma.getPrefix(p4));
Xnode p5 = xcodeml.createNode(Xcode.F_DO_STATEMENT);
p5.setValue("acc");
assertEquals("", Pragma.getPrefix(p5));
assertEquals("", Pragma.getPrefix(null));
Xnode p6 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p6.setValue(CompilerDirective.OPENACC.getPrefix() + " loop private(a)");
assertEquals(CompilerDirective.OPENACC.getPrefix(), Pragma.getPrefix(p6));
p6.setValue(CompilerDirective.OPENMP.getPrefix() + " target");
assertEquals(CompilerDirective.OPENMP.getPrefix(), Pragma.getPrefix(p6));
}
use of claw.tatsu.xcodeml.xnode.common.Xnode 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"));
}
Aggregations