use of claw.tatsu.xcodeml.xnode.fortran.FbasicType in project claw-compiler by C2SM-RCM.
the class Sca method insertVariableToIterateOverDimension.
/**
* Insert the declaration of the different variables needed to iterate over the
* additional dimensions.
*
* @param xcodeml Current XcodeML program unit in which element are created.
*/
private void insertVariableToIterateOverDimension(Configuration cfg, XcodeProgram xcodeml) {
// Create type and declaration for iterations over the new dimensions
FbasicType bt = xcodeml.createBasicType(FortranType.INTEGER, Intent.IN);
xcodeml.getTypeTable().add(bt);
// For each dimension defined in the directive
for (DimensionDefinition dimension : _claw.getDefaultLayout(cfg)) {
if (!forceAssumedShapedArrayPromotion) {
// Create the parameter for the lower bound
if (dimension.getLowerBound().isVar()) {
xcodeml.createIdAndDecl(dimension.getLowerBound().getValue(), bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getLowerBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
// Create parameter for the upper bound
if (dimension.getUpperBound().isVar()) {
xcodeml.createIdAndDecl(dimension.getUpperBound().getValue(), bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getUpperBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
// Create the parameter for the iteration lower bound
if (dimension.getIterationLowerBound().isVar()) {
String itLowerBound = dimension.getIterationLowerBound().getValue();
if (!itLowerBound.equals(dimension.getLowerBound().getValue())) {
xcodeml.createIdAndDecl(itLowerBound, bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getIterationLowerBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
}
// Create parameter for the upper bound
if (dimension.getIterationUpperBound().isVar()) {
String itUpperBound = dimension.getIterationUpperBound().getValue();
if (!itUpperBound.equals(dimension.getUpperBound().getValue())) {
xcodeml.createIdAndDecl(itUpperBound, bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getIterationUpperBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
}
}
// Create induction variable declaration
xcodeml.createIdAndDecl(dimension.getIdentifier(), FortranType.INTEGER, XstorageClass.F_LOCAL, _fctDef, DeclarationPosition.LAST);
}
}
use of claw.tatsu.xcodeml.xnode.fortran.FbasicType 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