Search in sources :

Example 21 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition in project claw-compiler by C2SM-RCM.

the class PragmaTest method splitByContTest.

@Test
public void splitByContTest() {
    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 p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    fd.body().append(p1);
    p1.setValue("acc data present(q,acc& p,acc& h)acc& create(pt)");
    try {
        Pragma.splitByCont(p1, CompilerDirective.OPENACC.getPrefix(), xcodeml);
        List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
        assertEquals(previous.size() + 4, splittedPragma.size());
    } catch (IllegalTransformationException e) {
        fail();
    }
    Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    fd.body().append(p2);
    p2.setValue("omp target teams omp& distribute simd");
    try {
        Pragma.splitByCont(p2, CompilerDirective.OPENMP.getPrefix(), xcodeml);
        List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
        assertEquals(previous.size() + 6, splittedPragma.size());
    } catch (IllegalTransformationException e) {
        fail();
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 22 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition 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());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 23 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition 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());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) FmoduleDefinition(claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition) Test(org.junit.Test)

Example 24 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition in project claw-compiler by C2SM-RCM.

the class XglobalDeclTest method simpleGlobalDeclarationTest.

@Test
public void simpleGlobalDeclarationTest() {
    XglobalDeclTable gdTable = XmlHelper.createGlobalDeclTable(SIMPLE_GLOB_DECL);
    assertNotNull(gdTable);
    assertEquals(2, gdTable.size());
    assertTrue(gdTable.hasDefinition("fct1"));
    assertTrue(gdTable.hasFunctionDefinition("fct1"));
    assertFalse(gdTable.hasModuleDefinition("fct1"));
    FfunctionDefinition fDef = gdTable.getFunctionDefinition("fct1");
    assertNotNull(fDef);
    assertEquals("fct1", fDef.getName());
    assertNotNull(fDef.body());
    assertNotNull(fDef.getDeclarationTable());
    assertNull(fDef.getParams());
    assertNotNull(fDef.getSymbolTable());
    assertEquals(917, fDef.lineNo());
    assertEquals("./src/module.f90", fDef.filename());
    assertTrue(gdTable.hasDefinition("module"));
    assertFalse(gdTable.hasFunctionDefinition("module"));
    assertTrue(gdTable.hasModuleDefinition("module"));
    FmoduleDefinition mDef = gdTable.getModuleDefinition("module");
    assertNotNull(mDef);
    assertEquals("module", mDef.getName());
    assertEquals(4, mDef.lineNo());
    assertEquals("./src/module.f90", mDef.filename());
}
Also used : FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) FmoduleDefinition(claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition) Test(org.junit.Test)

Example 25 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition in project claw-compiler by C2SM-RCM.

the class XnodeTest method utilityMethodTest.

@Test
public void utilityMethodTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    assertNotNull(xcodeml);
    List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
    assertFalse(pragmas.isEmpty());
    Xnode p = pragmas.get(0);
    assertNotNull(p.findParentFunction());
    assertNull(p.findParentFunction().findParentFunction());
    Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p.copyAttribute(p2, Xattr.LINENO);
    assertEquals("FpragmaStatement (children: 0) - 8", p2.toString());
    // No first child
    assertFalse(p.compareFirstChildValues(null));
    assertFalse(p.compareFirstChildValues(p2));
    // Depth
    assertTrue(p.depth() > 0);
    // Test attributes query and set
    assertNull(p2.child(10));
    p2.setBooleanAttribute(Xattr.IS_ASSUMED_SHAPE, false);
    assertFalse(p2.getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE));
    p2.removeAttribute(Xattr.IS_ASSUMED_SHAPE);
    assertFalse(p2.hasAttribute(Xattr.IS_ASSUMED_SHAPE));
    // Append/insert
    Xnode intConst = xcodeml.createIntConstant(10);
    FfunctionDefinition fctDef = p.findParentFunction();
    Xnode clone = intConst.cloneNode();
    assertNotNull(clone);
    assertNotEquals(clone.element(), intConst.element());
    fctDef.body().append(intConst);
    fctDef.body().append(clone);
    assertTrue(intConst.isDirectSibling(clone, Collections.emptyList()));
    fctDef.body().append(null);
    fctDef.body().insert(intConst, true);
    fctDef.body().insert(intConst);
    fctDef.body().insert(null);
    Xnode crt = intConst;
    while (crt != null) {
        assertNotNull(crt);
        crt = crt.prevSibling();
    }
    assertNotNull(fctDef.body().matchDirectDescendant(Xcode.F_PRAGMA_STATEMENT));
    assertNull(p.matchDirectDescendant(Xcode.F_PRAGMA_STATEMENT));
    // Methods should not crash on deleted node
    p.delete();
    assertTrue(p.depth() < 0);
    p.insertAfter(p2);
    p.insertBefore(p2);
    p.matchDescendant(Xcode.F_DO_STATEMENT);
    p.matchDirectDescendant(Xcode.F_DO_STATEMENT);
    p.matchDirectDescendant(Arrays.asList(Xcode.F_DO_STATEMENT, Xcode.F_DO_WHILE_STATEMENT));
    assertNull(p.nextSibling());
    assertNull(p.prevSibling());
    assertNull(p.matchSibling(Xcode.F_DO_STATEMENT));
    assertSame(p.matchAll(Xcode.F_PRAGMA_STATEMENT).size(), 0);
    assertFalse(p.isDirectSibling(null, Collections.emptyList()));
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Aggregations

FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)27 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)16 Context (claw.tatsu.common.Context)13 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)11 Test (org.junit.Test)10 TestContext (helper.Utils.TestContext)9 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)6 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)6 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)6 Xid (claw.tatsu.xcodeml.xnode.common.Xid)4 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)3 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)3 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)3 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)3 HoistedNestedDoStatement (claw.tatsu.xcodeml.abstraction.HoistedNestedDoStatement)2 ReshapeInfo (claw.tatsu.xcodeml.abstraction.ReshapeInfo)2 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)2 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)2 Configuration (claw.wani.x2t.configuration.Configuration)2 Transformation (claw.shenron.transformation.Transformation)1