From: jzhou Date: Tue, 15 May 2012 00:27:08 +0000 (+0000) Subject: Changes for reading input files in MGC version X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=681c8d879d5d19a37e29b816e2f4c9eab148a20f;p=IRC.git Changes for reading input files in MGC version --- diff --git a/Robust/src/ClassLibrary/MGC/Scanner.java b/Robust/src/ClassLibrary/MGC/Scanner.java index f4fba9b1..40796c9a 100644 --- a/Robust/src/ClassLibrary/MGC/Scanner.java +++ b/Robust/src/ClassLibrary/MGC/Scanner.java @@ -1,14 +1,16 @@ public class Scanner implements Iterator { - private String sourcename; + private FileInputStream source; private int currentpos; - private int filearray; + private int fd; public Scanner (final String source) { - this.sourcename = source; + this.source = new FileInputStream(source); + this.fd = this.source.getfd(); this.currentpos = 0; } public void close () { + this.source.close(); } public native double nextDouble (); diff --git a/Robust/src/Runtime/bamboo/multicoreruntime.c b/Robust/src/Runtime/bamboo/multicoreruntime.c index bed80cf4..0ebf81c9 100644 --- a/Robust/src/Runtime/bamboo/multicoreruntime.c +++ b/Robust/src/Runtime/bamboo/multicoreruntime.c @@ -16,6 +16,10 @@ #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 */ diff --git a/Robust/src/Runtime/file.c b/Robust/src/Runtime/file.c index 0eb7d901..f9401e84 100644 --- a/Robust/src/Runtime/file.c +++ b/Robust/src/Runtime/file.c @@ -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 index 00000000..c34e4031 --- /dev/null +++ b/Robust/src/Util/InputFileTranslator.java @@ -0,0 +1,209 @@ +package Util; + +import java.util.Vector; +import java.util.zip.GZIPInputStream; +import java.io.File; +import java.io.FileWriter; +import java.io.OutputStream; +import java.io.FileOutputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; + +public class InputFileTranslator{ + public static String PREFIX=""; + + public static void main(String args[]){ + try{ + //To Uncompress GZip File Contents we need to open the gzip file..... + if(args.length<=0){ + System.out.println("Please enter the valid file name"); + }else{ + int offset = 0; + if (args[offset].equals("-dir")) { + PREFIX=args[++offset]+"/"; + offset++; + } + + System.out.println("Opening the output file............. : opened"); + + //Create the .h file + String outFilename = PREFIX+"InputFileArrays.h"; + PrintWriter out = new PrintWriter(new FileWriter(new File(outFilename))); + out.println("#ifndef INPUT_FILE_ARRAYS_H"); + out.println("#define INPUT_FILE_ARRAYS_H"); + out.println(); + out.println("#ifndef bool"); + out.println("typedef int bool;"); + out.println("#define true 1"); + out.println("#define false 0"); + out.println("#endif"); + out.println(); + out.println("int filename2fd(char * filename, int length);"); + out.println("int nextInt(int fd, int * pos);"); + out.println("double nextDouble(int fd, int * pos);"); + out.println("#endif"); + out.close(); + + //Create the .c file that contains the big two-dimension array and + //read functions + outFilename = PREFIX+"InputFileArrays.c"; + out = new PrintWriter(new FileWriter(new File(outFilename))); + out.println("#include \"InputFileArrays.h\""); + out.println(); + Vector sourcefiles=new Vector(); + for(int i=0; i 0) { + //out.write(buf, 0, len); + for(int j = 0; j < len; j++) { + if('#' == buf[j]) { + // skip the comments + while(j 0) { + out.println(','); + } + out.print("&"+arrayname+"[0]"); + } + out.println(); + out.println("};"); + out.println(); + + //Create the read functions + out.println("int filename2fd(char * filename, int length) {"); + for(int i=0; i0) { + out.print(","); + } + out.print("'"+inFilename.charAt(j)+"'"); + } + out.println("};"); + out.println(" if(length==" + inFilename.length() + ") {"); + out.println(" int i;"); + out.println(" for(i = 0; i < length; i++) {"); + out.println(" if(filename[i]!="+arrayname+"[i]) {"); + out.println(" break;"); + out.println(" }"); + out.println(" }"); + out.println(" if(i==length) {"); + out.println(" return "+arrayname.toUpperCase() + ";"); + out.println(" }"); + out.println(" }"); + out.println(); + } + out.println("}"); + + out.println(); + out.println("int nextInt(int fd, int * pos) {"); + out.println(" int i = 0;"); + out.println(" unsigned char * filearray = inputFileArrays[fd];"); + out.println(" while((filearray[*pos]==\' \')||(filearray[*pos]==\'\\n\')){"); + out.println(" *pos++;"); + out.println(" }"); + out.println(" int value = 0;"); + out.println(" bool isNeg=false;"); + out.println(" int radix = 10;"); + out.println(); + out.println(" if (filearray[*pos]==\'-\') {"); + out.println(" isNeg=true;"); + out.println(" *pos++;"); + out.println(" }"); + out.println(" bool cont=true;"); + out.println(" do {"); + out.println(" unsigned char b=filearray[*pos];"); + out.println(" int val;"); + out.println(" if (b>=\'0\'&&b<=\'9\')"); + out.println(" val=b-\'0\';"); + out.println(" else if (b>=\'a\'&&b<=\'z\')"); + out.println(" val=10+b-\'a\';"); + out.println(" else if (b>=\'A\'&&b<=\'Z\')"); + out.println(" val=10+b-\'A\';"); + out.println(" else {"); + out.println(" cont=false;"); + out.println(" }"); + out.println(" if (cont) {"); + out.println(" if (val>=radix)"); + out.println(" printf(\"Error in nextInt(): val >= radix\");"); + out.println(" value=value*radix+val;"); + out.println(" *pos++;"); + out.println(" }"); + out.println(" }while(cont);"); + out.println(" if (isNeg)"); + out.println(" value=-value;"); + out.println(); + out.println(" return value;"); + out.println(" }"); + out.println(); + + out.println("double nextDouble(int fd, int * pos) {"); + out.println(" int i = 0;"); + out.println(" unsigned char * filearray = inputFileArrays[fd];"); + out.println(" while((filearray[*pos]==\' \')||(filearray[*pos]==\'\\n\')){"); + out.println(" *pos++;"); + out.println(" }"); + out.println(" double value = 0.0;"); + out.println("//TODO"); + out.println(" return value;"); + out.println(" }"); + out.println(); + + System.out.println("The file and stream is ......closing.......... : closed"); + out.close(); + } + } + catch(IOException e){ + System.out.println("Exception has been thrown" + e); + } + } +} diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 28d65c4c..ddf8cdb8 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -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"