use of helper.Utils.TestContext 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 helper.Utils.TestContext 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 helper.Utils.TestContext 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"));
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XcodeMLTest method createPragmaTest.
@Test
public void createPragmaTest() {
String shortPragma = "acc loop seq";
String longPragma = "acc data present(var1,var2,var3,var4,var5,var6,var7," + "var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18," + "var19,var20,var21,var22,var23,var24,var25,var26,var27,var28,var29," + "var30)";
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
List<Xnode> p1 = xcodeml.createPragma(null, 80);
assertNotNull(p1);
assertTrue(p1.isEmpty());
List<Xnode> p2 = xcodeml.createPragma("", 80);
assertNotNull(p2);
assertTrue(p2.isEmpty());
List<Xnode> p3 = xcodeml.createPragma(shortPragma, 80);
assertNotNull(p3);
assertEquals(1, p3.size());
assertEquals(shortPragma, p3.get(0).value());
List<Xnode> p4 = xcodeml.createPragma(longPragma, 80);
assertNotNull(p4);
assertEquals(4, p4.size());
assertEquals("acc data &", p4.get(0).value());
assertEquals("acc present(var1,var2,var3,var4,var5,var6,var7,var8,var9," + "var10,var11,var12 &", p4.get(1).value());
assertEquals("acc ,var13,var14,var15,var16,var17,var18,var19,var20," + "var21,var22,var23 &", p4.get(2).value());
assertEquals("acc ,var24,var25,var26,var27,var28,var29,var30)", p4.get(3).value());
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XdeclTableTest method addRemoveTest.
@Test
public void addRemoveTest() {
Context context = new TestContext();
XcodeProgram xcodeml = createFromFile(context);
List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
assertEquals(1, functions.size());
FfunctionDefinition fctDef = new FfunctionDefinition(functions.get(0));
assertNotNull(fctDef);
XdeclTable fctDecl = fctDef.getDeclarationTable();
assertNotNull(fctDecl);
String key1 = "key1";
String key2 = "key2";
String key3 = "key3";
// Add
Xnode varDecl1 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key1);
fctDecl.add(varDecl1);
assertNotNull(fctDecl.get(key1));
// Replace existing one
Xnode varDecl2 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key1);
fctDecl.replace(varDecl2, key1);
assertNotNull(fctDecl.get(key1));
assertEquals(varDecl2.getType(), fctDecl.get(key1).getType());
// Replace non-existing - like add
Xnode varDecl3 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key2);
fctDecl.replace(varDecl3, key2);
assertNotNull(fctDecl.get(key2));
assertEquals(varDecl3.getType(), fctDecl.get(key2).getType());
// Add at the beginning of the table
Xnode varDecl4 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key3);
fctDecl.addFirst(varDecl4);
assertEquals(varDecl4.getType(), fctDecl.firstChild().getType());
}
Aggregations