gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
MicroJavaInput, constructor, other improvements
authorDoni Pracner <quinnuendo@gmail.com>
Tue, 17 Jul 2018 22:24:13 +0000 (00:24 +0200)
committerDoni Pracner <quinnuendo@gmail.com>
Tue, 17 Jul 2018 22:24:13 +0000 (00:24 +0200)
change so the constructor gets the stream and inits what is
needed. also removed some parameters and methods that were not needed.

src/com/quemaster/transformations/mjc2wsl/MicroJavaInput.java
src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java

index 678243d..3dd6157 100644 (file)
@@ -35,8 +35,9 @@ public class MicroJavaInput {
        int numberOfWords;
        private int codesize;
 
-       public MicroJavaInput() {
-
+       public MicroJavaInput(InputStream input) throws Exception {
+               mainIn = input;
+               processHeader();
        }
 
        public int get() {
@@ -60,19 +61,16 @@ public class MicroJavaInput {
                return (get2() << 16) + (get2() << 16 >>> 16);
        }
 
-       public void processHeader(mjc2wsl mjc2wsl) throws Exception {
+       public void processHeader() throws Exception {
                byte m = (byte) get();
                byte j = (byte) get();
                if (m != 'M' || j != 'J')
                        throw new Exception("Wrong start of bytecode file");
                codesize = get4();
-               setNumberOfWords(get4());
-               setMainAdr(get4());
+               this.numberOfWords = get4();
+               this.mainAdr = get4();
        }
 
-       public void setStream(InputStream ins) {
-               mainIn = ins;
-       }
 
        public int getCounter() {
                return counter;
@@ -82,22 +80,14 @@ public class MicroJavaInput {
                return codesize;
        }
 
-       public int getMainAdr(mjc2wsl mjc2wsl) {
+       public int getMainAdr() {
                return mainAdr;
        }
 
-       public int getNumberOfWords(mjc2wsl mjc2wsl) {
+       public int getNumberOfWords() {
                return numberOfWords;
        }
 
-       void setNumberOfWords(int numberOfWords) {
-               this.numberOfWords = numberOfWords;
-       }
-
-       void setMainAdr(int mainAdr) {
-               this.mainAdr = mainAdr;
-       }
-
        String getRelationFor(int opcode) throws Exception {
                switch (opcode) {
                case mjc2wsl.jeq:
index 6488efd..3bbdf6e 100644 (file)
@@ -1,6 +1,6 @@
 package com.quemaster.transformations.mjc2wsl;
 /*
-   Copyright (C) 2014,2015, 2016  Doni Pracner
+   Copyright (C) 2014,2015, 2016, 2018  Doni Pracner
    
     This file is part of mjc2wsl.
 
@@ -152,7 +152,7 @@ public class mjc2wsl{
                        return versionN;
        }
        
-       MicroJavaInput mjInput = new MicroJavaInput();
+       private MicroJavaInput mjInput;
 
        private PrintWriter out = null;
 
@@ -364,12 +364,10 @@ public class mjc2wsl{
        }
 
        public void convertStream(InputStream ins) throws Exception{
-               mjInput.setStream(ins);
-               //process start 
-               mjInput.processHeader(this);
-               
-               prl(createStandardStart(mjInput.getNumberOfWords(this)));
-               prl("SKIP;\n ACTIONS a" + (14 + mjInput.getMainAdr(this)) + " :");
+               mjInput = new MicroJavaInput(ins);
+
+               prl(createStandardStart(mjInput.getNumberOfWords()));
+               prl("SKIP;\n ACTIONS a" + (14 + mjInput.getMainAdr()) + " :");
 
                // the number of Locals for procedures; need to remember it for exits
                int numberOfLocals = 0;
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner