use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class NestedDoStatementTest method ctorTest.
@Test
public void ctorTest() {
// One do statement
Xnode do1 = XmlHelper.createXnode(group1);
assertNotNull(do1);
NestedDoStatement ndo1 = new NestedDoStatement(do1);
assertNotNull(ndo1);
assertEquals(1, ndo1.size());
assertEquals(ndo1.getOuterStatement(), ndo1.getInnerStatement());
// Two do statements
Xnode do2 = XmlHelper.createXnode(group2);
assertNotNull(do2);
NestedDoStatement ndo2 = new NestedDoStatement(do2);
assertNotNull(ndo2);
assertEquals(2, ndo2.size());
assertEquals(ndo2.get(0), ndo2.getOuterStatement());
assertEquals(ndo2.get(1), ndo2.getInnerStatement());
assertNotEquals(ndo2.getOuterStatement(), ndo2.getInnerStatement());
// Two do statements
Xnode do3 = XmlHelper.createXnode(group3);
assertNotNull(do3);
NestedDoStatement ndo3 = new NestedDoStatement(do3);
assertNotNull(ndo3);
assertEquals(3, ndo3.size());
assertEquals(ndo3.get(0), ndo3.getOuterStatement());
assertEquals(ndo3.get(2), ndo3.getInnerStatement());
assertNotEquals(ndo3.getOuterStatement(), ndo3.getInnerStatement());
// Only two do statements in a potential 3 nested group one
NestedDoStatement ndo3Only2 = new NestedDoStatement(do3, 2);
assertNotNull(ndo3Only2);
assertEquals(2, ndo3Only2.size());
assertEquals(ndo3Only2.get(0), ndo3Only2.getOuterStatement());
assertEquals(ndo3Only2.get(1), ndo3Only2.getInnerStatement());
List<Xnode> doStmts = do3.matchAll(Xcode.F_DO_STATEMENT);
assertEquals(2, doStmts.size());
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class AddPrint method transform.
/**
* Insert a print statement with the function name after each function calls.
*
* @param xcodeml The XcodeML on which the transformations are applied.
* @param translator The translator used to applied the transformations.
* @param transformation Not used in this transformation
*/
@Override
public void transform(XcodeProgram xcodeml, Translator translator, Transformation transformation) {
for (Xnode fctDef : xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION)) {
Xnode printStatement = xcodeml.createPrintStatement("*", new String[] { "Call function", fctDef.matchDescendant(Xcode.NAME).value() });
fctDef.body().insert(printStatement, false);
}
}
use of claw.tatsu.xcodeml.xnode.common.Xnode 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());
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class ScaGPU method transformReturnStatement.
private void transformReturnStatement(XcodeProgram xcodeml) throws IllegalTransformationException {
List<Xnode> returns = _fctDef.matchAll(Xcode.F_RETURN_STATEMENT);
if (returns.isEmpty()) {
// No return statement to be transformed
return;
}
if (returns.size() > 1) {
throw new IllegalTransformationException("RETURN transformation is " + "currently limited to one per subroutine/function");
}
Xnode returnStmt = returns.get(0);
if (!canTransformReturn(returnStmt)) {
throw new IllegalTransformationException("RETURN statement cannot be " + "transformed.");
}
Xnode thenBody = returnStmt.ancestor();
Xnode thenNode = thenBody.ancestor();
Xnode ifNode = thenNode.ancestor();
Xnode elseNode = xcodeml.createElse();
ifNode.append(elseNode);
returnStmt.delete();
thenBody.append(xcodeml.createComment("CLAW: RETURN statement transformed for parallel region"));
Body.shiftIn(ifNode.nextSibling(), _fctDef.lastChild(), elseNode.body(), true);
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class VectorBlock method gatherUsedVariables.
/**
* Collect all variables names used within the block.
*/
private void gatherUsedVariables() {
if (_readAndWrittenVariables == null) {
_readAndWrittenVariables = new HashSet<>();
}
if (isSingleStatement()) {
_readAndWrittenVariables.addAll(_startStmt.matchAll(Xcode.VAR).stream().map(Xnode::value).collect(Collectors.toList()));
} else {
Xnode crt = getStartStmt();
while (!crt.equals(getEndStmt())) {
_readAndWrittenVariables.addAll(crt.matchAll(Xcode.VAR).stream().map(Xnode::value).collect(Collectors.toList()));
crt = crt.nextSibling();
}
if (crt.equals(getEndStmt())) {
_readAndWrittenVariables.addAll(crt.matchAll(Xcode.VAR).stream().map(Xnode::value).collect(Collectors.toList()));
}
}
}
Aggregations