fixed more fixmes/features
authorbrian <brian@brianweb.net>
Thu, 27 May 2004 08:41:32 +0000 (01:41 -0700)
committerbrian <brian@brianweb.net>
Thu, 27 May 2004 08:41:32 +0000 (01:41 -0700)
darcs-hash:20040527084132-24bed-06910857dbbe8e26811b028f34f7b4b600f7632c.gz

src/org/ibex/nestedvm/ClassFileCompiler.java
src/org/ibex/nestedvm/JavaSourceCompiler.java
src/org/ibex/nestedvm/Runtime.java
src/org/ibex/nestedvm/RuntimeCompiler.java
src/org/ibex/nestedvm/util/ELF.java

index d1ea2bd..64269fb 100644 (file)
@@ -6,7 +6,7 @@ import org.ibex.nestedvm.util.*;
 import org.ibex.classgen.*;
 
 // FEATURE: Use IINC where possible
-// FEATURE: Use BCEL to do peephole optimization
+// FEATURE: Some kind of peephole optimization
 // FEATURE: Special mode to support single-precision only - regs are floats not ints
 
 /* FEATURE: Span large binaries across several classfiles
@@ -156,9 +156,8 @@ public class ClassFileCompiler extends Compiler implements CGConst  {
         int start = tramp.size();
         tramp.add(ALOAD_0);
         tramp.add(GETFIELD,new FieldRef(me,"state",Type.INT));
-        tramp.add(LDC,Runtime.RUNNING);
+        int stateCheck = tramp.add(IFNE);
         
-        int stateCheck = tramp.add(IF_ICMPNE);
         tramp.add(ALOAD_0);
         tramp.add(ALOAD_0);
         tramp.add(GETFIELD,new FieldRef(me,"pc",Type.INT));
@@ -666,6 +665,8 @@ public class ClassFileCompiler extends Compiler implements CGConst  {
                 mg.add(LDC,pc);
                 setPC();
                 
+                // FEATURE: This is actually broken, but it happens to work for our code
+                // a func could theoretically jump back to here from a future point
                 restoreChangedRegs();
                 
                 preSetReg(R+V0);
@@ -682,9 +683,7 @@ public class ClassFileCompiler extends Compiler implements CGConst  {
                 
                 mg.add(ALOAD_0);
                 mg.add(GETFIELD,new FieldRef(me,"state",Type.INT));
-                // FEATURE: Set Runtime.RUNNING to 0 and just use IFEQ here 
-                mg.add(LDC,Runtime.RUNNING);
-                b1 = mg.add(IF_ICMPEQ);
+                b1 = mg.add(IFEQ);
                 preSetPC();
                 mg.add(LDC,pc+4);
                 setPC();
@@ -1675,11 +1674,17 @@ public class ClassFileCompiler extends Compiler implements CGConst  {
     private static final int FCSR = 66;
     private static final int REG_COUNT=67;
         
-    // FEATURE: Clean this up
     private int[] regLocalMapping = new int[REG_COUNT];  
     private int[] regLocalReadCount = new int[REG_COUNT];
     private int[] regLocalWriteCount = new int[REG_COUNT];
     private int nextAvailLocal; 
+    private int loadsStart;
+    private static final int MAX_LOCALS = 4;
+    private static final int LOAD_LENGTH = 3;
+    
+    private boolean doLocal(int reg) {
+        return reg == R+2 || reg == R+3 || reg == R+4 || reg == R+29;
+    }
     
     private int getLocalForReg(int reg) {
         if(regLocalMapping[reg] != 0) return regLocalMapping[reg];
@@ -1688,8 +1693,6 @@ public class ClassFileCompiler extends Compiler implements CGConst  {
         return regLocalMapping[reg];
     }
     
-    
-    private int loadsStart;
     private void fixupRegsStart() {
         for(int i=0;i<REG_COUNT;i++)
             regLocalMapping[i] = regLocalReadCount[i] = regLocalWriteCount[i] = 0;
@@ -1715,12 +1718,6 @@ public class ClassFileCompiler extends Compiler implements CGConst  {
         }
     }
         
-    private static final int MAX_LOCALS = 4;
-    private static final int LOAD_LENGTH = 3;
-    private boolean doLocal(int reg) {
-        return reg == R+2 || reg == R+3 || reg == R+4 || reg == R+29;
-    }
-        
     private void restoreChangedRegs() {
         for(int i=0;i<REG_COUNT;i++) {
             if(regLocalWriteCount[i] > 0) {
@@ -1756,7 +1753,7 @@ public class ClassFileCompiler extends Compiler implements CGConst  {
     }
     
     private int pushRegZ(int reg) {
-        if(reg == R+0) return mg.add(LDC,0);
+        if(reg == R+0) return mg.add(ICONST_0);
         else return pushReg(reg);
     }
     
index 103cfa1..499b218 100644 (file)
@@ -217,7 +217,7 @@ public class JavaSourceCompiler extends Compiler {
     private void endMethod() { endMethod(endOfMethod); }
     private void endMethod(int lastAddr) {
         if(startOfMethod == 0) return;
-        // FEATURE: We should be able to use if(!unreachable) here (i think)
+        // We should be able to use if(!unreachable) here (i think)
         // This isn't strictly necessary; its just here to work around unreachable code errors
         p("case " + toHex(lastAddr) + ":");
         indent++;
index ee02214..bfe1aab 100644 (file)
@@ -2,6 +2,9 @@
 // Based on org.xwt.imp.MIPS by Adam Megacz
 // Portions Copyright 2003 Adam Megacz
 
+// FEATURE: Add a patch to gcc that enabled -Wall -Werror by default
+// FIXME: Get a hotel for IVME :)
+
 package org.ibex.nestedvm;
 
 import org.ibex.nestedvm.util.*;
@@ -46,10 +49,10 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
     /** When the process started */
     private long startTime;
     
