rt/flow/src/main/java/org/apidesign/bck2brwsr/flow/GraalFlowAnalyzer.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 11 Sep 2015 14:51:09 +0200
branchflow
changeset 1842 dd4dabfead82
parent 1841 e38cdcd3c997
permissions -rw-r--r--
Giving the flow analyzer chance to generate the whole function body
jaroslav@1812
     1
/**
jaroslav@1812
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1812
     3
 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1812
     4
 *
jaroslav@1812
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1812
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1812
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1812
     8
 *
jaroslav@1812
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1812
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1812
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1812
    12
 * GNU General Public License for more details.
jaroslav@1812
    13
 *
jaroslav@1812
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1812
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1812
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1812
    17
 */
jaroslav@1812
    18
package org.apidesign.bck2brwsr.flow;
jaroslav@1812
    19
jaroslav@1842
    20
import java.io.IOException;
jaroslav@1812
    21
import org.apidesign.vm4brwsr.Bck2Brwsr;
jaroslav@1812
    22
jaroslav@1812
    23
/** Poweful flow analyzer. Based on internals used by Graal JVM
jaroslav@1812
    24
 * compiler.
jaroslav@1812
    25
 *
jaroslav@1812
    26
 * @author Jaroslav Tulach
jaroslav@1812
    27
 */
jaroslav@1812
    28
public final class GraalFlowAnalyzer {
jaroslav@1812
    29
    private GraalFlowAnalyzer() {
jaroslav@1812
    30
    }
jaroslav@1812
    31
    
jaroslav@1812
    32
    public static Bck2Brwsr.Flow.Analyzer getDefault() {
jaroslav@1812
    33
        return Impl.DEFAULT;
jaroslav@1812
    34
    }
jaroslav@1812
    35
jaroslav@1812
    36
    private static class Impl implements Bck2Brwsr.Flow.Analyzer {
jaroslav@1812
    37
        static Impl DEFAULT = new Impl();
jaroslav@1812
    38
        
jaroslav@1812
    39
        private Impl() {
jaroslav@1812
    40
        }
jaroslav@1812
    41
jaroslav@1812
    42
        @Override
jaroslav@1842
    43
        public boolean analyze(final Bck2Brwsr.Flow result) throws IOException {
jaroslav@1842
    44
            // Use Graal to generate optimal function, David.
jaroslav@1841
    45
            double x = com.oracle.graal.api.directives.GraalDirectives.FASTPATH_PROBABILITY;
jaroslav@1842
    46
            result.emit("function() { return 922869; }");
jaroslav@1842
    47
            return true;
jaroslav@1812
    48
        }
jaroslav@1812
    49
    }
jaroslav@1812
    50
}