├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── .travis.yml ├── Config.txt ├── Dockerfile ├── LICENSE ├── README.md ├── bin ├── benchmarks │ ├── generated │ │ ├── arithmetic │ │ │ ├── Average.java │ │ │ ├── ConditionalCount.java │ │ │ ├── ConditionalSum.java │ │ │ ├── Count.java │ │ │ ├── Delta.java │ │ │ ├── Equal.java │ │ │ ├── EqualFrequency.java │ │ │ ├── Max.java │ │ │ ├── MaxAbs.java │ │ │ ├── Min.java │ │ │ └── Sum.java │ │ ├── bigλ │ │ │ ├── CyclingSpeed.java │ │ │ ├── DatabaseSelect.java │ │ │ ├── ShakespearSentiment.java │ │ │ ├── TwitterCounts.java │ │ │ ├── WikiPageCount.java │ │ │ └── YelpKids.java │ │ ├── fiji │ │ │ ├── IJ_RedToMagenta │ │ │ │ └── Benchmark0.java │ │ │ ├── IJ_Temporal │ │ │ │ ├── Benchmark0.java │ │ │ │ ├── Benchmark1.java │ │ │ │ ├── Benchmark2.java │ │ │ │ ├── Benchmark3.java │ │ │ │ └── Benchmark4.java │ │ │ └── IJ_Trails │ │ │ │ ├── Benchmark0.java │ │ │ │ ├── Benchmark1.java │ │ │ │ ├── Benchmark2.java │ │ │ │ └── Benchmark3.java │ │ ├── phoenix │ │ │ ├── Histogram.java │ │ │ ├── KMeansJava.java │ │ │ ├── LinearRegression.java │ │ │ ├── PcaJava.java │ │ │ ├── StringMatch.java │ │ │ └── WordCount.java │ │ └── stats │ │ │ ├── Calculate.java │ │ │ ├── IOUtil.java │ │ │ ├── PlotReader.java │ │ │ ├── PlotUtil.java │ │ │ ├── PlotWriter.java │ │ │ └── StatsUtil.java │ ├── manual │ │ ├── arithmetic │ │ │ ├── Average.java │ │ │ ├── ConditionalCount.java │ │ │ ├── ConditionalSum.java │ │ │ ├── Count.java │ │ │ ├── Delta.java │ │ │ ├── Equal.java │ │ │ ├── EqualFrequency.java │ │ │ ├── Max.java │ │ │ ├── MaxAbs.java │ │ │ ├── Min.java │ │ │ └── Sum.java │ │ ├── bigλ │ │ │ ├── CyclingSpeed.java │ │ │ ├── DatabaseSelect.java │ │ │ ├── ShakespearSentiment.java │ │ │ ├── TwitterCounts.java │ │ │ ├── WikiPageCount.java │ │ │ └── YelpKids.java │ │ ├── fiji │ │ │ ├── IJ_RedToMagenta │ │ │ │ └── Benchmark0.java │ │ │ ├── IJ_Temporal │ │ │ │ ├── Benchmark0.java │ │ │ │ ├── Benchmark1.java │ │ │ │ ├── Benchmark2.java │ │ │ │ ├── Benchmark3.java │ │ │ │ └── Benchmark4.java │ │ │ └── IJ_Trails │ │ │ │ ├── Benchmark0.java │ │ │ │ ├── Benchmark1.java │ │ │ │ ├── Benchmark2.java │ │ │ │ └── Benchmark3.java │ │ ├── phoenix │ │ │ ├── Histogram.java │ │ │ ├── KMeansJava.java │ │ │ ├── LinearRegression.java │ │ │ ├── PcaJava.java │ │ │ ├── StringMatch.java │ │ │ └── WordCount.java │ │ └── stats │ │ │ ├── Calculate.java │ │ │ ├── IOUtil.java │ │ │ ├── PlotReader.java │ │ │ ├── PlotUtil.java │ │ │ ├── PlotWriter.java │ │ │ └── StatsUtil.java │ └── original │ │ ├── arithmetic │ │ ├── Average.java │ │ ├── ConditionalCount.java │ │ ├── ConditionalSum.java │ │ ├── Count.java │ │ ├── Delta.java │ │ ├── Equal.java │ │ ├── EqualFrequency.java │ │ ├── Max.java │ │ ├── MaxAbs.java │ │ ├── Min.java │ │ └── Sum.java │ │ ├── bigλ │ │ ├── CyclingSpeed.java │ │ ├── DatabaseSelect.java │ │ ├── ShakespearSentiment.java │ │ ├── TwitterCounts.java │ │ ├── WikiPageCount.java │ │ └── YelpKids.java │ │ ├── fiji │ │ ├── IJ_RedToMagenta │ │ │ └── fiji │ │ │ │ └── color │ │ │ │ └── Convert_Red_To_Magenta.java │ │ ├── IJ_Temporal │ │ │ ├── README.md │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── TemporalMedian_.java │ │ │ │ └── resources │ │ │ │ └── plugins.config │ │ └── IJ_Trails │ │ │ ├── README.md │ │ │ ├── pom.xml │ │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── Trails_.java │ │ │ └── resources │ │ │ └── plugins.config │ │ ├── phoenix │ │ ├── Histogram.java │ │ ├── KMeansJava.java │ │ ├── LinearRegression.java │ │ ├── PcaJava.java │ │ ├── StringMatch.java │ │ └── WordCount.java │ │ └── stats │ │ ├── AverageData.java │ │ ├── Calculate.java │ │ ├── ExtractColumn.java │ │ ├── FormatData.java │ │ ├── IOUtil.java │ │ ├── LinearData.java │ │ ├── MomentInertia.java │ │ ├── PlotReader.java │ │ ├── PlotUtil.java │ │ ├── PlotWriter.java │ │ └── StatsUtil.java ├── buildCompileAndRun.sh ├── casper ├── casperc ├── check.sh ├── compileAndRun.sh ├── debug.txt ├── debugRun.sh ├── indentationScript.js ├── output │ ├── Average.sk │ ├── Count.sk │ ├── MaxAbs.sk │ ├── Mean.sk │ ├── Min.sk │ ├── MulVecSca.sk │ ├── Sum.sk │ ├── main_double_0.dfy │ ├── main_double_0.sk │ ├── main_double_0.txt │ ├── main_int_0.dfy │ ├── main_int_0.sk │ ├── main_int_0.txt │ ├── outputTempDafny.txt │ ├── utils.dfy │ └── utils.sk ├── run.sh └── templates │ ├── dafny_skeleton.dfy │ ├── dafny_skeleton2.dfy │ ├── main_skeleton.sk │ ├── spark_skeleton.txt │ ├── spark_skeleton_demo.txt │ ├── utils.dfy │ └── utils.sk ├── build.xml ├── compiler └── src │ └── casper │ ├── CasperScheduler.java │ ├── Configuration.java │ ├── DafnyCodeGenerator.java │ ├── ExtensionInfo.java │ ├── JavaLibModel.java │ ├── Main.java │ ├── SketchCodeGenerator.java │ ├── SketchParser.java │ ├── Topics.java │ ├── Util.java │ ├── Version.java │ ├── ast │ ├── JavaAbstractExtFactory_c.java │ ├── JavaExt.java │ ├── JavaExtFactory.java │ ├── JavaExtFactory_c.java │ ├── JavaLang.java │ ├── JavaLang_c.java │ ├── JavaNodeFactory.java │ ├── JavaNodeFactory_c.java │ └── package.html │ ├── extension │ ├── MyStmtExt.java │ ├── MyWhileExt.java │ └── package.html │ ├── package.html │ ├── parse │ ├── Grm.java │ ├── Lexer_c.java │ ├── casper.flex │ ├── casper.ppg │ ├── casper_ppg.cup │ ├── jl5.ppg │ ├── jl7.ppg │ ├── package.html │ └── sym.java │ ├── types │ ├── ArrayAccessNode.java │ ├── ArrayUpdateNode.java │ ├── BinaryOperatorNode.java │ ├── CallNode.java │ ├── ConditionalNode.java │ ├── ConstantNode.java │ ├── CustomASTNode.java │ ├── Expression.java │ ├── FieldNode.java │ ├── IdentifierNode.java │ ├── JavaTypeSystem.java │ ├── JavaTypeSystem_c.java │ ├── MRStage.java │ ├── UnaryOperatorNode.java │ ├── Variable.java │ └── package.html │ └── visit │ ├── ExtractInputVariables.java │ ├── ExtractLoopCounters.java │ ├── ExtractLoopTerminateConditions.java │ ├── ExtractOperators.java │ ├── ExtractOutputVariables.java │ ├── ExtractUserDefinedDataTypes.java │ ├── GenerateScaffold.java │ ├── GenerateSparkCode.java │ ├── GenerateVerification.java │ ├── IdentifyDataSet.java │ ├── SelectLoopsForTranslation.java │ ├── SelectOptimalSolution.java │ ├── UpdateConfigurations.java │ └── package.html ├── lib ├── imagej-1.46.jar ├── java_cup.jar ├── jflex.jar ├── polyglot.jar ├── ppg.jar └── pth.jar ├── pom1.xml ├── target └── .gitignore └── tests ├── Hello.java ├── ProjectTester.java ├── pthScript └── test.sh /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *~ 3 | *.mdb 4 | *.dll -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Casper 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Nature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.8 13 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk7 4 | before_install: 5 | - sudo apt-get update && sudo apt-get -y install curl 6 | - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF 7 | - echo "deb http://download.mono-project.com/repo/ubuntu precise main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list 8 | - curl -sL https://deb.nodesource.com/setup_6.x | sudo bash - 9 | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 10 | - sudo apt-get update && sudo apt-get install -y bash g++-4.8 flex bison make ant openjdk-7-jdk nodejs unzip mono-complete git wget 11 | - export CXX="g++-4.8" CC="gcc-4.8" 12 | - wget "http://people.csail.mit.edu/asolar/sketch-1.7.2.tar.gz" 13 | - tar -xvzf sketch-1.7.2.tar.gz 14 | - rm sketch-1.7.2.tar.gz 15 | - cd sketch-1.7.2/sketch-backend/ 16 | - chmod +x ./configure 17 | - ./configure 18 | - make 19 | - cd ../../ 20 | - chmod a+rwx sketch-1.7.2/* 21 | - export PATH="$PATH:/home/travis/build/uwplse/Casper/sketch-1.7.2/sketch-frontend" 22 | - export SKETCH_HOME="/home/travis/build/uwplse/Casper/sketch-1.7.2/sketch-frontend/runtime" 23 | - wget -O dafny-1.9.7.zip "https://github.com/Microsoft/dafny/releases/download/v1.9.7/Dafny.1.9.7.for.Ubuntu.zip" 24 | - unzip dafny-1.9.7.zip -d . 25 | - rm dafny-1.9.7.zip 26 | - chmod -R a+rwx dafny/* 27 | - export PATH="$PATH:/home/travis/build/uwplse/Casper/dafny/" 28 | before_script: 29 | - chmod +x ./tests/ProjectTester.java 30 | - javac -d . ./tests/ProjectTester.java 31 | - ant 32 | jobs: 33 | include: 34 | - script: travis_wait 40 java ProjectTester 1 35 | - script: travis_wait 40 java ProjectTester 2 36 | - script: travis_wait 40 java ProjectTester 3 37 | notifications: 38 | email: false 39 | -------------------------------------------------------------------------------- /Config.txt: -------------------------------------------------------------------------------- 1 | Inbits=2, 2 | ArraySizeBound=4, 3 | IntRange=4, 4 | LoopUnrollBound=4, 5 | MaxNumMROps=5, 6 | MaxNumEmits=5, 7 | MaxTupleSize=5, 8 | MaxRecursionDepth=5 9 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Ubuntu 14.04 as base OS 2 | FROM ubuntu:14.04 3 | MAINTAINER Maaz Ahmad 4 | 5 | # Install dependencies 6 | RUN apt-get update && apt-get -y install curl 7 | RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF 8 | RUN echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list 9 | RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - 10 | RUN apt-get update && apt-get -y install \ 11 | bash \ 12 | g++ \ 13 | flex \ 14 | bison \ 15 | make \ 16 | ant \ 17 | openjdk-7-jdk \ 18 | nodejs \ 19 | unzip \ 20 | mono-complete \ 21 | git \ 22 | wget 23 | 24 | # Install SKETCH 25 | RUN wget "http://people.csail.mit.edu/asolar/sketch-1.7.2.tar.gz" 26 | RUN tar -xvzf sketch-1.7.2.tar.gz 27 | RUN rm sketch-1.7.2.tar.gz 28 | WORKDIR sketch-1.7.2/sketch-backend/ 29 | RUN chmod +x ./configure 30 | RUN ./configure 31 | RUN make 32 | WORKDIR ../../ 33 | RUN chmod a+rwx sketch-1.7.2/* 34 | ENV PATH $PATH:/sketch-1.7.2/sketch-frontend/ 35 | ENV SKETCH_HOME /sketch-1.7.2/sketch-frontend/runtime 36 | 37 | # Install Dafny 38 | RUN wget -O dafny-1.9.9.zip "https://github.com/Microsoft/dafny/releases/download/v1.9.9/dafny-1.9.9.40414-x64-ubuntu-14.04.zip" 39 | RUN unzip dafny-1.9.9.zip -d . 40 | RUN rm dafny-1.9.9.zip 41 | RUN /bin/bash -c "sed $'s/\r$//' ./dafny/dafny > ./dafny/dafny.Unix" 42 | RUN mv /dafny/dafny.Unix /dafny/dafny 43 | RUN chmod -R a+rwx dafny/* 44 | ENV PATH $PATH:/dafny/ 45 | 46 | # Clone CASPER 47 | RUN git clone https://github.com/uwplse/Casper.git 48 | WORKDIR Casper/ 49 | RUN git reset --hard 834d980 50 | RUN ant 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2015, University of Washington 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the University of Washington nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/Average.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | public class Average { 7 | 8 | public static double avgList(JavaRDD rdd_0_0){ 9 | int sum = 0; 10 | sum = 0; 11 | int count = 0; 12 | count = 0; 13 | Tuple2 output_rdd_0_0 = rdd_0_0.map(data_i -> new Tuple2(data_i,1)).reduce((val1, val2) -> new Tuple2((val1._1+val2._1),(val1._2+val2._2))); 14 | count = output_rdd_0_0._2; 15 | sum = output_rdd_0_0._1; 16 | int flat$6 = sum / count; 17 | return flat$6; 18 | } 19 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/ConditionalCount.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class ConditionalCount { 9 | public static Integer countList(JavaRDD rdd_0_0){ 10 | int count = 0; 11 | count = 0; 12 | count = rdd_0_0.flatMap(data_i -> { 13 | List emits = new ArrayList(); 14 | if(data_i < 100) emits.add(1); 15 | return emits.iterator(); 16 | }).reduce((val1, val2) -> (val1+val2)); 17 | return count; 18 | } 19 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/ConditionalSum.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class ConditionalSum { 9 | public static Integer sumList(JavaRDD rdd_0_0){ 10 | int sum = 0; 11 | sum = 0; 12 | sum = rdd_0_0.flatMap(data_i -> { 13 | List emits = new ArrayList(); 14 | if(data_i < 100) emits.add(data_i); 15 | return emits.iterator(); 16 | }).reduce((val1, val2) -> (val1+val2)); 17 | return sum; 18 | } 19 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/Count.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class Count { 6 | public static Integer countList(JavaRDD rdd_0_0){ 7 | int count = 0; 8 | count = 0; 9 | count = rdd_0_0.map(data_i -> 1).reduce((val1, val2) -> (val1+val2)); 10 | return count; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/Delta.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | public class Delta { 7 | public static Integer calcDelta(JavaRDD rdd_0_0){ 8 | int max = 0; 9 | max = Integer.MIN_VALUE; 10 | int min = 0; 11 | min = Integer.MAX_VALUE; 12 | Tuple2 output_rdd_0_0 = rdd_0_0.map(data_i -> new Tuple2(data_i,data_i)).reduce((val1, val2) -> new Tuple2((val1._1 < val2._1 ? val1._1 : val2._1), (val1._2 < val2._2 ? val2._2 : val1._2))); 13 | max = output_rdd_0_0._2; 14 | min = output_rdd_0_0._1; 15 | int flat$7 = max-min; 16 | return flat$7; 17 | } 18 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/Equal.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class Equal { 9 | public static boolean equal(JavaRDD rdd_0_0, int val){ 10 | boolean equal = false; 11 | equal = true; 12 | final int val_final = val; 13 | equal = rdd_0_0.flatMap(data_i -> { 14 | List emits = new ArrayList(); 15 | if(val_final != data_i) emits.add(false); 16 | return emits.iterator(); 17 | }).reduce((val1, val2) -> false); 18 | return equal; 19 | } 20 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/EqualFrequency.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class EqualFrequency { 11 | public static boolean equalFrequency(JavaRDD rdd_0_0) { 12 | int first = 0; 13 | first = 0; 14 | int second = 0; 15 | second = 0; 16 | Map> output_rdd_0_0 = rdd_0_0.flatMapToPair(data_i -> { 17 | List>> emits = new ArrayList>>(); 18 | if (data_i == 110) emits.add(new Tuple2(2, new Tuple2(2, 1))); 19 | if (data_i == 100) emits.add(new Tuple2(1, new Tuple2(1, 1))); 20 | return emits.iterator(); 21 | }).reduceByKey((val1, val2) -> { 22 | if (val1._1 == 1) return new Tuple2(val1._1, (val2._2 + val1._2)); 23 | else if (val1._1 == 2) return new Tuple2(val1._1, (val1._2 + val2._2)); 24 | else return null; 25 | }).collectAsMap(); 26 | second = output_rdd_0_0.get(2)._2; 27 | first = output_rdd_0_0.get(1)._2; 28 | boolean flat$7 = first == second; 29 | return flat$7; 30 | } 31 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/Max.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class Max { 6 | public static int maxList(JavaRDD rdd_0_0){ 7 | int max = 0; 8 | max = Integer.MIN_VALUE; 9 | max = rdd_0_0.reduce((val1, val2) -> (val2 > val1 ? val2 : val1)); 10 | return max; 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/MaxAbs.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class MaxAbs { 6 | public static int maxAbsList(JavaRDD rdd_0_0){ 7 | int max = 0; 8 | max = Integer.MIN_VALUE; 9 | max = rdd_0_0.reduce((val1, val2) -> (Math.abs(val1) > Math.abs(val2) ? val1 : val2)); 10 | return max; 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/Min.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class Min { 6 | public static int minList(JavaRDD rdd_0_0){ 7 | int min = 0; 8 | min = Integer.MAX_VALUE; 9 | min = rdd_0_0.reduce((val1, val2) -> (val2 > val1 ? val1 : val2)); 10 | return min; 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/arithmetic/Sum.java: -------------------------------------------------------------------------------- 1 | package generated.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class Sum { 6 | public static int sumList(JavaRDD rdd_0_0){ 7 | int sum = 0; 8 | sum = 0; 9 | sum = rdd_0_0.reduce((val1, val2) -> (val1 + val2)); 10 | return sum; 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/bigλ/CyclingSpeed.java: -------------------------------------------------------------------------------- 1 | package generated.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class CyclingSpeed { 10 | class Record { 11 | public int fst; 12 | public int snd; 13 | public int emit; 14 | public double speed; 15 | } 16 | 17 | public Map cyclingSpeed(JavaRDD rdd_0_0){ 18 | Map result = null; 19 | result = new HashMap(); 20 | 21 | result = rdd_0_0.mapToPair(data_index -> new Tuple2((int)Math.ceil(data_index.speed), 1)).reduceByKey((val1, val2) -> (val2+val1)).collectAsMap(); 22 | 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bin/benchmarks/generated/bigλ/DatabaseSelect.java: -------------------------------------------------------------------------------- 1 | package generated.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class DatabaseSelect { 9 | 10 | class Record { 11 | public List columns; 12 | } 13 | 14 | public List select(JavaRDD rdd_0_0, String key){ 15 | List result = null; 16 | result = new ArrayList(); 17 | 18 | final String key_final = key; 19 | result = rdd_0_0.flatMap(data_index -> { 20 | List emits = new ArrayList(); 21 | if(data_index.columns.get(0).equals(key_final)) emits.add(data_index); 22 | return emits.iterator(); 23 | }).collect(); 24 | 25 | return result; 26 | } 27 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/bigλ/ShakespearSentiment.java: -------------------------------------------------------------------------------- 1 | package generated.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public class ShakespearSentiment { 12 | public Map sentiment(JavaRDD rdd_0_0){ 13 | Map result = null; 14 | result = new HashMap(); 15 | 16 | result.put("love", 0); 17 | result.put("hate", 0); 18 | 19 | result = rdd_0_0.flatMapToPair(words_index -> { 20 | List> emits = new ArrayList>(); 21 | if("hate".equals(words_index.trim().toLowerCase())) emits.add(new Tuple2(words_index, 1)); 22 | if(words_index.trim().toLowerCase().equals("love")) emits.add(new Tuple2(words_index, 1)); 23 | return emits.iterator(); 24 | }).reduceByKey((val1, val2) -> (val2+val1)).collectAsMap(); 25 | 26 | return result; 27 | } 28 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/bigλ/TwitterCounts.java: -------------------------------------------------------------------------------- 1 | package generated.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.*; 7 | 8 | public class TwitterCounts { 9 | public Map pairs(JavaRDD rdd_0_0) { 10 | Map result = null; 11 | result = new HashMap(); 12 | 13 | result = rdd_0_0.flatMap(tweets_index -> { 14 | List emits = new ArrayList(); 15 | emits = Arrays.asList(tweets_index.split("\\s+")); 16 | return emits.iterator(); 17 | }).flatMapToPair(val -> { 18 | List> emits = new ArrayList>(); 19 | if('#' == val.charAt(0)) emits.add(new Tuple2(val, 1)); 20 | return emits.iterator(); 21 | }).reduceByKey((val1, val2) -> val1+val2).collectAsMap(); 22 | 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bin/benchmarks/generated/bigλ/WikiPageCount.java: -------------------------------------------------------------------------------- 1 | package generated.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class WikiPageCount { 10 | class Record { 11 | public String name; 12 | public int views; 13 | public int something; 14 | } 15 | 16 | public Map pageCount(JavaRDD rdd_0_0){ 17 | Map result = null; 18 | result = new HashMap(); 19 | 20 | result = rdd_0_0.mapToPair(data_index -> new Tuple2(data_index.name,data_index.views)).reduceByKey((val1, val2) -> (val2+val1)).collectAsMap(); 21 | 22 | return result; 23 | } 24 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/bigλ/YelpKids.java: -------------------------------------------------------------------------------- 1 | package generated.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public class YelpKids { 12 | class Record { 13 | public String state; 14 | public String city; 15 | public String comment; 16 | public int score; 17 | public boolean goodForKids; 18 | } 19 | 20 | public Map reviewCount(JavaRDD rdd_0_0){ 21 | Map result = null; 22 | result = new HashMap(); 23 | 24 | result = rdd_0_0.flatMapToPair(data_index -> { 25 | List> emits = new ArrayList>(); 26 | if(data_index.goodForKids) emits.add(new Tuple2(data_index.city, 1)); 27 | return emits.iterator(); 28 | } 29 | ).reduceByKey((val1, val2) -> (val2+val1)).collectAsMap(); 30 | 31 | return result; 32 | } 33 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_RedToMagenta/Benchmark0.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_RedToMagenta; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple3; 5 | 6 | /** 7 | * Convert_Red_To_Magenta.java: line 37 8 | */ 9 | public class Benchmark0 { 10 | public JavaRDD> benchmark(JavaRDD> rdd_0_0, int w, int h) { 11 | return rdd_0_0.map(pixels_i -> new Tuple3(pixels_i._1(), pixels_i._2(), (((pixels_i._3() >> 16) & 0xff) << 16) | (((pixels_i._3() >> 8) & 0xff) << 8) | ((pixels_i._3() >> 16) & 0xff))); 12 | } 13 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark0.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple3; 5 | 6 | /** 7 | * TemporalMedian_.java: line 142 8 | */ 9 | public class Benchmark0 { 10 | public JavaRDD> benchmark(JavaRDD> rdd_0_0, int w, int h) { 11 | return rdd_0_0.map(pix_i -> new Tuple3(pix_i._1(),pix_i._2(),Math.sqrt(pix_i._3() + 3 / 8) * 2)); 12 | } 13 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark1.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | import org.apache.spark.api.java.JavaRDD; 5 | import scala.Tuple2; 6 | import scala.Tuple3; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * TemporalMedian_.java: line 169 13 | */ 14 | public class Benchmark1 { 15 | public JavaPairRDD benchmark(JavaRDD> rdd_0_0, int v, int wmin, int wmax) { 16 | return rdd_0_0.flatMapToPair(tWinPix_i -> { 17 | List> emits = new ArrayList<>(); 18 | if (v == tWinPix_i._2()) new Tuple2(tWinPix_i._1(), tWinPix_i._3()); 19 | return emits.iterator(); 20 | }); 21 | } 22 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark2.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple3; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * TemporalMedian_.java: line 189 11 | */ 12 | public class Benchmark2 { 13 | public JavaRDD> benchmark(JavaRDD> rdd_0_0, int wmax) { 14 | return rdd_0_0.flatMap(tWinPix_i -> { 15 | List> emits = new ArrayList<>(); 16 | if (tWinPix_i._1() != 0) emits.add(new Tuple3(tWinPix_i._1()-1,tWinPix_i._2(),tWinPix_i._3())); 17 | return emits.iterator(); 18 | }); 19 | } 20 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark3.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | 5 | /** 6 | * TemporalMedian_.java: line 217 7 | */ 8 | public class Benchmark3 { 9 | public float benchmark(JavaPairRDD rdd_0_0) { 10 | return rdd_0_0.map(vec_i -> vec_i._2).reduce((v1,v2) -> v2 + v1); 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark4.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | 5 | /** 6 | * TemporalMedian_.java: line 221 7 | */ 8 | public class Benchmark4 { 9 | public float benchmark(JavaPairRDD rdd_0_0, float mean) { 10 | return rdd_0_0.map(vec_i -> (vec_i._2 - mean) * (vec_i._2 - mean)).reduce((v1,v2) -> v1 + v2); 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_Trails/Benchmark0.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_Trails; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | import org.apache.spark.api.java.JavaRDD; 5 | import scala.Tuple2; 6 | import scala.Tuple3; 7 | 8 | public class Benchmark0 { 9 | public JavaPairRDD benchmark(JavaRDD> rdd_0_0, int wcurr, int wmin, int wmax) { 10 | return rdd_0_0.mapToPair(tWinPix_i -> new Tuple2>(tWinPix_i._2(), new Tuple2<>(1, tWinPix_i._3()))).reduceByKey((v1,v2) -> new Tuple2(v1._1+v2._1,v1._2+v2._2)).mapValues(v -> v._2/v._1); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_Trails/Benchmark1.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_Trails; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | import org.apache.spark.api.java.JavaRDD; 5 | import scala.Tuple2; 6 | import scala.Tuple3; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Trails_.java: line 151 13 | */ 14 | public class Benchmark1 { 15 | public JavaPairRDD benchmark(JavaRDD> rdd_0_0, int v, int wmin, int wmax) { 16 | return rdd_0_0.flatMapToPair(tWinPix_i -> { 17 | List> emits = new ArrayList<>(); 18 | if (v == tWinPix_i._2()) new Tuple2(tWinPix_i._1(), tWinPix_i._3()); 19 | return emits.iterator(); 20 | }); 21 | } 22 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_Trails/Benchmark2.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_Trails; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | 5 | /** 6 | * Trails_.java: line 160 7 | */ 8 | public class Benchmark2 { 9 | public float benchmark(JavaPairRDD rdd_0_0) { 10 | return rdd_0_0.map(tvec_i -> tvec_i._2).reduce((v1,v2) -> v2 + v1); 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/fiji/IJ_Trails/Benchmark3.java: -------------------------------------------------------------------------------- 1 | package generated.fiji.IJ_Trails; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple3; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Trails_.java: line 169 11 | */ 12 | public class Benchmark3 { 13 | public JavaRDD> benchmark(JavaRDD> rdd_0_0, int wmax) { 14 | return rdd_0_0.flatMap(tWinPix_i -> { 15 | List> emits = new ArrayList<>(); 16 | if (tWinPix_i._1() != 0) emits.add(new Tuple3(tWinPix_i._1()-1,tWinPix_i._2(),tWinPix_i._3())); 17 | return emits.iterator(); 18 | }); 19 | } 20 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/phoenix/Histogram.java: -------------------------------------------------------------------------------- 1 | package generated.phoenix; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | class Histogram { 11 | public static class Pixel { 12 | public int r; 13 | public int g; 14 | public int b; 15 | 16 | public Pixel(int r, int g, int b) { 17 | super(); 18 | this.r = r; 19 | this.g = g; 20 | this.b = b; 21 | } 22 | } 23 | 24 | public static int[][] histogram(JavaRDD rdd_0_0, int[] hR, int[] hG, int[] hB) { 25 | int i = 0; 26 | Map,Integer> rdd_0_0_output = rdd_0_0.flatMapToPair(image_i -> { 27 | List,Integer>> emits = new ArrayList,Integer>>(); 28 | emits.add(new Tuple2(new Tuple2(0, image_i.g),1)); 29 | emits.add(new Tuple2(new Tuple2(1, image_i.b),1)); 30 | emits.add(new Tuple2(new Tuple2(2, image_i.r),1)); 31 | return emits.iterator(); 32 | }).reduceByKey((v1,v2) -> v1 + v2).collectAsMap(); 33 | for (Tuple2 rdd_0_0_output_k : rdd_0_0_output.keySet()) { 34 | if (rdd_0_0_output_k._1 == 0) { 35 | hG[rdd_0_0_output_k._2] = rdd_0_0_output.get(rdd_0_0_output_k); 36 | } 37 | if (rdd_0_0_output_k._1 == 1) { 38 | hB[rdd_0_0_output_k._2] = rdd_0_0_output.get(rdd_0_0_output_k); 39 | } 40 | if (rdd_0_0_output_k._1 == 2) { 41 | hR[rdd_0_0_output_k._2] = rdd_0_0_output.get(rdd_0_0_output_k); 42 | } 43 | } 44 | int[][] result = (int[][]) (new int[3][]); 45 | ((int[][]) result)[0] = (int[]) hR; 46 | ((int[][]) result)[1] = (int[]) hG; 47 | ((int[][]) result)[2] = (int[]) hB; 48 | return (int[][]) result; 49 | } 50 | 51 | public Histogram() { super(); } 52 | } 53 | -------------------------------------------------------------------------------- /bin/benchmarks/generated/phoenix/LinearRegression.java: -------------------------------------------------------------------------------- 1 | package generated.phoenix; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple5; 5 | 6 | public class LinearRegression { 7 | public static class Point { 8 | public int x; 9 | public int y; 10 | 11 | public Point(int x, int y) { 12 | super(); 13 | this.x = x; 14 | this.y = y; 15 | } 16 | } 17 | 18 | public static int[] regress(JavaRDD rdd_0_0) { 19 | int SX_ll = 0; 20 | int SY_ll = 0; 21 | int SXX_ll = 0; 22 | int SYY_ll = 0; 23 | int SXY_ll = 0; 24 | int i = 0; 25 | Tuple5 rdd_0_0_output = rdd_0_0.map(points_i -> new Tuple5(points_i.x*points_i.y,points_i.x*points_i.x,points_i.y,points_i.y*points_i.y,points_i.x)).reduce((v1,v2) -> new Tuple5(v1._1()+v2._1(),v1._2()+v2._2(),v1._3()+v2._3(),v1._4()+v2._4(),v1._5()+v2._5())); 26 | SXY_ll = rdd_0_0_output._1(); 27 | SXX_ll = rdd_0_0_output._2(); 28 | SY_ll = rdd_0_0_output._3(); 29 | SYY_ll = rdd_0_0_output._4(); 30 | SX_ll = rdd_0_0_output._5(); 31 | int[] result = (int[]) (new int[5]); 32 | ((int[]) result)[0] = SX_ll; 33 | ((int[]) result)[1] = SXX_ll; 34 | ((int[]) result)[2] = SY_ll; 35 | ((int[]) result)[3] = SYY_ll; 36 | ((int[]) result)[4] = SXY_ll; 37 | return (int[]) result; 38 | } 39 | 40 | public LinearRegression() { super(); } 41 | } 42 | -------------------------------------------------------------------------------- /bin/benchmarks/generated/phoenix/StringMatch.java: -------------------------------------------------------------------------------- 1 | package generated.phoenix; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class StringMatch { 11 | public static boolean[] matchWords(JavaRDD rdd_0_0) { 12 | String key1 = "key1"; 13 | String key2 = "key2"; 14 | String key3 = "key3"; 15 | boolean foundKey1 = false; 16 | boolean foundKey2 = false; 17 | boolean foundKey3 = false; 18 | int i = 0; 19 | Map rdd_0_0_output = rdd_0_0.flatMapToPair(words_i -> { 20 | List> emits = new ArrayList>(); 21 | if (words_i.equals(key3)) emits.add(new Tuple2(2,true)); 22 | if (key1.equals(words_i)) emits.add(new Tuple2(3,true)); 23 | if (key2.equals(words_i)) emits.add(new Tuple2(1,true)); 24 | return emits.iterator(); 25 | }).reduceByKey((v1,v2) -> v2 || v1).collectAsMap(); 26 | if (rdd_0_0_output.containsKey(2)) foundKey3 = rdd_0_0_output.get(2); 27 | if (rdd_0_0_output.containsKey(3)) foundKey1 = rdd_0_0_output.get(3); 28 | if (rdd_0_0_output.containsKey(1)) foundKey2 = rdd_0_0_output.get(1); 29 | boolean[] res = { foundKey1, foundKey2, foundKey3 }; 30 | return (boolean[]) res; 31 | } 32 | 33 | public StringMatch() { super(); } 34 | } 35 | -------------------------------------------------------------------------------- /bin/benchmarks/generated/phoenix/WordCount.java: -------------------------------------------------------------------------------- 1 | package generated.phoenix; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class WordCount { 10 | private static Map countWords(JavaRDD rdd_0_0) { 11 | Map counts = new HashMap(); 12 | int j = 0; 13 | counts = rdd_0_0.mapToPair(words_i -> new Tuple2(words_i, 1)).reduceByKey((v1,v2) -> v2 + v1).collectAsMap(); 14 | return (Map) counts; 15 | } 16 | 17 | public WordCount() { super(); } 18 | } 19 | -------------------------------------------------------------------------------- /bin/benchmarks/generated/stats/IOUtil.java: -------------------------------------------------------------------------------- 1 | package generated.stats; 2 | 3 | import java.util.Scanner; 4 | import java.io.*; 5 | 6 | public class IOUtil { 7 | public static double skipToDouble(Scanner scanner) { 8 | while (((Scanner) scanner).hasNext() && 9 | !((Scanner) scanner).hasNextDouble()) { 10 | ((Scanner) scanner).next(); 11 | } 12 | return ((Scanner) scanner).hasNextDouble() 13 | ? ((Scanner) scanner).nextDouble() 14 | : Double.NaN; 15 | } 16 | 17 | public static FileReader file(String fileName) 18 | throws FileNotFoundException { 19 | return new FileReader((String) fileName); 20 | } 21 | 22 | public static String typedInput() throws IOException { 23 | BufferedReader keyIn = 24 | new BufferedReader(new InputStreamReader(System.in)); 25 | return ((BufferedReader) keyIn).readLine(); 26 | } 27 | 28 | /** 29 | 30 | * does not accept anything but integers 31 | 32 | * @ return the first integer value 33 | 34 | */ 35 | public static int skipToInt(Scanner scanner) { 36 | while (((Scanner) scanner).hasNext() && 37 | !((Scanner) scanner).hasNextInt()) { 38 | ((Scanner) scanner).next(); 39 | } 40 | return ((Scanner) scanner).hasNextInt() 41 | ? ((Scanner) scanner).nextInt() 42 | : (int) Double.NaN; 43 | } 44 | 45 | /** 46 | 47 | * Call this every time wrong thing is typed. 48 | 49 | */ 50 | public static void abuse() { 51 | System.out.println("Invalid entry."); 52 | System.out.println("Abusive statement."); 53 | System.exit(0); 54 | } 55 | 56 | public static String fileName() throws IOException { 57 | System.out.printf("Type file name or hit \'!\' \n", 58 | (Object[]) (new Object[] { })); 59 | String typed = typedInput(); 60 | System.out.printf("Found %s \n", (Object[]) (new Object[] { typed })); 61 | return (String) typed; 62 | } 63 | 64 | public static String getFileName() throws IOException { 65 | System.out.printf("Type file name or hit \'!\' \n", 66 | (Object[]) (new Object[] { })); 67 | String typed = typedInput(); 68 | System.out.printf("Found %s \n", (Object[]) (new Object[] { typed })); 69 | return (String) typed; 70 | } 71 | 72 | public static String enterValue(String kindOf) { 73 | return (String) ("Enter " + kindOf + "value:"); 74 | } 75 | 76 | public IOUtil() { super(); } 77 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/stats/PlotReader.java: -------------------------------------------------------------------------------- 1 | package generated.stats; 2 | 3 | import java.util.Scanner; 4 | 5 | public class PlotReader { 6 | public static double[] data1Column(Scanner scan, int length) { 7 | double[] data = (double[]) (new double[length]); 8 | int i = 0; 9 | while (i < ((double[]) data).length) { 10 | ((double[]) data)[i] = IOUtil.skipToDouble((Scanner) scan); 11 | i++; 12 | } 13 | return (double[]) data; 14 | } 15 | 16 | public static double[][] data2Column(Scanner scan, int length) { 17 | double[][] data = (double[][]) (new double[length][2]); 18 | int i = 0; 19 | while (i < ((double[][]) data).length) { 20 | int j = 0; 21 | while (j < ((double[]) ((double[][]) data)[0]).length) { 22 | ((double[]) ((double[][]) data)[i])[j] = 23 | (float) IOUtil.skipToDouble((Scanner) scan); 24 | j++; 25 | } 26 | i++; 27 | } 28 | return (double[][]) data; 29 | } 30 | 31 | public static double[][] data3Column(Scanner scan, int length) { 32 | double[][] data = (double[][]) (new double[length][3]); 33 | int i = 0; 34 | while (i < ((double[][]) data).length) { 35 | int j = 0; 36 | while (j < ((double[]) ((double[][]) data)[0]).length) { 37 | ((double[]) ((double[][]) data)[i])[j] = 38 | (float) IOUtil.skipToDouble((Scanner) scan); 39 | j++; 40 | } 41 | i++; 42 | } 43 | return (double[][]) data; 44 | } 45 | 46 | public static double[][] data4Column(Scanner scan, int length) { 47 | double[][] data = (double[][]) (new double[length][4]); 48 | int i = 0; 49 | while (i < ((double[][]) data).length) { 50 | int j = 0; 51 | while (j < ((double[]) ((double[][]) data)[0]).length) { 52 | ((double[]) ((double[][]) data)[i])[j] = 53 | (float) IOUtil.skipToDouble((Scanner) scan); 54 | j++; 55 | } 56 | i++; 57 | } 58 | return (double[][]) data; 59 | } 60 | 61 | public PlotReader() { super(); } 62 | } -------------------------------------------------------------------------------- /bin/benchmarks/generated/stats/PlotUtil.java: -------------------------------------------------------------------------------- 1 | package generated.stats; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | import java.io.PrintWriter; 6 | 7 | /** 8 | 9 | * PlotUtil.java 10 | 11 | * ============= 12 | 13 | * 14 | 15 | * Copyright (C) 2013-2014 Magdalen Berns 16 | 17 | * 18 | 19 | * This program is free software: you can redistribute it and/or modify 20 | 21 | * it under the terms of the GNU General Public License as published by 22 | 23 | * the Free Software Foundation, either version 3 of the License, or 24 | 25 | * (at your option) any later version. 26 | 27 | * 28 | 29 | * This program is distributed in the hope that it will be useful, 30 | 31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | 35 | * GNU General Public License for more details. 36 | 37 | 38 | 39 | * You should have received a copy of the GNU General Public License 40 | 41 | * along with this program. If not, see . 42 | 43 | */ 44 | public class PlotUtil extends IOUtil { 45 | private double[] x; 46 | private double[] y; 47 | private JavaRDD data; 48 | 49 | public PlotUtil(JavaRDD rdd_0_0) { 50 | super(); 51 | this.data = (JavaRDD) data; 52 | x = (double[]) (new double[(int)rdd_0_0.count()]); 53 | y = (double[]) (new double[(int)rdd_0_0.count()]); 54 | } 55 | 56 | /** 57 | 58 | * x 59 | 60 | * Pull out the x column data 61 | 62 | * @return: 63 | 64 | * The x component of a 1d array of doubles 65 | 66 | */ 67 | public JavaRDD x(){ 68 | return data.map(data_i -> data_i[0]); 69 | } 70 | 71 | /** 72 | 73 | * x 74 | 75 | * Pull out the y column data 76 | 77 | * @return 78 | 79 | * The y component of a 1d array of doubles 80 | 81 | */ 82 | public JavaRDD y(){ 83 | return data.map(data_i -> data_i[1]); 84 | } 85 | 86 | /** 87 | 88 | * removeOffset 89 | 90 | * Convenience function to remove the y intecept offset value 91 | 92 | * @return 93 | 94 | * The 2D data array of doubles with offset removed. 95 | 96 | */ 97 | public static JavaRDD removeOffset(JavaRDD rdd_1_0, double offset){ 98 | return rdd_1_0.map(data_i -> { 99 | data_i[0] = data_i[0] - offset; 100 | return data_i; 101 | }); 102 | } 103 | 104 | public static void writeToFile(double[][] data, PrintWriter fileOut) { 105 | int i = 0; 106 | while (i < ((double[][]) data).length) { 107 | ((PrintWriter) fileOut). 108 | printf("%2.5f %2.5f", 109 | (Object[]) 110 | (new Object[] { Double.valueOf(((double[]) 111 | ((double[][]) 112 | data)[i])[0]), 113 | Double.valueOf(((double[]) 114 | ((double[][]) data)[i])[1]) })); 115 | ((PrintWriter) fileOut).println(); 116 | i++; 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/Average.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | public class Average { 7 | 8 | public static double avgList(JavaRDD data){ 9 | Tuple2 sumcount = data.aggregate( 10 | new Tuple2(0,0), 11 | (res, val) -> new Tuple2(res._1 + val, res._2 + 1), 12 | (res1, res2) -> new Tuple2(res1._1 + res2._1, res1._2 + res2._2)); 13 | return sumcount._1 / sumcount._2; 14 | } 15 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/ConditionalCount.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class ConditionalCount { 6 | public static Integer countList(JavaRDD data){ 7 | return data.aggregate( 8 | 0, 9 | (count, a) -> (a < 100 ? count + 1 : count), 10 | (c1, c2) -> c1 + c2 11 | ); 12 | } 13 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/ConditionalSum.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class ConditionalSum { 6 | public static Integer sumList(JavaRDD data){ 7 | return data.aggregate( 8 | 0, 9 | (sum, a) -> (a < 100 ? sum + a : sum), 10 | (s1, s2) -> s1 + s2 11 | ); 12 | } 13 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/Count.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class Count { 6 | public static int countList(JavaRDD data){ 7 | return (int) data.count(); 8 | } 9 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/Delta.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | public class Delta { 7 | public static int deltaList(JavaRDD data){ 8 | Tuple2 minmax = data.aggregate( 9 | new Tuple2(Integer.MIN_VALUE,Integer.MAX_VALUE), 10 | (res, val) -> new Tuple2(Math.max(res._1,val), Math.min(res._2,val)), 11 | (res1, res2) -> new Tuple2(Math.max(res1._1,res2._1), Math.min(res1._2, res2._2))); 12 | return minmax._1 - minmax._2; 13 | } 14 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/Equal.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class Equal { 6 | public static boolean equal(JavaRDD data, int val){ 7 | return (boolean) data.filter(a -> a != val).isEmpty(); 8 | } 9 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/EqualFrequency.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | public class EqualFrequency { 7 | public static boolean equalFrequency(JavaRDD data){ 8 | Tuple2 freq = data.aggregate( 9 | new Tuple2(0, 0), 10 | (res, val) -> new Tuple2((val == 100? res._1 + 1 : res._1), (val == 110? res._2 + 1 : res._2)), 11 | (res1, res2) -> new Tuple2(res1._1 + res2._1, res1._2 + res2._2)); 12 | return freq._1 == freq._2; 13 | } 14 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/Max.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class Max { 6 | public static int maxList(JavaRDD data){ 7 | return data.reduce((a, b) -> Math.max(a, b)); 8 | } 9 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/MaxAbs.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class MaxAbs { 6 | public static int maxAbsList(JavaRDD data){ 7 | return data.reduce((a, b) -> Math.max(Math.abs(a), Math.abs(b))); 8 | } 9 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/Min.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class Min { 6 | public static int minList(JavaRDD data){ 7 | return data.reduce((a, b) -> Math.min(a, b)); 8 | } 9 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/arithmetic/Sum.java: -------------------------------------------------------------------------------- 1 | package manual.arithmetic; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class Sum { 6 | public static int sumList(JavaRDD data){ 7 | return data.reduce((a, b) -> a+b); 8 | } 9 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/bigλ/CyclingSpeed.java: -------------------------------------------------------------------------------- 1 | package manual.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.Map; 7 | 8 | public class CyclingSpeed { 9 | class Record { 10 | public int fst; 11 | public int snd; 12 | public int emit; 13 | public double speed; 14 | } 15 | 16 | public Map cyclingSpeed(JavaRDD data){ 17 | return data.mapToPair(r -> new Tuple2((int)Math.ceil(r.speed),1)).reduceByKey((a, b) -> a+b).collectAsMap(); 18 | } 19 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/bigλ/DatabaseSelect.java: -------------------------------------------------------------------------------- 1 | package manual.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | import java.util.List; 6 | 7 | public class DatabaseSelect { 8 | 9 | class Record { 10 | public List columns; 11 | } 12 | 13 | public List select(JavaRDD table, String key){ 14 | return table.filter(r -> r.columns.get(0).equals(key)).collect(); 15 | } 16 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/bigλ/ShakespearSentiment.java: -------------------------------------------------------------------------------- 1 | package manual.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class ShakespearSentiment { 9 | public Map sentiment(JavaRDD words){ 10 | Map result = new HashMap(); 11 | result.put("love", 0); 12 | result.put("hate", 0); 13 | 14 | result = words.aggregate( 15 | result, 16 | (res, word) -> { 17 | if (word.trim().toLowerCase().equals("love")) { 18 | res.put("love", res.get("love")+1); 19 | } 20 | if (word.trim().toLowerCase().equals("hate")) { 21 | res.put("hate", res.get("hate")+1); 22 | } 23 | return res; 24 | }, 25 | (res1, res2) -> { 26 | res1.put("love", res1.get("love") + res2.get("love")); 27 | res1.put("hate", res1.get("hate") + res2.get("hate")); 28 | return res1; 29 | } 30 | ); 31 | 32 | return result; 33 | } 34 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/bigλ/TwitterCounts.java: -------------------------------------------------------------------------------- 1 | package manual.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class TwitterCounts { 11 | public Map pairs(JavaRDD tweets) { 12 | return tweets.flatMapToPair(tweet -> { 13 | List> freq = new ArrayList>(); 14 | for (String word : tweet.split("\\s+")) { 15 | if (word.charAt(0) == '#') { 16 | freq.add(new Tuple2(word, 1)); 17 | } 18 | } 19 | return freq.iterator(); 20 | }).reduceByKey((a, b) -> a+b).collectAsMap(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /bin/benchmarks/manual/bigλ/WikiPageCount.java: -------------------------------------------------------------------------------- 1 | package manual.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.Map; 7 | 8 | public class WikiPageCount { 9 | class Record { 10 | public String name; 11 | public int views; 12 | public int something; 13 | } 14 | 15 | public Map pageCount(JavaRDD data){ 16 | return data.mapToPair(r -> new Tuple2(r.name,r.views)).reduceByKey((a, b) -> a+b).collectAsMap(); 17 | } 18 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/bigλ/YelpKids.java: -------------------------------------------------------------------------------- 1 | package manual.bigλ; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.Map; 7 | 8 | public class YelpKids { 9 | class Record { 10 | public String state; 11 | public String city; 12 | public String comment; 13 | public int score; 14 | public boolean goodForKids; 15 | } 16 | 17 | public Map reviewCount(JavaRDD data){ 18 | return data.mapToPair(r -> new Tuple2(r.city,1)).reduceByKey((a, b) -> a+b).collectAsMap(); 19 | } 20 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_RedToMagenta/Benchmark0.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_RedToMagenta; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | /** 6 | * Convert_Red_To_Magenta.java: line 37 7 | */ 8 | public class Benchmark0 { 9 | class Pixel { 10 | int row; 11 | int col; 12 | int val; 13 | public Pixel(int r, int c, int v) { 14 | row = r; 15 | col = c; 16 | val = v; 17 | } 18 | } 19 | 20 | public JavaRDD benchmark(JavaRDD pixels, int w, int h) { 21 | return pixels.map(pixel -> { 22 | int value = pixel.val; 23 | int red = (value >> 16) & 0xff; 24 | int green = (value >> 8) & 0xff; 25 | int blue = value & 0xff; 26 | if (false && blue > 16) 27 | return pixel; 28 | else 29 | return new Pixel(pixel.row, pixel.col, (red << 16) | (green << 8) | red); 30 | }); 31 | } 32 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark0.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | /** 6 | * TemporalMedian_.java: line 142 7 | */ 8 | public class Benchmark0 { 9 | class Pixel { 10 | int frame; 11 | int pos; 12 | float val; 13 | public Pixel(int f, int p, float v) { 14 | frame = f; 15 | pos = p; 16 | val = v; 17 | } 18 | } 19 | 20 | public JavaRDD benchmark(JavaRDD pixels, int w, int h) { 21 | return pixels.map(pixel -> { 22 | double transf = 2 * Math.sqrt(pixel.val + 3 / 8); 23 | return new Pixel(pixel.frame, pixel.pos, (float)transf); 24 | }); 25 | } 26 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark1.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | import org.apache.spark.api.java.JavaRDD; 5 | import scala.Tuple2; 6 | 7 | /** 8 | * TemporalMedian_.java: line 169 9 | */ 10 | public class Benchmark1 { 11 | class Pixel { 12 | int frame; 13 | int pos; 14 | float val; 15 | public Pixel(int f, int p, float v) { 16 | frame = f; 17 | pos = p; 18 | val = v; 19 | } 20 | } 21 | 22 | public JavaPairRDD benchmark(JavaRDD tWinPix, int v, int wmin, int wmax) { 23 | return tWinPix.filter(pixel -> pixel.pos==v).mapToPair(pixel -> new Tuple2(pixel.frame, pixel.val)); 24 | } 25 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark2.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | /** 6 | * TemporalMedian_.java: line 189 7 | */ 8 | public class Benchmark2 { 9 | class Pixel { 10 | int frame; 11 | int pos; 12 | float val; 13 | public Pixel(int f, int p, float v) { 14 | frame = f; 15 | pos = p; 16 | val = v; 17 | } 18 | } 19 | 20 | public JavaRDD benchmark(JavaRDD tWinPix, int wmax) { 21 | return tWinPix.filter(pixel -> pixel.frame!=0).map(pixel -> new Pixel(pixel.frame-1,pixel.pos,pixel.val)); 22 | } 23 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark3.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | 5 | /** 6 | * TemporalMedian_.java: line 217 7 | */ 8 | public class Benchmark3 { 9 | public float benchmark(JavaPairRDD vec) { 10 | return vec.values().reduce((a, b) -> a + b); 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark4.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_Temporal; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | 5 | /** 6 | * TemporalMedian_.java: line 221 7 | */ 8 | public class Benchmark4 { 9 | public float benchmark(JavaPairRDD vec, float mean) { 10 | return vec.values().map(v -> (mean - v) * (mean - v)).reduce((a, b) -> a + b); 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_Trails/Benchmark0.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_Trails; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | import org.apache.spark.api.java.JavaRDD; 5 | import scala.Tuple2; 6 | 7 | public class Benchmark0 { 8 | class Pixel { 9 | int frame; 10 | int pos; 11 | float val; 12 | public Pixel(int f, int p, float v) { 13 | frame = f; 14 | pos = p; 15 | val = v; 16 | } 17 | } 18 | 19 | public JavaPairRDD benchmark(JavaRDD tWinPix, int wcurr, int wmin, int wmax) { 20 | return tWinPix.mapToPair(pixel -> new Tuple2(pixel.pos, pixel.val)) 21 | .aggregateByKey( 22 | new Tuple2((float)0, 0), 23 | (res, val) -> new Tuple2(res._1+val, res._2+1), 24 | (res1, res2) -> new Tuple2(res1._1+res2._1, res1._2+res2._2) 25 | ).mapValues(pixel -> pixel._1/pixel._2); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_Trails/Benchmark1.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_Trails; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | import org.apache.spark.api.java.JavaRDD; 5 | import scala.Tuple2; 6 | 7 | /** 8 | * Trails_.java: line 151 9 | */ 10 | public class Benchmark1 { 11 | class Pixel { 12 | int frame; 13 | int pos; 14 | float val; 15 | public Pixel(int f, int p, float v) { 16 | frame = f; 17 | pos = p; 18 | val = v; 19 | } 20 | } 21 | 22 | public JavaPairRDD benchmark(JavaRDD tWinPix, int v, int wmin, int wmax) { 23 | return tWinPix.filter(pixel -> pixel.pos==v).mapToPair(pixel -> new Tuple2(pixel.frame, pixel.val)); 24 | } 25 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_Trails/Benchmark2.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_Trails; 2 | 3 | import org.apache.spark.api.java.JavaPairRDD; 4 | 5 | /** 6 | * Trails_.java: line 160 7 | */ 8 | public class Benchmark2 { 9 | public float benchmark(JavaPairRDD vec) { 10 | return vec.values().reduce((a, b) -> a + b); 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/fiji/IJ_Trails/Benchmark3.java: -------------------------------------------------------------------------------- 1 | package manual.fiji.IJ_Trails; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | /** 6 | * Trails_.java: line 169 7 | */ 8 | public class Benchmark3 { 9 | class Pixel { 10 | int frame; 11 | int pos; 12 | float val; 13 | public Pixel(int f, int p, float v) { 14 | frame = f; 15 | pos = p; 16 | val = v; 17 | } 18 | } 19 | 20 | public JavaRDD benchmark(JavaRDD tWinPix, int wmax) { 21 | return tWinPix.filter(pixel -> pixel.frame!=0).map(pixel -> new Pixel(pixel.frame-1,pixel.pos,pixel.val)); 22 | } 23 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/phoenix/Histogram.java: -------------------------------------------------------------------------------- 1 | package manual.phoenix; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | class Histogram { 6 | 7 | public static class Pixel { 8 | public int r, g, b; 9 | 10 | public Pixel(int r, int g, int b) { 11 | this.r = r; 12 | this.g = g; 13 | this.b = b; 14 | } 15 | } 16 | 17 | public static int[][] histogram(JavaRDD image, int[] hR, int[] hG, int[] hB) { 18 | return image.aggregate(new int[3][256], 19 | (res, pixel) -> { 20 | res[0][pixel.r]++; 21 | res[1][pixel.g]++; 22 | res[2][pixel.b]++; 23 | return res; 24 | }, 25 | (res1, res2) -> { 26 | for (int i=0; i<256; i++) { 27 | res1[0][i] = res1[0][i] + res2[0][i]; 28 | res1[1][i] = res1[1][i] + res2[1][i]; 29 | res1[2][i] = res1[2][i] + res2[2][i]; 30 | } 31 | return res1; 32 | } 33 | ); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /bin/benchmarks/manual/phoenix/KMeansJava.java: -------------------------------------------------------------------------------- 1 | package manual.phoenix; 2 | 3 | import org.apache.spark.api.java.JavaDoubleRDD; 4 | import org.apache.spark.api.java.JavaPairRDD; 5 | 6 | /** 7 | * 8 | * Translation of Phoenix k-means implementation 9 | * 10 | */ 11 | 12 | public class KMeansJava { 13 | 14 | private static class Result{ 15 | public Double[][] means; 16 | public int[] clusters; 17 | boolean modified; 18 | 19 | Result(Double[][] m, int[] c, boolean mod){ 20 | this.means = m; 21 | this.clusters = c; 22 | this.modified = mod; 23 | } 24 | } 25 | 26 | final int GRID_SIZE = 1000; 27 | 28 | public static void main(String[] args) { 29 | 30 | int numPoints = 1000, numMeans = 10, dim = 3; 31 | 32 | Double[][] points = generatePoints(numPoints, dim); 33 | Double[][] means = generatePoints(numMeans, dim); 34 | int[] clusters = new int[numPoints]; 35 | 36 | boolean modified = false; 37 | 38 | while (!modified) { 39 | modified = findClustersAndCalcMeans(points,means, 40 | clusters).modified; 41 | } 42 | 43 | System.out.println("\n\nFinal Means:\n"); 44 | dumpMatrix(means); 45 | } 46 | 47 | private static void dumpMatrix(Double[][] a) { 48 | for (int i = 0; i < a.length; i++) { 49 | for (int j = 0; j < a[i].length; j++) 50 | System.out.print(" " + a[i][j]); 51 | System.out.println(); 52 | } 53 | } 54 | 55 | private static Result findClustersAndCalcMeans(Double[][] points, 56 | Double[][] means, int[] clusters) { 57 | int i, j; 58 | Double minDist, curDist; 59 | int minIdx; 60 | int dim = points[0].length; 61 | boolean modified = false; 62 | for (i = 0; i < points.length; i++) { 63 | minDist = getSqDist(points[i], means[0]); 64 | minIdx = 0; 65 | for (j = 1; j < means.length; j++) { 66 | curDist = getSqDist(points[i], means[j]); 67 | if (curDist < minDist) { 68 | minDist = curDist; 69 | minIdx = j; 70 | } 71 | } 72 | 73 | if (clusters[i] != minIdx) { 74 | clusters[i] = minIdx; 75 | modified = true; 76 | } 77 | } 78 | 79 | for (int ii = 0; ii < means.length; ii++) { 80 | Double[] sum = new Double[dim]; 81 | int groupSize = 0; 82 | for (int jj = 0; jj < points.length; jj++) { 83 | if (clusters[jj] == ii) { 84 | sum = add(sum, points[jj]); 85 | groupSize++; 86 | } 87 | } 88 | dim = points[0].length; 89 | Double[] meansi = means[ii]; 90 | for (int kk = 0; kk < dim; kk++) { 91 | if (groupSize != 0) { 92 | meansi[kk] = sum[kk] / groupSize; 93 | } 94 | } 95 | means[ii] = meansi; 96 | } 97 | return new Result(means, clusters, modified); 98 | } 99 | 100 | private static JavaDoubleRDD add(JavaDoubleRDD v1, JavaDoubleRDD v2) { 101 | JavaPairRDD t = v1.zip(v2); 102 | return t.mapToDouble(val -> val._1 + val._2); 103 | } 104 | 105 | private static Double getSqDist(JavaDoubleRDD v1, JavaDoubleRDD v2) { 106 | JavaPairRDD t = v1.zip(v2); 107 | return t.aggregate(0.0, 108 | (dist, val) -> dist + (val._1 - val._2) * (val._1 - val._2), 109 | (dist1, dist2) -> dist1 + dist2 110 | ); 111 | } 112 | 113 | private static Double[][] generatePoints(int numPoints, int dim) { 114 | Double[][] p = new Double[numPoints][dim]; 115 | for (int i = 0; i < numPoints; i++) { 116 | p[i] = new Double[dim]; 117 | for (int j = 0; j < dim; j++) 118 | p[i][j] = Math.random(); 119 | } 120 | return p; 121 | } 122 | 123 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/phoenix/LinearRegression.java: -------------------------------------------------------------------------------- 1 | package manual.phoenix; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class LinearRegression { 6 | 7 | public static class Point { 8 | public int x, y; 9 | 10 | public Point(int x, int y) { 11 | this.x = x; 12 | this.y = y; 13 | } 14 | } 15 | 16 | public static int[] regress(JavaRDD points) { 17 | return points.aggregate(new int[5], 18 | (res, point) -> { 19 | res[0] += point.x; 20 | res[1] += point.x * point.x; 21 | res[2] += point.y; 22 | res[3] += point.y * point.y; 23 | res[4] += point.x * point.y; 24 | return res; 25 | }, 26 | (res1, res2) -> { 27 | res1[0] += res2[0]; 28 | res1[1] += res2[1]; 29 | res1[2] += res2[2]; 30 | res1[3] += res2[3]; 31 | res1[4] += res2[4]; 32 | return res1; 33 | }); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/phoenix/StringMatch.java: -------------------------------------------------------------------------------- 1 | package manual.phoenix; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | 5 | public class StringMatch { 6 | public static boolean[] matchWords(JavaRDD words) { 7 | return words.aggregate(new boolean[3], 8 | (res, word) -> { 9 | res[0] = res[0] || (word == "key1"); 10 | res[1] = res[1] || (word == "key2"); 11 | res[2] = res[2] || (word == "key3"); 12 | return res; 13 | }, 14 | (res1, res2) -> { 15 | res1[0] = res1[0] || res2[0]; 16 | res1[1] = res1[1] || res2[1]; 17 | res1[2] = res1[2] || res2[2]; 18 | return res1; 19 | } 20 | ); 21 | } 22 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/phoenix/WordCount.java: -------------------------------------------------------------------------------- 1 | package manual.phoenix; 2 | 3 | import org.apache.spark.api.java.JavaRDD; 4 | import scala.Tuple2; 5 | 6 | import java.util.Map; 7 | 8 | public class WordCount { 9 | private static Map countWords(JavaRDD words) { 10 | return words.mapToPair(word -> new Tuple2(word,1)).reduceByKey((c1, c2) -> c1+c2).collectAsMap(); 11 | } 12 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/stats/Calculate.java: -------------------------------------------------------------------------------- 1 | package manual.stats; 2 | 3 | import org.apache.spark.api.java.JavaDoubleRDD; 4 | import org.apache.spark.api.java.JavaPairRDD; 5 | 6 | /** 7 | * Calculate.java 8 | * ============= 9 | * 10 | * Copyright (C) 2013-2014 Magdalen Berns 11 | * 12 | * This program is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | */ 25 | 26 | public class Calculate{ 27 | 28 | private double num1, num; 29 | 30 | //Initialise instance variables to be used by instance methods. 31 | public Calculate(){ 32 | num1=0.0; 33 | num=0.0; 34 | } 35 | 36 | /** 37 | * subtract 38 | * Method to subtract one double from another 39 | * @param a 40 | * double value to subtract b from 41 | * @param b 42 | * double value to be subtracted from a 43 | * @return 44 | * Double result of subtracting b from a 45 | */ 46 | public static double subtract(double a, double b){ 47 | return a - b; 48 | } 49 | 50 | /** 51 | * add 52 | * Method to add one double to another 53 | * @param a 54 | * double value to be added to b 55 | * @param b 56 | * double value to be added to a 57 | * @return 58 | * Double result of adding a to b 59 | */ 60 | public static double add(double a,double b){ 61 | return a+b; 62 | } 63 | 64 | /** 65 | * divide 66 | * Method to divide one double over another 67 | * @param a 68 | * double value to be divided by b 69 | * @param b 70 | * double value to divide a by 71 | * @return 72 | * Double result of dividing a from b 73 | */ 74 | public static double divide(double a, double b){ 75 | return a/b; 76 | } 77 | 78 | /** 79 | * multiply 80 | * Method to multiply one method to another 81 | * @param a 82 | * Double value to be multiplied by b 83 | * @param b 84 | * Double value to multiplied by a 85 | * @return 86 | * Double result of a * b 87 | */ 88 | public static double multiply(double a, double b){ 89 | return a*b; 90 | } 91 | 92 | /** 93 | * subtract 94 | * Instance method to subtract one double from another 95 | * @param num2 96 | * double value to be subtracted from num1 97 | * @return 98 | * Double result of subtracting num1 to num2 99 | */ 100 | public double subtract(double num2){ 101 | return num1-num2; 102 | } 103 | 104 | /** 105 | * add 106 | * Instance method to add one double to another 107 | * @param num2 108 | * double value to be added to num1 109 | * @return 110 | * Double result of adding num1 to num2 111 | */ 112 | public double add(double num2){ 113 | return num1+num2; 114 | } 115 | 116 | public double divide(double num2){ 117 | return num1/num2; 118 | } 119 | 120 | public double multiply(double num2){ 121 | return num1*num2; 122 | } 123 | 124 | public static JavaDoubleRDD multiply(JavaDoubleRDD a, double b){ 125 | return a.mapToDouble(x -> x * b); 126 | } 127 | 128 | public static JavaDoubleRDD multiply(JavaDoubleRDD a, JavaDoubleRDD b){ 129 | JavaPairRDD t = a.zip(b); 130 | return t.mapToDouble(x -> x._1 * x._2); 131 | } 132 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/stats/IOUtil.java: -------------------------------------------------------------------------------- 1 | package manual.stats; 2 | 3 | /** 4 | * IOUtil.java 5 | * ============ 6 | * Copyright (C) 2013 Magdalen Berns 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * This file provides a library of static methods for handling common 19 | * IO requirements. 20 | */ 21 | 22 | import java.util.Scanner; 23 | import java.io.*; 24 | 25 | public class IOUtil{ 26 | 27 | /* 28 | * does not accept anything but doubles 29 | * @ return the first double 30 | */ 31 | public static double skipToDouble(Scanner scanner){ 32 | 33 | while (scanner.hasNext() && !scanner.hasNextDouble()){ 34 | scanner.next(); 35 | } 36 | return scanner.hasNextDouble() ? scanner.nextDouble() : Double.NaN; 37 | } 38 | 39 | public static FileReader file(String fileName) throws FileNotFoundException { 40 | return new FileReader(fileName); 41 | } 42 | //read the user input 43 | public static String typedInput() throws IOException { 44 | BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in)); 45 | return keyIn.readLine(); 46 | } 47 | 48 | /** 49 | * does not accept anything but integers 50 | * @ return the first integer value 51 | */ 52 | public static int skipToInt(Scanner scanner) { 53 | 54 | while (scanner.hasNext() && !scanner.hasNextInt()) { 55 | scanner.next(); 56 | } 57 | return scanner.hasNextInt() ? scanner.nextInt() : (int) Double.NaN;//workaround 58 | } 59 | 60 | /** 61 | * Call this every time wrong thing is typed. 62 | */ 63 | public static void abuse() { 64 | System.out.println("Invalid entry."); 65 | System.out.println("Abusive statement."); 66 | System.exit(0); 67 | } 68 | 69 | public static String fileName() throws IOException { 70 | System.out.printf("Type file name or hit '!' \n"); 71 | String typed= typedInput(); 72 | System.out.printf("Found %s \n", typed); 73 | return typed; 74 | } 75 | 76 | public static String getFileName() throws IOException { 77 | System.out.printf("Type file name or hit '!' \n"); 78 | String typed= typedInput(); 79 | System.out.printf("Found %s \n", typed); 80 | return typed; 81 | } 82 | 83 | public static String enterValue(String kindOf) { 84 | return "Enter " + kindOf + "value:"; 85 | } 86 | } -------------------------------------------------------------------------------- /bin/benchmarks/manual/stats/PlotReader.java: -------------------------------------------------------------------------------- 1 | package manual.stats; 2 | 3 | /** 4 | * PlotUtil.java 5 | * ============== 6 | * 7 | * Copyright (C) 2013-2014 Magdalen Berns 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | import java.util.Scanner; 24 | 25 | 26 | public class PlotReader{ 27 | 28 | public static double[] data1Column(Scanner scan, int length){ 29 | double[] data=new double[length]; 30 | for (int i=0;i 13 | * 14 | * This program is free software: you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation, either version 3 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program. If not, see . 26 | */ 27 | public class PlotUtil extends IOUtil{ 28 | 29 | private JavaRDD data; 30 | 31 | private static class Element { 32 | double x; 33 | double y; 34 | public Element (double a, double b) { x = a; y = b; } 35 | } 36 | 37 | public PlotUtil(JavaRDD data){ 38 | this.data=data; 39 | } 40 | 41 | /** 42 | * x 43 | * Pull out the x column data 44 | * @return: 45 | * The x component of a 1d array of doubles 46 | */ 47 | public JavaDoubleRDD x(){ 48 | return data.mapToDouble(e -> e.x); 49 | } 50 | 51 | /** 52 | * x 53 | * Pull out the y column data 54 | * @return 55 | * The y component of a 1d array of doubles 56 | */ 57 | public JavaDoubleRDD y(){ 58 | return data.mapToDouble(e -> e.y); 59 | } 60 | 61 | /** 62 | * removeOffset 63 | * Convenience function to remove the y intecept offset value 64 | * @return 65 | * The 2D data array of doubles with offset removed. 66 | */ 67 | public static JavaRDD removeOffset(JavaRDD data, double offset){ 68 | return data.map(e -> new Element(e.x + -offset, e.y)); 69 | } 70 | 71 | public static void writeToFile(double[][] data, PrintWriter fileOut){ 72 | for(int i=0; i. 25 | */ 26 | 27 | import java.io.PrintWriter; 28 | 29 | public class PlotWriter{ 30 | 31 | 32 | public static void write(double[] x, double[] y, PrintWriter fileOut){ 33 | for(int i=0; idata[0][1]){ 82 | 83 | //if so check that it's significant 84 | if(data[i][1]>largeUp && data[i][1] > minValue){ 85 | 86 | largeUp = data[i][1]; 87 | System.out.printf("%2.2f ",data[i][0]); 88 | upFile.printf("%2.2f %2.2f ",data[i][0], largeUp); 89 | upFile.println(); 90 | } 91 | } 92 | } 93 | System.out.println(); 94 | } 95 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/arithmetic/Average.java: -------------------------------------------------------------------------------- 1 | package original.arithmetic; 2 | 3 | import java.util.List; 4 | 5 | public class Average { 6 | public static int avgList(List data) { 7 | int sum = 0; 8 | int count = 0; 9 | for(int i=0; i data) { 7 | int count = 0; 8 | for(int i=0; i data) { 7 | int sum = 0; 8 | for(int i=0; i data) { 7 | int count = 0; 8 | for(int i=0; i data) { 7 | int min = Integer.MAX_VALUE; 8 | int max = Integer.MIN_VALUE; 9 | for(int i=0; i val) 14 | min = val; 15 | } 16 | return max-min; 17 | } 18 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/arithmetic/Equal.java: -------------------------------------------------------------------------------- 1 | package original.arithmetic; 2 | 3 | import java.util.List; 4 | 5 | public class Equal { 6 | public static boolean equal(List data, int val) { 7 | boolean equal = true; 8 | for(int i=0; i data) { 7 | int first = 0; 8 | int second = 0; 9 | for(int i=0; i data) { 7 | int max = Integer.MIN_VALUE; 8 | for(int i=0; i data) { 7 | int max = Integer.MIN_VALUE; 8 | for(int i=0; i data) { 7 | int min = Integer.MAX_VALUE; 8 | for(int i=0; i val) 11 | min = val; 12 | } 13 | return min; 14 | } 15 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/arithmetic/Sum.java: -------------------------------------------------------------------------------- 1 | package original.arithmetic; 2 | 3 | import java.util.List; 4 | 5 | public class Sum { 6 | public static int sumList(List data) { 7 | int sum = 0; 8 | for(int i=0; i cyclingSpeed(List data) { 16 | Map result = new HashMap(); 17 | 18 | for(Record record : data) { 19 | int speed = ((int)Math.ceil(record.speed)); 20 | if(!result.containsKey(speed)) { 21 | result.put(speed,0); 22 | } 23 | result.put(speed, result.get(speed)+1); 24 | } 25 | 26 | return result; 27 | } 28 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/bigλ/DatabaseSelect.java: -------------------------------------------------------------------------------- 1 | package original.bigλ; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class DatabaseSelect { 7 | 8 | class Record { 9 | public List columns; 10 | } 11 | 12 | public List select(List table, String key) { 13 | List result = new ArrayList(); 14 | 15 | for (Record record : table) { 16 | if (record.columns.get(0).equals(key)) { 17 | result.add(record); 18 | } 19 | } 20 | 21 | return result; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /bin/benchmarks/original/bigλ/ShakespearSentiment.java: -------------------------------------------------------------------------------- 1 | package original.bigλ; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class ShakespearSentiment { 8 | public Map sentiment(List words) { 9 | Map result = new HashMap(); 10 | 11 | result.put("love", 0); 12 | result.put("hate", 0); 13 | 14 | for (String word : words) { 15 | if (word.trim().toLowerCase().equals("love")) { 16 | result.put("love", result.get("love")+1); 17 | } 18 | else if (word.trim().toLowerCase().equals("hate")) { 19 | result.put("hate", result.get("hate")+1); 20 | } 21 | } 22 | 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bin/benchmarks/original/bigλ/TwitterCounts.java: -------------------------------------------------------------------------------- 1 | package original.bigλ; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class TwitterCounts { 8 | public Map pairs(List tweets) { 9 | Map result = new HashMap(); 10 | 11 | for (String tweet : tweets) { 12 | for (String word : tweet.split("\\s+")) { 13 | if (word.charAt(0) == '#') { 14 | if (!result.containsKey(word)) { 15 | result.put(word, 0); 16 | } 17 | result.put(word, result.get(word) + 1); 18 | } 19 | } 20 | } 21 | 22 | return result; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /bin/benchmarks/original/bigλ/WikiPageCount.java: -------------------------------------------------------------------------------- 1 | package original.bigλ; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class WikiPageCount { 8 | class Record { 9 | public String name; 10 | public int views; 11 | public int something; 12 | } 13 | 14 | public Map pageCount(List data) { 15 | Map result = new HashMap(); 16 | 17 | for (Record record : data) { 18 | if (!result.containsKey(record.name)) { 19 | result.put(record.name, 0); 20 | } 21 | result.put(record.name, result.get(record.name) + record.views); 22 | } 23 | 24 | return result; 25 | } 26 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/bigλ/YelpKids.java: -------------------------------------------------------------------------------- 1 | package original.bigλ; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class YelpKids { 8 | class Record { 9 | public String state; 10 | public String city; 11 | public String comment; 12 | public int score; 13 | public boolean goodForKids; 14 | } 15 | 16 | public Map reviewCount(List data) { 17 | Map result = new HashMap(); 18 | 19 | for (Record record : data) { 20 | if (!result.containsKey(record.city)) { 21 | result.put(record.city, 0); 22 | } 23 | if (record.goodForKids) { 24 | result.put(record.city, result.get(record.city)+1); 25 | } 26 | } 27 | 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /bin/benchmarks/original/fiji/IJ_RedToMagenta/fiji/color/Convert_Red_To_Magenta.java: -------------------------------------------------------------------------------- 1 | package original.fiji.IJ_RedToMagenta.fiji.color; 2 | 3 | import ij.ImagePlus; 4 | import ij.plugin.filter.PlugInFilter; 5 | import ij.process.ColorProcessor; 6 | import ij.process.ImageProcessor; 7 | 8 | /** 9 | * Convert all reds to magentas (to help red-green blind viewers) 10 | */ 11 | public class Convert_Red_To_Magenta implements PlugInFilter { 12 | protected ImagePlus image; 13 | 14 | /** 15 | * This method gets called by ImageJ / Fiji to determine 16 | * whether the current image is of an appropriate type. 17 | * 18 | * @param arg can be specified in plugins.config 19 | * @param image is the currently opened image 20 | */ 21 | public int setup(String arg, ImagePlus image) { 22 | this.image = image; 23 | return DOES_RGB; 24 | } 25 | 26 | /** 27 | * This method is run when the current image was accepted. 28 | * 29 | * @param ip is the current slice (typically, plugins use 30 | * the ImagePlus set above instead). 31 | */ 32 | public void run(ImageProcessor ip) { 33 | process((ColorProcessor)ip); 34 | image.updateAndDraw(); 35 | } 36 | 37 | public static void process(ColorProcessor ip) { 38 | int w = ip.getWidth(), h = ip.getHeight(); 39 | int[] pixels = (int[])ip.getPixels(); 40 | for (int j = 0; j < h; j++) 41 | for (int i = 0; i < w; i++) { 42 | int value = pixels[i + j * w]; 43 | int red = (value >> 16) & 0xff; 44 | int green = (value >> 8) & 0xff; 45 | int blue = value & 0xff; 46 | if (false && blue > 16) 47 | continue; 48 | pixels[i + j * w] = (red << 16) | (green << 8) | red; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/fiji/IJ_Temporal/README.md: -------------------------------------------------------------------------------- 1 | Temporal Plugins 2 | ================ 3 | 4 | This Maven project implements ImageJ 1.x plugins for time sequences: 5 | 6 | * Temporal median: finds moving foreground features, see 7 | Parton et al. (2011), JCB 194 (1): 121. 8 | * Trails: does simple averaging over a time window, making tracks visible. 9 | 10 | The plugins ought to work for hyperstacks. 11 | 12 | Free software, released under the GNU General Public License, 13 | http://www.gnu.org/licenses/gpl.html 14 | 15 | Copyright Graeme Ball (2013), graemeball@googlemail.com, 16 | written while working at Micron Oxford: www.micron.ox.ac.uk 17 | 18 | **Latest .jar files for DOWNLOAD on the [Micron Oxford Website](http://www.micron.ox.ac.uk/microngroup/software/Temporal_plugins.jar)** 19 | 20 | The maven project structure is derived from: 21 | https://github.com/imagej/minimal-ij1-plugin 22 | 23 | Temporal Median filter 24 | ---------------------- 25 | 26 | This plugin can be used to find moving foreground features, which can be 27 | be a powerful way to suppress false background detections in subsequent 28 | tracking steps. 29 | 30 | * set time window, and standard deviations above background for foreground 31 | * time window should be more than 2x larger than time taken for a feature 32 | to traverse a pixel (NB. total window is 2x half-width +1) 33 | * moving foreground identified by intensity increase relative to background 34 | average (i.e. median) for a pixel over a given time window 35 | * "soft" segmenation, yielding foreground probability related to excess 36 | intensity (in standard deviations) over background level 37 | * crude Anscombe transform applied to data to stabilize the variance 38 | 39 | Trails 40 | ------ 41 | 42 | Averaging a short time window can be useful for enhancing signal-to-noise, 43 | and longer time windows can be used to create trajectory snapshots. 44 | 45 | * set a time window over which to average slices 46 | -------------------------------------------------------------------------------- /bin/benchmarks/original/fiji/IJ_Temporal/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | 9 | org.scijava 10 | pom-scijava 11 | 1.27 12 | 13 | 14 | uk.ac.ox.micron 15 | Temporal_plugins 16 | 1.0.0 17 | 18 | 19 | /Applications/Fiji.app 20 | 21 | 22 | plugins/Temporal_plugins.jar 23 | Temporal plugins for ImageJ 1.x - temporal median filter, trails 24 | 25 | 26 | 27 | net.imagej 28 | ij 29 | ${imagej1.version} 30 | 31 | 32 | 33 | 34 | 35 | 36 | imagej.releases 37 | http://maven.imagej.net/content/repositories/releases 38 | 39 | 40 | imagej.snapshots 41 | http://maven.imagej.net/content/repositories/snapshots 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /bin/benchmarks/original/fiji/IJ_Temporal/src/main/resources/plugins.config: -------------------------------------------------------------------------------- 1 | # Name: Temporal plugins 2 | # Author: Graeme Ball 3 | # Version: 1.0.0 4 | 5 | Plugins>Temporal, "Temporal Median", TemporalMedian_ 6 | Plugins>Temporal, "Trails", Trails_ 7 | -------------------------------------------------------------------------------- /bin/benchmarks/original/fiji/IJ_Trails/README.md: -------------------------------------------------------------------------------- 1 | Temporal Plugins 2 | ================ 3 | 4 | This Maven project implements ImageJ 1.x plugins for time sequences: 5 | 6 | * Temporal median: finds moving foreground features, see 7 | Parton et al. (2011), JCB 194 (1): 121. 8 | * Trails: does simple averaging over a time window, making tracks visible. 9 | 10 | The plugins ought to work for hyperstacks. 11 | 12 | Free software, released under the GNU General Public License, 13 | http://www.gnu.org/licenses/gpl.html 14 | 15 | Copyright Graeme Ball (2013), graemeball@googlemail.com, 16 | written while working at Micron Oxford: www.micron.ox.ac.uk 17 | 18 | **Latest .jar files for DOWNLOAD on the [Micron Oxford Website](http://www.micron.ox.ac.uk/microngroup/software/Temporal_plugins.jar)** 19 | 20 | The maven project structure is derived from: 21 | https://github.com/imagej/minimal-ij1-plugin 22 | 23 | Temporal Median filter 24 | ---------------------- 25 | 26 | This plugin can be used to find moving foreground features, which can be 27 | be a powerful way to suppress false background detections in subsequent 28 | tracking steps. 29 | 30 | * set time window, and standard deviations above background for foreground 31 | * time window should be more than 2x larger than time taken for a feature 32 | to traverse a pixel (NB. total window is 2x half-width +1) 33 | * moving foreground identified by intensity increase relative to background 34 | average (i.e. median) for a pixel over a given time window 35 | * "soft" segmenation, yielding foreground probability related to excess 36 | intensity (in standard deviations) over background level 37 | * crude Anscombe transform applied to data to stabilize the variance 38 | 39 | Trails 40 | ------ 41 | 42 | Averaging a short time window can be useful for enhancing signal-to-noise, 43 | and longer time windows can be used to create trajectory snapshots. 44 | 45 | * set a time window over which to average slices 46 | -------------------------------------------------------------------------------- /bin/benchmarks/original/fiji/IJ_Trails/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | 9 | org.scijava 10 | pom-scijava 11 | 1.27 12 | 13 | 14 | uk.ac.ox.micron 15 | Temporal_plugins 16 | 1.0.0 17 | 18 | 19 | /Applications/Fiji.app 20 | 21 | 22 | plugins/Temporal_plugins.jar 23 | Temporal plugins for ImageJ 1.x - temporal median filter, trails 24 | 25 | 26 | 27 | net.imagej 28 | ij 29 | ${imagej1.version} 30 | 31 | 32 | 33 | 34 | 35 | 36 | imagej.releases 37 | http://maven.imagej.net/content/repositories/releases 38 | 39 | 40 | imagej.snapshots 41 | http://maven.imagej.net/content/repositories/snapshots 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /bin/benchmarks/original/fiji/IJ_Trails/src/main/resources/plugins.config: -------------------------------------------------------------------------------- 1 | # Name: Temporal plugins 2 | # Author: Graeme Ball 3 | # Version: 1.0.0 4 | 5 | Plugins>Temporal, "Temporal Median", TemporalMedian_ 6 | Plugins>Temporal, "Trails", Trails_ 7 | -------------------------------------------------------------------------------- /bin/benchmarks/original/phoenix/Histogram.java: -------------------------------------------------------------------------------- 1 | package original.phoenix; 2 | 3 | import java.util.List; 4 | 5 | class Histogram { 6 | 7 | public static class Pixel { 8 | public int r, g, b; 9 | 10 | public Pixel(int r, int g, int b) { 11 | this.r = r; 12 | this.g = g; 13 | this.b = b; 14 | } 15 | } 16 | 17 | public static int[][] histogram(List image, int[] hR, int[] hG, int[] hB) { 18 | for (int i = 0; i < image.size(); i += 1) { 19 | int r = image.get(i).r; 20 | int g = image.get(i).g; 21 | int b = image.get(i).b; 22 | hR[r]++; 23 | hG[g]++; 24 | hB[b]++; 25 | } 26 | 27 | int[][] result = new int[3][]; 28 | result[0] = hR; 29 | result[1] = hG; 30 | result[2] = hB; 31 | 32 | return result; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /bin/benchmarks/original/phoenix/KMeansJava.java: -------------------------------------------------------------------------------- 1 | package original.phoenix; 2 | 3 | /** 4 | * 5 | * Translation of Phoenix k-means implementation 6 | * 7 | */ 8 | 9 | public class KMeansJava { 10 | 11 | private static class Result{ 12 | public Double[][] means; 13 | public int[] clusters; 14 | boolean modified; 15 | 16 | Result(Double[][] m, int[] c, boolean mod){ 17 | this.means = m; 18 | this.clusters = c; 19 | this.modified = mod; 20 | } 21 | } 22 | 23 | final int GRID_SIZE = 1000; 24 | 25 | public static void main(String[] args) { 26 | 27 | int numPoints = 1000, numMeans = 10, dim = 3; 28 | 29 | Double[][] points = generatePoints(numPoints, dim); 30 | Double[][] means = generatePoints(numMeans, dim); 31 | int[] clusters = new int[numPoints]; 32 | 33 | boolean modified = false; 34 | 35 | while (!modified) { 36 | modified = findClustersAndCalcMeans(points,means, 37 | clusters).modified; 38 | } 39 | 40 | System.out.println("\n\nFinal Means:\n"); 41 | dumpMatrix(means); 42 | } 43 | 44 | private static void dumpMatrix(Double[][] a) { 45 | for (int i = 0; i < a.length; i++) { 46 | for (int j = 0; j < a[i].length; j++) 47 | System.out.print(" " + a[i][j]); 48 | System.out.println(); 49 | } 50 | } 51 | 52 | private static Result findClustersAndCalcMeans(Double[][] points, 53 | Double[][] means, int[] clusters) { 54 | int i, j; 55 | Double minDist, curDist; 56 | int minIdx; 57 | int dim = points[0].length; 58 | boolean modified = false; 59 | for (i = 0; i < points.length; i++) { 60 | minDist = getSqDist(points[i], means[0]); 61 | minIdx = 0; 62 | for (j = 1; j < means.length; j++) { 63 | curDist = getSqDist(points[i], means[j]); 64 | if (curDist < minDist) { 65 | minDist = curDist; 66 | minIdx = j; 67 | } 68 | } 69 | 70 | if (clusters[i] != minIdx) { 71 | clusters[i] = minIdx; 72 | modified = true; 73 | } 74 | } 75 | 76 | for (int ii = 0; ii < means.length; ii++) { 77 | Double[] sum = new Double[dim]; 78 | int groupSize = 0; 79 | for (int jj = 0; jj < points.length; jj++) { 80 | if (clusters[jj] == ii) { 81 | sum = add(sum, points[jj]); 82 | groupSize++; 83 | } 84 | } 85 | dim = points[0].length; 86 | Double[] meansi = means[ii]; 87 | for (int kk = 0; kk < dim; kk++) { 88 | if (groupSize != 0) { 89 | meansi[kk] = sum[kk] / groupSize; 90 | } 91 | } 92 | means[ii] = meansi; 93 | } 94 | return new Result(means, clusters, modified); 95 | } 96 | 97 | private static Double[] add(Double[] v1, Double[] v2) { 98 | Double[] sum = new Double[v1.length]; 99 | for (int i = 0; i < sum.length; i++) 100 | sum[i] = v1[i] + v2[i]; 101 | return sum; 102 | } 103 | 104 | private static Double getSqDist(Double[] v1, Double[] v2) { 105 | Double dist = 0.0; 106 | for (int i = 0; i < v1.length; i++) 107 | dist += ((v1[i] - v2[i]) * (v1[i] - v2[i])); 108 | return dist; 109 | } 110 | 111 | private static Double[][] generatePoints(int numPoints, int dim) { 112 | Double[][] p = new Double[numPoints][dim]; 113 | for (int i = 0; i < numPoints; i++) { 114 | p[i] = new Double[dim]; 115 | for (int j = 0; j < dim; j++) 116 | p[i][j] = Math.random(); 117 | } 118 | return p; 119 | } 120 | 121 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/phoenix/LinearRegression.java: -------------------------------------------------------------------------------- 1 | package original.phoenix; 2 | 3 | import java.util.List; 4 | 5 | public class LinearRegression { 6 | 7 | public static class Point { 8 | public int x, y; 9 | 10 | public Point(int x, int y) { 11 | this.x = x; 12 | this.y = y; 13 | } 14 | } 15 | 16 | public static int[] regress(List points) { 17 | int SX_ll = 0, SY_ll = 0, SXX_ll = 0, SYY_ll = 0, SXY_ll = 0; 18 | 19 | // ADD UP RESULTS 20 | for (int i = 0; i < points.size(); i++) { 21 | // Compute SX, SY, SYY, SXX, SXY 22 | SX_ll += points.get(i).x; 23 | SXX_ll += points.get(i).x * points.get(i).x; 24 | SY_ll += points.get(i).y; 25 | SYY_ll += points.get(i).y * points.get(i).y; 26 | SXY_ll += points.get(i).x * points.get(i).y; 27 | } 28 | int[] result = new int[5]; 29 | result[0] = SX_ll; 30 | result[1] = SXX_ll; 31 | result[2] = SY_ll; 32 | result[3] = SYY_ll; 33 | result[4] = SXY_ll; 34 | return result; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/phoenix/StringMatch.java: -------------------------------------------------------------------------------- 1 | package original.phoenix; 2 | 3 | import java.util.List; 4 | 5 | public class StringMatch { 6 | public static boolean[] matchWords(List words) { 7 | String key1 = "key1"; 8 | String key2 = "key2"; 9 | String key3 = "key3"; 10 | 11 | boolean foundKey1 = false; 12 | boolean foundKey2 = false; 13 | boolean foundKey3 = false; 14 | 15 | for(int i=0; i countWords(List words) { 9 | Map counts = new HashMap(); 10 | for (int j = 0; j < words.size(); j++) { 11 | String word = words.get(j); 12 | Integer prev = counts.get(word); 13 | if (prev == null) 14 | prev = 0; 15 | counts.put(word, prev + 1); 16 | } 17 | return counts; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /bin/benchmarks/original/stats/AverageData.java: -------------------------------------------------------------------------------- 1 | package original.stats; 2 | 3 | /** 4 | * AverageData.java 5 | * ============= 6 | * 7 | * This is a program to help with data analysis. 8 | * You can open a one column array and average all the data points. 9 | * File must be in the format where the first line gives its length 10 | * e.g. 11 | * length = 30 12 | * x_1 13 | * x_2 14 | * * 15 | * * 16 | * * 17 | * * 18 | * x + n 19 | * 20 | * Copyright (C) 2013-2014 Magdalen Berns 21 | * 22 | * This program is free software: you can redistribute it and/or modify 23 | * it under the terms of the GNU General Public License as published by 24 | * the Free Software Foundation, either version 3 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This program is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU General Public License for more details. 31 | 32 | * You should have received a copy of the GNU General Public License 33 | * along with this program. If not, see . 34 | */ 35 | 36 | import java.io.BufferedReader; 37 | import java.io.FileReader; 38 | import java.io.IOException; 39 | import java.io.PrintWriter; 40 | import java.util.Scanner; 41 | 42 | public class AverageData { 43 | 44 | public static void main(String[] args) throws IOException{ 45 | System.out.printf("Please type the name of the data file you wish to average. \n"); 46 | String choice= IOUtil.getFileName(); 47 | 48 | if ( !choice.equals(null) ) { 49 | Scanner scan = new Scanner(new BufferedReader(new FileReader("files/"+choice))); 50 | int length = IOUtil.skipToInt(scan); 51 | double[] data = PlotReader.data1Column(scan,length); 52 | double mean = StatsUtil.mean(data); 53 | System.out.printf("Mean value %g \n", mean); 54 | System.out.printf("std Dev value %g \n", Math.sqrt(StatsUtil.variance(data,mean))); 55 | System.exit(0); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/stats/Calculate.java: -------------------------------------------------------------------------------- 1 | package original.stats; 2 | 3 | /** 4 | * Calculate.java 5 | * ============= 6 | * 7 | * Copyright (C) 2013-2014 Magdalen Berns 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | public class Calculate{ 24 | 25 | private double num1, num; 26 | 27 | //Initialise instance variables to be used by instance methods. 28 | public Calculate(){ 29 | num1=0.0; 30 | num=0.0; 31 | } 32 | 33 | /** 34 | * subtract 35 | * Method to subtract one double from another 36 | * @param a 37 | * double value to subtract b from 38 | * @param b 39 | * double value to be subtracted from a 40 | * @return 41 | * Double result of subtracting b from a 42 | */ 43 | public static double subtract(double a, double b){ 44 | return a - b; 45 | } 46 | 47 | /** 48 | * add 49 | * Method to add one double to another 50 | * @param a 51 | * double value to be added to b 52 | * @param b 53 | * double value to be added to a 54 | * @return 55 | * Double result of adding a to b 56 | */ 57 | public static double add(double a,double b){ 58 | return a+b; 59 | } 60 | 61 | /** 62 | * divide 63 | * Method to divide one double over another 64 | * @param a 65 | * double value to be divided by b 66 | * @param b 67 | * double value to divide a by 68 | * @return 69 | * Double result of dividing a from b 70 | */ 71 | public static double divide(double a, double b){ 72 | return a/b; 73 | } 74 | 75 | /** 76 | * multiply 77 | * Method to multiply one method to another 78 | * @param a 79 | * Double value to be multiplied by b 80 | * @param b 81 | * Double value to multiplied by a 82 | * @return 83 | * Double result of a * b 84 | */ 85 | public static double multiply(double a, double b){ 86 | return a*b; 87 | } 88 | 89 | /** 90 | * subtract 91 | * Instance method to subtract one double from another 92 | * @param num2 93 | * double value to be subtracted from num1 94 | * @return 95 | * Double result of subtracting num1 to num2 96 | */ 97 | public double subtract(double num2){ 98 | return num1-num2; 99 | } 100 | 101 | /** 102 | * add 103 | * Instance method to add one double to another 104 | * @param num2 105 | * double value to be added to num1 106 | * @return 107 | * Double result of adding num1 to num2 108 | */ 109 | public double add(double num2){ 110 | return num1+num2; 111 | } 112 | 113 | public double divide(double num2){ 114 | return num1/num2; 115 | } 116 | 117 | public double multiply(double num2){ 118 | return num1*num2; 119 | } 120 | 121 | public static double[] multiply(double[] a, double b){ 122 | double[] temp= new double[a.length]; 123 | for(int i=0; i. 22 | */ 23 | 24 | import java.io.BufferedReader; 25 | import java.io.FileReader; 26 | import java.io.IOException; 27 | import java.io.PrintWriter; 28 | import java.util.Scanner; 29 | 30 | public class ExtractColumn { 31 | 32 | public static void main(String[] args) throws IOException { 33 | 34 | System.out.printf("Which file would you like to pull a column out of? \n"); 35 | String inFileName = IOUtil.getFileName(); 36 | if(inFileName.equals("!")){ 37 | System.out.println("No file selected."); 38 | } 39 | else{ 40 | 41 | Scanner scan = new Scanner(new BufferedReader(new FileReader("files/"+inFileName))); 42 | PrintWriter outFile = new PrintWriter("column.txt"); 43 | int length = IOUtil.skipToInt(scan); 44 | double xError=IOUtil.skipToDouble(scan); 45 | double yError= IOUtil.skipToDouble(scan); 46 | double[][] data = PlotReader.data2Column(scan,length); 47 | PlotUtil p = new PlotUtil(data); 48 | 49 | PlotWriter.aColumn(p.y(),outFile); 50 | outFile.close(); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/stats/FormatData.java: -------------------------------------------------------------------------------- 1 | package original.stats; 2 | 3 | /** 4 | * Format Data.java 5 | * ============= 6 | * This file is a part of a program which serves as a utility for data analysis 7 | * of experimental data 8 | * 9 | * Copyright (C) 2013-2014 Magdalen Berns 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | import java.io.BufferedReader; 24 | import java.io.FileReader; 25 | import java.io.IOException; 26 | import java.io.PrintWriter; 27 | import java.util.Scanner; 28 | 29 | public class FormatData { 30 | 31 | public static void main(String[] args) throws IOException { 32 | String fileName = IOUtil.getFileName(); 33 | 34 | Scanner scan = new Scanner(new BufferedReader(new FileReader("files/"+fileName))); 35 | PrintWriter fitFout = new PrintWriter("files/data_"+fileName); 36 | 37 | int length = IOUtil.skipToInt(scan); 38 | 39 | double xError=IOUtil.skipToDouble(scan); 40 | double yError= IOUtil.skipToDouble(scan); 41 | double[][] data = PlotReader.data2Column(scan,length); 42 | PlotUtil p = new PlotUtil(data); 43 | 44 | PlotWriter.errors(p.x(), p.y(),xError,Calculate.multiply(p.y(),yError), fitFout); 45 | fitFout.close(); 46 | } 47 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/stats/IOUtil.java: -------------------------------------------------------------------------------- 1 | package original.stats; 2 | 3 | /** 4 | * IOUtil.java 5 | * ============ 6 | * Copyright (C) 2013 Magdalen Berns 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * This file provides a library of static methods for handling common 19 | * IO requirements. 20 | */ 21 | 22 | import java.util.Scanner; 23 | import java.io.*; 24 | 25 | public class IOUtil{ 26 | 27 | /* 28 | * does not accept anything but doubles 29 | * @ return the first double 30 | */ 31 | public static double skipToDouble(Scanner scanner){ 32 | 33 | while (scanner.hasNext() && !scanner.hasNextDouble()){ 34 | scanner.next(); 35 | } 36 | return scanner.hasNextDouble() ? scanner.nextDouble() : Double.NaN; 37 | } 38 | 39 | public static FileReader file(String fileName) throws FileNotFoundException { 40 | return new FileReader(fileName); 41 | } 42 | //read the user input 43 | public static String typedInput() throws IOException { 44 | BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in)); 45 | return keyIn.readLine(); 46 | } 47 | 48 | /** 49 | * does not accept anything but integers 50 | * @ return the first integer value 51 | */ 52 | public static int skipToInt(Scanner scanner) { 53 | 54 | while (scanner.hasNext() && !scanner.hasNextInt()) { 55 | scanner.next(); 56 | } 57 | return scanner.hasNextInt() ? scanner.nextInt() : (int) Double.NaN;//workaround 58 | } 59 | 60 | /** 61 | * Call this every time wrong thing is typed. 62 | */ 63 | public static void abuse() { 64 | System.out.println("Invalid entry."); 65 | System.out.println("Abusive statement."); 66 | System.exit(0); 67 | } 68 | 69 | public static String fileName() throws IOException { 70 | System.out.printf("Type file name or hit '!' \n"); 71 | String typed= typedInput(); 72 | System.out.printf("Found %s \n", typed); 73 | return typed; 74 | } 75 | 76 | public static String getFileName() throws IOException { 77 | System.out.printf("Type file name or hit '!' \n"); 78 | String typed= typedInput(); 79 | System.out.printf("Found %s \n", typed); 80 | return typed; 81 | } 82 | 83 | public static String enterValue(String kindOf) { 84 | return "Enter " + kindOf + "value:"; 85 | } 86 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/stats/MomentInertia.java: -------------------------------------------------------------------------------- 1 | package original.stats; 2 | 3 | /* 4 | MomentInertia.java 5 | ================== 6 | 7 | A class to calculate the moment of intertia for various situations. 8 | Copyright (C) 2013 Magdalen Berns 9 | 10 | 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program. If not, see . 24 | */ 25 | 26 | 27 | class MomentInertia{ 28 | 29 | public static double centerUniformRod(double length, double mass){ 30 | return (mass * length * length )/12; 31 | } 32 | public static double sphere(double length, double mass){ 33 | return (mass * length * length )/12; 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /bin/benchmarks/original/stats/PlotReader.java: -------------------------------------------------------------------------------- 1 | package original.stats; 2 | 3 | /** 4 | * PlotUtil.java 5 | * ============== 6 | * 7 | * Copyright (C) 2013-2014 Magdalen Berns 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | import java.util.Scanner; 24 | 25 | 26 | public class PlotReader{ 27 | 28 | public static double[] data1Column(Scanner scan, int length){ 29 | double[] data=new double[length]; 30 | for (int i=0;i 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | public class PlotUtil extends IOUtil{ 24 | 25 | private double[] x, y; 26 | private double [][] data; 27 | 28 | public PlotUtil(double[][] data){ 29 | this.data=data; 30 | x = new double[data.length]; 31 | y = new double[data.length]; 32 | } 33 | 34 | /** 35 | * x 36 | * Pull out the x column data 37 | * @return: 38 | * The x component of a 1d array of doubles 39 | */ 40 | public double[] x(){ 41 | for (int i=0;i=0; i--) data[i][0] +=-offset; 64 | return data; 65 | } 66 | 67 | public static void writeToFile(double[][] data, PrintWriter fileOut){ 68 | for(int i=0; i. 25 | */ 26 | 27 | import java.io.PrintWriter; 28 | 29 | public class PlotWriter{ 30 | 31 | 32 | public static void write(double[] x, double[] y, PrintWriter fileOut){ 33 | for(int i=0; idata[0][1]){ 82 | 83 | //if so check that it's significant 84 | if(data[i][1]>largeUp && data[i][1] > minValue){ 85 | 86 | largeUp = data[i][1]; 87 | System.out.printf("%2.2f ",data[i][0]); 88 | upFile.printf("%2.2f %2.2f ",data[i][0], largeUp); 89 | upFile.println(); 90 | } 91 | } 92 | } 93 | System.out.println(); 94 | } 95 | } -------------------------------------------------------------------------------- /bin/buildCompileAndRun.sh: -------------------------------------------------------------------------------- 1 | BASEDIR=$(dirname "$0") 2 | INPUTDIR=$(readlink -f "$1") 3 | OUTPUTDIR=$(readlink -f "$2") 4 | cd $BASEDIR 5 | cd .. 6 | ant clean 7 | ant 8 | cd bin 9 | ./casperc -nooutput -stdout -w 10000 $INPUTDIR > $OUTPUTDIR 10 | nodejs indentationScript.js $OUTPUTDIR 11 | -------------------------------------------------------------------------------- /bin/casper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | prg=`basename "$0"` 4 | dir=`dirname "$0"`/.. 5 | 6 | usage() { 7 | polyglot -h 8 | cat < pass options to the Java VM 10 | -J use a different Java VM (default java in path) 11 | -V echo the java command 12 | EOF 13 | } 14 | 15 | fixclasspath() { 16 | windows=0 17 | 18 | if [ `uname | grep -c CYGWIN` -ne 0 ]; then 19 | windows=1 20 | fi 21 | 22 | cp="$1" 23 | if [ "$windows" = 1 ]; then 24 | cygpath -pw "$cp" 25 | else 26 | echo "$cp" 27 | fi 28 | } 29 | 30 | extra_cp= 31 | args= 32 | vmargs= 33 | classpath= 34 | java=java 35 | ext=casper 36 | 37 | polyglot() { 38 | eval "$java" "$vmargs" -classpath "'$classpath'" "$@" 39 | } 40 | 41 | while true; do 42 | case "$1" in 43 | "") 44 | break 45 | ;; 46 | -V) 47 | verbose=1 48 | shift 49 | ;; 50 | -classpath) 51 | shift 52 | extra_cp="$extra_cp:$1" 53 | shift 54 | ;; 55 | -j) 56 | shift 57 | vmargs="$vmargs '$1'" 58 | shift 59 | ;; 60 | -J) 61 | shift 62 | java="'$1'" 63 | shift 64 | ;; 65 | -h) 66 | usage=1 67 | break 68 | ;; 69 | *) 70 | args="$args '$1'" 71 | shift 72 | ;; 73 | esac 74 | done 75 | 76 | if [ -n "$ext" ]; then 77 | args="-ext '$ext' $args" 78 | fi 79 | 80 | 81 | classpath="$dir/compiler/classes:$dir/runtime/classes:$dir/lib/polyglot.jar:$dir/lib/java_cup.jar" 82 | if [ -n "$ext" ]; then 83 | classpath="$classpath:$dir/lib/$ext.jar" 84 | fi 85 | classpath="$classpath:$extra_cp" 86 | classpath=`fixclasspath "$classpath"` 87 | 88 | 89 | if [ "$usage" = 1 ]; then 90 | usage 91 | exit 0 92 | fi 93 | 94 | if [ "$verbose" = 1 ]; then 95 | echo "$java" "$vmargs" -classpath "'$classpath'" "$@" 96 | fi 97 | 98 | polyglot "$args" -------------------------------------------------------------------------------- /bin/casperc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | prg=`basename "$0"` 4 | dir=`dirname "$0"`/.. 5 | 6 | usage() { 7 | polyglot -h 8 | cat < pass options to the Java VM 10 | -J use a different Java VM (default java in path) 11 | -V echo the java command 12 | EOF 13 | } 14 | 15 | fixclasspath() { 16 | windows=0 17 | 18 | if [ `uname | grep -c CYGWIN` -ne 0 ]; then 19 | windows=1 20 | fi 21 | 22 | cp="$1" 23 | if [ "$windows" = 1 ]; then 24 | cygpath -pw "$cp" 25 | else 26 | echo "$cp" 27 | fi 28 | } 29 | 30 | extra_cp=/home/Maaz/Desktop/Work/Alvin/Releases/Casper/lib/imagej-1.46.jar 31 | args= 32 | vmargs=-ea 33 | classpath= 34 | java=java 35 | ext=casper 36 | 37 | polyglot() { 38 | eval "$java" "$vmargs" -classpath "'$classpath'" casper.Main "$@" 39 | } 40 | 41 | while true; do 42 | case "$1" in 43 | "") 44 | break 45 | ;; 46 | -V) 47 | verbose=1 48 | shift 49 | ;; 50 | -classpath) 51 | shift 52 | extra_cp="$extra_cp:$1" 53 | shift 54 | ;; 55 | -j) 56 | shift 57 | vmargs="$vmargs '$1'" 58 | shift 59 | ;; 60 | -J) 61 | shift 62 | java="'$1'" 63 | shift 64 | ;; 65 | -h) 66 | usage=1 67 | break 68 | ;; 69 | *) 70 | args="$args '$1'" 71 | shift 72 | ;; 73 | esac 74 | done 75 | 76 | if [ -n "$ext" ]; then 77 | args=" $args" 78 | fi 79 | 80 | 81 | classpath="$dir/compiler/classes:$dir/runtime/classes:$dir/lib/polyglot.jar:$dir/lib/java_cup.jar" 82 | if [ -n "$ext" ]; then 83 | classpath="$classpath:$dir/lib/$ext.jar" 84 | fi 85 | classpath="$classpath:$extra_cp" 86 | classpath=`fixclasspath "$classpath"` 87 | 88 | 89 | if [ "$usage" = 1 ]; then 90 | usage 91 | exit 0 92 | fi 93 | 94 | if [ "$verbose" = 1 ]; then 95 | echo "$java" "$vmargs" -classpath "'$classpath'" "$@" 96 | fi 97 | 98 | polyglot "$args" -------------------------------------------------------------------------------- /bin/check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function require-program { 4 | echo -n "checking for $1... " 5 | if ! which $1; then 6 | echo "MISSING!" 7 | return 1 8 | fi 9 | } 10 | 11 | require-program java; 12 | if [[ $? == 0 ]]; then 13 | echo "FOUND!" 14 | fi 15 | 16 | require-program nodejs; 17 | if [[ $? == 0 ]]; then 18 | echo "FOUND!" 19 | fi 20 | 21 | require-program dafny; 22 | if [[ $? == 0 ]]; then 23 | echo "FOUND!" 24 | fi 25 | 26 | require-program sketch; 27 | if [[ $? == 0 ]]; then 28 | echo "FOUND!" 29 | fi 30 | 31 | require-program ant; 32 | if [[ $? == 0 ]]; then 33 | echo "FOUND!" 34 | fi -------------------------------------------------------------------------------- /bin/compileAndRun.sh: -------------------------------------------------------------------------------- 1 | BASEDIR=$(dirname "$0") 2 | INPUTDIR=$(readlink -f "$1") 3 | OUTPUTDIR=$(readlink -f "$2") 4 | cd $BASEDIR 5 | cd .. 6 | ant 7 | cd bin 8 | ./casperc -nooutput -stdout -w 10000 $INPUTDIR > $OUTPUTDIR 9 | nodejs indentationScript.js $OUTPUTDIR -------------------------------------------------------------------------------- /bin/debug.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/bin/debug.txt -------------------------------------------------------------------------------- /bin/debugRun.sh: -------------------------------------------------------------------------------- 1 | BASEDIR=$(dirname "$0") 2 | INPUTDIR=$(readlink -f "$1") 3 | OUTPUTDIR=$(readlink -f "$2") 4 | cd $BASEDIR 5 | cd .. 6 | ant 7 | cd bin 8 | ./casperc -nooutput -stdout -w 10000 $INPUTDIR slow > $OUTPUTDIR 9 | nodejs indentationScript.js $OUTPUTDIR 10 | -------------------------------------------------------------------------------- /bin/output/Average.sk: -------------------------------------------------------------------------------- 1 | struct Average{ 2 | } -------------------------------------------------------------------------------- /bin/output/Count.sk: -------------------------------------------------------------------------------- 1 | struct Count{ 2 | } -------------------------------------------------------------------------------- /bin/output/MaxAbs.sk: -------------------------------------------------------------------------------- 1 | struct MaxAbs{ 2 | } -------------------------------------------------------------------------------- /bin/output/Mean.sk: -------------------------------------------------------------------------------- 1 | struct Mean{ 2 | } -------------------------------------------------------------------------------- /bin/output/Min.sk: -------------------------------------------------------------------------------- 1 | struct Min{ 2 | } -------------------------------------------------------------------------------- /bin/output/MulVecSca.sk: -------------------------------------------------------------------------------- 1 | struct MulVecSca{ 2 | } -------------------------------------------------------------------------------- /bin/output/Sum.sk: -------------------------------------------------------------------------------- 1 | struct Sum{ 2 | } -------------------------------------------------------------------------------- /bin/output/main_double_0.dfy: -------------------------------------------------------------------------------- 1 | /***************************** INCLUDES *************************************/ 2 | include "utils.dfy" 3 | 4 | /******************************* UDTS ***************************************/ 5 | class MulVecSca{ 6 | } 7 | 8 | 9 | /***************************** DO MAP ***************************************/ 10 | 11 | function emit_0_0(a: seq, i0: int, i: int, loop0: bool, b: int) : 12 | 13 | ensures emit_0_0(a, i0, i, loop0, b) == [((1,i),(b*a[i],b))] 14 | { 15 | [((1,i),(b*a[i],b))] 16 | } 17 | 18 | 19 | 20 | function domap_0 (a: seq, i0: int, i: int, loop0: bool, b: int) : 21 | 22 | ensures domap_0(a, i0, i, loop0, b) == emit_0_0(a, i0, i, loop0, b) 23 | { 24 | emit_0_0(a, i0, i, loop0, b) 25 | } 26 | 27 | /***************************** MAPPER ***************************************/ 28 | 29 | function mapper_0 (a: seq, i0: int, i: int, loop0: bool, b: int) : 30 | 31 | { 32 | if then [] 33 | else domap_0(a, i0, i-1, loop0, b) + mapper_0(a, i0, i-1, loop0, b) 34 | } 35 | 36 | /***************************** DO REDUCE ************************************/ 37 | 38 | 39 | 40 | 41 | 42 | /******************************* HARNESS ************************************/ 43 | 44 | predicate loopInvariant (a: seq, temp: seq, temp0: seq, i: int, i0: int, loop0: bool, b: int) 45 | requires |temp| == |temp0| 46 | 47 | { 48 | 0 <= i <= |a| && 49 | (forall k :: 0 <= k < |temp| ==> temp[k] == (mapper_0(,loop0,b,temp0))[k]) 50 | } 51 | 52 | predicate postCondition (a: seq, temp: seq, temp0: seq, i: int, i0: int, loop0: bool, b: int) 53 | requires |temp| == |temp0| 54 | 55 | { 56 | i == |a| && 57 | (forall k :: 0 <= k < |temp| ==> temp[k] == (mapper_0(,loop0,b,temp0))[k]) 58 | } 59 | 60 | method harness (a: seq, temp: seq, temp0: seq, b: int, i: int) 61 | requires |temp| == |temp0| 62 | requires forall k :: 0 <= k < |temp0| ==> temp0[k] == 0 63 | { 64 | var loop0 := false; 65 | var i0 := 0; 66 | 67 | assert loopInvariant(a,temp0,temp0,i0,i0,loop0,b); 68 | 69 | if(loopInvariant(a,temp,temp0,i,i0,loop0,b) && (i<|a|)) 70 | { 71 | assert loopInvariant(a,int_setter(temp,i,(int_getter(a,i)*b)),temp0,(i+1),i0,loop0,b); 72 | } 73 | 74 | if(loopInvariant(a,temp,temp0,i,i0,loop0,b) && !(i<|a|)) 75 | { 76 | assert postCondition(a,temp,temp0,i,0,loop0,b); 77 | } 78 | } -------------------------------------------------------------------------------- /bin/output/main_double_0.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/bin/output/main_double_0.txt -------------------------------------------------------------------------------- /bin/output/main_int_0.dfy: -------------------------------------------------------------------------------- 1 | /***************************** INCLUDES *************************************/ 2 | include "utils.dfy" 3 | 4 | /******************************* UDTS ***************************************/ 5 | class Count{ 6 | } 7 | 8 | 9 | /***************************** DO MAP ***************************************/ 10 | 11 | 12 | 13 | 14 | 15 | /***************************** MAPPER ***************************************/ 16 | 17 | 18 | 19 | /***************************** DO REDUCE ************************************/ 20 | 21 | function reduce_0_count(val1: int, val2: int, loop0: bool, count0: int) : int 22 | { 23 | (1+val1) 24 | } 25 | 26 | 27 | function doreduce_0(data: seq, i: int, loop0: bool, count0: int) : int 28 | requires 0 <= i <= |data| 29 | { 30 | if i == 0 then 0 31 | else (reduce_0_count(doreduce_0(data,i-1,loop0,count0),data[i-1],loop0,count0)) 32 | } 33 | 34 | /******************************* HARNESS ************************************/ 35 | 36 | predicate loopInvariant (data: seq, count: int, count0: int, i: int, i0: int, loop0: bool) 37 | 38 | { 39 | 0 <= i <= |data| && 40 | (count == (doreduce_0(data,i,loop0,count0))) 41 | } 42 | 43 | predicate postCondition (data: seq, count: int, count0: int, i: int, i0: int, loop0: bool) 44 | 45 | { 46 | i == |data| && 47 | (count == (doreduce_0(data,i,loop0,count0))) 48 | } 49 | 50 | method harness (data: seq, count: int, i: int) 51 | 52 | { 53 | var count0 := 0; 54 | var loop0 := false; 55 | var i0 := 0; 56 | 57 | assert loopInvariant(data,count0,count0,i0,i0,loop0); 58 | 59 | if(loopInvariant(data,count,count0,i,i0,loop0) && (i<|data|)) 60 | { 61 | assert loopInvariant(data,(count+1),count0,(i+1),i0,loop0); 62 | } 63 | 64 | if(loopInvariant(data,count,count0,i,i0,loop0) && !(i<|data|)) 65 | { 66 | assert postCondition(data,count,0,i,0,loop0); 67 | } 68 | } -------------------------------------------------------------------------------- /bin/output/outputTempDafny.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/bin/output/outputTempDafny.txt -------------------------------------------------------------------------------- /bin/output/utils.dfy: -------------------------------------------------------------------------------- 1 | /***************************** UTIL Functions *******************************/ 2 | function casper_str_equal(val1: int, val2: int) : bool 3 | { 4 | val1 == val2 5 | } 6 | 7 | function casper_math_sqrt(val: int) : int 8 | requires val >= 0 9 | { 10 | casper_math_sqrt2(val,0) 11 | } 12 | 13 | function casper_math_sqrt2(val: int, i: int) : int 14 | requires val >= 0 15 | { 16 | if i*i < val then casper_math_sqrt2(val,i+1) 17 | else i 18 | } 19 | 20 | function casper_math_abs(val: int): int 21 | { 22 | if val < 0 then val*-1 23 | else val 24 | } 25 | 26 | function casper_math_min(val1: int, val2: int): int 27 | { 28 | if val1 < val2 then val1 29 | else val2 30 | } 31 | 32 | function casper_math_max(val1: int, val2: int): int 33 | { 34 | if val1 < val2 then val2 35 | else val1 36 | } 37 | 38 | function casper_math_pow(val1: int, val2: int): int 39 | requires val2 >= 0 40 | { 41 | if val2 == 0 then 1 42 | else val1 * casper_math_pow(val1, val2-1) 43 | } 44 | 45 | function casper_math_ceil(val: int): int 46 | { 47 | (val + 9) / 10 48 | } 49 | function int_setter(arrayvar: seq, index: int, value: int value) : seq { 50 | arrayvar[index := value] 51 | } 52 | 53 | function int_getter(arrayvar: seq, index: int) : int { 54 | arrayvar[index] 55 | } 56 | 57 | function int_ite(condition: bool, op1: int, op2: int) : int { 58 | if condition then op1 else op2 59 | } 60 | 61 | function intarray_ite(condition: bool, op1: seq, op2: seq) : seq { 62 | if condition then op1 else op2 63 | } -------------------------------------------------------------------------------- /bin/output/utils.sk: -------------------------------------------------------------------------------- 1 | bit casper_str_equal(int casper_a, int casper_b){ 2 | return casper_a == casper_b; 3 | } 4 | 5 | generator bit[32] casper_genRandBitVec(){ 6 | bit[32] casper_val; 7 | casper_val[0] = {| 0 | 1 |}; 8 | casper_val[1] = {| 0 | 1 |}; 9 | casper_val[2] = {| 0 | 1 |}; 10 | casper_val[3] = {| 0 | 1 |}; 11 | casper_val[4] = {| 0 | 1 |}; 12 | casper_val[5] = {| 0 | 1 |}; 13 | casper_val[6] = {| 0 | 1 |}; 14 | casper_val[7] = {| 0 | 1 |}; 15 | casper_val[8] = {| 0 | 1 |}; 16 | casper_val[9] = {| 0 | 1 |}; 17 | casper_val[10] = {| 0 | 1 |}; 18 | casper_val[11] = {| 0 | 1 |}; 19 | casper_val[12] = {| 0 | 1 |}; 20 | casper_val[13] = {| 0 | 1 |}; 21 | casper_val[14] = {| 0 | 1 |}; 22 | casper_val[15] = {| 0 | 1 |}; 23 | casper_val[16] = {| 0 | 1 |}; 24 | casper_val[17] = {| 0 | 1 |}; 25 | casper_val[18] = {| 0 | 1 |}; 26 | casper_val[19] = {| 0 | 1 |}; 27 | casper_val[20] = {| 0 | 1 |}; 28 | casper_val[21] = {| 0 | 1 |}; 29 | casper_val[22] = {| 0 | 1 |}; 30 | casper_val[23] = {| 0 | 1 |}; 31 | casper_val[24] = {| 0 | 1 |}; 32 | casper_val[25] = {| 0 | 1 |}; 33 | casper_val[26] = {| 0 | 1 |}; 34 | casper_val[27] = {| 0 | 1 |}; 35 | casper_val[28] = {| 0 | 1 |}; 36 | casper_val[29] = {| 0 | 1 |}; 37 | casper_val[30] = {| 0 | 1 |}; 38 | casper_val[31] = {| 0 | 1 |}; 39 | return casper_val; 40 | } 41 | 42 | int casper_math_pow(int casper_a, int casper_b){ 43 | if(casper_b == 0) 44 | return 1; 45 | if(casper_b == 1) 46 | return casper_a; 47 | if(casper_b == 2) 48 | return casper_a*casper_a; 49 | if(casper_b == 3) 50 | return casper_a*casper_a*casper_a; 51 | if(casper_b == 4) 52 | return casper_a*casper_a*casper_a*casper_a; 53 | if(casper_b == 5) 54 | return casper_a*casper_a*casper_a*casper_a*casper_a; 55 | if(casper_b == 6) 56 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 57 | if(casper_b == 7) 58 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 59 | if(casper_b == 8) 60 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 61 | if(casper_b == 9) 62 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 63 | if(casper_b == 10) 64 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 65 | } 66 | 67 | int casper_math_sqrt(int casper_b){ 68 | if(casper_b == 0) 69 | return 0; 70 | if(casper_b == 1) 71 | return 1; 72 | if(casper_b == 2) 73 | return 1; 74 | if(casper_b == 3) 75 | return 2; 76 | if(casper_b == 4) 77 | return 2; 78 | if(casper_b == 5) 79 | return 2; 80 | if(casper_b == 6) 81 | return 2; 82 | if(casper_b == 7) 83 | return 3; 84 | if(casper_b == 8) 85 | return 3; 86 | if(casper_b == 9) 87 | return 3; 88 | if(casper_b == 10) 89 | return 3; 90 | } 91 | 92 | int casper_math_ceil(int casper_a){ 93 | return (casper_a + 9) / 10; 94 | } 95 | 96 | int casper_math_min(int casper_a, int casper_b){ 97 | if(casper_a > casper_b) 98 | return casper_b; 99 | else 100 | return casper_a; 101 | } 102 | 103 | int casper_math_max(int casper_a, int casper_b){ 104 | if(casper_a > casper_b) 105 | return casper_a; 106 | else 107 | return casper_b; 108 | } 109 | 110 | int casper_math_abs(int casper_a){ 111 | if(casper_a < 0) 112 | return casper_a * -1; 113 | else 114 | return casper_a; 115 | } 116 | 117 | bit CASPER_TRUE; 118 | bit CASPER_FALSE; 119 | 120 | int[4] int_setter(int[4] array, int index, int value){ 121 | array[index] = value; 122 | return array; 123 | } 124 | 125 | int int_getter(int[4] array, int index){ 126 | return array[index]; 127 | } 128 | 129 | int int_ite(bit condition, int op1, int op2){ 130 | if(condition) return op1; else return op2; 131 | } 132 | 133 | int[4] intarray_ite(bit condition, int[4] op1, int[4] op2){ 134 | if(condition) return op1; else return op2; 135 | } 136 | 137 | bit bit_ite(bit condition, bit op1, bit op2){ 138 | if(condition) return op1; else return op2; 139 | } -------------------------------------------------------------------------------- /bin/run.sh: -------------------------------------------------------------------------------- 1 | BASEDIR=$(dirname "$0") 2 | INPUTDIR=$(readlink -f "$1") 3 | OUTPUTDIR=$(readlink -f "$2") 4 | cd $BASEDIR 5 | ./casperc -nooutput -stdout -w 10000 $INPUTDIR > $OUTPUTDIR 6 | nodejs indentationScript.js $OUTPUTDIR 7 | -------------------------------------------------------------------------------- /bin/templates/dafny_skeleton.dfy: -------------------------------------------------------------------------------- 1 | /***************************** INCLUDES *************************************/ 2 | include "utils.dfy" 3 | 4 | /******************************* UDTS ***************************************/ 5 | 6 | 7 | /***************************** DO MAP ***************************************/ 8 | 9 | 10 | 11 | 12 | 13 | /***************************** MAPPER ***************************************/ 14 | 15 | 16 | 17 | /***************************** DO REDUCE ************************************/ 18 | 19 | 20 | 21 | 22 | 23 | /******************************* HARNESS ************************************/ 24 | 25 | predicate loopInvariant () 26 | 27 | { 28 | 29 | } 30 | 31 | predicate postCondition () 32 | 33 | { 34 | 35 | } 36 | 37 | method harness () 38 | 39 | { 40 | 41 | 42 | } -------------------------------------------------------------------------------- /bin/templates/dafny_skeleton2.dfy: -------------------------------------------------------------------------------- 1 | /***************************** INCLUDES *************************************/ 2 | include "utils.dfy" 3 | 4 | /******************************* UDTS ***************************************/ 5 | 6 | 7 | /******************************* HARNESS ************************************/ 8 | 9 | 10 | function doreduce(input: , casper_key: ) : 11 | 12 | ensures (|input| > 0 && input[0].0 == casper_key) ==> 13 | doreduce(input, casper_key) == () 14 | ensures (|input| > 0 && input[0].0 != casper_key) ==> 15 | doreduce(input, casper_key) == doreduce(input[1..], casper_key) 16 | { 17 | if input == [] then ( ) 18 | else if input[0].0 == casper_key then () 19 | else doreduce(input[1..], casper_key) 20 | } 21 | 22 | -------------------------------------------------------------------------------- /bin/templates/main_skeleton.sk: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* Include necessory packages */ 3 | 4 | include "output/utils.sk"; 5 | 6 | /******************************************************************************/ 7 | /* Global Control Variables */ 8 | int CASPER_NUM_OUTVARS = ; 9 | 10 | 11 | 12 | // Input variables decl 13 | 14 | /******************************************************************************/ 15 | /* Main function to verify the two results generated are equal */ 16 | 17 | harness void main(){ 18 | // Initialize output variables. 19 | 20 | 21 | // Initialize input data and variables 22 | 23 | // Initialize input broadcast variables 24 | CASPER_TRUE = true; 25 | CASPER_FALSE = false; 26 | 27 | // Initialize loop counters 28 | 29 | 30 | // Verification code 31 | 32 | } 33 | 34 | /******************************************************************************/ 35 | /* Verification functions */ 36 | 37 | bit postCondition(){ 38 | [] casper_r; 39 | 40 | } 41 | 42 | bit loopInvariant(){ 43 | [] casper_r; 44 | 45 | } 46 | 47 | /******************************************************************************/ 48 | /* MapReduce Implementation */ 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /bin/templates/spark_skeleton.txt: -------------------------------------------------------------------------------- 1 | SparkConf conf = new SparkConf().setAppName("spark"); 2 | JavaSparkContext sc = new JavaSparkContext(conf); 3 | 4 | 5 | 6 | JavaPairRDD<, > mapEmits = .flatMapToPair(new PairFlatMapFunction<, , >() { 7 | public Iterator, >> call( ) throws Exception { 8 | List, >> emits = new ArrayList, >>(); 9 | 10 | 11 | 12 | return emits.iterator(); 13 | } 14 | }); 15 | 16 | JavaPairRDD<, > reduceEmits = mapEmits.reduceByKey(new Function2<,,>(){ 17 | public call( val1, val2) throws Exception { 18 | 19 | } 20 | }); 21 | 22 | 23 | -------------------------------------------------------------------------------- /bin/templates/spark_skeleton_demo.txt: -------------------------------------------------------------------------------- 1 | 2 | JavaPairRDD<, > mapEmits = .flatMapToPair(new PairFlatMapFunction<, , >() { 3 | public Iterator, >> call( ) throws Exception { 4 | List, >> emits = new ArrayList, >>(); 5 | 6 | 7 | 8 | return emits.iterator(); 9 | } 10 | }); 11 | 12 | JavaPairRDD<, > reduceEmits = mapEmits.reduceByKey(new Function2<,,>(){ 13 | public call( val1, val2) throws Exception { 14 | 15 | } 16 | }); 17 | 18 | 19 | -------------------------------------------------------------------------------- /bin/templates/utils.dfy: -------------------------------------------------------------------------------- 1 | /***************************** UTIL Functions *******************************/ 2 | function casper_str_equal(val1: int, val2: int) : bool 3 | { 4 | val1 == val2 5 | } 6 | 7 | function casper_math_sqrt(val: int) : int 8 | requires val >= 0 9 | { 10 | casper_math_sqrt2(val,0) 11 | } 12 | 13 | function casper_math_sqrt2(val: int, i: int) : int 14 | requires val >= 0 15 | { 16 | if i*i < val then casper_math_sqrt2(val,i+1) 17 | else i 18 | } 19 | 20 | function casper_math_abs(val: int): int 21 | { 22 | if val < 0 then val*-1 23 | else val 24 | } 25 | 26 | function casper_math_min(val1: int, val2: int): int 27 | { 28 | if val1 < val2 then val1 29 | else val2 30 | } 31 | 32 | function casper_math_max(val1: int, val2: int): int 33 | { 34 | if val1 < val2 then val2 35 | else val1 36 | } 37 | 38 | function casper_math_pow(val1: int, val2: int): int 39 | requires val2 >= 0 40 | { 41 | if val2 == 0 then 1 42 | else val1 * casper_math_pow(val1, val2-1) 43 | } 44 | 45 | function casper_math_ceil(val: int): int 46 | { 47 | (val + 9) / 10 48 | } 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /bin/templates/utils.sk: -------------------------------------------------------------------------------- 1 | bit casper_str_equal(int casper_a, int casper_b){ 2 | return casper_a == casper_b; 3 | } 4 | 5 | generator bit[32] casper_genRandBitVec(){ 6 | bit[32] casper_val; 7 | casper_val[0] = {| 0 | 1 |}; 8 | casper_val[1] = {| 0 | 1 |}; 9 | casper_val[2] = {| 0 | 1 |}; 10 | casper_val[3] = {| 0 | 1 |}; 11 | casper_val[4] = {| 0 | 1 |}; 12 | casper_val[5] = {| 0 | 1 |}; 13 | casper_val[6] = {| 0 | 1 |}; 14 | casper_val[7] = {| 0 | 1 |}; 15 | casper_val[8] = {| 0 | 1 |}; 16 | casper_val[9] = {| 0 | 1 |}; 17 | casper_val[10] = {| 0 | 1 |}; 18 | casper_val[11] = {| 0 | 1 |}; 19 | casper_val[12] = {| 0 | 1 |}; 20 | casper_val[13] = {| 0 | 1 |}; 21 | casper_val[14] = {| 0 | 1 |}; 22 | casper_val[15] = {| 0 | 1 |}; 23 | casper_val[16] = {| 0 | 1 |}; 24 | casper_val[17] = {| 0 | 1 |}; 25 | casper_val[18] = {| 0 | 1 |}; 26 | casper_val[19] = {| 0 | 1 |}; 27 | casper_val[20] = {| 0 | 1 |}; 28 | casper_val[21] = {| 0 | 1 |}; 29 | casper_val[22] = {| 0 | 1 |}; 30 | casper_val[23] = {| 0 | 1 |}; 31 | casper_val[24] = {| 0 | 1 |}; 32 | casper_val[25] = {| 0 | 1 |}; 33 | casper_val[26] = {| 0 | 1 |}; 34 | casper_val[27] = {| 0 | 1 |}; 35 | casper_val[28] = {| 0 | 1 |}; 36 | casper_val[29] = {| 0 | 1 |}; 37 | casper_val[30] = {| 0 | 1 |}; 38 | casper_val[31] = {| 0 | 1 |}; 39 | return casper_val; 40 | } 41 | 42 | int casper_math_pow(int casper_a, int casper_b){ 43 | if(casper_b == 0) 44 | return 1; 45 | if(casper_b == 1) 46 | return casper_a; 47 | if(casper_b == 2) 48 | return casper_a*casper_a; 49 | if(casper_b == 3) 50 | return casper_a*casper_a*casper_a; 51 | if(casper_b == 4) 52 | return casper_a*casper_a*casper_a*casper_a; 53 | if(casper_b == 5) 54 | return casper_a*casper_a*casper_a*casper_a*casper_a; 55 | if(casper_b == 6) 56 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 57 | if(casper_b == 7) 58 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 59 | if(casper_b == 8) 60 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 61 | if(casper_b == 9) 62 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 63 | if(casper_b == 10) 64 | return casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a*casper_a; 65 | } 66 | 67 | int casper_math_sqrt(int casper_b){ 68 | if(casper_b == 0) 69 | return 0; 70 | if(casper_b == 1) 71 | return 1; 72 | if(casper_b == 2) 73 | return 1; 74 | if(casper_b == 3) 75 | return 2; 76 | if(casper_b == 4) 77 | return 2; 78 | if(casper_b == 5) 79 | return 2; 80 | if(casper_b == 6) 81 | return 2; 82 | if(casper_b == 7) 83 | return 3; 84 | if(casper_b == 8) 85 | return 3; 86 | if(casper_b == 9) 87 | return 3; 88 | if(casper_b == 10) 89 | return 3; 90 | } 91 | 92 | int casper_math_ceil(int casper_a){ 93 | return (casper_a + 9) / 10; 94 | } 95 | 96 | int casper_math_min(int casper_a, int casper_b){ 97 | if(casper_a > casper_b) 98 | return casper_b; 99 | else 100 | return casper_a; 101 | } 102 | 103 | int casper_math_max(int casper_a, int casper_b){ 104 | if(casper_a > casper_b) 105 | return casper_a; 106 | else 107 | return casper_b; 108 | } 109 | 110 | int casper_math_abs(int casper_a){ 111 | if(casper_a < 0) 112 | return casper_a * -1; 113 | else 114 | return casper_a; 115 | } 116 | 117 | bit CASPER_TRUE; 118 | bit CASPER_FALSE; 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /compiler/src/casper/Configuration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class to keep all configuration values. 3 | * 4 | * - Maaz 5 | */ 6 | 7 | package casper; 8 | 9 | public class Configuration { 10 | // Synthesizer bounds 11 | static public int inbits = 2; 12 | static public int arraySizeBound = 4; 13 | static public int intRange = 4; 14 | static public int loopUnrollBound = 4; 15 | 16 | // Grammar bounds 17 | static public int maxNumMROps = 5; 18 | static public int maxNumEmits = 5; 19 | static public int maxTupleSize = 5; 20 | static public int maxRecursionDepth = 5; 21 | 22 | // Run in debug mode 23 | static public boolean slow = true; 24 | } -------------------------------------------------------------------------------- /compiler/src/casper/ExtensionInfo.java: -------------------------------------------------------------------------------- 1 | package casper; 2 | 3 | import java.io.Reader; 4 | 5 | import casper.ast.JavaExtFactory_c; 6 | import casper.ast.JavaLang_c; 7 | import casper.ast.JavaNodeFactory_c; 8 | import casper.parse.Grm; 9 | import casper.parse.Lexer_c; 10 | import casper.types.JavaTypeSystem_c; 11 | import polyglot.ast.NodeFactory; 12 | import polyglot.ext.jl5.ast.JL5ExtFactory_c; 13 | import polyglot.ext.jl7.ast.JL7ExtFactory_c; 14 | import polyglot.frontend.CupParser; 15 | import polyglot.frontend.FileSource; 16 | import polyglot.frontend.Parser; 17 | import polyglot.frontend.Scheduler; 18 | import polyglot.types.TypeSystem; 19 | import polyglot.util.ErrorQueue; 20 | 21 | /** 22 | * Extension information for javatosketch extension. 23 | */ 24 | public class ExtensionInfo extends polyglot.ext.jl7.JL7ExtensionInfo { 25 | static { 26 | // force Topics to load 27 | @SuppressWarnings("unused") 28 | Topics t = new Topics(); 29 | } 30 | 31 | @Override 32 | public String defaultFileExtension() { 33 | return "java"; 34 | } 35 | 36 | @Override 37 | public String compilerName() { 38 | return "casper"; 39 | } 40 | 41 | @Override 42 | public Parser parser(Reader reader, FileSource source, ErrorQueue eq) { 43 | reader = new polyglot.lex.EscapedUnicodeReader(reader); 44 | 45 | polyglot.lex.Lexer lexer = new Lexer_c(reader, source, eq); 46 | polyglot.parse.BaseParser parser = new Grm(lexer, ts, nf, eq); 47 | 48 | return new CupParser(parser, source, eq); 49 | } 50 | 51 | @Override 52 | protected NodeFactory createNodeFactory() { 53 | return new JavaNodeFactory_c(JavaLang_c.instance, new JavaExtFactory_c(new JL7ExtFactory_c(new JL5ExtFactory_c()))); 54 | } 55 | 56 | @Override 57 | protected TypeSystem createTypeSystem() { 58 | return new JavaTypeSystem_c(); 59 | } 60 | 61 | @Override 62 | public Scheduler createScheduler() { 63 | return new CasperScheduler(this); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /compiler/src/casper/Main.java: -------------------------------------------------------------------------------- 1 | package casper; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * Main is the main program of the compiler extension. 7 | * It simply invokes Polyglot's main, passing in the extension's 8 | * ExtensionInfo. 9 | */ 10 | public class Main 11 | { 12 | public static void main(String[] args) { 13 | polyglot.main.Main polyglotMain = new polyglot.main.Main(); 14 | 15 | try { 16 | if(args.length > 5 && args[5].equals("slow")){ 17 | Configuration.slow = true; 18 | polyglotMain.start(Arrays.copyOfRange(args, 0, 5), new casper.ExtensionInfo()); 19 | } 20 | else{ 21 | polyglotMain.start(args, new casper.ExtensionInfo()); 22 | } 23 | } 24 | catch (polyglot.main.Main.TerminationException e) { 25 | System.err.println(e.getMessage()); 26 | System.exit(1); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /compiler/src/casper/Topics.java: -------------------------------------------------------------------------------- 1 | package casper; 2 | 3 | import polyglot.main.Report; 4 | 5 | /** 6 | * Extension information for javatosketch extension. 7 | */ 8 | public class Topics { 9 | public static final String casper = "casper"; 10 | 11 | static { 12 | Report.topics.add(casper); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /compiler/src/casper/Version.java: -------------------------------------------------------------------------------- 1 | package casper; 2 | 3 | /** 4 | * Version information for javatosketch extension 5 | */ 6 | public class Version extends polyglot.main.Version { 7 | @Override 8 | public String name() { 9 | return "casper"; 10 | } 11 | 12 | @Override 13 | public int major() { 14 | return 2; 15 | } 16 | 17 | @Override 18 | public int minor() { 19 | return 0; 20 | } 21 | 22 | @Override 23 | public int patch_level() { 24 | return 0; 25 | } 26 | } -------------------------------------------------------------------------------- /compiler/src/casper/ast/JavaAbstractExtFactory_c.java: -------------------------------------------------------------------------------- 1 | package casper.ast; 2 | 3 | import polyglot.ast.ExtFactory; 4 | import polyglot.ext.jl7.ast.JL7AbstractExtFactory_c; 5 | 6 | public abstract class JavaAbstractExtFactory_c extends JL7AbstractExtFactory_c 7 | implements JavaExtFactory { 8 | 9 | public JavaAbstractExtFactory_c() { 10 | super(); 11 | } 12 | 13 | public JavaAbstractExtFactory_c(ExtFactory nextExtFactory) { 14 | super(nextExtFactory); 15 | } 16 | 17 | // TODO: Implement factory methods for new extension nodes in future 18 | // extensions. This entails calling the factory method for extension's 19 | // AST superclass. 20 | } 21 | -------------------------------------------------------------------------------- /compiler/src/casper/ast/JavaExt.java: -------------------------------------------------------------------------------- 1 | package casper.ast; 2 | 3 | import polyglot.ast.Ext; 4 | import polyglot.ast.Ext_c; 5 | import polyglot.ast.Node; 6 | import polyglot.util.InternalCompilerError; 7 | import polyglot.util.SerialVersionUID; 8 | 9 | public class JavaExt extends Ext_c { 10 | private static final long serialVersionUID = SerialVersionUID.generate(); 11 | 12 | public static JavaExt ext(Node n) { 13 | Ext e = n.ext(); 14 | while (e != null && !(e instanceof JavaExt)) { 15 | e = e.ext(); 16 | } 17 | if (e == null) { 18 | throw new InternalCompilerError("No Java extension object for node " 19 | + n + " (" + n.getClass() + ")", n.position()); 20 | } 21 | return (JavaExt) e; 22 | } 23 | 24 | @Override 25 | public final JavaLang lang() { 26 | return JavaLang_c.instance; 27 | } 28 | 29 | // TODO: Override operation methods for overridden AST operations. 30 | } 31 | -------------------------------------------------------------------------------- /compiler/src/casper/ast/JavaExtFactory.java: -------------------------------------------------------------------------------- 1 | package casper.ast; 2 | 3 | import polyglot.ext.jl7.ast.JL7ExtFactory; 4 | 5 | /** 6 | * Extension factory for javatosketch extension. 7 | */ 8 | public interface JavaExtFactory extends JL7ExtFactory { 9 | // TODO: Declare any factory methods for new extension nodes. 10 | } 11 | -------------------------------------------------------------------------------- /compiler/src/casper/ast/JavaExtFactory_c.java: -------------------------------------------------------------------------------- 1 | package casper.ast; 2 | 3 | import casper.extension.MyStmtExt; 4 | import casper.extension.MyWhileExt; 5 | import polyglot.ast.Ext; 6 | import polyglot.ast.ExtFactory; 7 | 8 | public final class JavaExtFactory_c extends JavaAbstractExtFactory_c { 9 | 10 | public JavaExtFactory_c() { 11 | super(); 12 | } 13 | 14 | public JavaExtFactory_c(ExtFactory nextExtFactory) { 15 | super(nextExtFactory); 16 | } 17 | 18 | @Override 19 | protected Ext extNodeImpl() { 20 | return new JavaExt(); 21 | } 22 | 23 | @Override 24 | protected Ext extWhileImpl(){ 25 | return new MyWhileExt(); 26 | } 27 | 28 | @Override 29 | protected Ext extExtendedForImpl(){ 30 | return new MyWhileExt(); 31 | } 32 | 33 | @Override 34 | protected Ext extStmtImpl(){ 35 | return new MyStmtExt(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /compiler/src/casper/ast/JavaLang.java: -------------------------------------------------------------------------------- 1 | package casper.ast; 2 | 3 | import polyglot.ext.jl7.ast.J7Lang; 4 | 5 | public interface JavaLang extends J7Lang { 6 | // TODO: Declare any dispatch methods for new AST operations 7 | } 8 | -------------------------------------------------------------------------------- /compiler/src/casper/ast/JavaLang_c.java: -------------------------------------------------------------------------------- 1 | package casper.ast; 2 | 3 | import polyglot.ast.Ext; 4 | import polyglot.ast.Lang; 5 | import polyglot.ast.Node; 6 | import polyglot.ast.NodeOps; 7 | import polyglot.ext.jl7.ast.J7Lang_c; 8 | import polyglot.util.InternalCompilerError; 9 | 10 | public class JavaLang_c extends J7Lang_c implements JavaLang { 11 | public static final JavaLang_c instance = new JavaLang_c(); 12 | 13 | public static JavaLang lang(NodeOps n) { 14 | while (n != null) { 15 | Lang lang = n.lang(); 16 | if (lang instanceof JavaLang) return (JavaLang) lang; 17 | if (n instanceof Ext) 18 | n = ((Ext) n).pred(); 19 | else return null; 20 | } 21 | throw new InternalCompilerError("Impossible to reach"); 22 | } 23 | 24 | protected JavaLang_c() { 25 | } 26 | 27 | protected static JavaExt javatosketchExt(Node n) { 28 | return JavaExt.ext(n); 29 | } 30 | 31 | @Override 32 | protected NodeOps NodeOps(Node n) { 33 | return javatosketchExt(n); 34 | } 35 | 36 | // TODO: Implement dispatch methods for new AST operations. 37 | // TODO: Override *Ops methods for AST nodes with new extension nodes. 38 | } 39 | -------------------------------------------------------------------------------- /compiler/src/casper/ast/JavaNodeFactory.java: -------------------------------------------------------------------------------- 1 | package casper.ast; 2 | 3 | import polyglot.ext.jl7.ast.JL7NodeFactory; 4 | 5 | /** 6 | * NodeFactory for javatosketch extension. 7 | */ 8 | public interface JavaNodeFactory extends JL7NodeFactory { 9 | // TODO: Declare any factory methods for new AST nodes. 10 | } 11 | -------------------------------------------------------------------------------- /compiler/src/casper/ast/JavaNodeFactory_c.java: -------------------------------------------------------------------------------- 1 | package casper.ast; 2 | 3 | import polyglot.ext.jl7.ast.JL7NodeFactory_c; 4 | 5 | /** 6 | * NodeFactory for javatosketch extension. 7 | */ 8 | public class JavaNodeFactory_c extends JL7NodeFactory_c implements JavaNodeFactory { 9 | public JavaNodeFactory_c(JavaLang lang, JavaExtFactory extFactory) { 10 | super(lang, extFactory); 11 | } 12 | 13 | @Override 14 | public JavaExtFactory extFactory() { 15 | return (JavaExtFactory) super.extFactory(); 16 | } 17 | 18 | // TODO: Implement factory methods for new AST nodes. 19 | // TODO: Override factory methods for overridden AST nodes. 20 | // TODO: Override factory methods for AST nodes with new extension nodes. 21 | } 22 | -------------------------------------------------------------------------------- /compiler/src/casper/ast/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | AST nodes for the Java language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /compiler/src/casper/extension/MyStmtExt.java: -------------------------------------------------------------------------------- 1 | package casper.extension; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import casper.ast.JavaExt; 7 | import casper.types.CustomASTNode; 8 | 9 | public class MyStmtExt extends JavaExt { 10 | private static final long serialVersionUID = 1L; 11 | 12 | // For input/output/lc var extraction. Used to mark blocks that should be processed. 13 | public boolean process = false; 14 | 15 | // The post condition of the statement (expressed using function postCondition(..) 16 | public Map postConditions = new HashMap(); 17 | 18 | // The pre condition of the loop (expressed using function postCondition(..) 19 | public Map preConditions = new HashMap(); 20 | } 21 | -------------------------------------------------------------------------------- /compiler/src/casper/extension/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | AST extensions and delegates for the Java language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /compiler/src/casper/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Java language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /compiler/src/casper/parse/casper.ppg: -------------------------------------------------------------------------------- 1 | // Assumes polyglot.jar is in classpath 2 | include "jl7.ppg" 3 | 4 | package javatosketch.parse; 5 | 6 | import javatosketch.types.JavaTypeSystem; 7 | import javatosketch.ast.JavaNodeFactory; 8 | //import polyglot.parse.Name; 9 | //import polyglot.parse.VarDeclarator; 10 | 11 | parser Grm extends polyglot.ext.jl7.parse.Grm {: 12 | public final JavaTypeSystem ts; 13 | public final JavaNodeFactory nf; 14 | 15 | public Grm(Lexer l, TypeSystem t, NodeFactory n, ErrorQueue q) { 16 | super(l, t, n, q); 17 | ts = (JavaTypeSystem) t; 18 | nf = (JavaNodeFactory) n; 19 | } 20 | :}; 21 | 22 | start with goal; 23 | 24 | // TODO: modify the default Java grammar using PPG operations 25 | -------------------------------------------------------------------------------- /compiler/src/casper/parse/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Parser for the Java language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /compiler/src/casper/types/ArrayAccessNode.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import casper.Configuration; 7 | import casper.Util; 8 | 9 | public class ArrayAccessNode extends CustomASTNode{ 10 | 11 | public CustomASTNode array; 12 | public CustomASTNode index; 13 | 14 | private static String fixType(String t) { 15 | return (Util.getSketchTypeFromRaw(t).endsWith("["+Configuration.arraySizeBound+"]") ? 16 | Util.getSketchTypeFromRaw(t).replace("["+Configuration.arraySizeBound+"]","") : 17 | Util.getSketchTypeFromRaw(t)); 18 | } 19 | 20 | public ArrayAccessNode(String t, CustomASTNode a, CustomASTNode i) { 21 | super(fixType(t)+"_getter("+a+","+i+")"); 22 | type = t; 23 | array = a; 24 | index = i; 25 | } 26 | 27 | @Override 28 | public CustomASTNode replaceAll(String lhs, CustomASTNode rhs){ 29 | if(name.equals(lhs)){ 30 | return rhs; 31 | } 32 | CustomASTNode newIndex = index.replaceAll(lhs, rhs); 33 | CustomASTNode newArray = array.replaceAll(lhs, rhs); 34 | return new ArrayAccessNode(type,newArray,newIndex); 35 | } 36 | 37 | public String toString(){ 38 | return name; 39 | } 40 | 41 | @Override 42 | public boolean contains(String exp) { 43 | return array.contains(exp) || index.contains(exp); 44 | } 45 | 46 | @Override 47 | public void getIndexes(String arrname, Map> indexes) { 48 | if(arrname.equals(array.toString())){ 49 | if(!indexes.get(arrname).contains(index)){ 50 | indexes.get(arrname).add(index); 51 | } 52 | } 53 | array.getIndexes(arrname, indexes); 54 | index.getIndexes(arrname, indexes); 55 | } 56 | 57 | @Override 58 | public CustomASTNode fixArrays() { 59 | return new FieldNode("CasperDataRecord_getter(casper_data_set,"+index.name+")."+array.toString(),"CasperDataRecord",new ArrayAccessNode("CasperDataRecord",new IdentifierNode("casper_data_set","CasperDataRecord"),index)); 60 | } 61 | 62 | @Override 63 | public void replaceIndexesWith(String k) { 64 | if(index instanceof IdentifierNode) 65 | index = new IdentifierNode(k,index.type); 66 | else 67 | index.replaceIndexesWith(k); 68 | array.replaceIndexesWith(k); 69 | } 70 | 71 | @Override 72 | public boolean containsArrayAccess() { 73 | return index.containsArrayAccess() || array.containsArrayAccess() || index instanceof IdentifierNode; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/ArrayUpdateNode.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import casper.Util; 7 | 8 | public class ArrayUpdateNode extends CustomASTNode{ 9 | 10 | public CustomASTNode array; 11 | public CustomASTNode index; 12 | public CustomASTNode value; 13 | 14 | public ArrayUpdateNode(String t, CustomASTNode a, CustomASTNode i, CustomASTNode v) { 15 | super(""); 16 | array = a; 17 | index = i; 18 | value = v; 19 | type = t; 20 | } 21 | 22 | @Override 23 | public CustomASTNode replaceAll(String lhs, CustomASTNode rhs){ 24 | CustomASTNode newArray = array.replaceAll(lhs, rhs); 25 | CustomASTNode newIndex = index.replaceAll(lhs, rhs); 26 | CustomASTNode newValue = value.replaceAll(lhs, rhs); 27 | return new ArrayUpdateNode(type,newArray,newIndex,newValue); 28 | } 29 | 30 | public String toString(){ 31 | return Util.getSketchTypeFromRaw(type)+"_setter(" + array + ","+ index +"," + value + ")"; 32 | } 33 | 34 | @Override 35 | public boolean contains(String exp) { 36 | return array.contains(exp) || index.contains(exp) || value.contains(exp); 37 | } 38 | 39 | public String toStringDafny() { 40 | return "ind_" + array + "["+ index +" := " + value + "]"; 41 | } 42 | 43 | @Override 44 | public void getIndexes(String arrname, Map> indexes) { 45 | if(arrname.equals(array.toString())){ 46 | if(!indexes.get(arrname).contains(index)){ 47 | indexes.get(arrname).add(index); 48 | } 49 | } 50 | array.getIndexes(arrname, indexes); 51 | index.getIndexes(arrname, indexes); 52 | value.getIndexes(arrname, indexes); 53 | } 54 | 55 | @Override 56 | public CustomASTNode fixArrays() { 57 | index = index.fixArrays(); 58 | value = value.fixArrays(); 59 | return this; 60 | } 61 | 62 | @Override 63 | public void replaceIndexesWith(String k) { 64 | if(index instanceof IdentifierNode) 65 | index = new IdentifierNode(k,index.type); 66 | else 67 | index.replaceIndexesWith(k); 68 | array.replaceIndexesWith(k); 69 | value.replaceIndexesWith(k); 70 | } 71 | 72 | @Override 73 | public boolean containsArrayAccess() { 74 | return index.containsArrayAccess() || array.containsArrayAccess() || value.containsArrayAccess() || index instanceof IdentifierNode; 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/BinaryOperatorNode.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class BinaryOperatorNode extends CustomASTNode{ 7 | 8 | public CustomASTNode operandLeft; 9 | public CustomASTNode operandRight; 10 | 11 | public BinaryOperatorNode(String n, String t, CustomASTNode oleft, CustomASTNode oright) { 12 | super(n); 13 | operandLeft = oleft; 14 | operandRight = oright; 15 | type = t; 16 | } 17 | 18 | @Override 19 | public CustomASTNode replaceAll(String lhs, CustomASTNode rhs){ 20 | CustomASTNode newOperandLeft = operandLeft.replaceAll(lhs, rhs); 21 | CustomASTNode newOperandRight = operandRight.replaceAll(lhs, rhs); 22 | return new BinaryOperatorNode(name,type,newOperandLeft,newOperandRight); 23 | } 24 | 25 | public String toString(){ 26 | return "(" + operandLeft.toString() + name + operandRight.toString() + ")"; 27 | } 28 | 29 | @Override 30 | public boolean contains(String exp) { 31 | return name.equals(exp) || operandLeft.contains(exp) || operandRight.contains(exp); 32 | } 33 | 34 | @Override 35 | public void getIndexes(String arrname, Map> indexes) { 36 | operandLeft.getIndexes(arrname, indexes); 37 | operandRight.getIndexes(arrname, indexes); 38 | } 39 | 40 | @Override 41 | public int convertConstToIDs(Map constMapping, int constID){ 42 | if(casper.Util.operatorType(name) == casper.Util.RELATIONAL_OP){ 43 | if(operandLeft instanceof ConstantNode){ 44 | if(((ConstantNode) operandLeft).type_code == ConstantNode.INTLIT){ 45 | if(!constMapping.containsKey(operandLeft.toString())){ 46 | constMapping.put(operandLeft.toString(), "casperConst"+constID); 47 | constID++; 48 | } 49 | operandLeft = new IdentifierNode(constMapping.get(operandLeft.toString()),operandLeft.type); 50 | } 51 | } 52 | if(operandRight instanceof ConstantNode){ 53 | if(((ConstantNode) operandRight).type_code == ConstantNode.INTLIT){ 54 | if(!constMapping.containsKey(operandRight.toString())){ 55 | constMapping.put(operandRight.toString(), "casperConst"+constID); 56 | constID++; 57 | } 58 | operandRight = new IdentifierNode(constMapping.get(operandRight.toString()),operandRight.type); 59 | } 60 | } 61 | } 62 | return constID; 63 | } 64 | 65 | @Override 66 | public CustomASTNode fixArrays() { 67 | operandLeft = operandLeft.fixArrays(); 68 | operandRight = operandRight.fixArrays(); 69 | return this; 70 | } 71 | 72 | @Override 73 | public void replaceIndexesWith(String k) { 74 | operandLeft.replaceIndexesWith(k); 75 | operandRight.replaceIndexesWith(k); 76 | } 77 | 78 | @Override 79 | public boolean containsArrayAccess() { 80 | return operandLeft.containsArrayAccess() || operandRight.containsArrayAccess(); 81 | } 82 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/CallNode.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class CallNode extends CustomASTNode { 8 | 9 | public ArrayList arguments; 10 | 11 | public CallNode(String n, String t, ArrayList args) { 12 | super(n); 13 | arguments = args; 14 | type = t; 15 | } 16 | 17 | @Override 18 | public CustomASTNode replaceAll(String lhs, CustomASTNode rhs){ 19 | ArrayList newArgs = new ArrayList(); 20 | for(CustomASTNode arg : arguments){ 21 | newArgs.add(arg.replaceAll(lhs, rhs)); 22 | } 23 | return new CallNode(name,type,newArgs); 24 | } 25 | 26 | public String toString(){ 27 | String args = ""; 28 | for(int i=0; i> indexes) { 52 | for(CustomASTNode arg : arguments){ 53 | arg.getIndexes(arrname, indexes); 54 | } 55 | } 56 | 57 | @Override 58 | public CustomASTNode fixArrays() { 59 | ArrayList args = new ArrayList(); 60 | for(CustomASTNode arg : arguments){ 61 | args.add(arg.fixArrays()); 62 | } 63 | return new CallNode(name,type,args); 64 | } 65 | 66 | @Override 67 | public void replaceIndexesWith(String k) { 68 | for(CustomASTNode arg : arguments) 69 | arg.replaceIndexesWith(k); 70 | } 71 | 72 | @Override 73 | public boolean containsArrayAccess() { 74 | boolean res = false; 75 | for(CustomASTNode arg : arguments) 76 | if(arg.containsArrayAccess()) 77 | res = true; 78 | return res; 79 | } 80 | 81 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/ConditionalNode.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class ConditionalNode extends CustomASTNode{ 7 | 8 | CustomASTNode cond; 9 | CustomASTNode cons; 10 | CustomASTNode alt; 11 | 12 | public ConditionalNode(CustomASTNode co, CustomASTNode c, CustomASTNode a) { 13 | super(""); 14 | cond = co; 15 | cons = c; 16 | alt = a; 17 | type = c.type; 18 | 19 | assert c.type.equals(a.type); 20 | } 21 | 22 | @Override 23 | public CustomASTNode replaceAll(String lhs, CustomASTNode rhs){ 24 | CustomASTNode newCond = cond.replaceAll(lhs, rhs); 25 | CustomASTNode newCons = cons.replaceAll(lhs, rhs); 26 | CustomASTNode newAlt = alt.replaceAll(lhs, rhs); 27 | return new ConditionalNode(newCond,newCons,newAlt); 28 | } 29 | 30 | @Override 31 | public boolean contains(String exp) { 32 | return cond.contains(exp) || cons.contains(exp) || alt.contains(exp); 33 | } 34 | 35 | public String toStringDafny(String vardecl) { 36 | return ""; 37 | /*String output = "if("+cond.toString()+")\n\t\t{\n\t\t\t"; 38 | if(cons instanceof ArrayUpdateNode){ 39 | output += vardecl + ((ArrayUpdateNode) cons).toStringDafny() + ";\n\t\t} \n\t\telse \n\t\t{\n\t\t\t"; 40 | } 41 | else if(cons instanceof ConditionalNode){ 42 | output += ((ConditionalNode) cons).toStringDafny(vardecl) + "\n\t\t} else {\n\t\t\t"; 43 | } 44 | 45 | else if(cons instanceof SequenceNode){ 46 | if(((SequenceNode) cons).inst1 instanceof ConditionalNode){ 47 | output += ((SequenceNode) cons).inst1ToStringDafny(vardecl) + "\n\t\t"; 48 | } 49 | else{ 50 | output += ((SequenceNode) cons).inst1ToStringDafny(vardecl) + ";\n\t\t"; 51 | } 52 | 53 | if(((SequenceNode) cons).inst2 instanceof ConditionalNode){ 54 | output += ((SequenceNode) cons).inst2ToStringDafny(vardecl) + "\n\t\t} else {\n\t\t\t"; 55 | } 56 | else{ 57 | output += ((SequenceNode) cons).inst2ToStringDafny(vardecl) + ";\n\t\t} else {\n\t\t\t"; 58 | } 59 | } 60 | else{ 61 | output += vardecl + cons.toString() + ";\n\t\t} else \n\t\t{\n\t\t\t"; 62 | } 63 | 64 | if(alt instanceof ArrayUpdateNode){ 65 | output += vardecl + ((ArrayUpdateNode) alt).toStringDafny() + ";\n\t\t}\n\t\t"; 66 | } 67 | else if(alt instanceof ConditionalNode){ 68 | output += ((ConditionalNode) alt).toStringDafny(vardecl) + "}\n\t\t"; 69 | } 70 | else if(alt instanceof SequenceNode){ 71 | if(((SequenceNode) alt).inst1 instanceof ConditionalNode){ 72 | output += ((SequenceNode) alt).inst1ToStringDafny(vardecl) + "\n\t\t"; 73 | } 74 | else{ 75 | output += ((SequenceNode) alt).inst1ToStringDafny(vardecl) + ";\n\t\t"; 76 | } 77 | 78 | if(((SequenceNode) alt).inst2 instanceof ConditionalNode){ 79 | output += ((SequenceNode) alt).inst2ToStringDafny(vardecl) + "\n\t\t} else {\n\t\t\t"; 80 | } 81 | else{ 82 | output += ((SequenceNode) alt).inst2ToStringDafny(vardecl) + ";\n\t\t} else {\n\t\t\t"; 83 | } 84 | } 85 | else{ 86 | output += vardecl + alt.toString() + ";\n\t\t}\n\t\t"; 87 | } 88 | return output;*/ 89 | } 90 | 91 | public String toString(){ 92 | return type+"_ite(" + cond + "," + cons + "," + alt +")"; 93 | } 94 | 95 | @Override 96 | public void getIndexes(String arrname, Map> indexes) { 97 | cond.getIndexes(arrname, indexes); 98 | cons.getIndexes(arrname, indexes); 99 | alt.getIndexes(arrname, indexes); 100 | } 101 | 102 | @Override 103 | public CustomASTNode fixArrays() { 104 | cond = cond.fixArrays(); 105 | cons = cons.fixArrays(); 106 | alt = alt.fixArrays(); 107 | return this; 108 | } 109 | 110 | @Override 111 | public void replaceIndexesWith(String k) { 112 | cond.replaceIndexesWith(k); 113 | cons.replaceIndexesWith(k); 114 | alt.replaceIndexesWith(k); 115 | } 116 | 117 | @Override 118 | public boolean containsArrayAccess() { 119 | return cond.containsArrayAccess() || cons.containsArrayAccess() || alt.containsArrayAccess(); 120 | } 121 | 122 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/ConstantNode.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class ConstantNode extends CustomASTNode { 7 | 8 | public static final int INTLIT = 0; 9 | public static final int STRINGLIT = 1; 10 | public static final int BOOLEANLIT = 2; 11 | public static final int NULLLIT = 3; 12 | public static final int ARRAYLIT = 4; 13 | public static final int UNKNOWNLIT = 5; 14 | 15 | public int type_code; 16 | 17 | public ConstantNode(String n, String t, int tc) { 18 | super(n); 19 | type = t; 20 | type_code = tc; 21 | } 22 | 23 | @Override 24 | public CustomASTNode replaceAll(String lhs, CustomASTNode rhs){ 25 | // Return clone of self 26 | return new ConstantNode(name,type,type_code); 27 | } 28 | 29 | public String toString(){ 30 | return name; 31 | } 32 | 33 | @Override 34 | public boolean contains(String exp) { 35 | return name.equals(exp); 36 | } 37 | 38 | @Override 39 | public void getIndexes(String arrname, Map> indexes) { 40 | } 41 | 42 | @Override 43 | public CustomASTNode fixArrays() { 44 | return this; 45 | } 46 | 47 | @Override 48 | public void replaceIndexesWith(String k) { 49 | return; 50 | } 51 | 52 | @Override 53 | public boolean containsArrayAccess() { 54 | return false; 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/Expression.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | //Custom class to represent an expression. 4 | public class Expression{ 5 | String exp; 6 | String expType; 7 | 8 | public Expression(String e, String t){ 9 | exp = e; 10 | expType = t; 11 | } 12 | 13 | @Override 14 | public String toString(){ 15 | return "{" + exp + " : " + expType + "}"; 16 | } 17 | 18 | @Override 19 | public boolean equals(Object obj){ 20 | if(obj != null && obj instanceof Expression){ 21 | Expression inp = (Expression)obj; 22 | return this.exp.equals(inp.exp) && this.expType.equals(inp.expType); 23 | } 24 | 25 | return false; 26 | } 27 | 28 | @Override 29 | public int hashCode(){ 30 | return 0; 31 | } 32 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/FieldNode.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class FieldNode extends CustomASTNode{ 7 | 8 | public CustomASTNode container; 9 | 10 | public FieldNode(String n, String t, CustomASTNode c) { 11 | super(n); 12 | container = c; 13 | type = t; 14 | } 15 | 16 | @Override 17 | public CustomASTNode replaceAll(String lhs, CustomASTNode rhs){ 18 | if(name.equals(lhs)){ 19 | return rhs; 20 | } 21 | CustomASTNode newContainer = container.replaceAll(lhs,rhs); 22 | String[] components = name.split("\\."); 23 | String newName = newContainer.toString() + "." + components[components.length-1]; 24 | return new FieldNode(newName,type,newContainer); 25 | } 26 | 27 | public String toString(){ 28 | return name; 29 | } 30 | 31 | @Override 32 | public boolean contains(String exp) { 33 | return name.equals(exp) || container.contains(exp); 34 | } 35 | 36 | @Override 37 | public void getIndexes(String arrname, Map> indexes) { 38 | container.getIndexes(arrname, indexes); 39 | } 40 | 41 | @Override 42 | public CustomASTNode fixArrays() { 43 | container = container.fixArrays(); 44 | return this; 45 | } 46 | 47 | @Override 48 | public void replaceIndexesWith(String k) { 49 | container.replaceIndexesWith(k); 50 | } 51 | 52 | @Override 53 | public boolean containsArrayAccess() { 54 | return container.containsArrayAccess(); 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/IdentifierNode.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class IdentifierNode extends CustomASTNode { 7 | 8 | public IdentifierNode(String n, String t) { 9 | super(n); 10 | type = t; 11 | } 12 | 13 | @Override 14 | public CustomASTNode replaceAll(String lhs, CustomASTNode rhs){ 15 | if(name.equals(lhs)){ 16 | return rhs; 17 | } 18 | // Return clone of self 19 | return new IdentifierNode(name, type); 20 | } 21 | 22 | public boolean equals(Object o){ 23 | if(o instanceof IdentifierNode){ 24 | return ((IdentifierNode) o).name.equals(name); 25 | } 26 | return false; 27 | } 28 | 29 | public String toString(){ 30 | return name; 31 | } 32 | 33 | @Override 34 | public boolean contains(String exp) { 35 | return name.equals(exp); 36 | } 37 | 38 | @Override 39 | public void getIndexes(String arrname, Map> indexes) { 40 | } 41 | 42 | @Override 43 | public CustomASTNode fixArrays() { 44 | return this; 45 | } 46 | 47 | @Override 48 | public void replaceIndexesWith(String k) { 49 | return; 50 | } 51 | 52 | @Override 53 | public boolean containsArrayAccess() { 54 | return false; 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/JavaTypeSystem.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import polyglot.ext.jl7.types.JL7TypeSystem; 4 | 5 | public interface JavaTypeSystem extends JL7TypeSystem { 6 | // TODO: declare any new methods needed 7 | } 8 | -------------------------------------------------------------------------------- /compiler/src/casper/types/JavaTypeSystem_c.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import polyglot.ext.jl7.types.JL7TypeSystem_c; 4 | 5 | public class JavaTypeSystem_c extends JL7TypeSystem_c implements JavaTypeSystem { 6 | // TODO: implement new methods in JavaTypeSystem. 7 | // TODO: override methods as needed from TypeSystem_c. 8 | } 9 | -------------------------------------------------------------------------------- /compiler/src/casper/types/MRStage.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import casper.SketchParser.KvPair; 7 | 8 | public class MRStage { 9 | public int stageType = -1; 10 | public Map> mapEmits = null; 11 | public Map reduceExps = null; 12 | public Map initExps = null; 13 | public Map mergeExps = null; 14 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/UnaryOperatorNode.java: -------------------------------------------------------------------------------- 1 | package casper.types; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import polyglot.ast.Expr; 7 | 8 | public class UnaryOperatorNode extends CustomASTNode{ 9 | 10 | CustomASTNode operand; 11 | 12 | public UnaryOperatorNode(String n, CustomASTNode o) { 13 | super(n); 14 | operand = o; 15 | } 16 | 17 | @Override 18 | public CustomASTNode replaceAll(String lhs, CustomASTNode rhs){ 19 | CustomASTNode newOperand = operand.replaceAll(lhs, rhs); 20 | return new UnaryOperatorNode(name,newOperand); 21 | } 22 | 23 | public String toString(){ 24 | return "(" + name + operand.toString() + ")"; 25 | } 26 | 27 | @Override 28 | public boolean contains(String exp) { 29 | return name.equals(exp) || operand.contains(exp); 30 | } 31 | 32 | @Override 33 | public void getIndexes(String arrname, Map> indexes) { 34 | operand.getIndexes(arrname, indexes); 35 | } 36 | 37 | @Override 38 | public CustomASTNode fixArrays() { 39 | operand = operand.fixArrays(); 40 | return this; 41 | } 42 | 43 | @Override 44 | public void replaceIndexesWith(String k) { 45 | operand.replaceIndexesWith(k); 46 | } 47 | 48 | @Override 49 | public boolean containsArrayAccess() { 50 | return operand.containsArrayAccess(); 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /compiler/src/casper/types/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Type objects for the Java language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /compiler/src/casper/visit/ExtractOperators.java: -------------------------------------------------------------------------------- 1 | package casper.visit; 2 | 3 | import java.util.ArrayList; 4 | 5 | import casper.JavaLibModel; 6 | import casper.JavaLibModel.SketchCall; 7 | import casper.ast.JavaExt; 8 | import casper.extension.MyStmtExt; 9 | import casper.extension.MyWhileExt; 10 | import polyglot.ast.Binary; 11 | import polyglot.ast.Block; 12 | import polyglot.ast.Call; 13 | import polyglot.ast.If; 14 | import polyglot.ast.Node; 15 | import polyglot.ast.Unary; 16 | import polyglot.ast.While; 17 | import polyglot.ext.jl5.ast.ExtendedFor; 18 | import polyglot.visit.NodeVisitor; 19 | 20 | public class ExtractOperators extends NodeVisitor { 21 | boolean debug; 22 | boolean ignore; 23 | ArrayList extensions; 24 | 25 | public ExtractOperators(){ 26 | this.debug = false; 27 | this.ignore = true; 28 | this.extensions = new ArrayList(); 29 | } 30 | 31 | public NodeVisitor enter(Node parent, Node n){ 32 | // If the node is a loop 33 | if(n instanceof While || n instanceof ExtendedFor){ 34 | // If the loop was marked as interesting 35 | if(((MyWhileExt)JavaExt.ext(n)).interesting){ 36 | // begin extraction 37 | this.extensions.add((MyWhileExt)JavaExt.ext(n)); 38 | } 39 | } 40 | else if(n instanceof Block){ 41 | // If statement 42 | MyStmtExt stmtext = (MyStmtExt)JavaExt.ext(n); 43 | if(stmtext.process) 44 | this.ignore = false; 45 | } 46 | 47 | // If we are not extracting, then do nothing 48 | if(this.extensions.size() == 0 || this.ignore) return this; 49 | 50 | if(n instanceof Binary){ 51 | for(MyWhileExt ext : extensions){ 52 | ext.binaryOperators.add(((Binary) n).operator().toString()); 53 | } 54 | } 55 | else if(n instanceof Unary){ 56 | for(MyWhileExt ext : extensions){ 57 | ext.unaryOperators.add(((Unary) n).operator().toString()); 58 | } 59 | } 60 | else if(n instanceof Call){ 61 | for(MyWhileExt ext : extensions){ 62 | if(JavaLibModel.recognizes((Call)n)){ 63 | SketchCall call = JavaLibModel.translate((Call)n); 64 | if(call.returnType != null && !ext.methodOperators.contains(call)){ 65 | ext.methodOperators.add(call); 66 | } 67 | } 68 | 69 | } 70 | } 71 | 72 | return this; 73 | } 74 | 75 | 76 | @Override 77 | public Node leave(Node old, Node n, NodeVisitor v){ 78 | // If the node is a loop 79 | if(n instanceof While || n instanceof ExtendedFor){ 80 | // If the loop was marked as interesting 81 | if(((MyWhileExt)JavaExt.ext(n)).interesting){ 82 | 83 | if(debug){ 84 | System.err.println("Binary Operators:\n"+((MyWhileExt)JavaExt.ext(n)).binaryOperators.toString()); 85 | System.err.println("Unary Operators:\n"+((MyWhileExt)JavaExt.ext(n)).unaryOperators.toString()); 86 | System.err.println("Method Operators:\n"+((MyWhileExt)JavaExt.ext(n)).methodOperators.toString()); 87 | } 88 | 89 | this.extensions.remove(((MyWhileExt)JavaExt.ext(n))); 90 | } 91 | } 92 | else if(n instanceof Block){ 93 | MyStmtExt stmtext = (MyStmtExt)JavaExt.ext(n); 94 | if(stmtext.process) 95 | this.ignore = true; 96 | } 97 | 98 | return n; 99 | } 100 | 101 | @Override 102 | public void finish(){ 103 | if(debug) 104 | System.err.println("\n************* Finished operator extraction complier pass *************"); 105 | } 106 | } -------------------------------------------------------------------------------- /compiler/src/casper/visit/ExtractUserDefinedDataTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This compiler pass is responsible for extracting all user 3 | * defined data types in the input code and create their 4 | * model in Sketch. 5 | * 6 | * - Maaz 7 | */ 8 | 9 | package casper.visit; 10 | 11 | import java.io.FileNotFoundException; 12 | import java.io.PrintWriter; 13 | import java.io.UnsupportedEncodingException; 14 | import java.util.ArrayList; 15 | import java.util.HashMap; 16 | import java.util.HashSet; 17 | import java.util.Map; 18 | import java.util.Set; 19 | import java.util.Stack; 20 | 21 | import casper.ast.JavaExt; 22 | import casper.extension.MyWhileExt; 23 | import casper.types.Variable; 24 | import polyglot.ast.ClassDecl; 25 | import polyglot.ast.FieldDecl; 26 | import polyglot.ast.Node; 27 | import polyglot.ast.While; 28 | import polyglot.ext.jl5.ast.ExtendedFor; 29 | import polyglot.visit.NodeVisitor; 30 | 31 | public class ExtractUserDefinedDataTypes extends NodeVisitor { 32 | boolean debug; 33 | ArrayList dataTypes; 34 | ArrayList extensions; 35 | Stack classes; 36 | Map> fields; 37 | 38 | @SuppressWarnings("deprecation") 39 | public ExtractUserDefinedDataTypes(){ 40 | this.debug = false; 41 | this.dataTypes = new ArrayList(); 42 | this.extensions = new ArrayList(); 43 | this.fields = new HashMap>(); 44 | this.classes = new Stack(); 45 | } 46 | 47 | @Override 48 | public NodeVisitor enter(Node parent, Node n){ 49 | // If the node is a loop 50 | if(n instanceof While || n instanceof ExtendedFor){ 51 | // Get extension of loop node 52 | MyWhileExt ext = (MyWhileExt) JavaExt.ext(n); 53 | 54 | // If loop is interesting 55 | if(ext.interesting){ 56 | this.extensions.add(ext); 57 | } 58 | } 59 | // Class decleration found 60 | else if(n instanceof ClassDecl){ 61 | // Add new data type 62 | this.dataTypes.add(((ClassDecl) n).id().toString()); 63 | 64 | // Save name of class 65 | this.classes.push(((ClassDecl) n).id().toString()); 66 | 67 | // Create empty field set 68 | Set fieldSet = new HashSet(); 69 | this.fields.put(this.classes.peek(), fieldSet); 70 | } 71 | else if(n instanceof FieldDecl){ 72 | // Class field definition found, save it 73 | this.fields.get(this.classes.peek()).add(new Variable(((FieldDecl) n).id().toString(),((FieldDecl) n).type().toString(),"",Variable.VAR)); 74 | } 75 | 76 | if(debug){ 77 | System.err.println(n.getClass() + " ==> " + n); 78 | } 79 | 80 | return this; 81 | } 82 | 83 | @Override 84 | public Node leave(Node old, Node n, NodeVisitor v){ 85 | // Class definition ends, we already have all the 86 | // fields, generate sketch model 87 | if(n instanceof ClassDecl){ 88 | try { 89 | // Get name of class 90 | String name = this.classes.pop(); 91 | 92 | if(debug){ 93 | System.err.println(fields + " :::: " + name); 94 | } 95 | 96 | // Generate sketch class file 97 | PrintWriter writer = new PrintWriter("output/"+name+".sk", "UTF-8"); 98 | 99 | // Generate class with field variables 100 | String text = "struct " + name + "{\n\t"; 101 | for(Variable field : fields.get(name)){ 102 | text += field.getSketchType() + " " + field.varName + ";\n\t"; 103 | } 104 | text += "}"; 105 | 106 | // Write to file 107 | writer.print(text); 108 | writer.close(); 109 | } catch (FileNotFoundException | UnsupportedEncodingException e) { 110 | e.printStackTrace(); 111 | } 112 | } 113 | 114 | return n; 115 | } 116 | 117 | @Override 118 | public void finish(){ 119 | // Save data-types in all interesting loop's extensions 120 | for(MyWhileExt ext : extensions){ 121 | ext.globalDataTypes = this.dataTypes; 122 | ext.globalDataTypesFields = this.fields; 123 | } 124 | 125 | if(debug){ 126 | System.err.println("Datatypes extracted: " + this.dataTypes); 127 | System.err.println("\n************* Finished prepare sequential code complier pass *************"); 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /compiler/src/casper/visit/IdentifyDataSet.java: -------------------------------------------------------------------------------- 1 | package casper.visit; 2 | 3 | import java.util.ArrayList; 4 | 5 | import casper.ast.JavaExt; 6 | import casper.extension.MyWhileExt; 7 | import casper.types.Variable; 8 | import polyglot.ast.Node; 9 | import polyglot.ast.While; 10 | import polyglot.ext.jl5.ast.ExtendedFor; 11 | import polyglot.visit.NodeVisitor; 12 | 13 | public class IdentifyDataSet extends NodeVisitor{ 14 | boolean debug; 15 | ArrayList extensions; 16 | 17 | @SuppressWarnings("deprecation") 18 | public IdentifyDataSet(){ 19 | this.debug = false; 20 | this.extensions = new ArrayList(); 21 | } 22 | 23 | public NodeVisitor enter(Node parent, Node n){ 24 | // If the node is a loop 25 | if(n instanceof While){ 26 | MyWhileExt ext = (MyWhileExt)JavaExt.ext(n); 27 | 28 | // If the loop was marked as interesting 29 | if(ext.interesting){ 30 | for(Variable var : ext.inputVars){ 31 | if(var.category == Variable.ARRAY_ACCESS){ 32 | ext.inputDataCollections.add(var); 33 | ext.hasInputData = true; 34 | } 35 | } 36 | 37 | if(!ext.hasInputData){ 38 | for(Variable var : ext.outputVars){ 39 | if(var.category == Variable.ARRAY_ACCESS){ 40 | ext.inputDataCollections.add(var); 41 | ext.hasInputData = true; 42 | ext.initInpCollection = false; 43 | } 44 | } 45 | } 46 | 47 | if(!ext.hasInputData) 48 | ext.interesting = false; 49 | } 50 | 51 | if(debug) 52 | System.err.println(ext.inputDataCollections); 53 | } 54 | else if(n instanceof ExtendedFor){ 55 | MyWhileExt ext = (MyWhileExt)JavaExt.ext(n); 56 | 57 | // If the loop was marked as interesting 58 | if(ext.interesting){ 59 | ext.hasInputData = true; 60 | ext.extForType = true; 61 | ext.inputDataSet = new Variable(((ExtendedFor) n).expr().toString(), ((ExtendedFor) n).expr().type().toString(), "", Variable.ARRAY_ACCESS) ; 62 | } 63 | 64 | if(debug) 65 | System.err.println(ext.inputDataCollections); 66 | } 67 | return this; 68 | } 69 | 70 | @Override 71 | public void finish(){ 72 | if(debug) 73 | System.err.println("\n************* Finished identify dataset complier pass *************"); 74 | } 75 | } -------------------------------------------------------------------------------- /compiler/src/casper/visit/SelectOptimalSolution.java: -------------------------------------------------------------------------------- 1 | package casper.visit; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import casper.ast.JavaExt; 7 | import casper.extension.MyWhileExt; 8 | import casper.types.Variable; 9 | import polyglot.ast.Node; 10 | import polyglot.ast.While; 11 | import polyglot.ext.jl5.ast.ExtendedFor; 12 | import polyglot.visit.NodeVisitor; 13 | 14 | public class SelectOptimalSolution extends NodeVisitor{ 15 | boolean debug; 16 | 17 | public SelectOptimalSolution(){ 18 | this.debug = false; 19 | } 20 | 21 | @Override 22 | public Node leave(Node old, Node n, NodeVisitor v){ 23 | // If the node is a loop 24 | if(n instanceof While || n instanceof ExtendedFor){ 25 | // If the loop was marked as interesting 26 | if(((MyWhileExt)JavaExt.ext(n)).interesting){ 27 | MyWhileExt ext = (MyWhileExt) JavaExt.ext(n); 28 | 29 | Set handledTypes = new HashSet(); 30 | 31 | int typeid = 0; 32 | for(Variable var : ext.outputVars){ 33 | if(!handledTypes.contains(var.varType)){ 34 | handledTypes.add(var.varType); 35 | 36 | if(!ext.generateCode.get(var.getReduceType())) continue; 37 | 38 | // Just select the first solution right now 39 | ext.selectedSolutionIndex = 0; 40 | } 41 | } 42 | } 43 | } 44 | 45 | return n; 46 | } 47 | 48 | @Override 49 | public void finish(){ 50 | if(debug) 51 | System.err.println("\n************* Finished generate code complier pass *************"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /compiler/src/casper/visit/UpdateConfigurations.java: -------------------------------------------------------------------------------- 1 | package casper.visit; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | 7 | import polyglot.visit.NodeVisitor; 8 | import casper.Configuration; 9 | 10 | public class UpdateConfigurations extends NodeVisitor { 11 | 12 | @SuppressWarnings("deprecation") 13 | public UpdateConfigurations() throws IOException { 14 | String text = ""; 15 | 16 | BufferedReader br = new BufferedReader(new FileReader("../Config.txt")); 17 | StringBuilder sb = new StringBuilder(); 18 | String line = br.readLine(); 19 | 20 | while (line != null) { 21 | sb.append(line); 22 | sb.append(System.lineSeparator()); 23 | line = br.readLine(); 24 | } 25 | text = sb.toString(); 26 | 27 | br.close(); 28 | 29 | String[] options = text.split(","); 30 | 31 | for(String option : options){ 32 | String[] keyVal = option.split("="); 33 | keyVal[0] = keyVal[0].trim(); 34 | keyVal[1] = keyVal[1].trim(); 35 | switch(keyVal[0]){ 36 | case "Inbits": 37 | Configuration.inbits = Integer.parseInt(keyVal[1]); 38 | break; 39 | case "ArraySizeBound": 40 | Configuration.arraySizeBound = Integer.parseInt(keyVal[1]); 41 | break; 42 | case "IntRange": 43 | Configuration.intRange = Integer.parseInt(keyVal[1]); 44 | break; 45 | case "LoopUnrollBound": 46 | Configuration.loopUnrollBound = Integer.parseInt(keyVal[1]); 47 | break; 48 | case "MaxNumMROps": 49 | Configuration.maxNumMROps = Integer.parseInt(keyVal[1]); 50 | break; 51 | case "MaxNumEmits": 52 | Configuration.maxNumEmits = Integer.parseInt(keyVal[1]); 53 | break; 54 | case "MaxTupleSize": 55 | Configuration.maxTupleSize = Integer.parseInt(keyVal[1]); 56 | break; 57 | case "MaxRecursionDepth": 58 | Configuration.maxRecursionDepth = Integer.parseInt(keyVal[1]); 59 | break; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /compiler/src/casper/visit/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Visitors for the Java language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /lib/imagej-1.46.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/lib/imagej-1.46.jar -------------------------------------------------------------------------------- /lib/java_cup.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/lib/java_cup.jar -------------------------------------------------------------------------------- /lib/jflex.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/lib/jflex.jar -------------------------------------------------------------------------------- /lib/polyglot.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/lib/polyglot.jar -------------------------------------------------------------------------------- /lib/ppg.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/lib/ppg.jar -------------------------------------------------------------------------------- /lib/pth.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/lib/pth.jar -------------------------------------------------------------------------------- /pom1.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java2Sketch 4 | Java2Sketch 5 | 0.0.1-SNAPSHOT 6 | Java2Sketch 7 | A compiler that generates mapreduce sketch spec file for a java program 8 | 9 | compiler/src 10 | tests 11 | 12 | 13 | compiler/src 14 | 15 | **/*.java 16 | 17 | 18 | 19 | 20 | 21 | tests 22 | 23 | **/*.java 24 | 25 | 26 | 27 | 28 | 29 | maven-compiler-plugin 30 | 3.1 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /target/.gitignore: -------------------------------------------------------------------------------- 1 | /classes/ 2 | /test-classes/ 3 | -------------------------------------------------------------------------------- /tests/Hello.java: -------------------------------------------------------------------------------- 1 | public class Hello { 2 | public static void main(String[] args) { 3 | System.out.println("Hello world!"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/ProjectTester.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class ProjectTester { 4 | 5 | public static final String PATH = "./bin/benchmarks/CompilerTests/"; 6 | 7 | public static final File TESTS1 = new File(PATH + "Tests1"); 8 | public static final File TESTS2 = new File(PATH + "Tests2"); 9 | public static final File TESTS3 = new File(PATH + "Tests3"); 10 | 11 | public static final String SUCCESS_MESSAGE = "Summary successfully verified"; 12 | public static final String SCRIPT = "./bin/run.sh"; 13 | 14 | public static int testNumber; 15 | public static int errorCount; 16 | 17 | public static void main(String[] args) { 18 | testNumber = 0; 19 | errorCount = 0; 20 | 21 | if (args[0].equals("1")) { 22 | runTests(TESTS1); 23 | } else if (args[0].equals("2")){ 24 | runTests(TESTS2); 25 | } else { 26 | runTests(TESTS3); 27 | } 28 | 29 | System.out.println(errorCount + " out of " + testNumber + " tests failed."); 30 | System.exit(errorCount); 31 | } 32 | 33 | public static void runTests(File file) { 34 | if (file.isDirectory()) { 35 | File[] subFiles = file.listFiles(); 36 | 37 | if (subFiles != null) { 38 | System.out.println(file.getName() + "\n"); 39 | for (File f : subFiles) { 40 | runTests(f); 41 | } 42 | } 43 | } else if (file.getName().contains(".java")) { 44 | testNumber++; 45 | System.out.println("Test " + testNumber + ": " + file.getName()); 46 | 47 | String[] script = {SCRIPT, file.getPath(), "Test" + testNumber + ".java"}; 48 | try { 49 | runScript(script); 50 | } catch (IOException e){ 51 | e.printStackTrace(); 52 | errorCount++; 53 | } 54 | System.out.println(); 55 | } 56 | 57 | } 58 | 59 | public static void runScript(String[] script) throws IOException { 60 | boolean successful = false; 61 | boolean outputProduced = false; 62 | 63 | ProcessBuilder pb = new ProcessBuilder(script); 64 | pb.redirectErrorStream(true); 65 | Process process = pb.start(); 66 | 67 | InputStream output = process.getInputStream(); 68 | BufferedReader reader = new BufferedReader(new InputStreamReader(output)); 69 | 70 | String line; 71 | while ((line = reader.readLine()) != null) { 72 | outputProduced = true; 73 | System.out.println(line); 74 | 75 | if (line.equals(SUCCESS_MESSAGE)) { 76 | successful = true; 77 | } 78 | } 79 | 80 | if (!successful && outputProduced) { 81 | errorCount++; 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /tests/pthScript: -------------------------------------------------------------------------------- 1 | # pth test script 2 | # 3 | # This file is a test script for pth (Polyglot Test Harness). It 4 | # conforms to the following grammar. 5 | # 6 | # ScriptFile ::= CompilerTest+ 7 | # CompilerTest ::= ExtClassName ["CmdLineArgs"] { FileTest [; FileTest]* } 8 | # FileTest ::= CompilationUnits [Description] [FailureSet] 9 | # CompilationUnits ::= Filenames [, Filenames]* 10 | # Filenames ::= Filename [Filename]* 11 | # Description ::= LitString 12 | # FailureSet ::= Failure [, Failure]* 13 | # Failure ::= ( ErrorKind ) 14 | # | ( ErrorKind, "RegExp" ) 15 | # | ( "RegExp" ) 16 | # | ( ) 17 | # ErrorKind : one of, or a unique prefix of one of the following 18 | # strings: "Warning", "Internal Error", "I/O Error", 19 | # "Lexical Error", "Syntax Error", "Semantic Error" 20 | # or "Post-compiler Error". 21 | # Filename : the name of a file. Is interpreted from the 22 | # directory where pth is run. 23 | # LitString : a literal string, enclosed in quotes. 24 | # RegExp : a regular expression, as in java.util.regex; 25 | # is always enclosed in quotes. 26 | # CmdLineArgs : additional command line args for the Polyglot 27 | # compiler; is always enclosed in quotes. 28 | 29 | javatosketch.ExtensionInfo "-d out" { 30 | Hello.java; 31 | } 32 | -------------------------------------------------------------------------------- /tests/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | pth=`dirname $0`/../../../bin/pth 4 | 5 | if [ ! -f "$pth" ]; then 6 | # TODO: make sure polyglot/bin (which is where pth lives) is in your path 7 | pth=pth 8 | fi 9 | 10 | $pth -classpath ../compiler/classes pthScript 11 | --------------------------------------------------------------------------------