-    /**  Text/Data loaded in memory  */
-    public final static int STOPPED = 0;
     /** Program is executing instructions */
-    public final static int RUNNING = 1;
+    public final static int RUNNING = 0; // Horrible things will happen if this isn't 0
+    /**  Text/Data loaded in memory  */
+    public final static int STOPPED = 1;
     /** Prgram has been started but is paused */
     public final static int PAUSED = 2;
     /** Program is executing a callJava() method */
@@ -1236,7 +1239,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
         public FStat _fstat() { return new FStat() { public int type() { return S_IFCHR; } public int mode() { return 0600; } }; }
     }
     
-    // FEATURE: TextInputStream: This is pretty inefficient but it is only used for reading from the console on win32
+    // This is pretty inefficient but it is only used for reading from the console on win32
     static class TextInputStream extends InputStream {
         private int pushedBack = -1;
         private final InputStream parent;
index 1a1a047..3252242 100644 (file)
@@ -6,19 +6,26 @@ import org.ibex.nestedvm.util.*;
 
 // FEATURE: This need a lot of work to support binaries spanned across many classes
 public class RuntimeCompiler {  
-    // FEATURE: Do we need to periodicly create a new classloader to allow old clases to be GCed?
-    private static SingleClassLoader singleClassLoader = new SingleClassLoader();
-    // FEATURE: Is it ok if this overflows?
-    private static long nextID = 1;
-    private static synchronized String uniqueID() { return Long.toString(nextID++); }
+    private static SingleClassLoader singleClassLoader;
+    private static int nextID;
     
-    public static Class compile(Seekable data) throws IOException, Compiler.Exn {
-        String className = "nextedvm.runtimecompiled_" + uniqueID();
+    public static Class compile(Seekable data) throws IOException, Compiler.Exn { return compile(data,null); }
+    public static Class compile(Seekable data, String extraoptions) throws IOException, Compiler.Exn {
+        int id;
+        synchronized(RuntimeCompiler.class) {
+            if(nextID == 32 || singleClassLoader == null) {
+                singleClassLoader = new SingleClassLoader();
+                nextID = 0;
+            }
+            id = nextID++;
+        }
+        String className = "nextedvm.runtimecompiled_" + id;
         System.err.println("RuntimeCompiler: Building " + className);
+        String options = "nosupportcall";
+        if(extraoptions != null) options += "," + extraoptions;
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ClassFileCompiler c = new ClassFileCompiler(data,className,baos);
-        // FEATURE: make this Optional, pass options on compile arguments
-        c.parseOptions("unixruntime,nosupportcall,maxinsnpermethod=512");
+        c.parseOptions(options);
         c.go();
         baos.close();
         byte[] bytecode = baos.toByteArray();
index 9d4c862..e33275e 100644 (file)
@@ -326,6 +326,7 @@ public class ELF {
         public byte type;
         public byte binding;
         public byte other;
+        public short shndx;
         public SHeader sheader;
         
         public final static int STT_FUNC = 2;
@@ -339,8 +340,7 @@ public class ELF {
             type = (byte)(info&0xf);
             binding = (byte)(info>>4);
             other = readByte();
-            // FEATURE: This should point to some other entry or something
-            readShort();
+            shndx = readShort();
         }
     }