Search in sources :

Example 1 with TransformationGroup

use of claw.shenron.transformation.TransformationGroup in project claw-compiler by C2SM-RCM.

the class ClawTranslatorDriver method transform.

/**
 * Apply all the transformation in the pipeline.
 *
 * @throws Exception
 */
public void transform() throws Exception {
    try {
        if (!_canTransform) {
            return;
        }
        for (Map.Entry<Class<?>, TransformationGroup> entry : _translator.getGroups().entrySet()) {
            Message.debug(context(), "Apply transformation: " + entry.getValue().transformationName() + " - " + entry.getValue().count());
            try {
                entry.getValue().applyTransformations(_translationUnit, _translator);
                Message.warnings(context(), _translationUnit);
            } catch (IllegalTransformationException itex) {
                _translationUnit.addError(itex.getMessage(), itex.getStartLine());
                flushErrors();
                throw itex;
            } catch (Exception ex) {
                _translationUnit.addError("Unexpected error: " + ex.getMessage(), 0);
                if (context().getXmOption().isDebugOutput()) {
                    StringWriter errors = new StringWriter();
                    ex.printStackTrace(new PrintWriter(errors));
                    _translationUnit.addError(errors.toString(), 0);
                }
                flushErrors();
                throw ex;
            }
        }
    } catch (Exception ex) {
        context().getErrorStream().println("Transformation exception: " + ex.getMessage());
        throw ex;
    }
}
Also used : StringWriter(java.io.StringWriter) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) TransformationGroup(claw.shenron.transformation.TransformationGroup) Map(java.util.Map) IllegalDirectiveException(claw.tatsu.xcodeml.exception.IllegalDirectiveException) IOException(java.io.IOException) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) PrintWriter(java.io.PrintWriter)

Example 2 with TransformationGroup

use of claw.shenron.transformation.TransformationGroup in project claw-compiler by C2SM-RCM.

the class ClawTranslator method reorderTransformations.

/**
 */
private void reorderTransformations() {
    if (getGroups().containsKey(ScaForward.class)) {
        TransformationGroup tg = getGroups().get(ScaForward.class);
        if (tg.count() <= 1) {
            return;
        }
        DirectedGraph<Transformation> dg = new DirectedGraph<>();
        Map<String, List<Transformation>> fctMap = new HashMap<>();
        for (Transformation t : tg.getTransformations()) {
            ScaForward p = (ScaForward) t;
            dg.addNode(p);
            if (fctMap.containsKey(p.getCallingFctName())) {
                List<Transformation> tList = fctMap.get(p.getCallingFctName());
                tList.add(p);
            } else {
                List<Transformation> tList = new ArrayList<>();
                tList.add(p);
                fctMap.put(p.getCallingFctName(), tList);
            }
        }
        for (Transformation t : tg.getTransformations()) {
            ScaForward p = (ScaForward) t;
            if (p.getCalledFctName() != null && fctMap.containsKey(p.getCalledFctName())) {
                List<Transformation> tList = fctMap.get(p.getCalledFctName());
                for (Transformation end : tList) {
                    dg.addEdge(p, end);
                }
            }
        }
        List<Transformation> ordered = TopologicalSort.sort(TopologicalSort.reverseGraph(dg));
        tg.setTransformations(ordered);
    }
}
Also used : ScaForward(claw.wani.transformation.sca.ScaForward) Transformation(claw.shenron.transformation.Transformation) DirectedGraph(claw.tatsu.analysis.topology.DirectedGraph) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) DependentTransformationGroup(claw.shenron.transformation.DependentTransformationGroup) IndependentTransformationGroup(claw.shenron.transformation.IndependentTransformationGroup) TransformationGroup(claw.shenron.transformation.TransformationGroup) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

TransformationGroup (claw.shenron.transformation.TransformationGroup)2 DependentTransformationGroup (claw.shenron.transformation.DependentTransformationGroup)1 IndependentTransformationGroup (claw.shenron.transformation.IndependentTransformationGroup)1 Transformation (claw.shenron.transformation.Transformation)1 DirectedGraph (claw.tatsu.analysis.topology.DirectedGraph)1 IllegalDirectiveException (claw.tatsu.xcodeml.exception.IllegalDirectiveException)1 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)1 ScaForward (claw.wani.transformation.sca.ScaForward)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1