Search in sources :

Example 6 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class XmlHelper method getDummyXcodeProgram.

public static XcodeProgram getDummyXcodeProgram(Context context) {
    assertTrue(Files.exists(TestConstant.TEST_DATA));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DATA, context);
    assertNotNull(xcodeml);
    return xcodeml;
}
Also used : XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram)

Example 7 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class FmoduleDefinitionTest method simpleModuleDefinitionTest.

@Test
public void simpleModuleDefinitionTest() {
    Context context = new TestContext();
    Xnode node = XmlHelper.createXnode(module1);
    FmoduleDefinition mod = new FmoduleDefinition(node);
    assertNotNull(mod);
    assertEquals("module", mod.getName());
    assertEquals(4, mod.lineNo());
    assertEquals("./src/module.f90", mod.filename());
    assertNull(mod.getSymbolTable());
    assertNull(mod.getDeclarationTable());
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DECLARATIONS, context);
    assertNotNull(xcodeml);
    List<Xnode> nodes = xcodeml.matchAll(Xcode.F_MODULE_DEFINITION);
    assertFalse(nodes.isEmpty());
    FmoduleDefinition modDef = new FmoduleDefinition(nodes.get(0));
    assertEquals("mod1", modDef.getName());
    assertFalse(modDef.getFunctionDefinition(null).isPresent());
    assertFalse(modDef.getFunctionDefinition("").isPresent());
    assertTrue(modDef.getFunctionDefinition("sub1").isPresent());
    assertNotNull(modDef.cloneNode());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 8 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class FbasicTypeTest method addDimensionTest.

@Test
public void addDimensionTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    FbasicType bt = xcodeml.createBasicType(FortranType.INTEGER, Intent.NONE);
    assertEquals(0, bt.getDimensions());
    assertFalse(bt.isArray());
    assertFalse(bt.isAllAssumedShape());
    Xnode d1 = xcodeml.createEmptyAssumedShaped();
    bt.addDimension(d1);
    assertEquals(1, bt.getDimensions());
    Xnode d2 = xcodeml.createEmptyAssumedShaped();
    bt.addDimension(d2);
    assertEquals(2, bt.getDimensions());
    assertTrue(bt.isAllAssumedShape());
    Xnode arrayIndex = xcodeml.createNode(Xcode.ARRAY_INDEX);
    arrayIndex.append(xcodeml.createIntConstant(10));
    bt.addDimension(arrayIndex, 0);
    assertEquals(3, bt.getDimensions());
    assertEquals(Xcode.ARRAY_INDEX, bt.getDimensions(0).opcode());
    assertEquals(Xcode.INDEX_RANGE, bt.getDimensions(1).opcode());
    assertEquals(Xcode.INDEX_RANGE, bt.getDimensions(2).opcode());
    assertTrue(bt.getDimensions(1).getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE));
    assertTrue(bt.getDimensions(2).getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE));
    assertFalse(bt.isAllAssumedShape());
    assertTrue(bt.isArray());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 9 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class FfunctionTypeTest method simpleFctTypeTest.

/**
 * Test simple fct type
 *
 * function foo(a,b) integer a, b
 */
@Test
public void simpleFctTypeTest() {
    Context context = new TestContext();
    FfunctionType f = XmlHelper.createXfctTypeFromString(fctType1);
    assertFunctionType(f);
    FfunctionType clone = f.cloneNode();
    assertNotEquals(clone.element(), f.element());
    assertFunctionType(clone);
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    FfunctionType emptyFctType = xcodeml.createFunctionType(null);
    assertFalse(emptyFctType.hasParam("a"));
    Xnode paramA = xcodeml.createName("a", FortranType.INTEGER.toString());
    Xnode paramB = xcodeml.createName("b", FortranType.INTEGER.toString());
    Xnode paramC = xcodeml.createName("c", FortranType.INTEGER.toString());
    Xnode paramD = xcodeml.createName("d", FortranType.INTEGER.toString());
    emptyFctType.addParameters(paramB);
    assertEquals(1, emptyFctType.getParameters().size());
    emptyFctType.addParameters(paramB, paramA);
    assertEquals(2, emptyFctType.getParameters().size());
    emptyFctType.addParameters(paramD, paramC);
    assertEquals(3, emptyFctType.getParameters().size());
    emptyFctType.addParameters(null);
    assertEquals(3, emptyFctType.getParameters().size());
    emptyFctType.addParameters(null, null);
    assertEquals(3, emptyFctType.getParameters().size());
    assertEquals("a", emptyFctType.getParameters().get(0).value());
    assertEquals("b", emptyFctType.getParameters().get(1).value());
    assertEquals("c", emptyFctType.getParameters().get(2).value());
    emptyFctType.addParameters(null, paramD);
    assertEquals(4, emptyFctType.getParameters().size());
    assertEquals("d", emptyFctType.getParameters().get(3).value());
    List<String> names = emptyFctType.getParamsNames();
    assertEquals(4, names.size());
    assertEquals("a", names.get(0));
    assertEquals("b", names.get(1));
    assertEquals("c", names.get(2));
    assertEquals("d", names.get(3));
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 10 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class FfunctionDefinitionTest method findContainingXmodTest.

@Test
public void findContainingXmodTest() {
    Context context = new TestContext();
    context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
    assertTrue(Files.exists(TestConstant.TEST_DECLARATIONS));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DECLARATIONS, context);
    assertNotNull(xcodeml);
    List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
    for (FfunctionDefinition fctDef : fctDefs) {
        // Search paths is not set so module cannot be found.
        assertNull(fctDef.findContainingXmod(context));
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Aggregations

XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)25 Context (claw.tatsu.common.Context)24 TestContext (helper.Utils.TestContext)22 Test (org.junit.Test)22 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)20 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)7 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)4 ArrayList (java.util.ArrayList)3 Transformation (claw.shenron.transformation.Transformation)2 Translator (claw.shenron.translator.Translator)2 Target (claw.tatsu.common.Target)2 DataMovement (claw.tatsu.directive.common.DataMovement)2 Directive (claw.tatsu.directive.common.Directive)2 Range (claw.tatsu.primitive.Range)2 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)2 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)2 XnodeUtil (claw.tatsu.xcodeml.xnode.XnodeUtil)2 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)2 Xcode (claw.tatsu.xcodeml.xnode.common.Xcode)2 Xid (claw.tatsu.xcodeml.xnode.common.Xid)2