rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java
branchflow
changeset 1812 4fef6b767f61
parent 1798 18b3a9a85716
child 1813 5c30fa1c8c5b
     1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Fri Feb 27 18:11:54 2015 +0100
     1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Wed Mar 11 18:58:39 2015 +0100
     1.3 @@ -20,6 +20,7 @@
     1.4  import java.io.IOException;
     1.5  import java.io.InputStream;
     1.6  import org.apidesign.bck2brwsr.core.JavaScriptBody;
     1.7 +import org.apidesign.vm4brwsr.Bck2Brwsr.Flow;
     1.8  import org.apidesign.vm4brwsr.ByteCodeParser.ClassData;
     1.9  import org.apidesign.vm4brwsr.ByteCodeParser.FieldData;
    1.10  import org.apidesign.vm4brwsr.ByteCodeParser.MethodData;
    1.11 @@ -35,11 +36,12 @@
    1.12      private final ExportedSymbols exportedSymbols;
    1.13      private final StringBuilder invokerMethods;
    1.14      private final StringArray asBinary;
    1.15 +    private final Flow.Analyzer flow;
    1.16      int exportedCount;
    1.17  
    1.18      private VM(
    1.19          Appendable out, Bck2Brwsr.Resources resources, 
    1.20 -        StringArray explicitlyExported, StringArray asBinary
    1.21 +        StringArray explicitlyExported, StringArray asBinary, Flow.Analyzer flow
    1.22      ) {
    1.23          super(out);
    1.24          this.resources = resources;
    1.25 @@ -47,6 +49,7 @@
    1.26          this.exportedSymbols = new ExportedSymbols(resources, explicitlyExported);
    1.27          this.invokerMethods = new StringBuilder();
    1.28          this.asBinary = asBinary;
    1.29 +        this.flow = flow;
    1.30      }
    1.31  
    1.32      static {
    1.33 @@ -79,7 +82,8 @@
    1.34              fixedNames.add(VM.class.getName().replace('.', '/'));
    1.35              vm = new Extension(out, 
    1.36                  config.getResources(), both, config.exported(),
    1.37 -                config.allResources(), config.classpath()
    1.38 +                config.allResources(), config.classpath(),
    1.39 +                config.flow()
    1.40              );
    1.41          } else {
    1.42              if (config.includeVM()) {
    1.43 @@ -87,7 +91,8 @@
    1.44              }
    1.45              vm = new Standalone(out, 
    1.46                  config.getResources(), config.exported(),
    1.47 -                config.allResources()
    1.48 +                config.allResources(),
    1.49 +                config.flow()
    1.50              );
    1.51          }            
    1.52          vm.doCompile(fixedNames.addAndNew(both));
    1.53 @@ -419,6 +424,15 @@
    1.54          return object + "." + mangledName;
    1.55      }
    1.56  
    1.57 +    @Override
    1.58 +    protected Flow checkFlow(byte[] byteCodes) {
    1.59 +        if (flow == null) {
    1.60 +            return null;
    1.61 +        }
    1.62 +        Flow f = new Flow(byteCodes);
    1.63 +        return flow.analyze(f) ? f : null;
    1.64 +    }
    1.65 +
    1.66      private final class ExportedMethodFinder
    1.67              implements ClassDataCache.TraversalCallback<MethodData> {
    1.68          private final ExportedSymbols exportedSymbols;
    1.69 @@ -452,9 +466,10 @@
    1.70      private static final class Standalone extends VM {
    1.71          private Standalone(Appendable out,
    1.72              Bck2Brwsr.Resources resources, 
    1.73 -            StringArray explicitlyExported, StringArray asBinary
    1.74 +            StringArray explicitlyExported, StringArray asBinary, 
    1.75 +            Flow.Analyzer flow
    1.76          ) {
    1.77 -            super(out, resources, explicitlyExported, asBinary);
    1.78 +            super(out, resources, explicitlyExported, asBinary, flow);
    1.79          }
    1.80  
    1.81          @Override
    1.82 @@ -700,9 +715,9 @@
    1.83  
    1.84          private Extension(Appendable out, Bck2Brwsr.Resources resources,
    1.85              String[] extClassesArray, StringArray explicitlyExported,
    1.86 -            StringArray asBinary, StringArray classpath
    1.87 +            StringArray asBinary, StringArray classpath, Flow.Analyzer flow
    1.88          ) throws IOException {
    1.89 -            super(out, resources, explicitlyExported, asBinary);
    1.90 +            super(out, resources, explicitlyExported, asBinary, flow);
    1.91              this.extensionClasses = StringArray.asList(extClassesArray);
    1.92              this.classpath = classpath;
    1.93          }