Search in sources :

Example 16 with FbasicType

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);
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Example 17 with FbasicType

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();
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) PromotionInfo(claw.tatsu.xcodeml.abstraction.PromotionInfo) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Aggregations

FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)17 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)8 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)7 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)4 Xid (claw.tatsu.xcodeml.xnode.common.Xid)4 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)4 Context (claw.tatsu.common.Context)3 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)2 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)2 ArrayList (java.util.ArrayList)2 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)1 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)1 XdeclTable (claw.tatsu.xcodeml.xnode.common.XdeclTable)1 XsymbolTable (claw.tatsu.xcodeml.xnode.common.XsymbolTable)1 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)1 FortranModule (claw.tatsu.xcodeml.xnode.fortran.FortranModule)1 FstructType (claw.tatsu.xcodeml.xnode.fortran.FstructType)1 ClawMapping (claw.wani.language.ClawMapping)1 ClawMappingVar (claw.wani.language.ClawMappingVar)1