use of cx2x.xcodeml.exception.IllegalDirectiveException in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidClawLoopExtract.
/**
* Assert the result for valid loop extract CLAW directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param induction Induction var to be found.
* @param lower Lower bound value to be found.
* @param upper Upper bound value to be found.
* @param step Step valu to be found if any.
*/
private ClawLanguage analyzeValidClawLoopExtract(String raw, String induction, String lower, String upper, String step, List<Target> targets) {
try {
Xnode p = XmlHelper.createXpragma();
p.setValue(raw);
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
ClawLanguage l = ClawLanguage.analyze(p, generator, Target.GPU);
assertEquals(ClawDirective.LOOP_EXTRACT, l.getDirective());
assertEquals(induction, l.getRange().getInductionVar());
assertEquals(lower, l.getRange().getLowerBound());
assertEquals(upper, l.getRange().getUpperBound());
if (step != null) {
assertEquals(step, l.getRange().getStep());
}
assertTargets(l, targets);
return l;
} catch (IllegalDirectiveException idex) {
System.err.println(idex.getMessage());
fail();
return null;
}
}
use of cx2x.xcodeml.exception.IllegalDirectiveException in project claw-compiler by C2SM-RCM.
the class ClawLanguage method analyze.
/**
* Analyze a raw string input and match it with the CLAW language definition.
*
* @param rawPragma A raw pragma statement to be analyzed against the CLAW
* language.
* @param lineno Line number of the pragma statement.
* @param generator Accelerator directive generator.
* @param target Target that influences the code transformation.
* @return A ClawLanguage object with the corresponding extracted information.
* @throws IllegalDirectiveException If directive does not follow the CLAW
* language specification.
*/
private static ClawLanguage analyze(String rawPragma, int lineno, AcceleratorGenerator generator, Target target) throws IllegalDirectiveException {
// Remove additional claw keyword
rawPragma = nakenize(rawPragma);
// Discard the ignored code after the claw ignore directive
if (rawPragma.toLowerCase().contains(IGNORE)) {
rawPragma = rawPragma.substring(0, rawPragma.toLowerCase().indexOf(IGNORE) + IGNORE.length());
}
// Instantiate the lexer with the raw string input
ClawLexer lexer = new ClawLexer(CharStreams.fromString(rawPragma));
// Get a list of matched tokens
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Pass the tokens to the parser
ClawParser parser = new ClawParser(tokens);
parser.setErrorHandler(new BailErrorStrategy());
parser.removeErrorListeners();
try {
// Start the parser analysis from the "analyze" entry point
ClawParser.AnalyzeContext ctx = parser.analyze();
// Get the ClawLanguage object return by the parser after analysis.
ctx.l.setAcceleratorGenerator(generator);
ctx.l.setTarget(target);
return ctx.l;
} catch (ParseCancellationException pcex) {
if (pcex.getCause() instanceof InputMismatchException) {
InputMismatchException imex = (InputMismatchException) pcex.getCause();
throw new IllegalDirectiveException(getTokens(imex.getExpectedTokens(), parser), lineno, imex.getOffendingToken().getCharPositionInLine());
} else if (pcex.getCause() instanceof NoViableAltException) {
NoViableAltException nvex = (NoViableAltException) pcex.getCause();
throw new IllegalDirectiveException(nvex.getOffendingToken(), getTokens(nvex.getExpectedTokens(), parser), lineno, nvex.getOffendingToken().getCharPositionInLine());
}
throw new IllegalDirectiveException(rawPragma, "Unsupported construct", lineno, 0);
}
}
use of cx2x.xcodeml.exception.IllegalDirectiveException in project claw-compiler by C2SM-RCM.
the class ClawXcodeMlTranslator method analyze.
/**
* Analysis the XcodeML code and produce a list of applicable transformation.
*/
public void analyze() {
_program = XcodeProgram.createFromFile(_xcodemlInputFile);
if (_program == null) {
abort();
}
// Check all pragma found in the program
for (Xnode pragma : _program.getAllStmt(Xcode.FPRAGMASTATEMENT)) {
// pragma does not start with the CLAW prefix
if (!ClawLanguage.startsWithClaw(pragma)) {
// Compile guard removal
if (_generator != null && _generator.isCompileGuard(pragma.value())) {
pragma.delete();
} else // Handle special transformation of OpenACC line continuation
if (pragma.value().toLowerCase().startsWith(ClawConstant.OPENACC_PREFIX)) {
OpenAccContinuation t = new OpenAccContinuation(new AnalyzedPragma(pragma));
addOrAbort(t);
}
// Not CLAW pragma, we do nothing
continue;
}
try {
// Analyze the raw pragma with the CLAW language parser
ClawLanguage analyzedPragma = ClawLanguage.analyze(pragma, _generator, _target);
// Create transformation object based on the directive
switch(analyzedPragma.getDirective()) {
case ARRAY_TO_CALL:
addOrAbort(new ArrayToFctCall(analyzedPragma));
break;
case KCACHE:
addOrAbort(new Kcaching(analyzedPragma));
break;
case LOOP_FUSION:
addOrAbort(new LoopFusion(analyzedPragma));
break;
case LOOP_INTERCHANGE:
addOrAbort(new LoopInterchange(analyzedPragma));
break;
case LOOP_EXTRACT:
addOrAbort(new LoopExtraction(analyzedPragma));
break;
case LOOP_HOIST:
HandleBlockDirective(analyzedPragma);
break;
case ARRAY_TRANSFORM:
HandleBlockDirective(analyzedPragma);
break;
case REMOVE:
HandleBlockDirective(analyzedPragma);
break;
case PARALLELIZE:
if (analyzedPragma.hasForwardClause()) {
addOrAbort(new ParallelizeForward(analyzedPragma));
} else {
addOrAbort(new Parallelize(analyzedPragma));
}
break;
case PRIMITIVE:
addOrAbort(new DirectivePrimitive(analyzedPragma));
break;
case IF_EXTRACT:
addOrAbort(new IfExtract(analyzedPragma));
break;
// driver handled directives
case IGNORE:
case VERBATIM:
break;
default:
_program.addError("Unrecognized CLAW directive", pragma.lineNo());
abort();
}
} catch (IllegalDirectiveException ex) {
System.err.println(ex.getMessage());
abort();
}
}
// Clean up block transformation map
for (Map.Entry<ClawDirectiveKey, ClawLanguage> entry : _blockDirectives.entrySet()) {
createBlockDirectiveTransformation(entry.getValue(), null);
}
// Add utility transformation
addOrAbort(new XcodeMLWorkaround(new ClawLanguage(_program)));
// Analysis done, the transformation can be performed.
_canTransform = true;
}
use of cx2x.xcodeml.exception.IllegalDirectiveException in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidParallelize.
/**
* Assert the result for valid CLAW parallelize directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param data Reference list for the data clause values.
* @param over Reference list for the over clause values.
* @param dimensions Reference list of dimensions.
* @param copyClause Expected value for copy clause (Null if no copy clause)
* @param updateClause Expected value for update clause
* (Null if no update clause)
*/
private void analyzeValidParallelize(String raw, List<List<String>> data, List<List<String>> over, List<ClawDimension> dimensions, ClawDMD copyClause, ClawDMD updateClause) {
try {
Xnode p = XmlHelper.createXpragma();
p.setValue(raw);
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
ClawLanguage l = ClawLanguage.analyze(p, generator, Target.GPU);
assertEquals(ClawDirective.PARALLELIZE, l.getDirective());
if (data != null) {
assertTrue(l.hasOverDataClause());
assertEquals(data.size(), l.getOverDataClauseValues().size());
for (int i = 0; i < data.size(); ++i) {
assertEquals(data.get(i).size(), l.getOverDataClauseValues().get(i).size());
for (int j = 0; j < data.get(i).size(); ++j) {
assertEquals(data.get(i).get(j), l.getOverDataClauseValues().get(i).get(j));
}
}
}
if (over != null) {
assertTrue(l.hasOverClause());
assertEquals(over.size(), l.getOverClauseValues().size());
for (int i = 0; i < over.size(); ++i) {
assertEquals(over.get(i).size(), l.getOverClauseValues().get(i).size());
for (int j = 0; j < over.get(i).size(); ++j) {
assertEquals(over.get(i).get(j), l.getOverClauseValues().get(i).get(j));
}
}
}
if (dimensions != null) {
assertEquals(dimensions.size(), l.getDimensionValues().size());
for (int i = 0; i < dimensions.size(); ++i) {
assertEquals(dimensions.get(i).getIdentifier(), l.getDimensionValues().get(i).getIdentifier());
assertEquals(dimensions.get(i).lowerBoundIsVar(), l.getDimensionValues().get(i).lowerBoundIsVar());
assertEquals(dimensions.get(i).upperBoundIsVar(), l.getDimensionValues().get(i).upperBoundIsVar());
assertEquals(dimensions.get(i).getLowerBoundInt(), l.getDimensionValues().get(i).getLowerBoundInt());
assertEquals(dimensions.get(i).getUpperBoundInt(), l.getDimensionValues().get(i).getUpperBoundInt());
assertEquals(dimensions.get(i).getLowerBoundId(), l.getDimensionValues().get(i).getLowerBoundId());
assertEquals(dimensions.get(i).getUpperBoundId(), l.getDimensionValues().get(i).getUpperBoundId());
}
}
if (data == null && over == null && dimensions == null) {
assertTrue(l.hasForwardClause());
}
if (copyClause == null) {
assertFalse(l.hasCopyClause());
assertNull(l.getCopyClauseValue());
} else {
assertTrue(l.hasCopyClause());
assertEquals(copyClause, l.getCopyClauseValue());
}
if (updateClause == null) {
assertFalse(l.hasUpdateClause());
assertNull(l.getUpdateClauseValue());
} else {
assertTrue(l.hasUpdateClause());
assertEquals(updateClause, l.getUpdateClauseValue());
}
} catch (IllegalDirectiveException idex) {
System.err.print(idex.getMessage());
fail();
}
}
use of cx2x.xcodeml.exception.IllegalDirectiveException in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidSimpleClaw.
/**
* Assert the result for valid simple CLAW directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param directive Directive to be match.
*/
private void analyzeValidSimpleClaw(String raw, ClawDirective directive, boolean isEnd, List<Target> targets) {
try {
Xnode p = XmlHelper.createXpragma();
p.setValue(raw);
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
ClawLanguage l = ClawLanguage.analyze(p, generator, Target.GPU);
assertEquals(directive, l.getDirective());
if (isEnd) {
assertTrue(l.isEndPragma());
} else {
assertFalse(l.isEndPragma());
}
assertTargets(l, targets);
} catch (IllegalDirectiveException idex) {
System.err.println(idex.getMessage());
fail();
}
}
Aggregations