use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class PragmaTest method splitTest.
@Test
public void splitTest() {
Context context = new TestContext();
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
String p1 = "acc data present(var1,var2,var3,var4,var5,var6,var7,var8," + "var10,var11,var12,var13,var14,var15,var16)";
int maxCol = 40;
// Just commas
List<String> splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENACC.getPrefix());
checkSplitted(splitted, 5, maxCol);
// Just spaces
p1 = "acc data present(var1, var2, var3, var4, var5, var6, var7, " + "var8, var10, var11, var12, var13, var14, var15, var16)";
splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENACC.getPrefix());
checkSplitted(splitted, 4, maxCol);
// Mixed spaces and commas
p1 = "acc data present(var1, var2,var3,var4, var5, var6, var7, " + "var8,var10,var11, var12,var13,var14, var15,var16, var17, var18)";
splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENACC.getPrefix());
checkSplitted(splitted, 5, maxCol);
p1 = "omp target teams distribute parallel do simd";
splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENMP.getPrefix());
checkSplitted(splitted, 2, maxCol);
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class AssignStatementTest method gatherAssignmentTest2.
@Test
public void gatherAssignmentTest2() {
Context context = new TestContext();
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ASSIGN_STMT2, 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(4, assignStatements.size());
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XdeclTableTest method allKindOfDeclTest.
@Test
public void allKindOfDeclTest() {
Context context = new TestContext();
XcodeProgram xcodeml = createFromFile(context);
XglobalDeclTable global = xcodeml.getGlobalDeclarationsTable();
assertNotNull(global);
assertNull(global.getFunctionDefinition("unknown"));
assertNull(global.getModuleDefinition("unknown"));
List<Xnode> modules = xcodeml.matchAll(Xcode.F_MODULE_DEFINITION);
assertEquals(1, modules.size());
FmoduleDefinition mod = new FmoduleDefinition(modules.get(0));
XdeclTable modDecl = mod.getDeclarationTable();
assertNotNull(modDecl);
List<Xnode> modDeclarations = modDecl.values();
assertEquals(2, modDeclarations.size());
assertEquals(Xcode.F_STRUCT_DECL, modDeclarations.get(0).opcode());
assertEquals(Xcode.F_INTERFACE_DECL, modDeclarations.get(1).opcode());
Xnode interface1 = modDecl.get("dummy");
assertNotNull(interface1);
assertEquals(Xcode.F_INTERFACE_DECL, interface1.opcode());
assertEquals(1, modDecl.values(Xcode.F_INTERFACE_DECL).size());
List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
assertEquals(1, functions.size());
FfunctionDefinition fctDef = new FfunctionDefinition(functions.get(0));
XdeclTable fctDecl = fctDef.getDeclarationTable();
assertNotNull(fctDecl);
List<Xnode> fctDeclarations = fctDecl.values();
assertEquals(10, fctDeclarations.size());
assertEquals(Xcode.VAR_DECL, fctDeclarations.get(0).opcode());
assertEquals(Xcode.VAR_DECL, fctDeclarations.get(1).opcode());
assertEquals(Xcode.F_NAMELIST_DECL, fctDeclarations.get(2).opcode());
assertEquals(Xcode.VAR_DECL, fctDeclarations.get(3).opcode());
assertEquals(Xcode.VAR_DECL, fctDeclarations.get(4).opcode());
assertEquals(Xcode.F_COMMON_DECL, fctDeclarations.get(5).opcode());
assertEquals(Xcode.F_USE_DECL, fctDeclarations.get(6).opcode());
assertEquals(Xcode.F_USE_ONLY_DECL, fctDeclarations.get(7).opcode());
assertEquals(Xcode.F_EQUIVALENCE_DECL, fctDeclarations.get(8).opcode());
assertEquals(Xcode.EXTERN_DECL, fctDeclarations.get(9).opcode());
Xnode varDecl1 = fctDecl.get("sub1");
assertNotNull(varDecl1);
assertEquals(Xcode.VAR_DECL, varDecl1.opcode());
Xnode namelist = fctDecl.get("case");
assertNotNull(namelist);
assertEquals(Xcode.F_NAMELIST_DECL, namelist.opcode());
Xnode useDecl = fctDecl.get("mod4");
assertNotNull(useDecl);
assertEquals(Xcode.F_USE_DECL, useDecl.opcode());
Xnode useOnlyDecl = fctDecl.get("mod5");
assertNotNull(useOnlyDecl);
assertEquals(Xcode.F_USE_ONLY_DECL, useOnlyDecl.opcode());
Xnode externDecl = fctDecl.get("interface_sub");
assertNotNull(externDecl);
assertEquals(Xcode.EXTERN_DECL, externDecl.opcode());
assertEquals(4, fctDecl.values(Xcode.VAR_DECL).size());
assertEquals(1, fctDecl.values(Xcode.F_USE_DECL).size());
assertEquals(1, fctDecl.values(Xcode.F_USE_ONLY_DECL).size());
assertEquals(1, fctDecl.values(Xcode.F_NAMELIST_DECL).size());
assertEquals(1, fctDecl.values(Xcode.F_EQUIVALENCE_DECL).size());
assertEquals(1, fctDecl.values(Xcode.EXTERN_DECL).size());
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class ModelDataTest method gatherVariableTest.
/**
* Basic test to gather variable names in model-data directive block.
*/
@Test
public void gatherVariableTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_MODEL_DATA1, context);
assertNotNull(xcodeml);
List<Xnode> nodes = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(3, nodes.size());
Xnode modelDataBegin = nodes.get(0);
Xnode modelDataEnd = nodes.get(1);
assertEquals("claw model-data", modelDataBegin.value());
assertEquals("claw end model-data", modelDataEnd.value());
Set<String> values = XnodeUtil.getAllVariables(modelDataBegin, modelDataEnd);
assertEquals(2, values.size());
assertTrue(values.contains("t"));
assertTrue(values.contains("q"));
assertFalse(values.contains("w"));
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class FbasicTypeTest method setterTest.
/**
* Test setter for FbasicType
*/
@Test
public void setterTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
FbasicType bt1 = new FbasicType(xcodeml.createNode(Xcode.F_BASIC_TYPE));
FbasicType bt2 = new FbasicType(xcodeml.createNode(Xcode.F_BASIC_TYPE));
String typeHash1 = xcodeml.getTypeTable().generateHash(FortranType.INTEGER);
String typeHash2 = xcodeml.getTypeTable().generateHash(FortranType.INTEGER);
bt1.setType(typeHash1);
bt2.setType(typeHash2);
bt1.setRef(typeHash2);
bt2.setRef(Xname.TYPE_F_INT);
assertEquals(Xname.TYPE_F_INT, bt2.getRef());
assertEquals(typeHash2, bt1.getRef());
assertFalse(bt1.hasIntent());
bt1.setIntent(Intent.IN);
assertTrue(bt1.hasIntent());
assertEquals(Intent.IN, bt1.getIntent());
bt1.removeAttribute(Xattr.INTENT);
assertEquals(Intent.NONE, bt1.getIntent());
assertFalse(bt1.hasIntent());
assertFalse(bt1.isArray());
assertFalse(bt2.isArray());
bt1.setBooleanAttribute(Xattr.IS_ALLOCATABLE, true);
assertTrue(bt1.isAllocatable());
bt1.removeAttribute(Xattr.IS_ALLOCATABLE);
assertFalse(bt1.isAllocatable());
}
Aggregations