Search in sources :

Example 11 with Context

use of claw.tatsu.common.Context 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 12 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class XnodeUtilTest method gatherArgumentsTest.

@Test
public void gatherArgumentsTest() {
    Context context = new TestContext();
    String arg1 = "nz";
    String arg2 = "q(:,1:60)";
    String arg3 = "ty%y(:,:)";
    String arg4 = "z(:)";
    String arg5 = "nproma";
    assertTrue(Files.exists(TestConstant.TEST_ARGUMENTS));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ARGUMENTS, context);
    assertNotNull(xcodeml);
    List<Xnode> functionCalls = xcodeml.matchAll(Xcode.FUNCTION_CALL);
    assertEquals(1, functionCalls.size());
    FunctionCall fctCall = new FunctionCall(functionCalls.get(0));
    assertSame(fctCall.opcode(), Xcode.FUNCTION_CALL);
    FfunctionType fctType = xcodeml.getTypeTable().getFunctionType(fctCall);
    List<String> allArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.ANY, false, false);
    assertEquals(5, allArguments.size());
    assertEquals(arg1, allArguments.get(0));
    assertEquals(arg2, allArguments.get(1));
    assertEquals(arg3, allArguments.get(2));
    assertEquals(arg4, allArguments.get(3));
    assertEquals(arg5, allArguments.get(4));
    List<String> inArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.IN, false, false);
    assertEquals(5, inArguments.size());
    assertEquals(arg1, inArguments.get(0));
    assertEquals(arg2, inArguments.get(1));
    assertEquals(arg3, inArguments.get(2));
    assertEquals(arg4, inArguments.get(3));
    assertEquals(arg5, inArguments.get(4));
    List<String> outArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.OUT, false, false);
    assertEquals(3, outArguments.size());
    assertEquals(arg2, outArguments.get(0));
    assertEquals(arg3, outArguments.get(1));
    assertEquals(arg4, outArguments.get(2));
    List<String> inArrayArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.IN, true, false);
    assertEquals(3, inArrayArguments.size());
    assertEquals(arg2, inArrayArguments.get(0));
    assertEquals(arg3, inArrayArguments.get(1));
    assertEquals(arg4, inArrayArguments.get(2));
    List<String> outArrayArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.OUT, true, false);
    assertEquals(3, outArrayArguments.size());
    assertEquals(arg2, outArrayArguments.get(0));
    assertEquals(arg3, outArrayArguments.get(1));
    assertEquals(arg4, outArrayArguments.get(2));
    List<String> inOutArrayArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.INOUT, true, false);
    assertEquals(3, inOutArrayArguments.size());
    assertEquals(arg2, inOutArrayArguments.get(0));
    assertEquals(arg3, inOutArrayArguments.get(1));
    assertEquals(arg4, inOutArrayArguments.get(2));
// TODO add test with optional arguments
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionType(claw.tatsu.xcodeml.xnode.fortran.FfunctionType) TestContext(helper.Utils.TestContext) FunctionCall(claw.tatsu.xcodeml.abstraction.FunctionCall) Test(org.junit.Test)

Example 13 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class XnodeUtilTest method xpathIntersectTest.

@Test
public void xpathIntersectTest() {
    Context context = new TestContext();
    assertTrue(Files.exists(TestConstant.TEST_PROGRAM));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PROGRAM, context);
    assertNotNull(xcodeml);
    List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
    assertEquals(4, pragmas.size());
    Xnode loopHoistStart = new Xnode(pragmas.get(1).element());
    assertNotNull(loopHoistStart);
    assertTrue(loopHoistStart.value().contains("loop-hoist"));
    Xnode loopHoistEnd = new Xnode(pragmas.get(2).element());
    assertNotNull(loopHoistEnd);
    assertTrue(loopHoistEnd.value().contains("end loop-hoist"));
    List<HoistedNestedDoStatement> stmts = XnodeUtil.findDoStatementForHoisting(loopHoistStart, loopHoistEnd, Arrays.asList("j", "i"));
    assertEquals(3, stmts.size());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) HoistedNestedDoStatement(claw.tatsu.xcodeml.abstraction.HoistedNestedDoStatement) Test(org.junit.Test)

Example 14 with Context

use of claw.tatsu.common.Context 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 15 with Context

use of claw.tatsu.common.Context 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)

Aggregations

Context (claw.tatsu.common.Context)54 TestContext (helper.Utils.TestContext)44 Test (org.junit.Test)43 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)27 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)22 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)12 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)9 Xid (claw.tatsu.xcodeml.xnode.common.Xid)4 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)4 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)3 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)3 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)3 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)3 Configuration (claw.wani.x2t.configuration.Configuration)3 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)3 ArrayList (java.util.ArrayList)3 DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)2 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 XcodeML (claw.tatsu.xcodeml.xnode.common.XcodeML)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2