Changes for reading input files in MGC version
authorjzhou <jzhou>
Tue, 15 May 2012 00:27:08 +0000 (00:27 +0000)
committerjzhou <jzhou>
Tue, 15 May 2012 00:27:08 +0000 (00:27 +0000)
Robust/src/ClassLibrary/MGC/Scanner.java
Robust/src/Runtime/bamboo/multicoreruntime.c
Robust/src/Runtime/file.c
Robust/src/Util/InputFileTranslator.java [new file with mode: 0644]
Robust/src/buildscript

index f4fba9b149489d518a81935944439a1ed2f57d9f..40796c9ae9878de74bec23ed462c6b0759d3a77b 100644 (file)
@@ -1,14 +1,16 @@
 public class Scanner implements Iterator {\r
-  private String sourcename;\r
+  private FileInputStream source;\r
   private int currentpos;\r
-  private int filearray;\r
+  private int fd;\r
 \r
   public Scanner (final String source) {\r
-    this.sourcename = source;\r
+    this.source = new FileInputStream(source);\r
+    this.fd = this.source.getfd();\r
     this.currentpos = 0;\r
   }\r
 \r
   public void close () {\r
+      this.source.close();\r
   }\r
 \r
   public native double nextDouble ();\r
index bed80cf40a50b49fd462a29a29000cded452cf55..0ebf81c96d2b39a4820a5bf701d4ec2e60dab44d 100644 (file)
 #ifdef MEMPERFCOUNT
 #include "memprof.h"
 #endif
+#ifdef INPUTFILE
+#include "InputFileArrays.h"
+#endif
+
 
 extern int classsize[];
 extern int typearray[];
@@ -429,45 +433,11 @@ void CALL01(___System______printString____L___String___, struct ___String___ * _
 }
 #endif
 
+#ifdef INPUTFILE
 #ifdef D___Scanner______nextInt____ 
 int CALL01(___Scanner______nextInt____, struct ___Scanner___ * ___this___) {
   int pos = VAR(___this___)->___currentpos___;
-  int i = 0;
-  unsigned char * filearray = (unsigned char *)(VAR(___this___)->___filearray___);
-  while((filearray[pos]==' ')||(filearray[pos]=='\n')){
-         pos++;
-  }
-  int value = 0;
-  bool isNeg=false;
-  int radix = 10;
-
-  if (filearray[pos]=='-') {
-         isNeg=true;
-      pos++;
-  }
-  bool cont=true;
-  do {
-         unsigned char b=filearray[pos];
-      int val;
-      if (b>='0'&&b<='9')
-        val=b-'0';
-      else if (b>='a'&&b<='z')
-        val=10+b-'a';
-      else if (b>='A'&&b<='Z')
-        val=10+b-'A';
-      else {
-        cont=false;
-      }
-      if (cont) {
-        if (val>=radix)
-          printf("Error in Scanner.nextInt(): val >= radix");
-        value=value*radix+val;
-               pos++;
-      }
-  }while(cont);
-  if (isNeg)
-         value=-value;
-
+  int value = nextInt(VAR(___this___)->___fd___, &pos);
   VAR(___this___)->___currentpos___ = pos;
   return value;
 }
@@ -476,49 +446,12 @@ int CALL01(___Scanner______nextInt____, struct ___Scanner___ * ___this___) {
 #ifdef D___Scanner______nextDouble____ 
 double CALL01(___Scanner______nextDouble____, struct ___Scanner___ * ___this___) {
   int pos = VAR(___this___)->___currentpos___;
-  int i = 0;
-  unsigned char * filearray = (unsigned char *)(VAR(___this___)->___filearray___);
-  while((filearray[pos]==' ')||(filearray[pos]=='\n')){
-         pos++;
-  }
-  double value = 0.0;
-  bool isNeg=false;
-  int radix = 10;
-
-  if (filearray[pos]=='-') {
-         isNeg=true;
-      pos++;
-  } else if(filearray[pos]=='+') {
-         pos++;
-  }
-  bool cont=true;
-  // TODO
-  /*do {
-         unsigned char b=filearray[pos];
-      int val;
-      if (b>='0'&&b<='9')
-        val=b-'0';
-      else if (b>='a'&&b<='z')
-        val=10+b-'a';
-      else if (b>='A'&&b<='Z')
-        val=10+b-'A';
-      else {
-        cont=false;
-      }
-      if (cont) {
-        if (val>=radix)
-          System.error();
-        value=value*radix+val;
-               pos++;
-      }
-  }while(cont)*/
-  if (isNeg)
-         value=-value;
-
+  double value = nextDouble(VAR(___this___)->___fd___, &pos);
   VAR(___this___)->___currentpos___ = pos;
   return value;
 }
 #endif
+#endif
 
 /* Object allocation function */
 
index 0eb7d901d1628489da087b24d6147c72aca19916..f9401e84d8c0836934182a524839d7db4821320c 100644 (file)
@@ -8,6 +8,9 @@
 #include "mem.h"
 #include "runtime.h"
 #include "methodheaders.h"
+#ifdef INPUTFILE
+#include "InputFileArrays.h"
+#endif
 
 #ifdef D___FileOutputStream______nativeWrite____I__AR_B_I_I
 void CALL34(___FileOutputStream______nativeWrite____I__AR_B_I_I, int fd, int off, int len, int fd, struct ArrayObject * ___array___, int off, int len) {
@@ -40,11 +43,16 @@ void CALL11(___FileOutputStream______nativeFlush____I, int fd, int fd) {
 
 #ifdef D___FileOutputStream______nativeOpen_____AR_B
 int CALL01(___FileOutputStream______nativeOpen_____AR_B, struct ArrayObject * ___filename___) {
+  int length=VAR(___filename___)->___length___;
+  char* filename= (((char *)&VAR(___filename___)->___length___)+sizeof(int));
 #ifdef MULTICORE
+#ifdef INPUTFILE
+  int fd=filename2fd(filename, length);
+  return fd;
+#else
   return 0;
+#endif
 #else
-  int length=VAR(___filename___)->___length___;
-  char* filename= (((char *)&VAR(___filename___)->___length___)+sizeof(int));
   int fd=open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
   return fd;
 #endif
@@ -66,8 +74,15 @@ int CALL01(___FileOutputStream______nativeAppend_____AR_B, struct ArrayObject *
 
 #ifdef D___FileInputStream______nativeOpen_____AR_B
 int CALL01(___FileInputStream______nativeOpen_____AR_B, struct ArrayObject * ___filename___) {
+  int length=VAR(___filename___)->___length___;
+  char* filename= (((char *)&VAR(___filename___)->___length___)+sizeof(int));
 #ifdef MULTICORE
+#ifdef INPUTFILE
+  int fd=filename2fd(filename, length);
+  return fd;
+#else
   return 0;
+#endif
 #else
   int length=VAR(___filename___)->___length___;
   char* filename= (((char *)&VAR(___filename___)->___length___)+sizeof(int));
diff --git a/Robust/src/Util/InputFileTranslator.java b/Robust/src/Util/InputFileTranslator.java
new file mode 100644 (file)
index 0000000..c34e403
--- /dev/null
@@ -0,0 +1,209 @@
+package Util;\r
+\r
+import java.util.Vector;\r
+import java.util.zip.GZIPInputStream;\r
+import java.io.File;\r
+import java.io.FileWriter;\r
+import java.io.OutputStream;\r
+import java.io.FileOutputStream;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.io.PrintWriter;\r
+\r
+public class InputFileTranslator{\r
+    public static String PREFIX="";\r
+    \r
+    public static void main(String args[]){\r
+       try{\r
+           //To Uncompress GZip File Contents we need to open the gzip file.....\r
+           if(args.length<=0){\r
+               System.out.println("Please enter the valid file name");\r
+           }else{\r
+               int offset = 0;\r
+               if (args[offset].equals("-dir")) {\r
+                   PREFIX=args[++offset]+"/";\r
+                   offset++;\r
+               }\r
+\r
+               System.out.println("Opening the output file............. : opened");\r
+               \r
+               //Create the .h file \r
+               String outFilename = PREFIX+"InputFileArrays.h";\r
+               PrintWriter out = new PrintWriter(new FileWriter(new File(outFilename)));\r
+               out.println("#ifndef INPUT_FILE_ARRAYS_H");\r
+               out.println("#define INPUT_FILE_ARRAYS_H");\r
+               out.println();\r
+               out.println("#ifndef bool");\r
+               out.println("typedef int bool;");\r
+               out.println("#define true 1");\r
+               out.println("#define false 0");\r
+               out.println("#endif");\r
+               out.println();\r
+               out.println("int filename2fd(char * filename, int length);");\r
+               out.println("int nextInt(int fd, int * pos);");\r
+               out.println("double nextDouble(int fd, int * pos);");\r
+               out.println("#endif");\r
+               out.close();\r
+               \r
+               //Create the .c file that contains the big two-dimension array and \r
+               //read functions\r
+               outFilename = PREFIX+"InputFileArrays.c";\r
+               out = new PrintWriter(new FileWriter(new File(outFilename)));\r
+               out.println("#include \"InputFileArrays.h\"");\r
+               out.println();\r
+               Vector<String> sourcefiles=new Vector<String>();\r
+               for(int i=0; i<args.length-offset; i++)  {\r
+                   String inFilename = args[i+offset];\r
+                   String arrayname = inFilename.replaceAll("\\.", "_");\r
+                   sourcefiles.add(arrayname);\r
+                   out.println("#define " + arrayname.toUpperCase() + " " + i);\r
+                   System.out.println("Opening the gzip file.......................... :  opened");\r
+                   GZIPInputStream gzipInputStream = null;\r
+                   FileInputStream fileInputStream = null;\r
+                   gzipInputStream = new GZIPInputStream(new FileInputStream(inFilename));\r
+                   //OutputStream out = new FileOutputStream(outFilename);\r
+                   System.out.println("Trsansferring bytes from the compressed file to the output file........:  Transfer successful");\r
+                   \r
+                   out.println("unsigned char " + arrayname + "[] = {");\r
+\r
+                   boolean printComma = false;\r
+                   boolean printReturn = false;\r
+                   byte[] buf = new byte[1024];  //size can be changed according to programmer's need.\r
+                   int len;\r
+                   while ((len = gzipInputStream.read(buf)) > 0) {\r
+                       //out.write(buf, 0, len);\r
+                       for(int j = 0; j < len; j++) {\r
+                           if('#' == buf[j]) {\r
+                               // skip the comments\r
+                               while(j<len && buf[j++] != '\n') {\r
+                               }\r
+                           } else {\r
+                               if(!printComma) {\r
+                                   printComma = true;\r
+                               } else {\r
+                                   out.print(',');\r
+                               }\r
+                               if(printReturn) {\r
+                                   out.println();\r
+                                   printReturn = false;\r
+                               }\r
+                               if('\n' == buf[j]) {\r
+                                   out.print("\'\\n\'");\r
+                                   printReturn = true;\r
+                               } else {\r
+                                   out.print(buf[j]);\r
+                               }\r
+                           }\r
+                       }\r
+                   }\r
+                   out.println("};");\r
+                   out.println();\r
+                   gzipInputStream.close();\r
+               }\r
+               \r
+               out.println();\r
+               out.println("unsigned char * inputFileArrays[]= {");\r
+               for(int i = 0; i < sourcefiles.size(); i++) {\r
+                   String arrayname = sourcefiles.elementAt(i);\r
+                   \r
+                   if(i > 0) {\r
+                       out.println(',');\r
+                   }\r
+                   out.print("&"+arrayname+"[0]");\r
+               }\r
+               out.println();\r
+               out.println("};");\r
+               out.println();\r
+               \r
+               //Create the read functions\r
+               out.println("int filename2fd(char * filename, int length) {");\r
+               for(int i=0; i<sourcefiles.size(); i++)  {\r
+                   String inFilename = sourcefiles.elementAt(i);\r
+                   String arrayname = inFilename.replaceAll("\\.", "_");\r
+                   out.print("  char " + arrayname + "[] = {");\r
+                   for(int j = 0; j < inFilename.length(); j++) {\r
+                       if(j>0) {\r
+                           out.print(",");\r
+                       }\r
+                       out.print("'"+inFilename.charAt(j)+"'");\r
+                   }\r
+                   out.println("};");\r
+                   out.println("  if(length==" + inFilename.length() + ") {");\r
+                   out.println("    int i;");\r
+                   out.println("    for(i = 0; i < length; i++) {");\r
+                   out.println("      if(filename[i]!="+arrayname+"[i]) {");\r
+                   out.println("        break;");\r
+                   out.println("      }");\r
+                   out.println("    }");\r
+                   out.println("    if(i==length) {");\r
+                   out.println("      return "+arrayname.toUpperCase() + ";");\r
+                   out.println("    }");\r
+                   out.println("  }");\r
+                   out.println();\r
+               }\r
+               out.println("}");\r
+               \r
+               out.println();\r
+               out.println("int nextInt(int fd, int * pos) {");\r
+               out.println("    int i = 0;");\r
+               out.println("    unsigned char * filearray = inputFileArrays[fd];");\r
+               out.println("    while((filearray[*pos]==\' \')||(filearray[*pos]==\'\\n\')){");\r
+               out.println("     *pos++;");\r
+               out.println("    }");\r
+               out.println("    int value = 0;");\r
+               out.println("    bool isNeg=false;");\r
+               out.println("    int radix = 10;");\r
+               out.println();\r
+               out.println("    if (filearray[*pos]==\'-\') {");\r
+               out.println("      isNeg=true;");\r
+               out.println("      *pos++;");\r
+               out.println("    }");\r
+               out.println("    bool cont=true;");\r
+               out.println("    do {");\r
+               out.println("     unsigned char b=filearray[*pos];");\r
+               out.println("        int val;");\r
+               out.println("        if (b>=\'0\'&&b<=\'9\')");\r
+               out.println("          val=b-\'0\';");\r
+               out.println("        else if (b>=\'a\'&&b<=\'z\')");\r
+               out.println("          val=10+b-\'a\';");\r
+               out.println("       else if (b>=\'A\'&&b<=\'Z\')");\r
+               out.println("          val=10+b-\'A\';");\r
+               out.println("        else {");\r
+               out.println("          cont=false;");\r
+               out.println("        }");\r
+               out.println("        if (cont) {");\r
+               out.println("          if (val>=radix)");\r
+               out.println("            printf(\"Error in nextInt(): val >= radix\");");\r
+               out.println("          value=value*radix+val;");\r
+               out.println("          *pos++;");\r
+               out.println("        }");\r
+               out.println("    }while(cont);");\r
+               out.println("    if (isNeg)");\r
+               out.println("     value=-value;");\r
+               out.println();\r
+               out.println("    return value;");\r
+               out.println("  }");\r
+               out.println();\r
+               \r
+               out.println("double nextDouble(int fd, int * pos) {");\r
+               out.println("    int i = 0;");\r
+               out.println("    unsigned char * filearray = inputFileArrays[fd];");\r
+               out.println("    while((filearray[*pos]==\' \')||(filearray[*pos]==\'\\n\')){");\r
+               out.println("     *pos++;");\r
+               out.println("    }");\r
+               out.println("    double value = 0.0;");\r
+               out.println("//TODO");\r
+               out.println("    return value;");\r
+               out.println("  }");\r
+               out.println();\r
+\r
+               System.out.println("The file and stream is ......closing.......... : closed");\r
+               out.close();\r
+           }\r
+       }\r
+       catch(IOException e){\r
+           System.out.println("Exception has been thrown" + e);\r
+       }\r
+    }\r
+}\r
index 28d65c4ca8e55cf56456137f286b4e951eda03db..ddf8cdb8f4128691e73238e5203c4f02f55641a9 100755 (executable)
@@ -94,6 +94,7 @@ echo -accurateprofile build with accurate profile information including pre/post
 echo -profile_interrupt build with profile information of interrupts
 echo "-useio use standard io to output profiling data (should be used together with -raw and -profile), it only works with single core version"
 echo -gccachecoherent turns on the cache coherence during gc
+echo -inputfile enables reading input files in Tilera
 echo
 echo Multicore GC options
 echo -perfcount performance counters
@@ -275,6 +276,8 @@ TILERA_PAGE_SIZE="0x10000"
 TILERA_PAGE_SIZE_BITS="16"
 TILERA_NUM_BLOCKS="20"
 TILERA_NUM_PAGES_PER_BLOCK="16"
+INPUTFILEFLAG=false
+INPUTFILES=''
 GCCACHECOHERENTFLAG=false
 COMPILER_HEAP_SIZE="1500"
 
@@ -612,6 +615,11 @@ elif [[ $1 = '-mgc' ]]
 then
 MGCFLAG=true
 JAVAOPTS="$JAVAOPTS -mgc"
+elif [[ $1 = '-inputfile' ]]
+then
+INPUTFILEFLAG=true
+INPUTFILES="$INPUTFILES $2"
+shift
 elif [[ $1 = '-mgcintel' ]]
 then
 MGCINTELFLAG=true
@@ -971,6 +979,16 @@ else
   fi
 fi
 
+# transfer the input files
+
+if $INPUTFILEFLAG
+then
+if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx${COMPILER_HEAP_SIZE}m -classpath $ROBUSTROOT Util.InputFileTranslator \
+       -dir $BUILDDIR $INPUTFILES
+    then exit $?
+fi
+fi
+
 # after executing Main, if -justanalyze flag, just exit
 if $EXITAFTERANALYSIS
 then
@@ -1113,6 +1131,11 @@ else
 export TILERACFLAGS="-DTASK -DMULTICORE -DCLOSE_PRINT -DTILERA"
 fi
 
+if $INPUTFILEFLAG
+then
+TILERACFLAGS="${TILERACFLAGS} -DINPUTFILE"
+fi
+
 if $GCTBLDEBUGFLAG
 then
 TILERACFLAGS="${TILERACFLAGS} -DGC_TBL_DEBUG"