Search in sources :

Example 1 with IllegalDirectiveException

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

the class ClawTranslator method handleBlockDirective.

/**
 * Associate correctly the start and end directive to form blocks.
 *
 * @param xcodeml        Current translation unit.
 * @param analyzedPragma Analyzed pragma object to be handle.
 */
private void handleBlockDirective(XcodeProgram xcodeml, ClawPragma analyzedPragma) throws IllegalDirectiveException, IllegalTransformationException {
    int depth = analyzedPragma.getPragma().depth();
    ClawDirectiveKey crtRemoveKey = new ClawDirectiveKey(analyzedPragma.getDirective(), depth);
    if (analyzedPragma.isEndPragma()) {
        ClawPragma start = getBlockDirectiveStart(crtRemoveKey);
        if (start == null) {
            throw new IllegalDirectiveException(analyzedPragma.getDirective().name(), "Invalid CLAW directive (end with no start)", analyzedPragma.getPragma().lineNo());
        } else {
            createBlockDirectiveTransformation(xcodeml, start, analyzedPragma);
        }
    } else {
        addStartBlockDirective(analyzedPragma, crtRemoveKey);
    }
}
Also used : IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException) ClawPragma(claw.wani.language.ClawPragma)

Example 2 with IllegalDirectiveException

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

the class ClawPragmaTest method analyze.

/**
 * Execute the parsing on the raw string and return a ClawPragma object if
 * successful.
 *
 * @param raw       Raw directive.
 * @param directive Expected directive.
 * @return ClawPragma object with information extracted from parsing.
 */
private ClawPragma analyze(String raw, ClawDirective directive) {
    try {
        Xnode p = XmlHelper.createXpragma();
        p.setValue(raw);
        ClawPragma l = ClawPragma.analyze(p);
        assertEquals(directive, l.getDirective());
        return l;
    } catch (IllegalDirectiveException idex) {
        fail();
    }
    return null;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException) ClawPragma(claw.wani.language.ClawPragma)

Example 3 with IllegalDirectiveException

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

the class ClawPragmaTest method analyzeInvalidClawLanguage.

/**
 * Assert any invalid claw raw input
 *
 * @param raw Raw string value of the CLAW directive to be analyzed.
 */
private void analyzeInvalidClawLanguage(String raw) {
    try {
        Xnode p = XmlHelper.createXpragma();
        p.setValue(raw);
        cfg.init(CompilerDirective.OPENACC, Target.GPU);
        context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
        ClawPragma.analyze(p);
        fail();
    } catch (IllegalDirectiveException pex) {
        assertNotNull(pex);
        assertNotNull(pex.getMessage());
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException)

Example 4 with IllegalDirectiveException

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

the class ClawPragma 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.
 * @return A ClawPragma object with the corresponding extracted information.
 * @throws IllegalDirectiveException If directive does not follow the CLAW
 *                                   language specification.
 */
private static ClawPragma analyze(String rawPragma, int lineno) 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 ClawPragma object return by the parser after analysis.
        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().getText(), getTokens(nvex.getExpectedTokens(), parser), lineno, nvex.getOffendingToken().getCharPositionInLine());
        }
        throw new IllegalDirectiveException(rawPragma, "Unsupported construct", lineno, 0);
    }
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ClawParser(claw.wani.language.parser.ClawParser) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) BailErrorStrategy(org.antlr.v4.runtime.BailErrorStrategy) NoViableAltException(org.antlr.v4.runtime.NoViableAltException) InputMismatchException(org.antlr.v4.runtime.InputMismatchException) ClawLexer(claw.wani.language.parser.ClawLexer)

Example 5 with IllegalDirectiveException

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

the class ClawPragmaTest method analyzeErrors.

private void analyzeErrors(String pragma, int nbExpectedToken) {
    Xnode p = XmlHelper.createXpragma();
    p.setValue(pragma);
    p.setLine(1);
    cfg.init(CompilerDirective.OPENACC, Target.GPU);
    context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
    try {
        ClawPragma.analyze(p);
    } catch (IllegalDirectiveException e) {
        if (nbExpectedToken != 0) {
            assertEquals(nbExpectedToken, e.getExpectedTokens().size());
        }
        assertNotNull(e.getMessage());
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException)

Aggregations

IllegalDirectiveException (claw.tatsu.xcodeml.exception.IllegalDirectiveException)6 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)4 ClawPragma (claw.wani.language.ClawPragma)3 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)1 ClawLexer (claw.wani.language.parser.ClawLexer)1 ClawParser (claw.wani.language.parser.ClawParser)1 GroupConfiguration (claw.wani.x2t.configuration.GroupConfiguration)1 IOException (java.io.IOException)1 BailErrorStrategy (org.antlr.v4.runtime.BailErrorStrategy)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 InputMismatchException (org.antlr.v4.runtime.InputMismatchException)1 NoViableAltException (org.antlr.v4.runtime.NoViableAltException)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1