clarify licensing
[nestedvm.git] / src / org / ibex / nestedvm / Compiler.java
index 7a1eb43..acf1c48 100644 (file)
@@ -1,4 +1,6 @@
-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
 
 package org.ibex.nestedvm;
 
@@ -7,8 +9,6 @@ import java.io.*;
 
 import org.ibex.nestedvm.util.*;
 
-// FEATURE: -d option for classfilecompiler (just like javac's -d)
-
 public abstract class Compiler implements Registers {    
     /** The ELF binary being read */
     ELF elf;
@@ -101,6 +101,7 @@ public abstract class Compiler implements Registers {
     
     public static void main(String[] args) throws IOException {
         String outfile = null;
+        String outdir = null;
         String o = null;
         String className = null;
         String mipsBinaryFileName = null;
@@ -112,6 +113,10 @@ public abstract class Compiler implements Registers {
                 arg++;
                 if(arg==args.length) usage();
                 outfile = args[arg];
+            } else if(args[arg].equals("-d")) {
+                arg++;
+                if(arg==args.length) usage();
+                outdir = args[arg];
             } else if(args[arg].equals("-outformat")) {
                 arg++;
                 if(arg==args.length) usage();
@@ -142,12 +147,20 @@ public abstract class Compiler implements Registers {
         OutputStream os = null;
         Compiler comp = null;
         if(outformat == null || outformat.equals("class")) {
-            if(outfile == null) {
+            if(outfile != null) {
+                os = new FileOutputStream(outfile);
+                comp = new ClassFileCompiler(mipsBinary,className,os);
+            } else if(outdir != null) {
+                File f = new File(outdir);
+                if(!f.isDirectory()) {
+                    System.err.println(outdir + " doesn't exist or is not a directory");
+                    System.exit(1);
+                }
+                comp = new ClassFileCompiler(mipsBinary,className,f);
+            } else {
                 System.err.println("Refusing to write a classfile to stdout - use -outfile foo.class");
                 System.exit(1);
             }
-            os = new FileOutputStream(outfile);
-            comp = new ClassFileCompiler(mipsBinary,className,os);
         } else if(outformat.equals("javasource") || outformat .equals("java")) {
             w = outfile == null ? new OutputStreamWriter(System.out): new FileWriter(outfile);
             comp = new JavaSourceCompiler(mipsBinary,className,w);
@@ -181,9 +194,9 @@ public abstract class Compiler implements Registers {
         this.fullClassName = fullClassName;
         elf = new ELF(binary);
         
-        if(elf.header.type != ELF.ELFHeader.ET_EXEC) throw new IOException("Binary is not an executable");
-        if(elf.header.machine != ELF.ELFHeader.EM_MIPS) throw new IOException("Binary is not for the MIPS I Architecture");
-        if(elf.ident.data != ELF.ELFIdent.ELFDATA2MSB) throw new IOException("Binary is not big endian");
+        if(elf.header.type != ELF.ET_EXEC) throw new IOException("Binary is not an executable");
+        if(elf.header.machine != ELF.EM_MIPS) throw new IOException("Binary is not for the MIPS I Architecture");
+        if(elf.ident.data != ELF.ELFDATA2MSB) throw new IOException("Binary is not big endian");
     }
 
     abstract void _go() throws Exn, IOException;
@@ -238,7 +251,7 @@ public abstract class Compiler implements Registers {
         
         for(int i=0;i<elf.sheaders.length;i++) {
             String name = elf.sheaders[i].name;
-            if(elf.sheaders[i].addr != 0 && !(
+            if((elf.sheaders[i].flags & ELF.SHF_ALLOC) !=0 && !(
                 name.equals(".text")|| name.equals(".data") || name.equals(".sdata") || name.equals(".rodata") ||
                 name.equals(".ctors") || name.equals(".dtors") || name.equals(".bss") || name.equals(".sbss")))
                     throw new Exn("Unknown section: " + name);