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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations