Search in sources :

Example 11 with IllegalTransformationException

use of claw.tatsu.xcodeml.exception.IllegalTransformationException in project claw-compiler by C2SM-RCM.

the class Field method promote.

/**
 * Promote a field with the information stored in the defined dimensions.
 *
 * @param fieldInfo Promotion information. Must contains identifier and
 *                  dimensions.
 * @param fctDef    Function definition node in which the promotion is
 *                  performed.
 * @param xcodeml   Current XcodeML translation unit.
 * @throws IllegalTransformationException If promotion information are not
 *                                        sufficient. If types cannot be found
 *                                        in typeTable.
 */
public static void promote(PromotionInfo fieldInfo, FfunctionDefinition fctDef, XcodeProgram xcodeml) throws IllegalTransformationException {
    Xid id = fctDef.getSymbolTable().get(fieldInfo.getIdentifier());
    Xnode decl = fctDef.getDeclarationTable().get(fieldInfo.getIdentifier());
    FbasicType crtType = xcodeml.getTypeTable().getBasicType(id);
    FfunctionType tmpFctType = xcodeml.getTypeTable().getFunctionType(id);
    boolean returnTypePromotion = false;
    if (crtType == null && tmpFctType != null) {
        // Have to retrieve function return type.
        crtType = xcodeml.getTypeTable().getBasicType(tmpFctType.getReturnType());
        returnTypePromotion = true;
    }
    if (!FortranType.isBuiltInType(id.getType()) && crtType == null) {
        throw new IllegalTransformationException("Basic type of field " + fieldInfo.getIdentifier() + " could not be found");
    }
    FfunctionType fctType = xcodeml.getTypeTable().getFunctionType(fctDef);
    if (fctType == null) {
        throw new IllegalTransformationException("Function type " + fctDef.getType() + " could not be found", fctDef.lineNo());
    }
    if (fieldInfo.getDimensions() == null || fieldInfo.getDimensions().isEmpty()) {
        throw new IllegalTransformationException("Promotion information has not " + "enough information. Dimension empty!", decl.lineNo());
    }
    String type = xcodeml.getTypeTable().generateHash(FortranType.ARRAY);
    FbasicType newType;
    if (crtType != null && crtType.isArray()) {
        fieldInfo.setPromotionType(PromotionInfo.PromotionType.ARRAY_TO_ARRAY);
        if (FortranType.isBuiltInType(id.getType())) {
            newType = xcodeml.createBasicType(type, id.getType(), Intent.NONE);
        } else {
            FbasicType old = xcodeml.getTypeTable().getBasicType(id);
            if (old == null) {
                throw new IllegalTransformationException("Cannot find type for " + fieldInfo.getIdentifier(), decl.lineNo());
            } else {
                newType = old.cloneNode();
                newType.setType(type);
            }
        }
    } else {
        fieldInfo.setPromotionType(PromotionInfo.PromotionType.SCALAR_TO_ARRAY);
        Intent newIntent = crtType != null ? crtType.getIntent() : Intent.NONE;
        if (returnTypePromotion) {
            newType = xcodeml.createBasicType(type, crtType != null ? crtType.getRef() : "", newIntent);
        } else {
            newType = xcodeml.createBasicType(type, id.getType(), newIntent);
        }
        newType.copyAttributes(crtType);
    }
    // Save promotion information (base dimensions, target dimensions, type)
    fieldInfo.setBaseDimension(newType.getDimensions());
    fieldInfo.setTargetDimension(newType.getDimensions() + fieldInfo.getDimensions().size());
    fieldInfo.setTargetType(newType);
    if (fieldInfo.getPromotionType() == PromotionInfo.PromotionType.ARRAY_TO_ARRAY) {
        if (newType.isAllAssumedShape() && (fctType.hasParam(fieldInfo.getIdentifier()) || newType.isAllocatable() || newType.isPointer())) {
            for (int i = 0; i < fieldInfo.diffDimension(); ++i) {
                Xnode index = xcodeml.createEmptyAssumedShaped();
                newType.addDimension(index, 0);
            }
        } else {
            int beforePositionIndex = 0;
            int inMiddlePositionIndex = 1;
            for (DimensionDefinition dim : fieldInfo.getDimensions()) {
                switch(dim.getInsertionPosition()) {
                    case BEFORE:
                        newType.addDimension(dim.generateIndexRange(xcodeml, false, false), beforePositionIndex);
                        ++beforePositionIndex;
                        // Update index to insert in middle
                        ++inMiddlePositionIndex;
                        break;
                    case IN_MIDDLE:
                        newType.addDimension(dim.generateIndexRange(xcodeml, false, false), inMiddlePositionIndex);
                        ++inMiddlePositionIndex;
                        break;
                    case AFTER:
                        newType.addDimension(dim.generateIndexRange(xcodeml, false, false));
                        break;
                }
            }
        }
    } else {
        // SCALAR to ARRAY promotion
        for (DimensionDefinition dim : fieldInfo.getDimensions()) {
            Xnode index;
            if (fieldInfo.isForcedAssumedShape()) {
                index = xcodeml.createEmptyAssumedShaped();
            } else {
                index = dim.generateIndexRange(xcodeml, false, false);
            }
            newType.addDimension(index);
        }
    }
    // Set type hash to id and declaration node
    id.setType(type);
    decl.matchSeq(Xcode.NAME).setType(type);
    xcodeml.getTypeTable().add(newType);
    if (returnTypePromotion) {
        fctType.setAttribute(Xattr.RETURN_TYPE, type);
    }
    // Update params in function type with correct type hash
    for (Xnode param : fctType.getParameters()) {
        if (param.value().equals(fieldInfo.getIdentifier())) {
            // Update type with new promoted type
            param.setType(type);
            // Save the over clause for one_column forward transformation
            param.setAttribute(Xattr.PROMOTION_INFO, fieldInfo.getFormattedDimensions());
        }
    }
    if (fctType.hasAttribute(Xattr.RESULT_NAME) && fctType.getAttribute(Xattr.RESULT_NAME).equals(fieldInfo.getIdentifier())) {
        fctType.setAttribute(Xattr.PROMOTION_INFO, fieldInfo.getFormattedDimensions());
    }
}
Also used : IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition)

Example 12 with IllegalTransformationException

use of claw.tatsu.xcodeml.exception.IllegalTransformationException in project claw-compiler by C2SM-RCM.

the class Body method append.

/**
 * Append the slave body to the master body.
 *
 * @param masterBody Master body node.
 * @param slaveBody  Slave body bode.
 * @throws IllegalTransformationException If given nodes are null or not body
 *                                        nodes.
 */
public static void append(Xnode masterBody, Xnode slaveBody) throws IllegalTransformationException {
    if (!Xnode.isOfCode(masterBody, Xcode.BODY) || !Xnode.isOfCode(slaveBody, Xcode.BODY)) {
        throw new IllegalTransformationException(String.format("%s for Body.append. opcode: %s - %s", TatsuConstant.ERROR_INCOMPATIBLE, masterBody == null ? "null" : masterBody.opcode(), slaveBody == null ? "null" : slaveBody.opcode()));
    }
    // Move all nodes to master body
    Xnode crtNode = slaveBody.firstChild();
    while (crtNode != null) {
        Xnode nextSibling = crtNode.nextSibling();
        masterBody.append(crtNode);
        crtNode = nextSibling;
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException)

Example 13 with IllegalTransformationException

use of claw.tatsu.xcodeml.exception.IllegalTransformationException in project claw-compiler by C2SM-RCM.

the class Body method shiftIn.

/**
 * Shift all statements from the first siblings of the "from" element until the
 * "until" element if "included" is true.
 *
 * @param from       Start element for the shifting.
 * @param until      End element for the shifting.
 * @param targetBody Body element in which statements are inserted.
 * @param included   If true, until element is shifted.
 * @throws IllegalTransformationException If one element is null or the
 *                                        targetBody element is not a body
 *                                        element.
 */
public static void shiftIn(Xnode from, Xnode until, Xnode targetBody, boolean included) throws IllegalTransformationException {
    if (from == null && until == null) {
        return;
    }
    if (from == null || until == null || !Xnode.isOfCode(targetBody, Xcode.BODY)) {
        throw new IllegalTransformationException(String.format("%s for Body.shiftIn. opcode: %s, from: %s, until: %s", TatsuConstant.ERROR_INCOMPATIBLE, targetBody == null ? "null" : targetBody.opcode(), from == null ? "null" : from.opcode(), until == null ? "null" : until.opcode()));
    }
    Node currentSibling = from.element();
    if (!included) {
        currentSibling = from.element().getNextSibling();
    }
    Node firstStatementInBody = targetBody.element().getFirstChild();
    while (currentSibling != null && currentSibling != until.element()) {
        Node nextSibling = currentSibling.getNextSibling();
        targetBody.element().insertBefore(currentSibling, firstStatementInBody);
        currentSibling = nextSibling;
    }
    if (included && currentSibling == until.element()) {
        targetBody.element().insertBefore(currentSibling, firstStatementInBody);
    }
}
Also used : IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) Node(org.w3c.dom.Node)

