use of claw.tatsu.common.Context 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 claw.tatsu.common.Context 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 claw.tatsu.common.Context 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 claw.tatsu.common.Context 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());
}
use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.
the class DependenceAnalysisTest method perfectlyNestedNoDependencyTest.
@Test
public void perfectlyNestedNoDependencyTest() {
Context context = new TestContext();
// Load test data file
assertTrue(Files.exists(TestConstant.TEST_PERFECTLY_NESTED_NO_DEP));
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PERFECTLY_NESTED_NO_DEP, context);
assertNotNull(xcodeml);
// Match all the function definitions
List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
assertEquals(1, functions.size());
// Match all the pragmas
List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(1, pragmas.size());
// Analyze the pragma
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
// Get the function definition that interests us
Xnode fctDef = functions.get(0);
// Match all the do statements in the function
List<Xnode> loops = fctDef.matchAll(Xcode.F_DO_STATEMENT);
assertEquals(2, loops.size());
// Create an iteration space
try {
IterationSpace is = new IterationSpace(loops);
System.out.println();
assertEquals(2, is.getNbLevel());
is.printDebug(true);
assertTrue(is.isPerfectlyNested());
} catch (Exception e) {
fail();
}
}
Aggregations