Search in sources :

Example 21 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class XnodeUtil method getArrayAssignInBlock.

/**
 * Find all array assignment statement from a node until the to node.
 *
 * @param from Node from which the search is initiated.
 * @param to   Node until the search is done.
 * @return A list of all assign statements found. List is empty if no statements
 *         are found.
 */
public static List<Xnode> getArrayAssignInBlock(Xnode from, Xnode to) {
    List<Xnode> assignments = new ArrayList<>();
    Xnode crt = from.nextSibling();
    while (crt != null && !crt.equals(to)) {
        if (crt.is(Xcode.F_ASSIGN_STATEMENT) && crt.firstChild() != null && crt.firstChild().is(Xcode.F_ARRAY_REF)) {
            assignments.add(crt);
        }
        crt = crt.nextSibling();
    }
    return assignments;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) ArrayList(java.util.ArrayList)

Example 22 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class XnodeUtil method getNodes.

/**
 * Get given statements in between from and to included.
 *
 * @param from        Node from.
 * @param to          Node to.
 * @param nodeOpCodes List of statements to look for.
 * @return List of statement found.
 */
public static List<Xnode> getNodes(Xnode from, Xnode to, List<Xcode> nodeOpCodes) {
    List<Xnode> unsupportedStatements = new ArrayList<>();
    Xnode crt = from;
    while (crt != null && crt.element() != to.element()) {
        if (nodeOpCodes.contains(crt.opcode())) {
            unsupportedStatements.add(crt);
        }
        // Get all nodes matching in the subtree
        unsupportedStatements.addAll(getNodes(crt, nodeOpCodes));
        crt = crt.nextSibling();
    }
    if (crt != null && crt.equals(to) && nodeOpCodes.contains(crt.opcode())) {
        unsupportedStatements.add(crt);
    }
    return unsupportedStatements;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) ArrayList(java.util.ArrayList)

Example 23 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class XnodeUtil method findDoStatementForHoisting.

/**
 * Find all the nested do statement groups following the inductions iterations
 * define in inductionVars and being located between the "from" element and the
 * end pragma.
 *
 * @param from          Element from which the search is started.
 * @param endPragma     End pragma that terminates the search block.
 * @param inductionVars Induction variables that define the nested group to
 *                      locates.
 * @return List of do statements elements (outer most loops for each nested
 *         group) found between the "from" element and the end pragma.
 */
public static List<HoistedNestedDoStatement> findDoStatementForHoisting(Xnode from, Xnode endPragma, List<String> inductionVars) {
    /*
         * s1 is selecting all the nested do statement groups that meet the criteria
         * from the "from" element down to the end of the block.
         */
    String s1 = "following::";
    String dynamicPartS1 = "";
    for (int i = inductionVars.size() - 1; i >= 0; --i) {
        /*
             * Here is example of there xpath query format for 1,2 and 3 nested loops
             *
             * FdoStatement[Var[text()="induction_var"]]
             *
             * FdoStatement[Var[text()="induction_var"] and
             * body[FdoStatement[Var[text()="induction_var"]]]
             *
             * FdoStatement[Var[text()="induction_var"] and
             * body[FdoStatement[Var[text()="induction_var"] and
             * body[FdoStatement[Var[text()="induction_var"]]]]
             */
        String tempQuery;
        if (i == inductionVars.size() - 1) {
            // first iteration
            tempQuery = String.format("%s[%s[text()=\"%s\"]]", Xname.F_DO_STATEMENT, Xname.VAR, inductionVars.get(i));
        } else {
            tempQuery = String.format("%s[%s[text()=\"%s\"] and %s[%s]]", Xname.F_DO_STATEMENT, Xname.VAR, inductionVars.get(i), Xname.BODY, // Including previously formed xpath query
            dynamicPartS1);
        }
        dynamicPartS1 = tempQuery;
    }
    s1 += dynamicPartS1;
    List<HoistedNestedDoStatement> doStatements = new ArrayList<>();
    try {
        NodeList output = evaluateXpath(from.element(), s1);
        for (int i = 0; i < output.getLength(); i++) {
            Element el = (Element) output.item(i);
            Xnode doStmt = new Xnode(el);
            if (doStmt.lineNo() != 0 && doStmt.lineNo() < endPragma.lineNo() && doStmt.lineNo() > from.lineNo()) {
                doStatements.add(new HoistedNestedDoStatement(doStmt, inductionVars.size()));
            }
        }
    } catch (XPathExpressionException ignored) {
    }
    return doStatements;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) HoistedNestedDoStatement(claw.tatsu.xcodeml.abstraction.HoistedNestedDoStatement)

Example 24 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class XnodeUtil method gatherReturnValue.

/**
 * Gather string representation of the return value if there is one.
 *
 * @param xcodeml Current XcodeML translation unit.
 * @param fctCall Function call to retrieve the return value.
 * @return String representation of the return value if any. Null otherwise.
 */
public static String gatherReturnValue(XcodeProgram xcodeml, Xnode fctCall) {
    if (!Xnode.isOfCode(fctCall, Xcode.FUNCTION_CALL)) {
        return null;
    }
    Xnode fctCallAncestor = fctCall.matchAncestor(Xcode.F_ASSIGN_STATEMENT);
    if (fctCallAncestor == null) {
        return null;
    }
    Xnode returnNode = fctCallAncestor.firstChild();
    if (xcodeml.getTypeTable().isBasicType(returnNode) && xcodeml.getTypeTable().getBasicType(returnNode).isArray()) {
        return returnNode.constructRepresentation(false, false);
    }
    return null;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode)

Example 25 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class XnodeUtil method findIndexes.

/**
 * Find all the index elements (arrayIndex and indexRange) in an element.
 *
 * @param parent Root element to search from.
 * @return A list of all index ranges found.
 */
public static List<Xnode> findIndexes(Xnode parent) {
    List<Xnode> indexRanges = new ArrayList<>();
    if (parent == null || parent.element() == null) {
        return indexRanges;
    }
    Node node = parent.element().getFirstChild();
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            if (element.getTagName().equals(Xname.ARRAY_INDEX) || element.getTagName().equals(Xname.INDEX_RANGE)) {
                indexRanges.add(new Xnode(element));
            }
        }
        node = node.getNextSibling();
    }
    return indexRanges;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Aggregations

Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)124 Context (claw.tatsu.common.Context)29 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)24 Test (org.junit.Test)24 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)20 TestContext (helper.Utils.TestContext)20 ArrayList (java.util.ArrayList)18 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)17 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)9 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)8 Xid (claw.tatsu.xcodeml.xnode.common.Xid)8 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)8 HashSet (java.util.HashSet)7 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)6 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)6 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)5 ClawPragma (claw.wani.language.ClawPragma)5 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)5 NodeList (org.w3c.dom.NodeList)5 DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)4