From: Doni Pracner Date: Tue, 17 Jul 2018 22:24:13 +0000 (+0200) Subject: MicroJavaInput, constructor, other improvements X-Git-Tag: v1.0.0~6 X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=8684ef3ea2d843b29bf54b2078d2e0d17498f0f3;p=mjc2wsl.git MicroJavaInput, constructor, other improvements change so the constructor gets the stream and inits what is needed. also removed some parameters and methods that were not needed. --- diff --git a/src/com/quemaster/transformations/mjc2wsl/MicroJavaInput.java b/src/com/quemaster/transformations/mjc2wsl/MicroJavaInput.java index 678243d..3dd6157 100644 --- a/src/com/quemaster/transformations/mjc2wsl/MicroJavaInput.java +++ b/src/com/quemaster/transformations/mjc2wsl/MicroJavaInput.java @@ -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: diff --git a/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java b/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java index 6488efd..3bbdf6e 100644 --- a/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java +++ b/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java @@ -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;