use of claw.tatsu.xcodeml.abstraction.PromotionInfo in project claw-compiler by C2SM-RCM.
the class FieldTest method readFromFormattedDimensionTest.
@Test
public void readFromFormattedDimensionTest() {
DimensionDefinition dim1 = new DimensionDefinition("dim1", "1", "30");
DimensionDefinition dim2 = new DimensionDefinition("dim2", "1", "nproma");
PromotionInfo p1 = new PromotionInfo("a");
p1.readDimensionsFromString("dim1(1:30),:");
dim1.setInsertionPosition(InsertionPosition.BEFORE);
assertEquals(1, p1.getDimensions().size());
assertDimensionEquals(dim1, p1.getDimensions().get(0));
p1.readDimensionsFromString(":,dim1(1:30)");
dim1.setInsertionPosition(InsertionPosition.AFTER);
assertEquals(1, p1.getDimensions().size());
assertDimensionEquals(dim1, p1.getDimensions().get(0));
p1.readDimensionsFromString(":,dim1(1:30),:");
dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
assertEquals(1, p1.getDimensions().size());
assertDimensionEquals(dim1, p1.getDimensions().get(0));
p1.readDimensionsFromString("dim1(1:30),dim2(1:nproma),:");
dim1.setInsertionPosition(InsertionPosition.BEFORE);
dim2.setInsertionPosition(InsertionPosition.BEFORE);
assertEquals(2, p1.getDimensions().size());
assertDimensionEquals(dim1, p1.getDimensions().get(0));
assertDimensionEquals(dim2, p1.getDimensions().get(1));
p1.readDimensionsFromString(":,dim1(1:30),dim2(1:nproma),:");
dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
assertEquals(2, p1.getDimensions().size());
assertDimensionEquals(dim1, p1.getDimensions().get(0));
assertDimensionEquals(dim2, p1.getDimensions().get(1));
p1.readDimensionsFromString(":,dim1(1:30),dim2(1:nproma)");
dim1.setInsertionPosition(InsertionPosition.AFTER);
dim2.setInsertionPosition(InsertionPosition.AFTER);
assertEquals(2, p1.getDimensions().size());
assertDimensionEquals(dim1, p1.getDimensions().get(0));
assertDimensionEquals(dim2, p1.getDimensions().get(1));
p1.readDimensionsFromString("dim1(1:30),:,dim2(1:nproma)");
dim1.setInsertionPosition(InsertionPosition.BEFORE);
dim2.setInsertionPosition(InsertionPosition.AFTER);
assertEquals(2, p1.getDimensions().size());
assertDimensionEquals(dim1, p1.getDimensions().get(0));
assertDimensionEquals(dim2, p1.getDimensions().get(1));
p1.readDimensionsFromString("dim1(1:30),:,dim2(1:nproma),:");
dim1.setInsertionPosition(InsertionPosition.BEFORE);
dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
assertEquals(2, p1.getDimensions().size());
assertDimensionEquals(dim1, p1.getDimensions().get(0));
assertDimensionEquals(dim2, p1.getDimensions().get(1));
p1.readDimensionsFromString(":,dim1(1:30),:,dim2(1:nproma)");
dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
dim2.setInsertionPosition(InsertionPosition.AFTER);
assertEquals(2, p1.getDimensions().size());
assertDimensionEquals(dim1, p1.getDimensions().get(0));
assertDimensionEquals(dim2, p1.getDimensions().get(1));
}
use of claw.tatsu.xcodeml.abstraction.PromotionInfo in project claw-compiler by C2SM-RCM.
the class FieldTest method performAndAssertPromotion.
/**
* Perform the promotion transformation and assert its result.
*
* @param id Identifier of the field to be promoted.
* @param dims Dimension definitions to use.
* @param fctDef Function definition in which the promotion is performed.
* @param xcodeml Current XcodeML translation unit.
* @param base Number of dimension before the promotion.
* @param target Number of dimension after the promotion.
* @param dimensions Expected dimensions after promotion.
*/
private void performAndAssertPromotion(String id, List<DimensionDefinition> dims, FfunctionDefinition fctDef, XcodeProgram xcodeml, int base, int target, int[] dimensions) {
try {
int diff = target - base;
PromotionInfo promotionInfo = new PromotionInfo(id);
promotionInfo.setDimensions(dims);
Xnode decl = fctDef.getDeclarationTable().get(id);
assertNotNull(decl);
FbasicType bt;
if (base != 0) {
bt = xcodeml.getTypeTable().getBasicType(decl);
assertNotNull(bt);
assertTrue(bt.isArray());
assertEquals(base, bt.getDimensions());
} else {
assertEquals(FortranType.REAL, FortranType.fromString(decl.getType()));
}
// Perform the promotion
Field.promote(promotionInfo, fctDef, xcodeml);
decl = fctDef.getDeclarationTable().get(id);
assertNotNull(decl);
bt = xcodeml.getTypeTable().getBasicType(decl);
assertNotNull(bt);
assertTrue(bt.isArray());
assertEquals(target, bt.getDimensions());
assertEquals(target, dimensions.length / 2);
assertEquals(target, promotionInfo.getTargetDimension());
assertEquals(base, promotionInfo.getBaseDimension());
assertEquals(diff, promotionInfo.diffDimension());
assertEquals(bt.getType(), promotionInfo.getTargetType().getType());
if (base > 0) {
assertEquals(PromotionInfo.PromotionType.ARRAY_TO_ARRAY, promotionInfo.getPromotionType());
} else {
assertEquals(PromotionInfo.PromotionType.SCALAR_TO_ARRAY, promotionInfo.getPromotionType());
}
for (int i = 0; i < dimensions.length / 2; ++i) {
assertDimension(bt.getDimensions(i), dimensions[i * 2], dimensions[(i * 2) + 1]);
}
} catch (IllegalTransformationException itex) {
System.err.println(itex.getMessage());
fail();
}
}
Aggregations