├── .cstyle ├── .gitattributes ├── .gitignore ├── .gitmodules ├── .javastyle ├── .travis.yml ├── Dockerfile ├── GPL2.erb ├── LICENSE ├── README.md ├── README_MJC ├── build.xml ├── docker_mjc ├── docs └── proposal.tex ├── runTests.py ├── src ├── Compiler.java ├── Runtime.j ├── checker │ ├── Checker.java │ ├── Context.java │ ├── Env.java │ ├── FieldEnv.java │ ├── MemberEnv.java │ ├── MethEnv.java │ └── VarEnv.java ├── codegen │ ├── Assembly.java │ └── LLVM.java ├── compiler │ ├── Diagnostic.java │ ├── Failure.java │ ├── Handler.java │ ├── JavaSource.java │ ├── Lexer.java │ ├── Phase.java │ ├── Position.java │ ├── SimpleHandler.java │ ├── Source.java │ ├── SourceLexer.java │ ├── SourcePosition.java │ ├── StdinSource.java │ └── Warning.java ├── interp │ ├── ArrayValue.java │ ├── BoolValue.java │ ├── CharValue.java │ ├── IntValue.java │ ├── Interp.java │ ├── ObjValue.java │ ├── State.java │ └── Value.java ├── lexer │ ├── MjcLexer.java │ └── Test.java ├── runtime_llvm.c ├── runtime_x86.c ├── syntax │ ├── AddExpr.java │ ├── AllocArrayInvocation.java │ ├── AllocInvocation.java │ ├── Args.java │ ├── ArrayAccess.java │ ├── ArrayLiteral.java │ ├── ArrayType.java │ ├── AssignExpr.java │ ├── BinaryOp.java │ ├── BitAndExpr.java │ ├── BitOpExpr.java │ ├── BitOrExpr.java │ ├── BitXorExpr.java │ ├── Block.java │ ├── BooleanLiteral.java │ ├── CastExpr.java │ ├── CharLiteral.java │ ├── ClassAccess.java │ ├── ClassInvocation.java │ ├── ClassType.java │ ├── CondAndExpr.java │ ├── CondOrExpr.java │ ├── ConstructorInvocation.java │ ├── Decls.java │ ├── DieInvocation.java │ ├── DivExpr.java │ ├── DoWhile.java │ ├── Empty.java │ ├── EqualExpr.java │ ├── ExprStmt.java │ ├── Expression.java │ ├── ExternalInvocation.java │ ├── FieldAccess.java │ ├── FieldDecl.java │ ├── Formals.java │ ├── FrameAccess.java │ ├── GreaterThanExpr.java │ ├── Id.java │ ├── IfThenElse.java │ ├── IntLiteral.java │ ├── InterfaceType.java │ ├── Invocation.java │ ├── LeftHandSide.java │ ├── LessThanExpr.java │ ├── Literal.java │ ├── LocalVarDecl.java │ ├── LogicOpExpr.java │ ├── MethDecl.java │ ├── Mjc.jacc │ ├── MjcList.java │ ├── ModExpr.java │ ├── Modifiers.java │ ├── MulExpr.java │ ├── Name.java │ ├── NameAccess.java │ ├── NameInvocation.java │ ├── NameType.java │ ├── NegExpr.java │ ├── NewArrayExpr.java │ ├── NewExpr.java │ ├── NotEqualExpr.java │ ├── NotExpr.java │ ├── NullCheck.java │ ├── NullLiteral.java │ ├── NumericOpExpr.java │ ├── ObjectAccess.java │ ├── ObjectInvocation.java │ ├── Parser.java │ ├── PrimitiveType.java │ ├── RelOpExpr.java │ ├── Return.java │ ├── SimpleAccess.java │ ├── Statement.java │ ├── StatementExpr.java │ ├── StringLiteral.java │ ├── SubExpr.java │ ├── SuperAccess.java │ ├── SuperInvocation.java │ ├── Syntax.java │ ├── This.java │ ├── ThisInvocation.java │ ├── TmpAccess.java │ ├── Tokens.java │ ├── Type.java │ ├── TypeLen.java │ ├── UnaryOp.java │ ├── VarDecls.java │ └── While.java ├── ts.j └── util │ ├── ListIterator.java │ └── ListIteratorIF.java └── unitTests ├── array.gcc.ref ├── array.j ├── array.mjc.ref ├── array.run.ref ├── arrayAcces.gcc.ref ├── arrayAcces.j ├── arrayAcces.mjc.ref ├── arrayAcces.run.ref ├── arrayAccess2.gcc.ref ├── arrayAccess2.j ├── arrayAccess2.mjc.ref ├── arrayAccess2.run.ref ├── arrayClass.gcc.ref ├── arrayClass.j ├── arrayClass.mjc.ref ├── arrayClass.run.ref ├── arrayInherit.gcc.ref ├── arrayInherit.j ├── arrayInherit.mjc.ref ├── arrayInherit.run.ref ├── arrayInst.gcc.ref ├── arrayInst.j ├── arrayInst.mjc.ref ├── arrayInst.run.ref ├── arraylit1.gcc.ref ├── arraylit1.j ├── arraylit1.mjc.ref ├── arraylit1.run.ref ├── arraylit2.gcc.ref ├── arraylit2.j ├── arraylit2.mjc.ref ├── arraylit2.run.ref ├── arraylit3.gcc.ref ├── arraylit3.j ├── arraylit3.mjc.ref ├── arraylit3.run.ref ├── arraylit4.gcc.ref ├── arraylit4.j ├── arraylit4.mjc.ref ├── arraylit4.run.ref ├── badArrayInherit.j ├── badArrayInherit.mjc.ref ├── badArrayInherit2.j ├── badArrayInherit2.mjc.ref ├── badConstructor.j ├── badConstructor.mjc.ref ├── badIface.j ├── badIface.mjc.ref ├── badIface2.j ├── badIface2.mjc.ref ├── badIface3.j ├── badIface3.mjc.ref ├── badIface4.j ├── badIface4.mjc.ref ├── badIface5.j ├── badIface5.mjc.ref ├── badIface6.j ├── badIface6.mjc.ref ├── badIface7.j ├── badIface7.mjc.ref ├── badScope.j ├── badScope.mjc.ref ├── badScope2.j ├── badScope2.mjc.ref ├── badScope2.run.ref ├── badSuper1.j ├── badSuper1.mjc.ref ├── badSuper2.j ├── badSuper2.mjc.ref ├── badSuper3.j ├── badSuper3.mjc.ref ├── badSuper4.j ├── badSuper4.mjc.ref ├── badSuper5.j ├── badSuper5.mjc.ref ├── bad_max_int.j ├── bad_max_int.mjc.ref ├── bad_min_int.j ├── bad_min_int.mjc.ref ├── benchmark.gcc.ref ├── benchmark.j ├── benchmark.mjc.ref ├── benchmark.run.ref ├── blob.gcc.ref ├── blob.j ├── blob.mjc.ref ├── blob.run.ref ├── classClass.gcc.ref ├── classClass.j ├── classClass.mjc.ref ├── classClass.run.ref ├── gcArrays.gcc.ref ├── gcArrays.j ├── gcArrays.mjc.ref ├── gcArrays.run.ref ├── gcArrays2.gcc.ref ├── gcArrays2.j ├── gcArrays2.mjc.ref ├── gcArrays2.run.ref ├── gcCircular.gcc.ref ├── gcCircular.j ├── gcCircular.mjc.ref ├── gcCircular.run.ref ├── gcClass.gcc.ref ├── gcClass.j ├── gcClass.mjc.ref ├── gcClass.run.ref ├── gcComplex.gcc.ref ├── gcComplex.j ├── gcComplex.mjc.ref ├── gcComplex.run.ref ├── gcHeterogenous.gcc.ref ├── gcHeterogenous.j ├── gcHeterogenous.mjc.ref ├── gcHeterogenous.run.ref ├── gcgentest1.gcc.ref ├── gcgentest1.j ├── gcgentest1.mjc.ref ├── gcgentest1.run.ref ├── gcgentest10.gcc.ref ├── gcgentest10.j ├── gcgentest10.mjc.ref ├── gcgentest10.run.ref ├── gcgentest2.gcc.ref ├── gcgentest2.j ├── gcgentest2.mjc.ref ├── gcgentest2.run.ref ├── gcgentest3.gcc.ref ├── gcgentest3.j ├── gcgentest3.mjc.ref ├── gcgentest3.run.ref ├── gcgentest4.gcc.ref ├── gcgentest4.j ├── gcgentest4.mjc.ref ├── gcgentest4.run.ref ├── gcgentest5.gcc.ref ├── gcgentest5.j ├── gcgentest5.mjc.ref ├── gcgentest5.run.ref ├── gcgentest6.gcc.ref ├── gcgentest6.j ├── gcgentest6.mjc.ref ├── gcgentest6.run.ref ├── gcgentest7.gcc.ref ├── gcgentest7.j ├── gcgentest7.mjc.ref ├── gcgentest7.run.ref ├── gcgentest8.gcc.ref ├── gcgentest8.j ├── gcgentest8.mjc.ref ├── gcgentest8.run.ref ├── gcgentest9.gcc.ref ├── gcgentest9.j ├── gcgentest9.mjc.ref ├── gcgentest9.run.ref ├── gctest1.gcc.ref ├── gctest1.j ├── gctest1.mjc.ref ├── gctest1.run.ref ├── gctest10.gcc.ref ├── gctest10.j ├── gctest10.mjc.ref ├── gctest10.run.ref ├── gctest2.gcc.ref ├── gctest2.j ├── gctest2.mjc.ref ├── gctest2.run.ref ├── gctest3.gcc.ref ├── gctest3.j ├── gctest3.mjc.ref ├── gctest3.run.ref ├── gctest4.gcc.ref ├── gctest4.j ├── gctest4.mjc.ref ├── gctest4.run.ref ├── gctest5.gcc.ref ├── gctest5.j ├── gctest5.mjc.ref ├── gctest5.run.ref ├── gctest6.gcc.ref ├── gctest6.j ├── gctest6.mjc.ref ├── gctest6.run.ref ├── gctest7.gcc.ref ├── gctest7.j ├── gctest7.mjc.ref ├── gctest7.run.ref ├── gctest8.gcc.ref ├── gctest8.j ├── gctest8.mjc.ref ├── gctest8.run.ref ├── gctest9.gcc.ref ├── gctest9.j ├── gctest9.mjc.ref ├── gctest9.run.ref ├── iface.gcc.ref ├── iface.j ├── iface.mjc.ref ├── iface.run.ref ├── iface2.gcc.ref ├── iface2.j ├── iface2.mjc.ref ├── iface2.run.ref ├── iface3.gcc.ref ├── iface3.j ├── iface3.mjc.ref ├── iface3.run.ref ├── iface4.gcc.ref ├── iface4.j ├── iface4.mjc.ref ├── iface4.run.ref ├── iface5.gcc.ref ├── iface5.j ├── iface5.mjc.ref ├── iface5.run.ref ├── iface6.gcc.ref ├── iface6.j ├── iface6.mjc.ref ├── iface6.run.ref ├── iface7.gcc.ref ├── iface7.j ├── iface7.mjc.ref ├── iface7.run.ref ├── nullCheck.gcc.ref ├── nullCheck.j ├── nullCheck.mjc.ref ├── nullCheck.run.ref ├── nullCheck2.gcc.ref ├── nullCheck2.j ├── nullCheck2.mjc.ref ├── nullCheck2.run.ref ├── nullCheck3.gcc.ref ├── nullCheck3.j ├── nullCheck3.mjc.ref ├── nullCheck3.run.ref ├── retNull.gcc.ref ├── retNull.j ├── retNull.mjc.ref ├── retNull.run.ref ├── segFault.gcc.ref ├── segFault.j ├── segFault.mjc.ref ├── segFault.run.ref ├── string.gcc.ref ├── string.j ├── string.mjc.ref ├── string.run.ref ├── super1.gcc.ref ├── super1.j ├── super1.mjc.ref ├── super1.run.ref ├── super2.gcc.ref ├── super2.j ├── super2.mjc.ref ├── super2.run.ref ├── super3.gcc.ref ├── super3.j ├── super3.mjc.ref ├── super3.run.ref ├── systemOut.gcc.ref ├── systemOut.j ├── systemOut.mjc.ref ├── systemOut.run.ref ├── test.gcc.ref ├── test.j ├── test.mjc.ref ├── test.run.ref ├── thisInvocation.gcc.ref ├── thisInvocation.j ├── thisInvocation.mjc.ref ├── thisInvocation.run.ref ├── ts.gcc.ref ├── ts.j ├── ts.mjc.ref └── ts.run.ref /.cstyle: -------------------------------------------------------------------------------- 1 | --style=java --indent=spaces=2 2 | --indent-col1-comments 3 | --min-conditional-indent=0 4 | --unpad-paren 5 | --convert-tabs 6 | --max-code-length=80 7 | --lineend=linux 8 | --pad-oper 9 | --suffix=none 10 | --pad-header 11 | --add-brackets 12 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.java filter=java_code 2 | *.j filter=java_code 3 | *.c filter=c_code -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # list of files to ignore for MiniJavaLLVM 2 | 3 | #no backup edits 4 | *.*~ 5 | 6 | #no java class files 7 | *.class 8 | *.jar 9 | 10 | #no parser output 11 | src/syntax/MjcParser.java 12 | src/syntax/MjcTokens.java 13 | build 14 | *.out 15 | *.bc 16 | 17 | #no eclipse projects or metadata 18 | *.project 19 | *.metadata 20 | *.classpath -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "llvm-j"] 2 | path = llvm-j 3 | url = https://github.com/crzysdrs/llvm-j 4 | -------------------------------------------------------------------------------- /.javastyle: -------------------------------------------------------------------------------- 1 | --style=java --indent=spaces=4 2 | --indent-col1-comments 3 | --min-conditional-indent=0 4 | --unpad-paren 5 | --convert-tabs 6 | --max-code-length=80 7 | --lineend=linux 8 | --pad-oper 9 | --suffix=none 10 | --pad-header 11 | --add-brackets 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | before_install: 3 | - sudo apt-get install -y ant-contrib 4 | - sudo ln -s /usr/share/java/ant-contrib.jar /usr/share/ant/lib/ 5 | - ant deps 6 | install: "ant -v jar" 7 | script: 8 | - ./runTests.py --verbose --show_diff --jobs 2 9 | jdk: 10 | - oraclejdk8 11 | - oraclejdk7 12 | - openjdk7 13 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | RUN apt-get update 4 | #Need these before running ant deps 5 | RUN apt-get install -y \ 6 | default-jdk \ 7 | default-jre \ 8 | ant-contrib \ 9 | astyle \ 10 | wget \ 11 | git 12 | RUN adduser --disabled-password --gecos '' mjc 13 | ADD . /project 14 | RUN chown -R mjc:mjc /project 15 | 16 | WORKDIR /project 17 | RUN ant deps 18 | USER mjc 19 | RUN ant clean 20 | RUN ant test 21 | -------------------------------------------------------------------------------- /GPL2.erb: -------------------------------------------------------------------------------- 1 | <%=copyright_software%> - <%=copyright_software_description%> 2 | Copyright (C) <%=copyright_years.join(', ')%> <%=copyright_holders.join(', ')%> 3 | 4 | <%=copyright_software%> is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | <%=copyright_software%> is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with <%=copyright_software%>; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -------------------------------------------------------------------------------- /docker_mjc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | docker run -v "$(pwd)":/local -w /local crzysdrs/minijavallvm java -Xms512m -Xmx1024m -jar /project/build/jar/mjc.jar "$@" 3 | -------------------------------------------------------------------------------- /src/checker/Env.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package checker; 22 | 23 | import compiler.*; 24 | import syntax.*; 25 | import codegen.*; 26 | 27 | import org.llvm.TypeRef; 28 | 29 | /** Provides a base representation for environments. 30 | */ 31 | public abstract class Env { 32 | protected Id id; 33 | protected Type type; 34 | 35 | public Env(Id id, Type type) { 36 | this.id = id; 37 | this.type = type; 38 | } 39 | 40 | /** Returns the identifier for this entry. 41 | */ 42 | public final Id getId() { 43 | return id; 44 | } 45 | 46 | /** Returns the name for this entry. 47 | */ 48 | public final String getName() { 49 | return id.getName(); 50 | } 51 | 52 | /** Returns the position for this entry. 53 | */ 54 | public final Position getPos() { 55 | return id.getPos(); 56 | } 57 | 58 | /** Returns the result type for this entry. 59 | */ 60 | public final Type getType() { 61 | return type; 62 | } 63 | 64 | public org.llvm.TypeRef llvmType() { 65 | return type.llvmType(); 66 | } 67 | 68 | public org.llvm.TypeRef llvmTypeField() { 69 | return type.llvmTypeField(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/compiler/Failure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package compiler; 22 | 23 | /** Represents an error diagnostic. To avoid a clash with java.lang.Error, 24 | * we resisted the temptation to call this class Error. 25 | */ 26 | public class Failure extends Diagnostic { 27 | /** Construct a simple failure report with a fixed description. 28 | */ 29 | public Failure(String text) { 30 | super(text); 31 | } 32 | 33 | /** Construct a failure report for a particular source position. 34 | */ 35 | public Failure(Position position) { 36 | super(position); 37 | } 38 | 39 | /** Construct a simple failure report with a fixed description 40 | * and a source position. 41 | */ 42 | public Failure(Position position, String text) { 43 | super(position, text); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/compiler/Handler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package compiler; 22 | 23 | /** Represents a handler for diagnostics. In particular applications, 24 | * we can use subclasses to specify how diagnostics should be handled. 25 | */ 26 | public abstract class Handler { 27 | /** Count how many diagnostics have been reported. 28 | */ 29 | private int numDiagnostics = 0; 30 | public int getNumDiagnostics() { 31 | return numDiagnostics; 32 | } 33 | 34 | /** Count how many failures have been reported. 35 | */ 36 | private int numFailures = 0; 37 | public int getNumFailures() { 38 | return numFailures; 39 | } 40 | 41 | /** Report a problem to this diagnostic handler. 42 | */ 43 | public void report(Diagnostic d) { 44 | numDiagnostics++; 45 | if (d instanceof Failure) { 46 | numFailures++; 47 | } 48 | respondTo(d); 49 | } 50 | 51 | /** Respond to a diagnostic report. Subclasses should 52 | * override this method to deal with diagnostic reports in an 53 | * appropriate way. Diagnostics will normally be passed to this 54 | * method indirectly via a call to report() in the client code. 55 | */ 56 | protected abstract void respondTo(Diagnostic d); 57 | 58 | /** Reset the diagnostic handler. This should set the diagnostic 59 | * handler back to the state of a freshly created handler. As a 60 | * default, we just reset the counters. 61 | */ 62 | public void reset() { 63 | numDiagnostics = 0; 64 | numFailures = 0; 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /src/compiler/Phase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package compiler; 22 | 23 | /** Base class for compiler phases. Its only real purpose is to provide 24 | * convenient access to a diagnostic handler. 25 | */ 26 | public abstract class Phase { 27 | private Handler handler; 28 | 29 | /** Construct a new phase with a specified diagnostic handler. 30 | */ 31 | protected Phase(Handler handler) { 32 | this.handler = handler; 33 | } 34 | 35 | /** Return the handler for this phase. 36 | */ 37 | public Handler getHandler() { 38 | return handler; 39 | } 40 | 41 | /** Report a diagnostic detected in this phase. 42 | */ 43 | public void report(Diagnostic d) { 44 | if (handler != null) { 45 | handler.report(d); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/compiler/SimpleHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package compiler; 22 | 23 | /** A simple implementation of the Handler interface that prints the 24 | * position and description of each diagnostic on System.err, and 25 | * then returns to the caller. 26 | */ 27 | public class SimpleHandler extends Handler { 28 | /** Respond to a diagnostic by displaying it on the error output 29 | * stream. 30 | */ 31 | protected void respondTo(Diagnostic d) { 32 | Position pos = d.getPos(); 33 | if (d instanceof Warning) { 34 | System.err.print("WARNING: "); 35 | } else { 36 | System.err.print("ERROR: "); 37 | } 38 | if (pos != null) { 39 | System.err.println(pos.describe()); 40 | } 41 | String txt = d.getText(); 42 | if (txt != null) { 43 | System.err.println(txt); 44 | } 45 | System.err.println(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/compiler/Warning.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package compiler; 22 | 23 | /** Represents a warning diagnostic. 24 | */ 25 | public class Warning extends Diagnostic { 26 | /** Construct a simple warning with a fixed description. 27 | */ 28 | public Warning(String text) { 29 | super(text); 30 | } 31 | 32 | /** Construct a warning object for a particular source position. 33 | */ 34 | public Warning(Position position) { 35 | super(position); 36 | } 37 | 38 | /** Construct a simple warning with a fixed description 39 | * and a source position. 40 | */ 41 | public Warning(Position position, String text) { 42 | super(position, text); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/interp/BoolValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package interp; 22 | 23 | import interp.Value.COMPARE_OP; 24 | 25 | /** Provides a representation for Boolean values. 26 | */ 27 | public class BoolValue extends Value { 28 | private boolean value; 29 | 30 | public BoolValue(boolean value) { 31 | this.value = value; 32 | } 33 | 34 | public static BoolValue make(boolean value) { 35 | return value ? Value.TRUE : Value.FALSE; 36 | } 37 | 38 | /** Convert this value into a Boolean, or fail with an error message 39 | * if this value does not represent a Boolean. 40 | */ 41 | public boolean getBool() { 42 | return value; 43 | } 44 | public boolean compare(COMPARE_OP op, Value v) { 45 | if (v instanceof BoolValue) { 46 | boolean c = v.getBool(); 47 | switch (op) { 48 | case OP_NE: 49 | return value == c; 50 | case OP_EQ: 51 | return value != c; 52 | case OP_LE: 53 | Interp.abort("Type error: Invalid Comparison"); 54 | return false; 55 | case OP_GT: 56 | Interp.abort("Type error: Invalid Comparison"); 57 | return false; 58 | } 59 | } else { 60 | Interp.abort("Type error: Invalid Comparison"); 61 | return false; 62 | } 63 | return false; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/interp/CharValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package interp; 22 | 23 | /** Provides a representation for Boolean values. 24 | */ 25 | public class CharValue extends Value { 26 | private char value; 27 | 28 | public CharValue(char value) { 29 | this.value = value; 30 | } 31 | 32 | public static CharValue make(char s) { 33 | return new CharValue(s); 34 | } 35 | /** Convert this value into a Boolean, or fail with an error message 36 | * if this value does not represent a Boolean. 37 | */ 38 | public char getChar() { 39 | return value; 40 | } 41 | public boolean compare(COMPARE_OP op, Value v) { 42 | if (v instanceof CharValue) { 43 | char c = v.getChar(); 44 | switch (op) { 45 | case OP_NE: 46 | return value != c; 47 | case OP_EQ: 48 | return value == c; 49 | case OP_LE: 50 | return value < c; 51 | case OP_GT: 52 | return value > c; 53 | } 54 | } else { 55 | return false; 56 | } 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/interp/IntValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package interp; 22 | 23 | public class IntValue extends Value { 24 | private int value; 25 | 26 | public IntValue(int value) { 27 | this.value = value; 28 | } 29 | 30 | /** Convert this value into an int, or fail with an error message 31 | * if this value does not represent an integer. 32 | */ 33 | public int getInt() { 34 | return value; 35 | } 36 | 37 | public boolean compare(Value.COMPARE_OP op, Value v) { 38 | if (v instanceof IntValue) { 39 | int c = v.getInt(); 40 | switch (op) { 41 | case OP_NE: 42 | return value != c; 43 | case OP_EQ: 44 | return value == c; 45 | case OP_LE: 46 | return value < c; 47 | case OP_GT: 48 | return value > c; 49 | } 50 | } else { 51 | Interp.abort("Type error: Invalid Comparison"); 52 | return false; 53 | } 54 | return false; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/runtime_x86.c: -------------------------------------------------------------------------------- 1 | /* * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 2 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 3 | * 4 | * MiniJava Compiler is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * MiniJava Compiler is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with MiniJava Compiler; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | extern void Main_main(); 23 | extern void MJCStatic_init(); 24 | 25 | void System_out_int(int x) { 26 | printf("%d\n", x); 27 | } 28 | 29 | #define HEAPLEN (256 * 1024 * 1024) 30 | int freeHeap = 0; 31 | int heap[HEAPLEN]; 32 | 33 | void MJC_globalRoot(void *root) { 34 | // not used as no gc for x86 35 | return; 36 | } 37 | 38 | int* MJC_allocObject_int(int size) { 39 | int* newObj = heap + freeHeap; 40 | if (size + freeHeap >= HEAPLEN) { 41 | fprintf(stderr, "Out of memory!"); 42 | exit(1); 43 | } 44 | freeHeap += size; 45 | return newObj; 46 | } 47 | 48 | void MJC_die() { 49 | exit(-1); 50 | } 51 | 52 | int* MJC_allocArray_int_int(int elementSize, int len) { 53 | int size = elementSize * len; 54 | int* newArr = heap + freeHeap; 55 | if (size + freeHeap >= HEAPLEN) { 56 | fprintf(stderr, "Out of memory!"); 57 | exit(1); 58 | } 59 | freeHeap += size; 60 | return newArr; 61 | 62 | } 63 | 64 | void MJC_putc_char(char c) { 65 | printf("%c", c); 66 | } 67 | int main() { 68 | // printf("Starting:\n"); 69 | MJCStatic_init(); 70 | Main_main(); 71 | // printf("Finishing (%d words allocated).\n",freeHeap); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /src/syntax/AddExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | // 21 | // Modified Mark Smith, Portland State University 22 | // Added compileLLVMExpr 23 | // Apr 27, 2014 24 | 25 | package syntax; 26 | 27 | import compiler.*; 28 | import checker.*; 29 | import codegen.*; 30 | import interp.*; 31 | 32 | /** Provides a representation for addition expressions. 33 | */ 34 | public final class AddExpr extends NumericOpExpr { 35 | public AddExpr(Position pos, Expression left, Expression right) { 36 | super(pos, left, right); 37 | } 38 | 39 | /** Return a true value to indicate that addition is commutative. 40 | */ 41 | boolean commutes() { 42 | return true; 43 | } 44 | 45 | /** Generate code to evaluate this expression and 46 | * leave the result in the specified free variable. 47 | */ 48 | public void compileExpr(Assembly a, int free) { 49 | compileOp(a, "addl", free); 50 | } 51 | 52 | /** Evaluate this expression. 53 | */ 54 | public Value eval(State st) { 55 | return new IntValue(left.eval(st).getInt() + right.eval(st).getInt()); 56 | } 57 | 58 | public org.llvm.Value llvmBuildOp(LLVM l, org.llvm.Value left, 59 | org.llvm.Value right) { 60 | return l.getBuilder().buildAdd(left, right, "addtemp"); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/syntax/AllocArrayInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | import syntax.*; 28 | 29 | import java.util.ArrayList; 30 | import org.llvm.TypeRef; 31 | 32 | /** Provides a representation for method invocations. 33 | */ 34 | public class AllocArrayInvocation extends ExternalInvocation { 35 | private ArrayType arrayType; 36 | private Type array; 37 | private Expression size; 38 | public AllocArrayInvocation(Position pos, Type array, Type elem, 39 | Expression size) { 40 | super( 41 | new Name(new Name(new Id(pos, "MJC")), new Id(pos, "allocArray")), 42 | new Args(size, 43 | new Args(new TypeLen(pos, elem), null))); 44 | this.array = array; 45 | this.size = size; 46 | } 47 | public Type typeOf(Context ctxt, VarEnv env) 48 | throws Diagnostic { 49 | arrayType = array.check(ctxt).isArray(); 50 | if (arrayType == null) { 51 | throw new Failure("AllocArrayInvocation expects array type"); 52 | } 53 | return super.typeOf(ctxt, env); 54 | } 55 | public Value eval(State st) { 56 | return new ArrayValue(size.eval(st).getInt(), arrayType); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/syntax/AllocInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | import java.util.ArrayList; 29 | import org.llvm.TypeRef; 30 | 31 | /** Provides a representation for method invocations. 32 | */ 33 | public class AllocInvocation extends ExternalInvocation { 34 | private ClassType object; 35 | public AllocInvocation(Position pos, ClassType t) { 36 | super( 37 | new Name(new Name(new Id(pos, "MJC")), new Id(pos, "allocObject")), 38 | new Args(new TypeLen(pos, t), null)); 39 | this.object = t; 40 | } 41 | public Value eval(State st) { 42 | return object.newObject(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/syntax/BitAndExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import codegen.*; 25 | import interp.*; 26 | 27 | /** Provides a representation for bitwise and expressions (&). 28 | */ 29 | public final class BitAndExpr extends BitOpExpr { 30 | public BitAndExpr(Position pos, Expression left, Expression right) { 31 | super(pos, left, right); 32 | } 33 | 34 | /** Return a true value to indicate that bitwise and is commutative. 35 | */ 36 | boolean commutes() { 37 | return true; 38 | } 39 | 40 | /** Generate code to evaluate this expression and 41 | * leave the result in the specified free variable. 42 | */ 43 | public void compileExpr(Assembly a, int free) { 44 | compileOp(a, "andl", free); 45 | } 46 | 47 | /** Evaluate this expression. 48 | */ 49 | public Value eval(State st) { 50 | return new IntValue(left.eval(st).getInt() & right.eval(st).getInt()); 51 | } 52 | 53 | public org.llvm.Value llvmGenBitOp(LLVM l, org.llvm.Value l_v, 54 | org.llvm.Value r_v) { 55 | return l.getBuilder().buildAnd(l_v, r_v, "andtemp"); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/syntax/BitOrExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Provides a representation for bitwise or expressions (|). 29 | */ 30 | public final class BitOrExpr extends BitOpExpr { 31 | public BitOrExpr(Position pos, Expression left, Expression right) { 32 | super(pos, left, right); 33 | } 34 | 35 | /** Return a true value to indicate that bitwise or is commutative. 36 | */ 37 | boolean commutes() { 38 | return true; 39 | } 40 | 41 | /** Generate code to evaluate this expression and 42 | * leave the result in the specified free variable. 43 | */ 44 | public void compileExpr(Assembly a, int free) { 45 | compileOp(a, "orl", free); 46 | } 47 | 48 | /** Evaluate this expression. 49 | */ 50 | public Value eval(State st) { 51 | return new IntValue(left.eval(st).getInt() | right.eval(st).getInt()); 52 | } 53 | 54 | public org.llvm.Value llvmGenBitOp(LLVM l, org.llvm.Value l_v, 55 | org.llvm.Value r_v) { 56 | return l.getBuilder().buildOr(l_v, r_v, "ortemp"); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/syntax/BitXorExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Provides a representation for bitwise exclusive or expressions (^). 29 | */ 30 | public final class BitXorExpr extends BitOpExpr { 31 | public BitXorExpr(Position pos, Expression left, Expression right) { 32 | super(pos, left, right); 33 | } 34 | 35 | /** Return a true value to indicate that bitwise xor is commutative. 36 | */ 37 | boolean commutes() { 38 | return true; 39 | } 40 | 41 | /** Generate code to evaluate this expression and 42 | * leave the result in the specified free variable. 43 | */ 44 | public void compileExpr(Assembly a, int free) { 45 | compileOp(a, "xorl", free); 46 | } 47 | 48 | /** Evaluate this expression. 49 | */ 50 | public Value eval(State st) { 51 | return new IntValue(left.eval(st).getInt() ^ right.eval(st).getInt()); 52 | } 53 | 54 | public org.llvm.Value llvmGenBitOp(LLVM l, org.llvm.Value l_v, 55 | org.llvm.Value r_v) { 56 | return l.getBuilder().buildXor(l_v, r_v, "ortemp"); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/syntax/ConstructorInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | import org.llvm.Builder; 29 | 30 | /** Represents an instance method invocation. 31 | */ 32 | public final class ConstructorInvocation extends ObjectInvocation { 33 | public ConstructorInvocation(Name n, Args args) { 34 | super( 35 | new NewExpr(n.getPos(), n), n.getId(), args); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/syntax/Decls.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import checker.Context; 24 | 25 | /** Provides a representation for lists of declarations. 26 | */ 27 | public abstract class Decls { 28 | protected Modifiers mods; 29 | private Decls next; 30 | 31 | public Modifiers getMods() { 32 | return mods; 33 | } 34 | public Decls(Modifiers mods) { 35 | this.mods = mods; 36 | } 37 | 38 | /** Returns the next argument in this list. 39 | */ 40 | public Decls getNext() { 41 | return next; 42 | } 43 | 44 | /** Link a new element onto the front of this list by setting its 45 | * next pointer. 46 | */ 47 | public Decls link(Decls next) { 48 | this.next = next; 49 | return this; 50 | } 51 | 52 | /** Reverse the elements in this list. 53 | */ 54 | public static Decls reverse(Decls decls) { 55 | Decls result = null; 56 | while (decls != null) { 57 | Decls temp = decls.next; 58 | decls.next = result; 59 | result = decls; 60 | decls = temp; 61 | } 62 | return result; 63 | } 64 | 65 | /** Add a declared item to a specified class. 66 | */ 67 | public abstract void addToClass(Context ctxt, ClassType cls); 68 | } 69 | -------------------------------------------------------------------------------- /src/syntax/DieInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | import syntax.*; 28 | 29 | import java.util.ArrayList; 30 | import org.llvm.TypeRef; 31 | 32 | /** Provides a representation for method invocations. 33 | */ 34 | public class DieInvocation extends ExternalInvocation { 35 | public DieInvocation(Position pos) { 36 | super( 37 | new Name(new Name(new Id(pos, "MJC")), new Id(pos, "die")), null); 38 | } 39 | public Value eval(State st) { 40 | System.exit(-1); 41 | return null; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/syntax/Empty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Provides a representation for the empty statement. 29 | */ 30 | public final class Empty extends Statement { 31 | public Empty(Position pos) { 32 | super(pos); 33 | } 34 | 35 | public void llvmGen(LLVM l) { 36 | /* does nothing */ 37 | } 38 | 39 | /** Check whether this statement is valid and return a boolean 40 | * indicating whether execution can continue at the next statement. 41 | */ 42 | public boolean check(Context ctxt, VarEnv env, int frameOffset) { 43 | return true; // Always run on 44 | } 45 | 46 | /** Emit code to execute this statement. 47 | */ 48 | void compile(Assembly a) { 49 | // Nothing to do! 50 | } 51 | 52 | /** Execute this statement. If the statement is terminated by a 53 | * return statement, return the corresponding value. Otherwise, 54 | * a null indicates that no result was returned. 55 | */ 56 | public Value exec(State st) { 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/syntax/EqualExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | import org.llvm.binding.LLVMLibrary.LLVMIntPredicate; 29 | import org.llvm.binding.LLVMLibrary.LLVMRealPredicate; 30 | 31 | /** Provides a representation for the equality test (==). 32 | */ 33 | public final class EqualExpr extends RelOpExpr { 34 | public EqualExpr(Position pos, Expression left, Expression right) { 35 | super(pos, left, right); 36 | } 37 | 38 | /** Generate code to evaluate this expression and 39 | * leave the result in the specified free variable. 40 | */ 41 | public void compileExpr(Assembly a, int free) { 42 | compileComp(a, "jz", free); 43 | } 44 | 45 | /** Generate code to evaluate this expression and 46 | * branch to a specified label if the result is false. 47 | */ 48 | void branchFalse(Assembly a, String lab, int free) { 49 | branchCond(a, "jnz", lab, free); 50 | } 51 | 52 | /** Generate code to evaluate this expression and 53 | * branch to a specified label if the result is true. 54 | */ 55 | void branchTrue(Assembly a, String lab, int free) { 56 | branchCond(a, "jz", lab, free); 57 | } 58 | 59 | public Value.COMPARE_OP getInterpRelOp() { 60 | return Value.COMPARE_OP.OP_EQ; 61 | } 62 | 63 | public LLVMIntPredicate getllvmRelOp() { 64 | return LLVMIntPredicate.LLVMIntEQ; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/syntax/ExprStmt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Provides a representation for expressions used as statements. 29 | */ 30 | public final class ExprStmt extends Statement { 31 | private StatementExpr expr; 32 | 33 | public ExprStmt(Position pos, StatementExpr expr) { 34 | super(pos); 35 | this.expr = expr; 36 | } 37 | 38 | public StatementExpr getStmtExpr() { 39 | return expr; 40 | } 41 | public void setStmtExpr(StatementExpr expr) { 42 | this.expr = expr; 43 | } 44 | /** Check whether this statement is valid and return a boolean 45 | * indicating whether execution can continue at the next statement. 46 | */ 47 | public boolean check(Context ctxt, VarEnv env, int frameOffset) { 48 | try { 49 | expr.checkExpr(ctxt, env); 50 | } catch (Diagnostic d) { 51 | ctxt.report(d); 52 | } 53 | return true; 54 | } 55 | 56 | /** Emit code to execute this statement. 57 | */ 58 | void compile(Assembly a) { 59 | expr.compileExpr(a); 60 | } 61 | 62 | public void llvmGen(LLVM l) { 63 | expr.llvmGen(l); 64 | } 65 | /** Execute this statement. If the statement is terminated by a 66 | * return statement, return the corresponding value. Otherwise, 67 | * a null indicates that no result was returned. 68 | */ 69 | public Value exec(State st) { 70 | expr.eval(st); 71 | return null; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/syntax/ExternalInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | 27 | import java.util.ArrayList; 28 | import org.llvm.TypeRef; 29 | 30 | /** Provides a representation for method invocations. 31 | */ 32 | public abstract class ExternalInvocation extends NameInvocation { 33 | public ExternalInvocation(Name name, Args args) { 34 | super(name, args); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/syntax/FieldAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.Position; 24 | 25 | /** Provides a representation for field accesses. 26 | */ 27 | public abstract class FieldAccess extends LeftHandSide { 28 | public FieldAccess(Position pos) { 29 | super(pos); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/syntax/FieldDecl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import checker.*; 24 | 25 | /** Provides a representation for a field declaration in a class. 26 | */ 27 | public class FieldDecl extends Decls { 28 | private Type type; 29 | private VarDecls vardecls; 30 | public FieldDecl(Modifiers mods, Type type, VarDecls vardecls) { 31 | super(mods); 32 | this.type = type; 33 | this.vardecls = vardecls; 34 | } 35 | 36 | /** Add a declared item to a specified class. 37 | */ 38 | public void addToClass(Context ctxt, ClassType cls) { 39 | type = type.check(ctxt); 40 | if (type != null) { 41 | for (VarDecls vs = vardecls; vs != null; vs = vs.getNext()) { 42 | cls.addField(ctxt, mods, vs.getId(), type, vs.getInitExpr()); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/syntax/Formals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | import checker.*; 23 | 24 | /** Provides a representation for formal parameter declarations. 25 | */ 26 | public class Formals { 27 | private Type type; 28 | private Id id; 29 | private Formals next; 30 | public Formals(Type type, Id id) { 31 | this.type = type; 32 | this.id = id; 33 | } 34 | 35 | /** Returns the type for this formal parameter. 36 | */ 37 | public Type getType() { 38 | return type; 39 | } 40 | 41 | /** Returns the identifier for this formal parameter. 42 | */ 43 | public Id getId() { 44 | return id; 45 | } 46 | 47 | /** Returns the next formal parameter in this list. 48 | */ 49 | public Formals getNext() { 50 | return next; 51 | } 52 | 53 | /** Link a new element onto the front of this list by setting its 54 | * next pointer. 55 | */ 56 | public Formals link(Formals next) { 57 | this.next = next; 58 | return this; 59 | } 60 | 61 | /** Reverse the elements in this list. 62 | */ 63 | public static Formals reverse(Formals formals) { 64 | Formals result = null; 65 | while (formals != null) { 66 | Formals temp = formals.next; 67 | formals.next = result; 68 | result = formals; 69 | formals = temp; 70 | } 71 | return result; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/syntax/GreaterThanExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.Position; 24 | import codegen.*; 25 | import interp.*; 26 | 27 | import org.llvm.binding.LLVMLibrary.LLVMIntPredicate; 28 | import org.llvm.binding.LLVMLibrary.LLVMRealPredicate; 29 | 30 | /** Provides a representation for greater than comparsions. 31 | */ 32 | public final class GreaterThanExpr extends RelOpExpr { 33 | public GreaterThanExpr(Position pos, Expression left, Expression right) { 34 | super(pos, left, right); 35 | } 36 | 37 | /** Generate code to evaluate this expression and 38 | * leave the result in the specified free variable. 39 | */ 40 | public void compileExpr(Assembly a, int free) { 41 | compileComp(a, "jg", free); 42 | } 43 | 44 | /** Generate code to evaluate this expression and 45 | * branch to a specified label if the result is false. 46 | */ 47 | void branchFalse(Assembly a, String lab, int free) { 48 | branchCond(a, "jng", lab, free); 49 | } 50 | 51 | /** Generate code to evaluate this expression and 52 | * branch to a specified label if the result is true. 53 | */ 54 | void branchTrue(Assembly a, String lab, int free) { 55 | branchCond(a, "jg", lab, free); 56 | } 57 | 58 | public Value.COMPARE_OP getInterpRelOp() { 59 | return Value.COMPARE_OP.OP_GT; 60 | } 61 | 62 | public LLVMIntPredicate getllvmRelOp() { 63 | return LLVMIntPredicate.LLVMIntSGT; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/syntax/Id.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | 25 | /** Provides a representation for identifiers annotated with positions. 26 | */ 27 | public final class Id extends Syntax { 28 | private String name; 29 | public Id(Position pos, String name) { 30 | super(pos); 31 | this.name = name; 32 | } 33 | 34 | /** Returns the name for this identifier. 35 | */ 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | /** Determine whether two identifiers have the same name, ignoring 41 | * position details. 42 | */ 43 | public boolean sameId(Id id) { 44 | return name.equals(id.name); 45 | } 46 | 47 | /** Return a string representation for this identifier. 48 | */ 49 | public String toString() { 50 | return name; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/syntax/LeftHandSide.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import codegen.*; 25 | import interp.*; 26 | 27 | /** Provides a representation for left hand sides of assignments. 28 | */ 29 | public abstract class LeftHandSide extends Expression { 30 | public LeftHandSide(Position pos) { 31 | super(pos); 32 | } 33 | 34 | /** Save the value in the free register in the variable specified by 35 | * this expression. 36 | */ 37 | abstract void saveVar(Assembly a, int free); 38 | 39 | /** Save a value in the location specified by this left hand side. 40 | */ 41 | public abstract void save(State st, Value val); 42 | 43 | public abstract void llvmSave(LLVM l, org.llvm.Value v); 44 | } 45 | -------------------------------------------------------------------------------- /src/syntax/LessThanExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import codegen.*; 25 | import interp.*; 26 | 27 | import org.llvm.binding.LLVMLibrary.LLVMIntPredicate; 28 | import org.llvm.binding.LLVMLibrary.LLVMRealPredicate; 29 | 30 | /** Provides a representation for less than comparisons. 31 | */ 32 | public final class LessThanExpr extends RelOpExpr { 33 | public LessThanExpr(Position pos, Expression left, Expression right) { 34 | super(pos, left, right); 35 | } 36 | 37 | /** Generate code to evaluate this expression and 38 | * leave the result in the specified free variable. 39 | */ 40 | public void compileExpr(Assembly a, int free) { 41 | compileComp(a, "jl", free); 42 | } 43 | 44 | /** Generate code to evaluate this expression and 45 | * branch to a specified label if the result is false. 46 | */ 47 | void branchFalse(Assembly a, String lab, int free) { 48 | branchCond(a, "jnl", lab, free); 49 | } 50 | 51 | /** Generate code to evaluate this expression and 52 | * branch to a specified label if the result is true. 53 | */ 54 | void branchTrue(Assembly a, String lab, int free) { 55 | branchCond(a, "jl", lab, free); 56 | } 57 | 58 | public Value.COMPARE_OP getInterpRelOp() { 59 | return Value.COMPARE_OP.OP_LE; 60 | } 61 | 62 | public LLVMIntPredicate getllvmRelOp() { 63 | return LLVMIntPredicate.LLVMIntSLT; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/syntax/Literal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | 25 | /** Provides a representation for literal expressions. 26 | */ 27 | public abstract class Literal extends Expression { 28 | public Literal(Position pos) { 29 | super(pos); 30 | } 31 | 32 | /** Return the depth of this expression tree as a measure of its 33 | * complexity. Literals never require any evaluation so they 34 | * always have zero depth. 35 | */ 36 | int getDepth() { 37 | return 0; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/syntax/LogicOpExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | 27 | /** Provides a representation for logical binary connectives. 28 | */ 29 | public abstract class LogicOpExpr extends BinaryOp { 30 | public LogicOpExpr(Position pos, Expression left, Expression right) { 31 | super(pos, left, right); 32 | } 33 | 34 | /** Check this expression and return an object that describes its 35 | * type (or throw an exception if an unrecoverable error occurs). 36 | */ 37 | public Type typeOf(Context ctxt, VarEnv env) 38 | throws Diagnostic { 39 | try { 40 | required(ctxt, "Left operand", 41 | left.typeOf(ctxt, env), Type.BOOLEAN); 42 | required(ctxt, "Right operand", 43 | right.typeOf(ctxt, env), Type.BOOLEAN); 44 | } catch (Diagnostic d) { 45 | ctxt.report(d); 46 | } 47 | return Type.BOOLEAN; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/syntax/MjcList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package syntax; 21 | import java.util.ArrayList; 22 | import java.lang.reflect.Array; 23 | import syntax.*; 24 | 25 | abstract public class MjcList extends ArrayList { 26 | public static class TypeList extends MjcList { 27 | public TypeList(Type x) { 28 | this(); 29 | append(x); 30 | } 31 | public TypeList() { 32 | super(Type.class); 33 | } 34 | } 35 | public static class StmtList extends MjcList { 36 | public StmtList(Statement x) { 37 | this(); 38 | append(x); 39 | } 40 | public StmtList() { 41 | super(Statement.class); 42 | } 43 | } 44 | public static class StringLiteralList extends MjcList { 45 | public StringLiteralList(StringLiteral x) { 46 | this(); 47 | append(x); 48 | } 49 | public StringLiteralList() { 50 | super(StringLiteral.class); 51 | } 52 | } 53 | private Class classType; 54 | public MjcList(Class c) { 55 | super(); 56 | classType = c; 57 | } 58 | public MjcList append(T x) { 59 | super.add(x); 60 | return this; 61 | } 62 | public T [] toArray() { 63 | return super.toArray((T[])Array.newInstance(classType, 0)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/syntax/ModExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Provides a representation for multiplication expressions. 29 | */ 30 | public final class ModExpr extends NumericOpExpr { 31 | public ModExpr(Position pos, Expression left, Expression right) { 32 | super(pos, left, right); 33 | } 34 | 35 | /** Return a true value to indicate that multiplication is commutative. 36 | */ 37 | boolean commutes() { 38 | return false; 39 | } 40 | 41 | /** Generate code to evaluate this expression and 42 | * leave the result in the specified free variable. 43 | */ 44 | public void compileExpr(Assembly a, int free) { 45 | int freed = a.spillTo(free, "%eax"); 46 | left.compileExpr(a, freed); 47 | a.spill(freed + 1); 48 | right.compileExpr(a, freed + 1); 49 | a.emit("movl", a.immed(0), "%edx"); 50 | a.emit("idivl", a.reg(freed + 1)); 51 | 52 | /* %edx will not be touched by this */ 53 | a.unspillTo(freed + 1, free); 54 | a.emit("movl", "%edx", a.reg(free)); 55 | } 56 | 57 | /** Evaluate this expression. 58 | */ 59 | public Value eval(State st) { 60 | return new IntValue(left.eval(st).getInt() % right.eval(st).getInt()); 61 | } 62 | 63 | public org.llvm.Value llvmBuildOp(LLVM l, org.llvm.Value left, 64 | org.llvm.Value right) { 65 | return l.getBuilder().buildSRem(left, right, "modtemp"); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/syntax/MulExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Provides a representation for multiplication expressions. 29 | */ 30 | public final class MulExpr extends NumericOpExpr { 31 | public MulExpr(Position pos, Expression left, Expression right) { 32 | super(pos, left, right); 33 | } 34 | 35 | /** Return a true value to indicate that multiplication is commutative. 36 | */ 37 | boolean commutes() { 38 | return true; 39 | } 40 | 41 | /** Generate code to evaluate this expression and 42 | * leave the result in the specified free variable. 43 | */ 44 | public void compileExpr(Assembly a, int free) { 45 | compileOp(a, "imull", free); 46 | } 47 | 48 | /** Evaluate this expression. 49 | */ 50 | public Value eval(State st) { 51 | return new IntValue(left.eval(st).getInt() * right.eval(st).getInt()); 52 | } 53 | 54 | public org.llvm.Value llvmBuildOp(LLVM l, org.llvm.Value left, 55 | org.llvm.Value right) { 56 | return l.getBuilder().buildMul(left, right, "multemp"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/syntax/NameInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Represents an access to a method by an as yet unresolved name. 29 | */ 30 | public class NameInvocation extends Invocation { 31 | private Name name; 32 | private Invocation resolved; 33 | 34 | public NameInvocation(Name name, Args args) { 35 | super(name.getPos(), args); 36 | this.name = name; 37 | this.resolved = null; 38 | } 39 | 40 | /** Calculate the type of this method invocation. 41 | */ 42 | Type typeInvocation(Context ctxt, VarEnv env) 43 | throws Diagnostic { 44 | resolved = name.asMethod(ctxt, env, args); 45 | if (resolved == null) { 46 | throw new Failure(pos, "Undefined method name " + name); 47 | } 48 | return resolved.typeInvocation(ctxt, env); 49 | } 50 | 51 | /** Generate code for this method invocation, leaving 52 | * the result in the specified free variable. 53 | */ 54 | void compileInvocation(Assembly a, int free) { 55 | resolved.compileInvocation(a, free); 56 | } 57 | 58 | /** Evaluate this expression. 59 | */ 60 | public Value eval(State st) { 61 | return resolved.eval(st); 62 | } 63 | 64 | public org.llvm.Value llvmGen(LLVM l) { 65 | return resolved.llvmGen(l); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/syntax/NegExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Provides a representation for unary negation. 29 | */ 30 | public final class NegExpr extends UnaryOp { 31 | public NegExpr(Position pos, Expression expr) { 32 | super(pos, expr); 33 | } 34 | 35 | /** Check this expression and return an object that describes its 36 | * type (or throw an exception if an unrecoverable error occurs). 37 | */ 38 | public Type typeOf(Context ctxt, VarEnv env) throws Diagnostic { 39 | try { 40 | required(ctxt, "operand", expr.typeOf(ctxt, env), Type.INT); 41 | } catch (Diagnostic d) { 42 | ctxt.report(d); 43 | } 44 | return Type.INT; 45 | } 46 | 47 | /** Generate code to evaluate this expression and 48 | * leave the result in the specified free variable. 49 | */ 50 | public void compileExpr(Assembly a, int free) { 51 | expr.compileExpr(a, free); 52 | a.emit("negl", a.reg(free)); 53 | } 54 | 55 | /** Evaluate this expression. 56 | */ 57 | public Value eval(State st) { 58 | return new IntValue(-expr.eval(st).getInt()); 59 | } 60 | 61 | public org.llvm.Value llvmGen(LLVM l) { 62 | return l.getBuilder().buildNeg(expr.llvmGen(l), "neg_temp"); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/syntax/NewArrayExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | import org.llvm.Builder; 28 | import org.llvm.TypeRef; 29 | 30 | /** Provides a representation for "new" expressions that allocate an 31 | * instance of a class. 32 | */ 33 | public final class NewArrayExpr extends NewExpr { 34 | private Expression size; 35 | public static Name buildArrayExprName(Position pos, Type elementType) { 36 | return new Name(new Id(pos, elementType.toString() + "[]")); 37 | } 38 | 39 | public NewArrayExpr(Position pos, Type elementType, Expression size) { 40 | super(pos, buildArrayExprName(pos, elementType)); 41 | this.size = size; 42 | } 43 | 44 | /** Check this expression and return an object that describes its 45 | * type (or throw an exception if an unrecoverable error occurs). 46 | */ 47 | public Type typeOf(Context ctxt, VarEnv env) throws Diagnostic { 48 | if (size.typeOf(ctxt, env).equal(Type.INT)) { 49 | throw new Failure(pos, "Array size must be of Type INT"); 50 | } 51 | return super.typeOf(ctxt, env); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/syntax/NotEqualExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import codegen.*; 25 | import interp.*; 26 | 27 | import org.llvm.binding.LLVMLibrary.LLVMIntPredicate; 28 | import org.llvm.binding.LLVMLibrary.LLVMRealPredicate; 29 | 30 | /** Provides a representation for the inequality test (!=). 31 | */ 32 | public final class NotEqualExpr extends RelOpExpr { 33 | public NotEqualExpr(Position pos, Expression left, Expression right) { 34 | super(pos, left, right); 35 | } 36 | 37 | /** Generate code to evaluate this expression and 38 | * leave the result in the specified free variable. 39 | */ 40 | public void compileExpr(Assembly a, int free) { 41 | compileComp(a, "jnz", free); 42 | } 43 | 44 | /** Generate code to evaluate this expression and 45 | * branch to a specified label if the result is false. 46 | */ 47 | void branchFalse(Assembly a, String lab, int free) { 48 | branchCond(a, "jz", lab, free); 49 | } 50 | 51 | /** Generate code to evaluate this expression and 52 | * branch to a specified label if the result is true. 53 | */ 54 | void branchTrue(Assembly a, String lab, int free) { 55 | branchCond(a, "jnz", lab, free); 56 | } 57 | public Value.COMPARE_OP getInterpRelOp() { 58 | return Value.COMPARE_OP.OP_NE; 59 | } 60 | public LLVMIntPredicate getllvmRelOp() { 61 | return LLVMIntPredicate.LLVMIntNE; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/syntax/NotExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Provides a representation for unary Boolean not. 29 | */ 30 | public final class NotExpr extends UnaryOp { 31 | public NotExpr(Position pos, Expression expr) { 32 | super(pos, expr); 33 | } 34 | 35 | /** Check this expression and return an object that describes its 36 | * type (or throw an exception if an unrecoverable error occurs). 37 | */ 38 | public Type typeOf(Context ctxt, VarEnv env) throws Diagnostic { 39 | try { 40 | required(ctxt, "operand", expr.typeOf(ctxt, env), Type.BOOLEAN); 41 | } catch (Diagnostic d) { 42 | ctxt.report(d); 43 | } 44 | return Type.BOOLEAN; 45 | } 46 | 47 | /** Generate code to evaluate this expression and 48 | * leave the result in the specified free variable. 49 | */ 50 | public void compileExpr(Assembly a, int free) { 51 | expr.compileExpr(a, free); 52 | a.emit("xorl", a.immed(1), a.reg(free)); 53 | } 54 | 55 | /** Evaluate this expression. 56 | */ 57 | public Value eval(State st) { 58 | return BoolValue.make(!expr.eval(st).getBool()); 59 | } 60 | 61 | public org.llvm.Value llvmGen(LLVM l) { 62 | return l.getBuilder().buildNot(expr.llvmGen(l), "not_temp"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/syntax/NumericOpExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | 27 | /** Provides a representation for binary expressions with numeric 28 | * operands. 29 | */ 30 | public abstract class NumericOpExpr extends BinaryOp { 31 | public NumericOpExpr(Position pos, Expression left, Expression right) { 32 | super(pos, left, right); 33 | } 34 | 35 | /** Check this expression and return an object that describes its 36 | * type (or throw an exception if an unrecoverable error occurs). 37 | */ 38 | public Type typeOf(Context ctxt, VarEnv env) 39 | throws Diagnostic { 40 | try { 41 | required(ctxt, "Left operand", left.typeOf(ctxt, env), Type.INT); 42 | required(ctxt, "Right operand", right.typeOf(ctxt, env), Type.INT); 43 | } catch (Diagnostic d) { 44 | ctxt.report(d); 45 | } 46 | return Type.INT; 47 | } 48 | public org.llvm.Value llvmGen(LLVM l) { 49 | org.llvm.Value llvm_left = left.llvmGen(l); 50 | org.llvm.Value llvm_right = right.llvmGen(l); 51 | 52 | return llvmBuildOp(l, llvm_left, llvm_right); 53 | } 54 | 55 | public abstract org.llvm.Value llvmBuildOp(LLVM l, org.llvm.Value left, 56 | org.llvm.Value right); 57 | } 58 | -------------------------------------------------------------------------------- /src/syntax/Parser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.Handler; 24 | import lexer.MjcLexer; 25 | 26 | /** Provides public access to the MjcParser. 27 | */ 28 | public class Parser extends MjcParser { 29 | public Parser(Handler handler, MjcLexer lexer) { 30 | super(handler, lexer); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/syntax/StatementExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | 26 | /** Provides a representation for expressions that can appear 27 | * in a statement. 28 | */ 29 | public abstract class StatementExpr extends Expression { 30 | public StatementExpr(Position pos) { 31 | super(pos); 32 | } 33 | 34 | /** Type check this expression in places where it is used as a statement. 35 | * We override this method in Invocation to deal with methods that 36 | * return void. 37 | */ 38 | void checkExpr(Context ctxt, VarEnv env) throws Diagnostic { 39 | typeOf(ctxt, env); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/syntax/SubExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | // 21 | // Modified Mark Smith, Portland State University 22 | // Added compileLLVMExpr 23 | // Apr 27, 2014 24 | 25 | package syntax; 26 | 27 | import compiler.*; 28 | import checker.*; 29 | import codegen.*; 30 | import interp.*; 31 | 32 | /** Provides a representation for addition expressions. 33 | */ 34 | public final class SubExpr extends NumericOpExpr { 35 | public SubExpr(Position pos, Expression left, Expression right) { 36 | super(pos, left, right); 37 | } 38 | 39 | /** Return a true value to indicate that addition is commutative. 40 | */ 41 | boolean commutes() { 42 | return false; 43 | } 44 | 45 | /** Generate code to evaluate this expression and 46 | * leave the result in the specified free variable. 47 | */ 48 | public void compileExpr(Assembly a, int free) { 49 | compileOp(a, "subl", free); 50 | } 51 | 52 | /** Evaluate this expression. 53 | */ 54 | public Value eval(State st) { 55 | return new IntValue(left.eval(st).getInt() - right.eval(st).getInt()); 56 | } 57 | 58 | public org.llvm.Value llvmBuildOp(LLVM l, org.llvm.Value left, 59 | org.llvm.Value right) { 60 | return l.getBuilder().buildSub(left, right, "subtemp"); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/syntax/Syntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import codegen.*; 25 | 26 | /** Provides a representation for syntactic elements, each of which is 27 | * annotated with a position in the input file. 28 | */ 29 | public abstract class Syntax { 30 | protected Position pos; 31 | 32 | public Syntax(Position pos) { 33 | this.pos = pos; 34 | } 35 | 36 | /** Returns the position of this syntactic element. 37 | */ 38 | public Position getPos() { 39 | return pos; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/syntax/This.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | 28 | /** Provides a representation for the "this" pointer to the current object. 29 | */ 30 | public final class This extends Expression { 31 | private int size; 32 | 33 | public This(Position pos) { 34 | super(pos); 35 | } 36 | 37 | /** Check this expression and return an object that describes its 38 | * type (or throw an exception if an unrecoverable error occurs). 39 | */ 40 | public Type typeOf(Context ctxt, VarEnv env) 41 | throws Diagnostic { 42 | if (ctxt.isStatic()) { 43 | throw new Failure(pos, "Cannot access this in a static context"); 44 | } 45 | size = ctxt.getCurrMethod().getSize(); 46 | return ctxt.getCurrClass(); 47 | } 48 | 49 | /** Generate code to evaluate this expression and 50 | * leave the result in the specified free variable. 51 | */ 52 | public void compileExpr(Assembly a, int free) { 53 | a.loadThis(size, free); 54 | } 55 | 56 | /** Evaluate this expression. 57 | */ 58 | public Value eval(State st) { 59 | return st.getThis(size); 60 | } 61 | 62 | public org.llvm.Value llvmGen(LLVM l) { 63 | return l.getFunction().getParam(0); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/syntax/Tokens.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | /** A public class that allows us to access the definitions of the 24 | * Mjc tokens from outside the syntax package; this works around a 25 | * design decision in jacc that restricts the generated token file 26 | * to package level access only. 27 | */ 28 | public interface Tokens extends MjcTokens { 29 | } 30 | -------------------------------------------------------------------------------- /src/syntax/TypeLen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | import checker.*; 25 | import codegen.*; 26 | import interp.*; 27 | import org.llvm.Builder; 28 | 29 | /** Provides a representation for "new" expressions that allocate an 30 | * instance of a class. 31 | */ 32 | public class TypeLen extends Expression { 33 | private Type type; 34 | public TypeLen(Position pos, Type type) { 35 | super(pos); 36 | this.type = type; 37 | } 38 | 39 | /** Check this expression and return an object that describes its 40 | * type (or throw an exception if an unrecoverable error occurs). 41 | */ 42 | public Type typeOf(Context ctxt, VarEnv env) throws Diagnostic { 43 | type = type.check(ctxt); 44 | return Type.INT; 45 | } 46 | 47 | /** Generate code to evaluate this expression and 48 | * leave the result in the specified free variable. 49 | */ 50 | public void compileExpr(Assembly a, int free) { 51 | a.emit("movl", a.immed(type.size()), a.reg(free)); 52 | } 53 | 54 | /** Evaluate this expression. 55 | */ 56 | public Value eval(State st) { 57 | return new IntValue(type.getWidth()); 58 | } 59 | 60 | public org.llvm.Value llvmGen(LLVM l) { 61 | return l.getBuilder().buildTrunc(type.llvmTypeField().sizeOf(), 62 | Type.INT.llvmType(), "typelen_cast"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/syntax/UnaryOp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | import compiler.*; 24 | 25 | /** Provides a representation for expressions using unary operators. 26 | */ 27 | public abstract class UnaryOp extends Expression { 28 | protected Expression expr; 29 | public UnaryOp(Position pos, Expression expr) { 30 | super(pos); 31 | this.expr = expr; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/syntax/VarDecls.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | package syntax; 22 | 23 | /** Provides a representation for variable declaration lists. 24 | */ 25 | public class VarDecls { 26 | private Id id; 27 | private VarDecls next; 28 | private Expression init; 29 | public VarDecls(Id id) { 30 | this.id = id; 31 | } 32 | 33 | public VarDecls(Id id, Expression init) { 34 | this.id = id; 35 | this.init = init; 36 | } 37 | 38 | public Expression getInitExpr() { 39 | return this.init; 40 | } 41 | 42 | /** Returns the identifier for this variable declaration. 43 | */ 44 | public Id getId() { 45 | return id; 46 | } 47 | 48 | /** Returns the next argument in this list. 49 | */ 50 | public VarDecls getNext() { 51 | return next; 52 | } 53 | 54 | /** Link a new element onto the front of this list by setting its 55 | * next pointer. 56 | */ 57 | public VarDecls link(VarDecls next) { 58 | this.next = next; 59 | return this; 60 | } 61 | 62 | /** Reverse the elements in this list. 63 | */ 64 | public static VarDecls reverse(VarDecls vardecls) { 65 | VarDecls result = null; 66 | while (vardecls != null) { 67 | VarDecls temp = vardecls.next; 68 | vardecls.next = result; 69 | result = vardecls; 70 | vardecls = temp; 71 | } 72 | return result; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/ts.j: -------------------------------------------------------------------------------- 1 | // Here is a small program for the Mini Java compiler: 2 | // 3 | 4 | class System { 5 | static void out(int x); 6 | } 7 | 8 | class Expr { 9 | int eval() { 10 | return 0; // should never be called 11 | } 12 | } 13 | 14 | class IntExpr extends Expr { 15 | int value; 16 | 17 | static IntExpr make(int value) { 18 | IntExpr e; 19 | e = new IntExpr(); 20 | e.value = value; 21 | return e; 22 | } 23 | 24 | int eval() { 25 | return value; 26 | } 27 | } 28 | 29 | class AddExpr extends Expr { 30 | Expr left; 31 | Expr right; 32 | 33 | static AddExpr make(Expr l, Expr r) { 34 | AddExpr e; 35 | e = new AddExpr(); 36 | e.left = l; 37 | e.right = r; 38 | return e; 39 | } 40 | 41 | int eval() { 42 | return left.eval() + right.eval(); 43 | } 44 | } 45 | 46 | class Main { 47 | static void main() { 48 | Expr e; 49 | e = AddExpr.make(IntExpr.make(1), IntExpr.make(2)); 50 | e = AddExpr.make(e, e); 51 | System.out(e.eval()); 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/util/ListIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package util; 21 | import java.util.Iterator; 22 | 23 | public class ListIterator> implements Iterator { 24 | private T next; 25 | private T curr; 26 | public ListIterator(T head) { 27 | this.next = head; 28 | this.curr = null; 29 | } 30 | public boolean hasNext() { 31 | return this.next != null; 32 | } 33 | public T next() { 34 | this.curr = this.next; 35 | this.next = this.curr.getNext(); 36 | return this.curr; 37 | } 38 | 39 | public void remove() { 40 | throw new RuntimeException("Iterator does not allow removal."); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/util/ListIteratorIF.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniJava Compiler - X86, LLVM Compiler/Interpreter for MiniJava. 3 | * Copyright (C) 2014, 2008 Mitch Souders, Mark A. Smith, Mark P. Jones 4 | * 5 | * MiniJava Compiler is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * MiniJava Compiler is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with MiniJava Compiler; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package util; 21 | 22 | public interface ListIteratorIF { 23 | T getNext(); 24 | } 25 | -------------------------------------------------------------------------------- /unitTests/array.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/array.gcc.ref -------------------------------------------------------------------------------- /unitTests/array.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | System.out.println("Test"); 4 | char [] test = new char[3]; 5 | test[0] = 'p'; 6 | test[1] = 'q'; 7 | test[2] = '\n'; 8 | String s = String.makeStringChar(test); 9 | System.out.print(s); 10 | String big = "test123"; 11 | String big2 = "something else"; 12 | String biggest = big.append(big2); 13 | System.out.println(biggest); 14 | 15 | System.out.println(1742); 16 | System.out.println(-253); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /unitTests/array.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/array.bc 2 | -------------------------------------------------------------------------------- /unitTests/array.run.ref: -------------------------------------------------------------------------------- 1 | Test 2 | pq 3 | test123something else 4 | 1742 5 | -253 6 | -------------------------------------------------------------------------------- /unitTests/arrayAcces.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arrayAcces.gcc.ref -------------------------------------------------------------------------------- /unitTests/arrayAcces.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | System.out = new PrintStream(); 4 | System.out.println("test"); 5 | } 6 | } -------------------------------------------------------------------------------- /unitTests/arrayAcces.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/arrayAcces.bc 2 | -------------------------------------------------------------------------------- /unitTests/arrayAcces.run.ref: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /unitTests/arrayAccess2.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arrayAccess2.gcc.ref -------------------------------------------------------------------------------- /unitTests/arrayAccess2.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main() { 3 | int [] test = new int[5]; 4 | /* this is bad! */ 5 | test[10] = 1; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /unitTests/arrayAccess2.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/arrayAccess2.bc 2 | -------------------------------------------------------------------------------- /unitTests/arrayAccess2.run.ref: -------------------------------------------------------------------------------- 1 | EXCEPTION: unitTests/arrayAccess2.j:5 Array access out of bounds (index 10, length 5). 2 | -------------------------------------------------------------------------------- /unitTests/arrayClass.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arrayClass.gcc.ref -------------------------------------------------------------------------------- /unitTests/arrayClass.j: -------------------------------------------------------------------------------- 1 | class Element { 2 | int x; 3 | int y; 4 | int z; 5 | Element other; 6 | } 7 | 8 | class Main { 9 | static void main() { 10 | int elem_size = 10; 11 | Element [] elems = new Element[elem_size]; 12 | 13 | int x = 0; 14 | do { 15 | Element e = elems[x] = new Element(); 16 | e.x = x * 5; 17 | e.y = x * 7; 18 | e.z = x * -1; 19 | x = x + 1; 20 | } while (x < elem_size); 21 | 22 | System.out.println(elems[5].x); 23 | System.out.println(elems[7].y); 24 | System.out.println(elems[2].z); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /unitTests/arrayClass.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/arrayClass.bc 2 | -------------------------------------------------------------------------------- /unitTests/arrayClass.run.ref: -------------------------------------------------------------------------------- 1 | 25 2 | 49 3 | -2 4 | -------------------------------------------------------------------------------- /unitTests/arrayInherit.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arrayInherit.gcc.ref -------------------------------------------------------------------------------- /unitTests/arrayInherit.j: -------------------------------------------------------------------------------- 1 | class A { 2 | } 3 | 4 | class B extends A { 5 | } 6 | 7 | class Main { 8 | static void main() { 9 | A [] a = new A[10]; 10 | B [] b = new B[10]; 11 | a = b; 12 | A [] a2 = new B[10]; 13 | System.out.println("Completed Successfully"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /unitTests/arrayInherit.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/arrayInherit.bc 2 | -------------------------------------------------------------------------------- /unitTests/arrayInherit.run.ref: -------------------------------------------------------------------------------- 1 | Completed Successfully 2 | -------------------------------------------------------------------------------- /unitTests/arrayInst.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arrayInst.gcc.ref -------------------------------------------------------------------------------- /unitTests/arrayInst.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | char [] test; 4 | test = new char[10]; 5 | test.toString(); 6 | } 7 | } -------------------------------------------------------------------------------- /unitTests/arrayInst.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/arrayInst.bc 2 | -------------------------------------------------------------------------------- /unitTests/arrayInst.run.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arrayInst.run.ref -------------------------------------------------------------------------------- /unitTests/arraylit1.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arraylit1.gcc.ref -------------------------------------------------------------------------------- /unitTests/arraylit1.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | char [] test = new char[] {'a', 'b', 'c'}; 4 | String s = String.makeStringChar(test); 5 | System.out.println(s); 6 | 7 | int [] test2 = new int[] {1, 2, 3, 4, 5, 6}; 8 | int x = 0; 9 | while (x < test2.length) { 10 | System.out.println(test2[x]); 11 | x = x + 1; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /unitTests/arraylit1.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/arraylit1.bc 2 | -------------------------------------------------------------------------------- /unitTests/arraylit1.run.ref: -------------------------------------------------------------------------------- 1 | abc 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | -------------------------------------------------------------------------------- /unitTests/arraylit2.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arraylit2.gcc.ref -------------------------------------------------------------------------------- /unitTests/arraylit2.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | int [][] test2 = new int[][] { 4 | new int[]{1, 2, 3, 4, 5, 6}, 5 | new int[]{1, 2, 3}, 6 | new int[]{9, 2, 3, 4}, 7 | new int[]{}, 8 | new int[]{1, 2, 3, 4, 5, 6, 7, 8} 9 | }; 10 | int x = 0; 11 | while (x < test2.length) { 12 | int y = 0; 13 | while (y < test2[x].length) { 14 | System.out.print(test2[x][y]); 15 | System.out.print(" "); 16 | y = y + 1; 17 | } 18 | System.out.println(""); 19 | x = x + 1; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /unitTests/arraylit2.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/arraylit2.bc 2 | -------------------------------------------------------------------------------- /unitTests/arraylit2.run.ref: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 2 | 1 2 3 3 | 9 2 3 4 4 | 5 | 1 2 3 4 5 6 7 8 6 | -------------------------------------------------------------------------------- /unitTests/arraylit3.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arraylit3.gcc.ref -------------------------------------------------------------------------------- /unitTests/arraylit3.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | int [][] test2 = new int[][] { 4 | new int[]{2147483647 / 2 / 2 / 2 / 2 / 2 / 2 / 2 / 2 / 2 / 2 / 2, 2, 3, 4, 5, 6}, 5 | new int[]{1, 2, 3}, 6 | new int[]{9, 2, 3, 4}, 7 | new int[]{}, 8 | new int[]{1, 2, 3, 4, 5, 6, 7, 8} 9 | }; 10 | int x = 0; 11 | while (x < test2.length) { 12 | int y = 0; 13 | while (y < test2[x].length) { 14 | System.out.print(test2[x][y]); 15 | System.out.print(" "); 16 | y = y + 1; 17 | } 18 | System.out.println(""); 19 | x = x + 1; 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /unitTests/arraylit3.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/arraylit3.bc 2 | -------------------------------------------------------------------------------- /unitTests/arraylit3.run.ref: -------------------------------------------------------------------------------- 1 | 1048575 2 3 4 5 6 2 | 1 2 3 3 | 9 2 3 4 4 | 5 | 1 2 3 4 5 6 7 8 6 | -------------------------------------------------------------------------------- /unitTests/arraylit4.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/arraylit4.gcc.ref -------------------------------------------------------------------------------- /unitTests/arraylit4.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | int [][] test2 = new int[][] { 4 | new int[]{Integer.MIN_VALUE, Integer.MAX_VALUE} 5 | }; 6 | int x = 0; 7 | while (x < test2.length) { 8 | int y = 0; 9 | while (y < test2[x].length) { 10 | System.out.print(x); 11 | System.out.print(" "); 12 | System.out.print(y); 13 | System.out.print(": "); 14 | System.out.print(test2[x][y]); 15 | System.out.print(", "); 16 | y = y + 1; 17 | } 18 | System.out.println(""); 19 | x = x + 1; 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /unitTests/arraylit4.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/arraylit4.bc 2 | -------------------------------------------------------------------------------- /unitTests/arraylit4.run.ref: -------------------------------------------------------------------------------- 1 | 0 0: -2147483648, 0 1: 2147483647, 2 | -------------------------------------------------------------------------------- /unitTests/badArrayInherit.j: -------------------------------------------------------------------------------- 1 | class A { 2 | } 3 | 4 | class B extends A { 5 | } 6 | 7 | class Main { 8 | static void main() { 9 | B [] b = new A[10]; 10 | System.out.println("Should not be successful"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /unitTests/badArrayInherit.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badArrayInherit.j", line 9 2 | Cannot initialize value of type B[] to variable of type A[] 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badArrayInherit2.j: -------------------------------------------------------------------------------- 1 | class A { 2 | } 3 | 4 | class B extends A { 5 | } 6 | 7 | class Main { 8 | static void main() { 9 | B [] b = null; 10 | b = new A[10]; 11 | System.out.println("Should not be successful"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /unitTests/badArrayInherit2.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badArrayInherit2.j", line 10 2 | Cannot assign value of type A[] to variable of type B[] 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badConstructor.j: -------------------------------------------------------------------------------- 1 | class Constructed { 2 | public Constructed() { 3 | 4 | } 5 | public Constructed() { 6 | } 7 | } 8 | 9 | class Main { 10 | public static void main() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /unitTests/badConstructor.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badConstructor.j", line 2 2 | Multiple definitions for method Constructed 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badIface.j: -------------------------------------------------------------------------------- 1 | interface Iface { 2 | void test(int test123); 3 | } 4 | 5 | class SomeClass implements Iface { 6 | void test(int xyz) { 7 | System.out.println("Does something"); 8 | } 9 | } 10 | class Main { 11 | public static void main() { 12 | Iface x; 13 | Iface y = new Iface(); 14 | System.out.println("Test123"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /unitTests/badIface.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badIface.j", line 13 2 | Unable to instantiate abstract class or interface Iface 3 | 4 | ERROR: "unitTests/badIface.j", line 13 5 | Unable to instantiate abstract class or interface Iface 6 | 7 | -------------------------------------------------------------------------------- /unitTests/badIface2.j: -------------------------------------------------------------------------------- 1 | interface Iface { 2 | void test(int test123); 3 | void other(int test123); 4 | } 5 | 6 | class SomeClass implements SomeOtherClass { 7 | void test(int xyz) { 8 | System.out.println("Does something"); 9 | System.out.println(xyz); 10 | } 11 | void other(int xyz) { 12 | System.out.println("Something else"); 13 | System.out.println(xyz); 14 | } 15 | } 16 | class SomeOtherClass implements Iface { 17 | void test(int xyz) { 18 | System.out.println("XXXX Does something"); 19 | System.out.println(xyz); 20 | } 21 | void other(int xyz) { 22 | System.out.println("XXX Something else"); 23 | System.out.println(xyz); 24 | } 25 | } 26 | 27 | 28 | class Main { 29 | public static void main() { 30 | Iface x; 31 | Iface y = new SomeClass(); 32 | y.test(200); 33 | y.other(70); 34 | y = new SomeOtherClass(); 35 | y.test(12); 36 | y.other(15); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /unitTests/badIface2.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badIface2.j", line 6 2 | Can only implement interface types. SomeOtherClass is not an interface. 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badIface3.j: -------------------------------------------------------------------------------- 1 | interface Iface { 2 | void test(int test123); 3 | void other(int test123); 4 | } 5 | 6 | class SomeClass implements Iface { 7 | void other(int xyz) { 8 | System.out.println("Something else"); 9 | System.out.println(xyz); 10 | } 11 | } 12 | 13 | class SomeOtherClass implements Iface { 14 | void test(int xyz) { 15 | System.out.println("XXXX Does something"); 16 | System.out.println(xyz); 17 | } 18 | } 19 | 20 | class Main { 21 | public static void main() { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /unitTests/badIface3.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badIface3.j", line 13 2 | SomeOtherClass does not implement method other from Iface 3 | 4 | ERROR: "unitTests/badIface3.j", line 6 5 | SomeClass does not implement method test from Iface 6 | 7 | -------------------------------------------------------------------------------- /unitTests/badIface4.j: -------------------------------------------------------------------------------- 1 | interface Iface { 2 | void test(int test123); 3 | void other(int test123); 4 | } 5 | 6 | class SomeClass implements Iface { 7 | void other(int xyz, SomeClass FORGOTTEN) { 8 | System.out.println("Something else"); 9 | System.out.println(xyz); 10 | } 11 | } 12 | class SomeOtherClass implements Iface { 13 | void test(int xyz, int FORGOTTEN) { 14 | System.out.println("XXXX Does something"); 15 | System.out.println(xyz); 16 | } 17 | } 18 | 19 | class Main { 20 | public static void main() { 21 | Iface x; 22 | Iface y = new SomeClass(); 23 | y.test(200); 24 | y.other(70); 25 | y = new SomeOtherClass(); 26 | y.test(12); 27 | y.other(15); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /unitTests/badIface4.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badIface4.j", line 12 2 | SomeOtherClass does not implement method other from Iface 3 | 4 | ERROR: "unitTests/badIface4.j", line 12 5 | SomeOtherClass does not match signature of test from Iface 6 | 7 | ERROR: "unitTests/badIface4.j", line 6 8 | SomeClass does not match signature of other from Iface 9 | 10 | ERROR: "unitTests/badIface4.j", line 6 11 | SomeClass does not implement method test from Iface 12 | 13 | -------------------------------------------------------------------------------- /unitTests/badIface5.j: -------------------------------------------------------------------------------- 1 | interface Iface { 2 | void test(int test123); 3 | void other(int test123, int NOT_USED); 4 | } 5 | 6 | class SomeClass implements Iface { 7 | void test(int xyz) { 8 | System.out.println("Does something"); 9 | System.out.println(xyz); 10 | } 11 | void other(int xyz) { 12 | System.out.println("Something else"); 13 | System.out.println(xyz); 14 | } 15 | } 16 | 17 | class SomeOtherClass implements Iface { 18 | void test(int xyz) { 19 | System.out.println("XXXX Does something"); 20 | System.out.println(xyz); 21 | } 22 | void other(int xyz) { 23 | System.out.println("XXX Something else"); 24 | System.out.println(xyz); 25 | } 26 | } 27 | 28 | 29 | class Main { 30 | public static void main() { 31 | Iface x; 32 | Iface y = new SomeClass(); 33 | y.test(200); 34 | y.other(70); 35 | y = new SomeOtherClass(); 36 | y.test(12); 37 | y.other(15); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /unitTests/badIface5.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badIface5.j", line 17 2 | SomeOtherClass does not match signature of other from Iface 3 | 4 | ERROR: "unitTests/badIface5.j", line 6 5 | SomeClass does not match signature of other from Iface 6 | 7 | -------------------------------------------------------------------------------- /unitTests/badIface6.j: -------------------------------------------------------------------------------- 1 | interface Iface { 2 | int test(int test123); 3 | String other(int test123); 4 | } 5 | 6 | class SomeClass implements Iface { 7 | int test(int test123) {} 8 | int other(int xyz) { 9 | System.out.println("Something else"); 10 | System.out.println(xyz); 11 | } 12 | } 13 | class SomeOtherClass implements Iface { 14 | void test(int xyz) { 15 | System.out.println("XXXX Does something"); 16 | System.out.println(xyz); 17 | } 18 | String other(int test123) {} 19 | } 20 | 21 | class Main { 22 | public static void main() { 23 | Iface x; 24 | Iface y = new SomeClass(); 25 | y.test(200); 26 | y.other(70); 27 | y = new SomeOtherClass(); 28 | y.test(12); 29 | y.other(15); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /unitTests/badIface6.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badIface6.j", line 14 2 | SomeOtherClass does not match signature of test from Iface 3 | 4 | ERROR: "unitTests/badIface6.j", line 8 5 | SomeClass does not match signature of other from Iface 6 | 7 | -------------------------------------------------------------------------------- /unitTests/badIface7.j: -------------------------------------------------------------------------------- 1 | interface If1 { 2 | void test(int xyz); 3 | } 4 | 5 | interface If2 extends If2 { 6 | void test(int pyq); 7 | } 8 | 9 | class Test implements If1 { 10 | void test(int pyq) { 11 | System.out.println(pyq); 12 | } 13 | } 14 | 15 | class Main { 16 | public static void main() { 17 | If1 iface = new Test(); 18 | iface.test(12); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /unitTests/badIface7.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badIface7.j", line 5 2 | Class If2 extends itself! 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badScope.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static public void main() { 3 | int p; 4 | p = 5; 5 | test(); 6 | System.out.println(p); 7 | if (true) { 8 | int p; 9 | p = 2; 10 | } 11 | } 12 | 13 | static void test() { 14 | int p; 15 | p = 0; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /unitTests/badScope.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badScope.j", line 8 2 | Repeated definition for variable p 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badScope2.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static public void main() { 3 | if (true) { 4 | int p; 5 | p = 2; 6 | System.out.println(p); 7 | } 8 | int p; 9 | p = 5; 10 | System.out.println(p); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /unitTests/badScope2.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/badScope2.bc 2 | -------------------------------------------------------------------------------- /unitTests/badScope2.run.ref: -------------------------------------------------------------------------------- 1 | 2 2 | 5 3 | -------------------------------------------------------------------------------- /unitTests/badSuper1.j: -------------------------------------------------------------------------------- 1 | class Test { 2 | int x; 3 | public Test(int test) { 4 | x = test; 5 | } 6 | public void test() { 7 | System.out.println("Test"); 8 | System.out.println(x); 9 | } 10 | } 11 | 12 | class Test2 extends Test { 13 | public Test2() { 14 | super(); /* wrong number of args */ 15 | } 16 | public void test2() { 17 | super.x = 5; 18 | super.test(); 19 | super.x = 10; 20 | super.test(); 21 | System.out.println(super.x); 22 | } 23 | } 24 | 25 | class Main { 26 | public static void main() { 27 | Test2 t = new Test2(); 28 | t.test2(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /unitTests/badSuper1.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badSuper1.j", line 14 2 | Cannot find corresponding superclass constructor. 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badSuper2.j: -------------------------------------------------------------------------------- 1 | class Test { 2 | int x; 3 | public Test(int test) { 4 | x = test; 5 | } 6 | public void test() { 7 | System.out.println("Test"); 8 | System.out.println(x); 9 | } 10 | } 11 | 12 | class Test2 extends Test { 13 | public Test2() { 14 | /* no constructor but needed, since there can be no default */ 15 | } 16 | public void test2() { 17 | super.x = 5; 18 | super.test(); 19 | super.x = 10; 20 | super.test(); 21 | System.out.println(super.x); 22 | } 23 | } 24 | 25 | class Main { 26 | public static void main() { 27 | Test2 t = new Test2(); 28 | t.test2(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /unitTests/badSuper2.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badSuper2.j", line 13 2 | Constructor needs a super class constructor (maybe it's not the first statement?). 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badSuper3.j: -------------------------------------------------------------------------------- 1 | class Test { 2 | int x; 3 | public Test(int test) { 4 | x = test; 5 | } 6 | public void test() { 7 | System.out.println("Test"); 8 | System.out.println(x); 9 | } 10 | } 11 | 12 | class Test2 extends Test { 13 | public Test2() { 14 | int test; 15 | super(17); /* must be the first statement */ 16 | } 17 | public void test2() { 18 | super.x = 5; 19 | super.test(); 20 | super.x = 10; 21 | super.test(); 22 | System.out.println(super.x); 23 | } 24 | } 25 | 26 | class Main { 27 | public static void main() { 28 | Test2 t = new Test2(); 29 | t.test2(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /unitTests/badSuper3.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badSuper3.j", line 13 2 | Constructor needs a super class constructor (maybe it's not the first statement?). 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badSuper4.j: -------------------------------------------------------------------------------- 1 | class Test { 2 | int x; 3 | public Test(int test) { 4 | x = test; 5 | } 6 | public void test() { 7 | System.out.println("Test"); 8 | System.out.println(x); 9 | } 10 | } 11 | 12 | class Test2 extends Test { 13 | public Test2() { 14 | test(); 15 | super(17); /* must be the first statement */ 16 | } 17 | public void test2() { 18 | super.x = 5; 19 | super.test(); 20 | super.x = 10; 21 | super.test(); 22 | System.out.println(super.x); 23 | } 24 | } 25 | 26 | class Main { 27 | public static void main() { 28 | Test2 t = new Test2(); 29 | t.test2(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /unitTests/badSuper4.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badSuper4.j", line 13 2 | Constructor needs a super class constructor (maybe it's not the first statement?). 3 | 4 | -------------------------------------------------------------------------------- /unitTests/badSuper5.j: -------------------------------------------------------------------------------- 1 | class Test { 2 | int x; 3 | public Test(int test) { 4 | x = test; 5 | } 6 | public void test() { 7 | System.out.println("Test"); 8 | System.out.println(x); 9 | } 10 | } 11 | 12 | class Test2 extends Test { 13 | public Test2() { 14 | super(17); 15 | test(); 16 | super(17); /* not allowed supers in later statements */ 17 | } 18 | public void test2() { 19 | super.x = 5; 20 | super.test(); 21 | super.x = 10; 22 | super.test(); 23 | System.out.println(super.x); 24 | } 25 | } 26 | 27 | class Main { 28 | public static void main() { 29 | Test2 t = new Test2(); 30 | t.test2(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /unitTests/badSuper5.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/badSuper5.j", line 16 2 | Super constructor must be first instruction in constructor. 3 | 4 | -------------------------------------------------------------------------------- /unitTests/bad_max_int.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | int max_int = 2147483647; //2^31 - 1 4 | int too_big = 2147483648; //2^31 5 | int x; 6 | x = max_int; 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /unitTests/bad_max_int.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/bad_max_int.j", line 4 2 | Invalid Integer Literal: 2147483648. 3 | 4 | -------------------------------------------------------------------------------- /unitTests/bad_min_int.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | int min_int = -2147483648; // -2^31 4 | int too_small = -2147483649; // -2^31 -1 5 | int x; 6 | x = min_int; 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /unitTests/bad_min_int.mjc.ref: -------------------------------------------------------------------------------- 1 | ERROR: "unitTests/bad_min_int.j", line 4 2 | Invalid Integer Literal: -2147483649. 3 | 4 | -------------------------------------------------------------------------------- /unitTests/benchmark.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/benchmark.gcc.ref -------------------------------------------------------------------------------- /unitTests/benchmark.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/benchmark.bc 2 | -------------------------------------------------------------------------------- /unitTests/benchmark.run.ref: -------------------------------------------------------------------------------- 1 | Benchmarks Completed Successfully 2 | -------------------------------------------------------------------------------- /unitTests/blob.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/blob.gcc.ref -------------------------------------------------------------------------------- /unitTests/blob.j: -------------------------------------------------------------------------------- 1 | class Blob { 2 | int y; 3 | } 4 | 5 | class TestObj { 6 | static Blob b; 7 | } 8 | 9 | class Main { 10 | static void main() { 11 | TestObj.b = new Blob(); 12 | TestObj.b.y = 3; 13 | System.out.println(42); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /unitTests/blob.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/blob.bc 2 | -------------------------------------------------------------------------------- /unitTests/blob.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /unitTests/classClass.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/classClass.gcc.ref -------------------------------------------------------------------------------- /unitTests/classClass.j: -------------------------------------------------------------------------------- 1 | class TestObjOne { 2 | int x; 3 | int z; 4 | } 5 | 6 | class TestObjTwo extends TestObjOne { 7 | int p; 8 | int q; 9 | } 10 | 11 | class Main { 12 | static void main() { 13 | TestObjOne oo; 14 | TestObjTwo pp; 15 | oo = new TestObjOne(); 16 | pp = new TestObjTwo(); 17 | System.out.println("Class Name"); 18 | System.out.println(oo.getClass().getName()); 19 | System.out.println(oo.getClass().isInstance(pp)); 20 | System.out.println(pp.getClass().isInstance(oo)); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /unitTests/classClass.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/classClass.bc 2 | -------------------------------------------------------------------------------- /unitTests/classClass.run.ref: -------------------------------------------------------------------------------- 1 | Class Name 2 | TestObjOne 3 | false 4 | true 5 | -------------------------------------------------------------------------------- /unitTests/gcArrays.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcArrays.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcArrays.j: -------------------------------------------------------------------------------- 1 | class Element { 2 | int x; 3 | int y; 4 | int z; 5 | } 6 | 7 | class Main { 8 | static void set_array(Element [] ary, int n) { 9 | int x = 0; 10 | while (x < ary.length) { 11 | ary[x] = new Element(); 12 | ary[x].x = n; 13 | ary[x].y = n * 2; 14 | ary[x].z = n * 3; 15 | x = x + 1; 16 | } 17 | } 18 | 19 | static void check_array(Element [] ary, int n) { 20 | int x = 0; 21 | while (x < ary.length) { 22 | if (ary[x].x != n || ary[x].y != n * 2 || ary[x].z != n * 3) { 23 | System.out.println("Value mismatch"); 24 | } 25 | x = x + 1; 26 | } 27 | } 28 | static void array_test(int x, Element [] elems1, Element [] elems2, 29 | Element [] elems3) { 30 | set_array(elems1, x % 7); 31 | new Element[37]; 32 | set_array(elems2, x % 123); 33 | new Element[37]; 34 | set_array(elems3, x % 105); 35 | new Element[37]; 36 | check_array(elems1, x % 7); 37 | new Element[37]; 38 | check_array(elems2, x % 123); 39 | new Element[37]; 40 | check_array(elems3, x % 105); 41 | } 42 | 43 | static void main() { 44 | int repitition = 50; 45 | int x = 0; 46 | while (x < repitition) { 47 | array_test(x, new Element[7], new Element[17], new Element[23]); 48 | new Element[37]; 49 | x = x + 1; 50 | } 51 | System.out.println("Completed Successfully"); 52 | System.out.println(x); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /unitTests/gcArrays.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcArrays.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcArrays.run.ref: -------------------------------------------------------------------------------- 1 | Completed Successfully 2 | 50 3 | -------------------------------------------------------------------------------- /unitTests/gcArrays2.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcArrays2.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcArrays2.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | if (true) { 4 | int [] test = new int[113]; 5 | test[0] = 1; 6 | } 7 | if (true) { 8 | int [] test = new int[113]; 9 | test[0] = 1; 10 | } 11 | if (true) { 12 | int [] test = new int[113]; 13 | test[0] = 1; 14 | } 15 | if (true) { 16 | int [] test = new int[113]; 17 | test[0] = 1; 18 | } 19 | if (true) { 20 | int [] test = new int[113]; 21 | test[0] = 1; 22 | } 23 | if (true) { 24 | int [] test = new int[113]; 25 | test[0] = 1; 26 | } 27 | if (true) { 28 | int [] test = new int[113]; 29 | test[0] = 1; 30 | } 31 | if (true) { 32 | int [] test = new int[113]; 33 | test[0] = 1; 34 | } 35 | if (true) { 36 | int [] test = new int[113]; 37 | test[0] = 1; 38 | } 39 | if (true) { 40 | int [] test = new int[113]; 41 | test[0] = 1; 42 | } 43 | if (true) { 44 | int [] test = new int[113]; 45 | test[0] = 1; 46 | } 47 | if (true) { 48 | int [] test = new int[113]; 49 | test[0] = 1; 50 | } 51 | if (true) { 52 | int [] test = new int[113]; 53 | test[0] = 1; 54 | } 55 | if (true) { 56 | int [] test = new int[113]; 57 | test[0] = 1; 58 | } 59 | if (true) { 60 | int [] test = new int[113]; 61 | test[0] = 1; 62 | } 63 | if (true) { 64 | int [] test = new int[113]; 65 | test[0] = 1; 66 | } 67 | System.out.println("Completed Successfully"); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /unitTests/gcArrays2.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcArrays2.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcArrays2.run.ref: -------------------------------------------------------------------------------- 1 | Completed Successfully 2 | -------------------------------------------------------------------------------- /unitTests/gcCircular.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcCircular.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcCircular.j: -------------------------------------------------------------------------------- 1 | /* utility class */ 2 | class List { 3 | public List next; 4 | public int data; 5 | public List(List next) { 6 | this.next = next; 7 | } 8 | } 9 | class Main { 10 | public static void cleanup(List node) { 11 | if (node.next != null) { 12 | cleanup(node.next); 13 | } 14 | node.next = null; 15 | } 16 | public static void main() { 17 | int mem = 10; 18 | int i; 19 | while (i < mem) { 20 | int [] garbage2 = new int [7]; 21 | int j; 22 | while (j < 100) { 23 | //both of these cycles should disappear 24 | // after this loop and never fill up all of memory. 25 | List self_cycle = new List(null); 26 | int [] garbagex = new int [13]; 27 | self_cycle.next = self_cycle; 28 | List circle_1 = new List(null); 29 | int [] garbagey = new int [3]; 30 | List circle_2 = new List(null); 31 | circle_1.next = circle_2; 32 | int [] garbagez = new int [37]; 33 | circle_2.next = circle_1; 34 | j = j + 1; 35 | } 36 | int [] garbageq = new int [17]; 37 | i = i + 1; 38 | } 39 | System.out.println("Finished Successfully"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /unitTests/gcCircular.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcCircular.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcCircular.run.ref: -------------------------------------------------------------------------------- 1 | Finished Successfully 2 | -------------------------------------------------------------------------------- /unitTests/gcClass.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcClass.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcClass.j: -------------------------------------------------------------------------------- 1 | class Element { 2 | int x; 3 | int y; 4 | int z; 5 | } 6 | 7 | class Main { 8 | static Element create_elem(int n) { 9 | Element temp = new Element(); 10 | temp.x = n + 5; 11 | temp.y = n + 2; 12 | temp.z = n + 7; 13 | return temp; 14 | } 15 | 16 | static void main() { 17 | int repitition = 500; 18 | int x = 0; 19 | while (x < repitition) { 20 | int y = create_elem(5).x + create_elem(7).y + create_elem(2).z; 21 | y = y + 1; 22 | x = x + 1; 23 | } 24 | System.out.println("Completed Successfully"); 25 | System.out.println(x); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /unitTests/gcClass.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcClass.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcClass.run.ref: -------------------------------------------------------------------------------- 1 | Completed Successfully 2 | 500 3 | -------------------------------------------------------------------------------- /unitTests/gcComplex.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcComplex.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcComplex.j: -------------------------------------------------------------------------------- 1 | /* utility class */ 2 | class List { 3 | public List next; 4 | public int data; 5 | public List(List next, int data) { 6 | this.next = next; 7 | this.data = data; 8 | } 9 | } 10 | class Main { 11 | public static void cleanup(int depth, List node) { 12 | if (node.next != null) { 13 | cleanup(depth + 1, node.next); 14 | } 15 | node.next = null; 16 | } 17 | public static void main() { 18 | int mem = 100; 19 | /* this should keep allocated more than 20 | the possible memory space. 21 | Some are nulled, but garbage collection 22 | is the only reason it should non memory 23 | error. */ 24 | List prev = null; 25 | int i = 0; 26 | while (i < mem) { 27 | int [] garbage2 = new int [7]; 28 | int j = 0; 29 | while (j < 15) { 30 | List l = new List(prev, j); 31 | int [] garbage = new int [13]; 32 | prev = l; 33 | j = j + 1; 34 | } 35 | cleanup(0, prev); 36 | i = i + 1; 37 | } 38 | System.out.println("Completed Successfully"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /unitTests/gcComplex.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcComplex.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcComplex.run.ref: -------------------------------------------------------------------------------- 1 | Completed Successfully 2 | -------------------------------------------------------------------------------- /unitTests/gcHeterogenous.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcHeterogenous.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcHeterogenous.j: -------------------------------------------------------------------------------- 1 | class Small { 2 | int small; 3 | int [] ary; 4 | public Small(int s) { 5 | this.small = s; 6 | this.ary = new int[s]; 7 | } 8 | } 9 | 10 | class Main { 11 | public static void fill_array(int i, int [] ary) { 12 | int x = 0; 13 | while (x < ary.length) { 14 | ary[x] = i + x; 15 | x = x + 1; 16 | } 17 | } 18 | public static void print_array(int [] ary) { 19 | int x = 0; 20 | while (x < ary.length) { 21 | System.out.print(ary[x]); 22 | System.out.print(" "); 23 | x = x + 1; 24 | } 25 | System.out.print("\n"); 26 | } 27 | public static void main() { 28 | int mem = 10; 29 | /* this should keep allocated more than 30 | the possible memory space. 31 | Some are nulled, but garbage collection 32 | is the only reason it should non memory 33 | error. */ 34 | int i = 0; 35 | while (i < mem) { 36 | int [] x0 = new int [7]; 37 | fill_array(i, x0); 38 | Small x1 = new Small(i); 39 | int [] x2 = new int [6]; 40 | fill_array(i, x2); 41 | int q = 5; 42 | int [] x3 = new int [3]; 43 | fill_array(i, x3); 44 | Small x4 = new Small(i); 45 | int y = 2; 46 | int [] x5 = new int [12]; 47 | fill_array(i, x5); 48 | Small x6 = new Small(i); 49 | int [] x7 = new int [120]; 50 | int p = 7; 51 | 52 | fill_array(i, x7); 53 | 54 | x1 = null; 55 | x3 = null; 56 | x4 = null; 57 | 58 | print_array(x5); 59 | i = i + 1; 60 | } 61 | System.out.println("Finished Successfully"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /unitTests/gcHeterogenous.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcHeterogenous.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcHeterogenous.run.ref: -------------------------------------------------------------------------------- 1 | 0 1 2 3 4 5 6 7 8 9 10 11 2 | 1 2 3 4 5 6 7 8 9 10 11 12 3 | 2 3 4 5 6 7 8 9 10 11 12 13 4 | 3 4 5 6 7 8 9 10 11 12 13 14 5 | 4 5 6 7 8 9 10 11 12 13 14 15 6 | 5 6 7 8 9 10 11 12 13 14 15 16 7 | 6 7 8 9 10 11 12 13 14 15 16 17 8 | 7 8 9 10 11 12 13 14 15 16 17 18 9 | 8 9 10 11 12 13 14 15 16 17 18 19 10 | 9 10 11 12 13 14 15 16 17 18 19 20 11 | Finished Successfully 12 | -------------------------------------------------------------------------------- /unitTests/gcgentest1.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest1.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest1.j: -------------------------------------------------------------------------------- 1 | // Small program for testing gen garbage collector: 2 | // Test two objects with gc. One is fixed and one is refreshed in the loop 3 | 4 | class TestObjOne { 5 | int x; 6 | int z; 7 | } 8 | 9 | class TestObjTwo { 10 | int a; 11 | int c; 12 | } 13 | 14 | class Main { 15 | static void main() { 16 | int x; 17 | int loops; 18 | TestObjOne oo; 19 | TestObjTwo ot; 20 | 21 | oo = new TestObjOne(); 22 | oo.x = 42; 23 | 24 | ot = new TestObjTwo(); 25 | ot.a = 42; 26 | 27 | x = 0; 28 | loops = 1000000; 29 | while (x < loops) { 30 | ot = new TestObjTwo(); 31 | ot.a = x; 32 | x = x + 1; 33 | } 34 | System.out.println(oo.x); 35 | System.out.println(ot.a); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /unitTests/gcgentest1.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest1.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest1.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | 999999 3 | -------------------------------------------------------------------------------- /unitTests/gcgentest10.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest10.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest10.j: -------------------------------------------------------------------------------- 1 | // Small program for testing gen garbage collector: 2 | // Test two objects with gc. 3 | // Create one object and also assign it to a 2nd object 4 | 5 | class TestObjOne { 6 | int x; 7 | int z; 8 | } 9 | 10 | class Main { 11 | static void main() { 12 | int x; 13 | int loops; 14 | TestObjOne oo; 15 | TestObjOne ocopy = null; 16 | 17 | oo = new TestObjOne(); 18 | oo.x = 42; 19 | 20 | 21 | x = 0; 22 | loops = 1000000; 23 | while (x < loops) { 24 | oo = new TestObjOne(); 25 | oo.x = x; 26 | ocopy = oo; 27 | x = x + 1; 28 | } 29 | System.out.println(oo.x); 30 | System.out.println(ocopy.x); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /unitTests/gcgentest10.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest10.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest10.run.ref: -------------------------------------------------------------------------------- 1 | 999999 2 | 999999 3 | -------------------------------------------------------------------------------- /unitTests/gcgentest2.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest2.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest2.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test gc with derived class 3 | // Derived class is steady (for old gen) 4 | // Another base class is repeatedly created 5 | 6 | class TestObjOne { 7 | int x; 8 | int z; 9 | } 10 | 11 | class TestObjTwo extends TestObjOne { 12 | int a; 13 | int c; 14 | } 15 | 16 | class Main { 17 | static void main() { 18 | int x; 19 | int loops; 20 | TestObjOne oo; 21 | TestObjTwo ot; 22 | 23 | oo = new TestObjOne(); 24 | oo.x = 42; 25 | 26 | ot = new TestObjTwo(); 27 | ot.a = 42; 28 | 29 | x = 0; 30 | loops = 1000000; 31 | while (x < loops) { 32 | oo = new TestObjOne(); 33 | oo.x = x; 34 | x = x + 1; 35 | } 36 | System.out.println(oo.x); 37 | System.out.println(ot.a); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /unitTests/gcgentest2.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest2.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest2.run.ref: -------------------------------------------------------------------------------- 1 | 999999 2 | 42 3 | -------------------------------------------------------------------------------- /unitTests/gcgentest3.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest3.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest3.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // gc test for object containing another object 3 | 4 | class TestObjOne { 5 | int x; 6 | int z; 7 | } 8 | 9 | class TestObjTwo { 10 | TestObjOne too; 11 | } 12 | 13 | class Main { 14 | static void main() { 15 | int x; 16 | int loops; 17 | TestObjOne oo; 18 | TestObjTwo old; 19 | TestObjTwo ot; 20 | 21 | 22 | oo = new TestObjOne(); 23 | oo.x = 42; 24 | 25 | ot = new TestObjTwo(); 26 | ot.too = new TestObjOne(); 27 | ot.too.z = 42; 28 | 29 | old = new TestObjTwo(); 30 | old.too = new TestObjOne(); 31 | old.too.z = 77; 32 | 33 | 34 | x = 0; 35 | loops = 100000; 36 | while (x < loops) { 37 | oo = new TestObjOne(); 38 | ot = new TestObjTwo(); 39 | ot.too = new TestObjOne(); 40 | oo.x = x; 41 | ot.too.z = 42; 42 | x = x + 1; 43 | } 44 | System.out.println(oo.x); 45 | System.out.println(ot.too.z); 46 | System.out.println(old.too.z); 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /unitTests/gcgentest3.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest3.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest3.run.ref: -------------------------------------------------------------------------------- 1 | 99999 2 | 42 3 | 77 4 | -------------------------------------------------------------------------------- /unitTests/gcgentest4.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest4.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest4.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test basic array creation/deletion/gc 3 | 4 | 5 | class Main { 6 | static void main() { 7 | int x; 8 | int loops; 9 | int [] o; 10 | o = new int[10]; 11 | 12 | int [] old; 13 | old = new int[100]; 14 | old[0] = 77; 15 | old[10] = 770; 16 | 17 | x = 0; 18 | loops = 1000; 19 | while (x < loops) { 20 | o = new int[10]; 21 | x = x + 1; 22 | o[x % 10] = x; 23 | } 24 | o[0] = 42; 25 | o[9] = 8; 26 | System.out.println(o[0]); 27 | System.out.println(o[9]); 28 | System.out.println(old[0]); 29 | System.out.println(old[10]); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /unitTests/gcgentest4.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest4.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest4.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | 8 3 | 77 4 | 770 5 | -------------------------------------------------------------------------------- /unitTests/gcgentest5.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest5.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest5.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test three array creation/deletion/gc 3 | 4 | 5 | class Main { 6 | static void main() { 7 | int x; 8 | int loops; 9 | int [] o; 10 | int [] p; 11 | int [] old; 12 | old = new int[5]; 13 | old[0] = 7; 14 | old[1] = 8; 15 | old[2] = 9; 16 | old[3] = 10; 17 | old[4] = 3; 18 | 19 | x = 0; 20 | loops = 10000; 21 | while (x < loops) { 22 | o = new int[10]; 23 | x = x + 1; 24 | o[x % 10] = x; 25 | } 26 | x = 0; 27 | while (x < loops) { 28 | p = new int[10]; 29 | x = x + 1; 30 | p[x % 10] = x; 31 | } 32 | 33 | o[0] = 42; 34 | o[9] = 8; 35 | p[0] = x; 36 | p[9] = x + 1; 37 | System.out.println(o[0]); 38 | System.out.println(o[9]); 39 | System.out.println(p[0]); 40 | System.out.println(p[9]); 41 | System.out.println(old[0]); 42 | System.out.println(old[4]); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /unitTests/gcgentest5.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest5.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest5.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | 8 3 | 10000 4 | 10001 5 | 7 6 | 3 7 | -------------------------------------------------------------------------------- /unitTests/gcgentest6.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest6.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest6.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test big object for gc gen 3 | 4 | 5 | class Main { 6 | static void main() { 7 | int x; 8 | int loops; 9 | int [] o; 10 | int [] p; 11 | int [] old; 12 | old = new int[100]; 13 | old[0] = 7; 14 | old[1] = 8; 15 | old[2] = 9; 16 | old[3] = 10; 17 | old[99] = 3; 18 | 19 | x = 0; 20 | loops = 10000; 21 | while (x < loops) { 22 | o = new int[10]; 23 | x = x + 1; 24 | o[x % 10] = x; 25 | } 26 | x = 0; 27 | while (x < loops) { 28 | p = new int[10]; 29 | x = x + 1; 30 | p[x % 10] = x; 31 | } 32 | 33 | o[0] = 42; 34 | o[9] = 8; 35 | p[0] = x; 36 | p[9] = x + 1; 37 | System.out.println(o[0]); 38 | System.out.println(o[9]); 39 | System.out.println(p[0]); 40 | System.out.println(p[9]); 41 | System.out.println(old[0]); 42 | System.out.println(old[99]); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /unitTests/gcgentest6.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest6.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest6.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | 8 3 | 10000 4 | 10001 5 | 7 6 | 3 7 | -------------------------------------------------------------------------------- /unitTests/gcgentest7.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest7.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest7.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test nested loop for gc gen 3 | 4 | class Main { 5 | static void main() { 6 | int x; 7 | int y; 8 | int loops; 9 | int [] o; 10 | int [] p; 11 | int [] old; 12 | old = new int[100]; 13 | old[0] = 7; 14 | old[1] = 8; 15 | old[2] = 9; 16 | old[3] = 10; 17 | old[99] = 3; 18 | 19 | x = 0; 20 | loops = 100; 21 | while (x < loops) { 22 | o = new int[10]; 23 | x = x + 1; 24 | o[x % 10] = x; 25 | 26 | y = 0; 27 | while (y < loops) { 28 | p = new int[10]; 29 | y = y + 1; 30 | p[y % 10] = y; 31 | } 32 | } 33 | 34 | 35 | o[0] = 42; 36 | o[9] = 8; 37 | p[0] = x; 38 | p[9] = x + 1; 39 | System.out.println(o[0]); 40 | System.out.println(o[9]); 41 | System.out.println(p[0]); 42 | System.out.println(p[9]); 43 | System.out.println(old[0]); 44 | System.out.println(old[99]); 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /unitTests/gcgentest7.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest7.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest7.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | 8 3 | 100 4 | 101 5 | 7 6 | 3 7 | -------------------------------------------------------------------------------- /unitTests/gcgentest8.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest8.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest8.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test nested loop for gc gen 3 | 4 | class A { 5 | int x; 6 | int y; 7 | int z; 8 | int [] o; 9 | A() { 10 | o = new int[100]; 11 | } 12 | } 13 | 14 | class Main { 15 | static void main() { 16 | A Ao; 17 | int x; 18 | int y; 19 | int loops; 20 | int [] o; 21 | int [] old; 22 | old = new int[100]; 23 | old[0] = 42; 24 | old[99] = 7; 25 | 26 | x = 0; 27 | loops = 10000; 28 | while (x < loops) { 29 | Ao = new A(); 30 | x = x + 1; 31 | Ao.o[x % 10] = x; 32 | } 33 | Ao.o[0] = x; 34 | Ao.o[9] = x + 1; 35 | System.out.println(Ao.o[0]); 36 | System.out.println(Ao.o[9]); 37 | System.out.println(old[0]); 38 | System.out.println(old[99]); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /unitTests/gcgentest8.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest8.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest8.run.ref: -------------------------------------------------------------------------------- 1 | 10000 2 | 10001 3 | 42 4 | 7 5 | -------------------------------------------------------------------------------- /unitTests/gcgentest9.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gcgentest9.gcc.ref -------------------------------------------------------------------------------- /unitTests/gcgentest9.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test nested loop for gc gen 3 | 4 | class A { 5 | int x; 6 | int y; 7 | int z; 8 | int [] o; 9 | A() { 10 | o = new int[100]; 11 | } 12 | } 13 | 14 | class B { 15 | int [] b; 16 | B() { 17 | b = new int[100]; 18 | } 19 | 20 | int getBB() { 21 | int x; 22 | int loops; 23 | x = 0; 24 | loops = 100; 25 | while (x < loops) { 26 | b[x] = x; 27 | x = x + 1; 28 | } 29 | return b[99]; 30 | } 31 | } 32 | 33 | class Main { 34 | static void main() { 35 | A Ao; 36 | B Bo; 37 | int x; 38 | int y; 39 | int loops; 40 | int [] o; 41 | int [] old; 42 | old = new int[100]; 43 | old[0] = 42; 44 | old[99] = 7; 45 | 46 | Bo = new B(); 47 | 48 | x = 0; 49 | loops = 10000; 50 | while (x < loops) { 51 | Ao = new A(); 52 | x = x + 1; 53 | Ao.o[x % 10] = x; 54 | } 55 | 56 | old[0] = Bo.getBB(); 57 | Ao.o[0] = x; 58 | Ao.o[9] = x + 1; 59 | System.out.println(Ao.o[0]); 60 | System.out.println(Ao.o[9]); 61 | System.out.println(old[0]); 62 | System.out.println(old[99]); 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /unitTests/gcgentest9.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gcgentest9.bc 2 | -------------------------------------------------------------------------------- /unitTests/gcgentest9.run.ref: -------------------------------------------------------------------------------- 1 | 10000 2 | 10001 3 | 99 4 | 7 5 | -------------------------------------------------------------------------------- /unitTests/gctest1.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest1.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest1.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test basic object construction and gc relocation 3 | 4 | class TestObj { 5 | int x; 6 | int y; 7 | int z; 8 | } 9 | 10 | class Main { 11 | static void main() { 12 | int x; 13 | int loops; 14 | TestObj o; 15 | 16 | o = new TestObj(); 17 | o.x = 42; 18 | 19 | x = 0; 20 | loops = 1000; 21 | while (x < loops) { 22 | o = new TestObj(); 23 | o.x = x; 24 | x = x + 1; 25 | } 26 | System.out.println(o.x); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /unitTests/gctest1.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest1.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest1.run.ref: -------------------------------------------------------------------------------- 1 | 999 2 | -------------------------------------------------------------------------------- /unitTests/gctest10.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest10.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest10.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test array within object creation/deletion/gc 3 | 4 | class TestObj { 5 | TestObj o; 6 | int x; 7 | } 8 | 9 | class Main { 10 | static void main() { 11 | TestObj o = new TestObj(); 12 | o.x = 0; 13 | int x = 0; 14 | int loops = 10000; 15 | /* get o into old set */ 16 | while (x < loops) { 17 | new int[13]; 18 | x = x + 1; 19 | } 20 | x = 0; 21 | o.o = new TestObj(); 22 | o.o.x = 9999; 23 | /* trigger another collection */ 24 | while (x < loops) { 25 | new int[13]; 26 | x = x + 1; 27 | } 28 | /* o should exist, but does o.o? */ 29 | System.out.println(o.o.x); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /unitTests/gctest10.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest10.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest10.run.ref: -------------------------------------------------------------------------------- 1 | 9999 2 | -------------------------------------------------------------------------------- /unitTests/gctest2.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest2.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest2.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test two objects with gc 3 | 4 | class TestObjOne { 5 | int x; 6 | int z; 7 | } 8 | 9 | class TestObjTwo { 10 | int a; 11 | int c; 12 | } 13 | 14 | class Main { 15 | static void main() { 16 | int x; 17 | int loops; 18 | TestObjOne oo; 19 | TestObjTwo ot; 20 | 21 | oo = new TestObjOne(); 22 | oo.x = 42; 23 | 24 | ot = new TestObjTwo(); 25 | ot.a = 42; 26 | 27 | x = 0; 28 | loops = 1000; 29 | while (x < loops) { 30 | oo = new TestObjOne(); 31 | ot = new TestObjTwo(); 32 | oo.x = x; 33 | ot.a = 42; 34 | x = x + 1; 35 | } 36 | System.out.println(oo.x); 37 | System.out.println(ot.a); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /unitTests/gctest2.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest2.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest2.run.ref: -------------------------------------------------------------------------------- 1 | 999 2 | 42 3 | -------------------------------------------------------------------------------- /unitTests/gctest3.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest3.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest3.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test gc with derived class 3 | 4 | class TestObjOne { 5 | int x; 6 | int z; 7 | } 8 | 9 | class TestObjTwo extends TestObjOne { 10 | int a; 11 | int c; 12 | } 13 | 14 | class Main { 15 | static void main() { 16 | int x; 17 | int loops; 18 | TestObjOne oo; 19 | TestObjTwo ot; 20 | 21 | oo = new TestObjOne(); 22 | oo.x = 42; 23 | 24 | ot = new TestObjTwo(); 25 | ot.a = 42; 26 | 27 | x = 0; 28 | loops = 10000; 29 | while (x < loops) { 30 | oo = new TestObjOne(); 31 | ot = new TestObjTwo(); 32 | oo.x = x; 33 | ot.a = 42; 34 | x = x + 1; 35 | } 36 | System.out.println(oo.x); 37 | System.out.println(ot.a); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /unitTests/gctest3.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest3.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest3.run.ref: -------------------------------------------------------------------------------- 1 | 9999 2 | 42 3 | -------------------------------------------------------------------------------- /unitTests/gctest4.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest4.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest4.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // gc test for object containing another object 3 | 4 | class TestObjOne { 5 | int x; 6 | int z; 7 | } 8 | 9 | class TestObjTwo { 10 | TestObjOne too; 11 | } 12 | 13 | class Main { 14 | static void main() { 15 | int x; 16 | int loops; 17 | TestObjOne oo; 18 | TestObjTwo ot; 19 | 20 | oo = new TestObjOne(); 21 | oo.x = 42; 22 | 23 | ot = new TestObjTwo(); 24 | ot.too = new TestObjOne(); 25 | ot.too.z = 42; 26 | 27 | x = 0; 28 | loops = 100000; 29 | while (x < loops) { 30 | oo = new TestObjOne(); 31 | ot = new TestObjTwo(); 32 | ot.too = new TestObjOne(); 33 | oo.x = x; 34 | ot.too.z = 42; 35 | x = x + 1; 36 | } 37 | System.out.println(oo.x); 38 | System.out.println(ot.too.z); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /unitTests/gctest4.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest4.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest4.run.ref: -------------------------------------------------------------------------------- 1 | 99999 2 | 42 3 | -------------------------------------------------------------------------------- /unitTests/gctest5.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest5.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest5.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // 3 | 4 | class TestObjOne { 5 | int a; 6 | int b; 7 | } 8 | 9 | class TestObjTwo { 10 | int c; 11 | int d; 12 | } 13 | class TestObjThree { 14 | int e; 15 | int f; 16 | } 17 | class TestObjFour { 18 | int g; 19 | int h; 20 | } 21 | class Main { 22 | static void main() { 23 | int x; 24 | int loops; 25 | TestObjOne oo; 26 | TestObjTwo ot; 27 | TestObjThree ott; 28 | TestObjFour of; 29 | 30 | oo = new TestObjOne(); 31 | ot = new TestObjTwo(); 32 | ott = new TestObjThree(); 33 | of = new TestObjFour(); 34 | oo.a = 42; 35 | oo.b = 1; 36 | 37 | x = 0; 38 | loops = 1000; 39 | while (x < loops) { 40 | oo = new TestObjOne(); 41 | ot = new TestObjTwo(); 42 | oo.a = x / 5; 43 | oo.b = x / 4; 44 | ot.c = x / 3; 45 | ot.d = x / 2; 46 | of.g = oo.a + x; 47 | of.h = ot.c + x; 48 | x = x + 1; 49 | } 50 | 51 | System.out.println(oo.a); 52 | System.out.println(oo.b); 53 | System.out.println(ot.c); 54 | System.out.println(ot.d); 55 | System.out.println(of.g); 56 | System.out.println(of.h); 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /unitTests/gctest5.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest5.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest5.run.ref: -------------------------------------------------------------------------------- 1 | 199 2 | 249 3 | 333 4 | 499 5 | 1198 6 | 1332 7 | -------------------------------------------------------------------------------- /unitTests/gctest6.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest6.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest6.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test basic array creation/deletion/gc 3 | 4 | 5 | class Main { 6 | static void main() { 7 | int x; 8 | int loops; 9 | int [] o; 10 | o = new int[10]; 11 | 12 | x = 0; 13 | loops = 1000; 14 | while (x < loops) { 15 | o = new int[10]; 16 | x = x + 1; 17 | o[x % 10] = x; 18 | } 19 | o[0] = 42; 20 | o[9] = 8; 21 | System.out.println(o[0]); 22 | System.out.println(o[9]); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /unitTests/gctest6.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest6.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest6.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | 8 3 | -------------------------------------------------------------------------------- /unitTests/gctest7.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest7.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest7.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test two array creation/deletion/gc 3 | 4 | 5 | class Main { 6 | static void main() { 7 | int x; 8 | int loops; 9 | int [] o; 10 | int [] p; 11 | o = new int[10]; 12 | p = new int[5]; 13 | p[0] = 7; 14 | p[1] = 8; 15 | p[2] = 9; 16 | p[3] = 10; 17 | p[4] = 3; 18 | 19 | x = 0; 20 | loops = 1000; 21 | while (x < loops) { 22 | o = new int[10]; 23 | x = x + 1; 24 | o[x % 10] = x; 25 | } 26 | o[0] = 42; 27 | o[9] = 8; 28 | System.out.println(o[0]); 29 | System.out.println(o[9]); 30 | System.out.println(p[0]); 31 | System.out.println(p[4]); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /unitTests/gctest7.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest7.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest7.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | 8 3 | 7 4 | 3 5 | -------------------------------------------------------------------------------- /unitTests/gctest8.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest8.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest8.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test array within object creation/deletion/gc 3 | 4 | class TestObj { 5 | int [] arr; 6 | } 7 | 8 | class Main { 9 | static void main() { 10 | int x; 11 | int loops; 12 | TestObj o; 13 | o = new TestObj(); 14 | o.arr = new int[10]; 15 | 16 | x = 0; 17 | loops = 1000; 18 | while (x < loops) { 19 | o.arr = new int[10]; 20 | x = x + 1; 21 | o.arr[0] = 42; 22 | o.arr[9] = x; 23 | } 24 | System.out.println(o.arr[0]); 25 | System.out.println(o.arr[9]); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /unitTests/gctest8.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest8.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest8.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | 1000 3 | -------------------------------------------------------------------------------- /unitTests/gctest9.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/gctest9.gcc.ref -------------------------------------------------------------------------------- /unitTests/gctest9.j: -------------------------------------------------------------------------------- 1 | // Small program for testing garbage collector: 2 | // Test class with static fields 3 | 4 | class TestObj { 5 | int x; 6 | int y; 7 | int z; 8 | } 9 | 10 | class Stat { 11 | static TestObj stc; 12 | } 13 | 14 | class Main { 15 | static void main() { 16 | int x; 17 | int loops; 18 | Stat.stc = new TestObj(); 19 | Stat.stc.x = 5; 20 | 21 | x = 0; 22 | loops = 1000; 23 | while (x < loops) { 24 | Stat.stc = new TestObj(); 25 | x = x + 1; 26 | Stat.stc.x = x; 27 | } 28 | 29 | Stat.stc.x = 42; 30 | System.out.println(Stat.stc.x); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /unitTests/gctest9.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/gctest9.bc 2 | -------------------------------------------------------------------------------- /unitTests/gctest9.run.ref: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /unitTests/iface.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/iface.gcc.ref -------------------------------------------------------------------------------- /unitTests/iface.j: -------------------------------------------------------------------------------- 1 | interface Iface { 2 | void test(int test123); 3 | void other(int test123); 4 | } 5 | 6 | class SomeClass implements Iface { 7 | void ignored() { 8 | 9 | } 10 | void test(int xyz) { 11 | System.out.println("Does something"); 12 | System.out.println(xyz); 13 | } 14 | void ignored2() { 15 | 16 | } 17 | void other(int xyz) { 18 | System.out.println("Something else"); 19 | System.out.println(xyz); 20 | } 21 | } 22 | 23 | class SomeOtherClass implements Iface { 24 | void test(int xyz) { 25 | System.out.println("XXXX Does something"); 26 | System.out.println(xyz); 27 | } 28 | void ignored() { 29 | 30 | } 31 | void other(int xyz) { 32 | System.out.println("XXX Something else"); 33 | System.out.println(xyz); 34 | } 35 | void ignored2() { 36 | 37 | } 38 | } 39 | 40 | 41 | class Main { 42 | public static void main() { 43 | Iface x; 44 | Iface y = new SomeClass(); 45 | y.test(200); 46 | y.other(70); 47 | y = new SomeOtherClass(); 48 | y.test(12); 49 | y.other(15); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /unitTests/iface.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/iface.bc 2 | -------------------------------------------------------------------------------- /unitTests/iface.run.ref: -------------------------------------------------------------------------------- 1 | Does something 2 | 200 3 | Something else 4 | 70 5 | XXXX Does something 6 | 12 7 | XXX Something else 8 | 15 9 | -------------------------------------------------------------------------------- /unitTests/iface2.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/iface2.gcc.ref -------------------------------------------------------------------------------- /unitTests/iface2.j: -------------------------------------------------------------------------------- 1 | interface Iface2 { 2 | void test(int test123); 3 | } 4 | 5 | interface Iface { 6 | void other(int test123); 7 | } 8 | 9 | class SomeClass implements Iface, Iface2 { 10 | void ignored() { 11 | 12 | } 13 | void test(int xyz) { 14 | System.out.println("Does something"); 15 | System.out.println(xyz); 16 | } 17 | void ignored2() { 18 | 19 | } 20 | void other(int xyz) { 21 | System.out.println("Something else"); 22 | System.out.println(xyz); 23 | } 24 | } 25 | 26 | class SomeOtherClass implements Iface, Iface2 { 27 | void test(int xyz) { 28 | System.out.println("XXXX Does something"); 29 | System.out.println(xyz); 30 | } 31 | void ignored() { 32 | 33 | } 34 | void other(int xyz) { 35 | System.out.println("XXX Something else"); 36 | System.out.println(xyz); 37 | } 38 | void ignored2() { 39 | 40 | } 41 | } 42 | 43 | 44 | class Main { 45 | public static void main() { 46 | Iface x; 47 | Iface2 y = new SomeClass(); 48 | y.test(200); 49 | x = new SomeOtherClass(); 50 | x.other(15); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /unitTests/iface2.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/iface2.bc 2 | -------------------------------------------------------------------------------- /unitTests/iface2.run.ref: -------------------------------------------------------------------------------- 1 | Does something 2 | 200 3 | XXX Something else 4 | 15 5 | -------------------------------------------------------------------------------- /unitTests/iface3.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/iface3.gcc.ref -------------------------------------------------------------------------------- /unitTests/iface3.j: -------------------------------------------------------------------------------- 1 | interface Iface2 { 2 | void test(int test123); 3 | } 4 | 5 | interface Iface extends Iface2 { 6 | void other(int test123); 7 | } 8 | 9 | class SomeClass implements Iface { 10 | void ignored() { 11 | 12 | } 13 | void test(int xyz) { 14 | System.out.println("Does something"); 15 | System.out.println(xyz); 16 | } 17 | void ignored2() { 18 | 19 | } 20 | void other(int xyz) { 21 | System.out.println("Something else"); 22 | System.out.println(xyz); 23 | } 24 | } 25 | 26 | class SomeOtherClass implements Iface, Iface2 { 27 | void test(int xyz) { 28 | System.out.println("XXXX Does something"); 29 | System.out.println(xyz); 30 | } 31 | void ignored() { 32 | 33 | } 34 | void other(int xyz) { 35 | System.out.println("XXX Something else"); 36 | System.out.println(xyz); 37 | } 38 | void ignored2() { 39 | 40 | } 41 | } 42 | 43 | 44 | class Main { 45 | public static void main() { 46 | Iface x; 47 | Iface2 y = new SomeClass(); 48 | y.test(200); 49 | x = new SomeOtherClass(); 50 | x.other(15); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /unitTests/iface3.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/iface3.bc 2 | -------------------------------------------------------------------------------- /unitTests/iface3.run.ref: -------------------------------------------------------------------------------- 1 | Does something 2 | 200 3 | XXX Something else 4 | 15 5 | -------------------------------------------------------------------------------- /unitTests/iface4.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/iface4.gcc.ref -------------------------------------------------------------------------------- /unitTests/iface4.j: -------------------------------------------------------------------------------- 1 | interface Iface { 2 | static void test(int test123) { 3 | System.out.println(test123); 4 | } 5 | } 6 | 7 | 8 | class Main { 9 | public static void main() { 10 | Iface.test(123); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /unitTests/iface4.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/iface4.bc 2 | -------------------------------------------------------------------------------- /unitTests/iface4.run.ref: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /unitTests/iface5.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/iface5.gcc.ref -------------------------------------------------------------------------------- /unitTests/iface5.j: -------------------------------------------------------------------------------- 1 | interface Iface2 { 2 | int test(int test123); 3 | } 4 | 5 | interface Iface extends Iface2 { 6 | int other(int test123); 7 | } 8 | 9 | class SomeClass implements Iface { 10 | int test(int xyz) { 11 | System.out.println("Does something"); 12 | System.out.println(xyz); 13 | return 12834; 14 | } 15 | int other(int xyz) { 16 | System.out.println("Something else"); 17 | System.out.println(xyz); 18 | return 12738; 19 | } 20 | } 21 | 22 | class SomeOtherClass implements Iface, Iface2 { 23 | int test(int xyz) { 24 | System.out.println("XXXX Does something"); 25 | System.out.println(xyz); 26 | return 123; 27 | } 28 | int other(int xyz) { 29 | System.out.println("XXX Something else"); 30 | System.out.println(xyz); 31 | return 100; 32 | } 33 | } 34 | 35 | 36 | class Main { 37 | public static void main() { 38 | Iface x; 39 | Iface2 y = new SomeClass(); 40 | System.out.println(y.test(200)); 41 | x = new SomeOtherClass(); 42 | System.out.println(x.other(15)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /unitTests/iface5.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/iface5.bc 2 | -------------------------------------------------------------------------------- /unitTests/iface5.run.ref: -------------------------------------------------------------------------------- 1 | Does something 2 | 200 3 | 12834 4 | XXX Something else 5 | 15 6 | 100 7 | -------------------------------------------------------------------------------- /unitTests/iface6.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/iface6.gcc.ref -------------------------------------------------------------------------------- /unitTests/iface6.j: -------------------------------------------------------------------------------- 1 | interface Iface2 { 2 | int test_num = 777; 3 | int test(int test123); 4 | } 5 | 6 | class Test { 7 | static int test_num = 888; 8 | } 9 | 10 | class Main { 11 | public static void main() { 12 | System.out.println(Test.test_num); 13 | System.out.println(Iface2.test_num); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /unitTests/iface6.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/iface6.bc 2 | -------------------------------------------------------------------------------- /unitTests/iface6.run.ref: -------------------------------------------------------------------------------- 1 | 888 2 | 777 3 | -------------------------------------------------------------------------------- /unitTests/iface7.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/iface7.gcc.ref -------------------------------------------------------------------------------- /unitTests/iface7.j: -------------------------------------------------------------------------------- 1 | interface If1 { 2 | void test(int xyz); 3 | void test(String overloaded); 4 | } 5 | 6 | class Test implements If1 { 7 | void test(int pyq) { 8 | System.out.println(pyq); 9 | } 10 | void test(String pyq) { 11 | System.out.println(pyq); 12 | } 13 | } 14 | 15 | class Main { 16 | public static void main() { 17 | If1 iface = new Test(); 18 | iface.test(12); 19 | iface.test("Hello"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /unitTests/iface7.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/iface7.bc 2 | -------------------------------------------------------------------------------- /unitTests/iface7.run.ref: -------------------------------------------------------------------------------- 1 | 12 2 | Hello 3 | -------------------------------------------------------------------------------- /unitTests/nullCheck.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/nullCheck.gcc.ref -------------------------------------------------------------------------------- /unitTests/nullCheck.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main() { 3 | int [] test = null; 4 | /* should fail null check */ 5 | test[10] = 5; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /unitTests/nullCheck.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/nullCheck.bc 2 | -------------------------------------------------------------------------------- /unitTests/nullCheck.run.ref: -------------------------------------------------------------------------------- 1 | EXCEPTION: unitTests/nullCheck.j:5 Null Reference 2 | -------------------------------------------------------------------------------- /unitTests/nullCheck2.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/nullCheck2.gcc.ref -------------------------------------------------------------------------------- /unitTests/nullCheck2.j: -------------------------------------------------------------------------------- 1 | class SomeClass { 2 | int x; 3 | } 4 | 5 | class Main { 6 | public static void main() { 7 | SomeClass test = null; 8 | /* should fail null check */ 9 | test.x = 7; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /unitTests/nullCheck2.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/nullCheck2.bc 2 | -------------------------------------------------------------------------------- /unitTests/nullCheck2.run.ref: -------------------------------------------------------------------------------- 1 | EXCEPTION: unitTests/nullCheck2.j:9 Null Reference 2 | -------------------------------------------------------------------------------- /unitTests/nullCheck3.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/nullCheck3.gcc.ref -------------------------------------------------------------------------------- /unitTests/nullCheck3.j: -------------------------------------------------------------------------------- 1 | class SomeClass { 2 | SomeClass deep; 3 | int x; 4 | public SomeClass() { 5 | deep = null; 6 | } 7 | } 8 | 9 | class Main { 10 | public static void main() { 11 | SomeClass test = new SomeClass(); 12 | /* should fail null check */ 13 | test.deep.x = 7; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /unitTests/nullCheck3.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/nullCheck3.bc 2 | -------------------------------------------------------------------------------- /unitTests/nullCheck3.run.ref: -------------------------------------------------------------------------------- 1 | EXCEPTION: unitTests/nullCheck3.j:13 Null Reference 2 | -------------------------------------------------------------------------------- /unitTests/retNull.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/retNull.gcc.ref -------------------------------------------------------------------------------- /unitTests/retNull.j: -------------------------------------------------------------------------------- 1 | class Expr { 2 | static Expr retnull() { 3 | return null; 4 | } 5 | } 6 | 7 | class Main { 8 | static void main() { 9 | Expr.retnull(); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /unitTests/retNull.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/retNull.bc 2 | -------------------------------------------------------------------------------- /unitTests/retNull.run.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/retNull.run.ref -------------------------------------------------------------------------------- /unitTests/segFault.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/segFault.gcc.ref -------------------------------------------------------------------------------- /unitTests/segFault.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | char [] test; 4 | test = new char[10]; 5 | test.toString(); 6 | } 7 | } -------------------------------------------------------------------------------- /unitTests/segFault.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/segFault.bc 2 | -------------------------------------------------------------------------------- /unitTests/segFault.run.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/segFault.run.ref -------------------------------------------------------------------------------- /unitTests/string.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/string.gcc.ref -------------------------------------------------------------------------------- /unitTests/string.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | String s = "test"; 4 | System.out.println(s); 5 | } 6 | } 7 | 8 | -------------------------------------------------------------------------------- /unitTests/string.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/string.bc 2 | -------------------------------------------------------------------------------- /unitTests/string.run.ref: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /unitTests/super1.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/super1.gcc.ref -------------------------------------------------------------------------------- /unitTests/super1.j: -------------------------------------------------------------------------------- 1 | class Test { 2 | int x; 3 | public void test() { 4 | System.out.println("Test"); 5 | System.out.println(x); 6 | } 7 | } 8 | 9 | class Test2 extends Test { 10 | public void test2() { 11 | super.x = 5; 12 | super.test(); 13 | super.x = 10; 14 | super.test(); 15 | System.out.println(super.x); 16 | } 17 | } 18 | 19 | class Main { 20 | public static void main() { 21 | Test2 t = new Test2(); 22 | t.test2(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /unitTests/super1.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/super1.bc 2 | -------------------------------------------------------------------------------- /unitTests/super1.run.ref: -------------------------------------------------------------------------------- 1 | Test 2 | 5 3 | Test 4 | 10 5 | 10 6 | -------------------------------------------------------------------------------- /unitTests/super2.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/super2.gcc.ref -------------------------------------------------------------------------------- /unitTests/super2.j: -------------------------------------------------------------------------------- 1 | class Test { 2 | int x; 3 | public void test() { 4 | System.out.println("Test"); 5 | System.out.println(x); 6 | } 7 | } 8 | 9 | class Test2 extends Test { 10 | public Test2() { 11 | super(); 12 | } 13 | public void test2() { 14 | super.x = 5; 15 | super.test(); 16 | super.x = 10; 17 | super.test(); 18 | System.out.println(super.x); 19 | } 20 | } 21 | 22 | class Main { 23 | public static void main() { 24 | Test2 t = new Test2(); 25 | t.test2(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /unitTests/super2.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/super2.bc 2 | -------------------------------------------------------------------------------- /unitTests/super2.run.ref: -------------------------------------------------------------------------------- 1 | Test 2 | 5 3 | Test 4 | 10 5 | 10 6 | -------------------------------------------------------------------------------- /unitTests/super3.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/super3.gcc.ref -------------------------------------------------------------------------------- /unitTests/super3.j: -------------------------------------------------------------------------------- 1 | class Test { 2 | int x; 3 | public Test(int test) { 4 | x = test; 5 | } 6 | public void test() { 7 | System.out.println("Test"); 8 | System.out.println(x); 9 | } 10 | } 11 | 12 | class Test2 extends Test { 13 | public Test2() { 14 | super(17); 15 | } 16 | public void test2() { 17 | super.x = 5; 18 | super.test(); 19 | super.x = 10; 20 | super.test(); 21 | System.out.println(super.x); 22 | } 23 | } 24 | 25 | class Main { 26 | public static void main() { 27 | Test2 t = new Test2(); 28 | t.test2(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /unitTests/super3.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/super3.bc 2 | -------------------------------------------------------------------------------- /unitTests/super3.run.ref: -------------------------------------------------------------------------------- 1 | Test 2 | 5 3 | Test 4 | 10 5 | 10 6 | -------------------------------------------------------------------------------- /unitTests/systemOut.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/systemOut.gcc.ref -------------------------------------------------------------------------------- /unitTests/systemOut.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | int i = 0; 4 | do { 5 | System.out.println(i); 6 | i = i + 1; 7 | } while (i < 10); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /unitTests/systemOut.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/systemOut.bc 2 | -------------------------------------------------------------------------------- /unitTests/systemOut.run.ref: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 7 9 | 8 10 | 9 11 | -------------------------------------------------------------------------------- /unitTests/test.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/test.gcc.ref -------------------------------------------------------------------------------- /unitTests/test.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | static void main() { 3 | PrintStream s = System.out; 4 | System.out.println("Test"); 5 | MJC.putc('x'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /unitTests/test.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/test.bc 2 | -------------------------------------------------------------------------------- /unitTests/test.run.ref: -------------------------------------------------------------------------------- 1 | Test 2 | x -------------------------------------------------------------------------------- /unitTests/thisInvocation.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/thisInvocation.gcc.ref -------------------------------------------------------------------------------- /unitTests/thisInvocation.j: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main() { 3 | int p; 4 | p = 5; 5 | test(); 6 | System.out.println(p); 7 | } 8 | 9 | static void test() { 10 | int p; 11 | p = 0; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /unitTests/thisInvocation.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/thisInvocation.bc 2 | -------------------------------------------------------------------------------- /unitTests/thisInvocation.run.ref: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /unitTests/ts.gcc.ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniJavaCompiler/MiniJavaLLVM/2d9641a5e510773f089886e304c329bdc494f0d0/unitTests/ts.gcc.ref -------------------------------------------------------------------------------- /unitTests/ts.j: -------------------------------------------------------------------------------- 1 | // Here is a small program for the Mini Java compiler: 2 | // 3 | class Expr { 4 | int eval() { 5 | return 0; // should never be called 6 | } 7 | } 8 | 9 | class IntExpr extends Expr { 10 | int value; 11 | 12 | static IntExpr make(int value) { 13 | IntExpr e; 14 | e = new IntExpr(); 15 | e.value = value; 16 | return e; 17 | } 18 | int eval() { 19 | return value; 20 | } 21 | } 22 | 23 | class AddExpr extends Expr { 24 | Expr left; 25 | Expr right; 26 | static AddExpr make(Expr l, Expr r) { 27 | AddExpr e = new AddExpr(); 28 | e.left = l; 29 | e.right = r; 30 | return e; 31 | } 32 | 33 | int eval() { 34 | return left.eval() + right.eval(); 35 | } 36 | } 37 | 38 | class Main { 39 | static void main() { 40 | Expr e; 41 | e = AddExpr.make(IntExpr.make(1), IntExpr.make(2)); 42 | e = AddExpr.make(e, e); 43 | System.out.println(e.eval()); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /unitTests/ts.mjc.ref: -------------------------------------------------------------------------------- 1 | Writing LLVM Bitcode to build/test/ts.bc 2 | -------------------------------------------------------------------------------- /unitTests/ts.run.ref: -------------------------------------------------------------------------------- 1 | 6 2 | --------------------------------------------------------------------------------