Example 14 with IllegalTransformationException

use of claw.tatsu.xcodeml.exception.IllegalTransformationException in project claw-compiler by C2SM-RCM.

the class Pragma method splitByCont.

/**
 * Split the line by its previous continuation mark.
 *
 * @param pragma  Pragma node.
 * @param prefix  Pragma prefix.
 * @param xcodeml Current XcodeML translation unit.
 * @throws IllegalTransformationException If the given element is not a
 *                                        FpragmaStatement.
 */
public static void splitByCont(Xnode pragma, String prefix, XcodeProgram xcodeml) throws IllegalTransformationException {
    if (!Xnode.isOfCode(pragma, Xcode.F_PRAGMA_STATEMENT)) {
        throw new IllegalTransformationException(TatsuConstant.ERROR_INCOMPATIBLE);
    }
    String allPragma = pragma.value();
    int lineIndex = pragma.lineNo();
    String splitter = prefix.trim();
    if (allPragma.contains(prefix.trim() + TatsuConstant.CONTINUATION_LINE_SYMBOL)) {
        splitter = prefix.trim() + TatsuConstant.CONTINUATION_LINE_SYMBOL;
    }
    Xnode newlyInserted = pragma;
    String[] lines = allPragma.split(splitter);
    for (int i = 0; i < lines.length - 1; ++i) {
        if (!lines[i].isEmpty()) {
            newlyInserted = createAndInsertPragma(xcodeml, newlyInserted, pragma.filename(), lineIndex, lines[i], true);
            ++lineIndex;
        }
    }
    createAndInsertPragma(xcodeml, newlyInserted, pragma.filename(), lineIndex, lines[lines.length - 1], false);
    pragma.delete();
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException)

Example 15 with IllegalTransformationException

use of claw.tatsu.xcodeml.exception.IllegalTransformationException in project claw-compiler by C2SM-RCM.

the class Kcaching method generateInferredOffsets.

/**
 * Generate correct offset inferred by the dimension of the variable.
 *
 * @param xcodeml The current program
 * @param fctDef  The function definition which holds the variable information.
 * @param var     The variable on which the offset are inferred.
 * @return List of integer representing the offset for the given variable.
 * @throws IllegalTransformationException if symbol id is not found.
 */
private List<Integer> generateInferredOffsets(XcodeProgram xcodeml, FfunctionDefinition fctDef, String var) throws IllegalTransformationException {
    Xid id = fctDef.getSymbolTable().get(var);
    if (id == null) {
        throw new IllegalTransformationException("Variable " + var + " defined in the data clause has not been found", _claw.getPragma().lineNo());
    }
    FbasicType basicType = xcodeml.getTypeTable().getBasicType(id);
    int dim = basicType.getDimensions();
    List<Integer> offsets = new ArrayList<>();
    for (int i = 0; i < dim; ++i) {
        offsets.add(0);
    }
    return offsets;
}
Also used : IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) ArrayList(java.util.ArrayList) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Aggregations

IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)33 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)23 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)11 Context (claw.tatsu.common.Context)10 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)7 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)6 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)6 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)4 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)4 Xid (claw.tatsu.xcodeml.xnode.common.Xid)4 TestContext (helper.Utils.TestContext)4 Test (org.junit.Test)4 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)3 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)3 Configuration (claw.wani.x2t.configuration.Configuration)3 ArrayList (java.util.ArrayList)3 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)2 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)2 IllegalDirectiveException (claw.tatsu.xcodeml.exception.IllegalDirectiveException)2 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)2