use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class Directive method findParallelRegionEnd.
/**
* Skip elements in epilogue and find the last element that will be included in
* the parallel region.
*
* @param functionDefinition Function definition in which body checked.
* @param from Optional element to start from. If null, starts
* from last element in function's body.
* @return Last element for the parallel region.
*/
public static Xnode findParallelRegionEnd(Context context, Xnode functionDefinition, Xnode from) {
DirectiveGenerator dg = context.getGenerator();
if (!Xnode.isOfCode(functionDefinition, Xcode.F_FUNCTION_DEFINITION)) {
return null;
}
Xnode last = functionDefinition.body().lastChild();
if (last == null) {
return null;
}
if (from != null) {
// Start from given element
last = from;
if (last.is(Xcode.F_CONTAINS_STATEMENT)) {
last = last.prevSibling();
}
}
if (dg.getSkippedStatementsInEpilogue().isEmpty() || !last.matchAll(Xcode.F_ASSIGN_STATEMENT).isEmpty()) {
return last;
} else {
while (last.prevSibling() != null && dg.getSkippedStatementsInEpilogue().contains(last.opcode())) {
if (last.hasBody() || last.is(Xcode.F_IF_STATEMENT)) {
List<Xnode> children = (last.hasBody()) ? last.body().children() : last.matchDirectDescendant(Xcode.THEN).body().children();
for (Xnode child : children) {
if (!dg.getSkippedStatementsInEpilogue().contains(child.opcode())) {
return last;
}
}
}
last = last.prevSibling();
}
}
return last;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode 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;
}
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class Pragma method findPrevious.
/**
* Find a pragma element in the previous nodes containing a given keyword.
*
* @param from Element to start from.
* @param keyword Keyword to be found in the pragma.
* @return The pragma if found. Null otherwise.
*/
public static Xnode findPrevious(Xnode from, String keyword) {
if (from == null || from.element() == null) {
return null;
}
Xnode prev = from.prevSibling();
Xnode parent = from;
do {
while (prev != null) {
if (prev.is(Xcode.F_PRAGMA_STATEMENT) && prev.value().toLowerCase().contains(keyword.toLowerCase())) {
return prev;
}
prev = prev.prevSibling();
}
parent = parent.ancestor();
prev = parent;
} while (parent != null);
return null;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class Pragma method moveInExecution.
/**
* If the first pragma statement is located as the first statement of the
* execution block, the OMNI Compiler front-end places it with the declaration
* block. If this doesn't make sense for a specific pragma, this method will
* move it to the execution block.
*
* @param pragma The pragma to be moved.
*/
public static void moveInExecution(Xnode pragma) {
if (!Xnode.isOfCode(pragma, Xcode.F_PRAGMA_STATEMENT)) {
return;
}
if (Xnode.isOfCode(pragma.ancestor(), Xcode.DECLARATIONS)) {
FfunctionDefinition fdef = pragma.findParentFunction();
if (fdef != null) {
if (Xnode.isOfCode(fdef.body().firstChild(), Xcode.F_PRAGMA_STATEMENT)) {
Xnode hook = null;
Xnode crtNode = fdef.body().firstChild();
while (Xnode.isOfCode(crtNode, Xcode.F_PRAGMA_STATEMENT) && pragma.lineNo() > crtNode.lineNo()) {
hook = crtNode;
crtNode = crtNode.nextSibling();
}
if (hook != null) {
hook.insertAfter(pragma);
} else {
fdef.body().append(pragma);
}
} else {
fdef.body().insert(pragma);
}
}
}
}
use of claw.tatsu.xcodeml.xnode.common.Xnode 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();
}
Aggregations