Enable the nextDoublt() call for reading input files
authorjzhou <jzhou>
Thu, 17 May 2012 03:01:58 +0000 (03:01 +0000)
committerjzhou <jzhou>
Thu, 17 May 2012 03:01:58 +0000 (03:01 +0000)
Robust/src/Makefile
Robust/src/Util/InputFileTranslator.java
Robust/src/buildscript

index 3482903..56fb430 100644 (file)
@@ -101,6 +101,7 @@ Analysis/OoOJava/VariableSourceToken.class                          \
 Analysis/OoOJava/ContextTaskNames.class                                        \
 Util/GraphNode.class Util/Namer.class Util/Relation.class              \
 Util/UtilAlgorithms.class                                               \
+Util/InputFileTranslator.class                                               \
 Interface/HTTPHeader.class Interface/HTTPResponse.class                        \
 Interface/HTTPServices.class Interface/HashStrings.class               \
 Interface/JhttpServer.class Interface/JhttpWorker.class                        \
@@ -120,7 +121,7 @@ Analysis/Scheduling/Schedule.class                                      \
 Analysis/Scheduling/ScheduleSimulator.class                             \
 Analysis/Scheduling/SchedulingUtil.class                                \
 Analysis/Scheduling/TaskSimulator.class                                 \
-Analysis/Scheduling/TransTaskSimulator.class
+Analysis/Scheduling/TransTaskSimulator.class 
 
 JAVAFILES=IR/*.java \
        IR/Flat/*.java \
index c34e403..760b5b9 100644 (file)
@@ -51,12 +51,13 @@ public class InputFileTranslator{
                outFilename = PREFIX+"InputFileArrays.c";\r
                out = new PrintWriter(new FileWriter(new File(outFilename)));\r
                out.println("#include \"InputFileArrays.h\"");\r
+               out.println("#include \"math.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
+                   sourcefiles.add(inFilename);\r
                    out.println("#define " + arrayname.toUpperCase() + " " + i);\r
                    System.out.println("Opening the gzip file.......................... :  opened");\r
                    GZIPInputStream gzipInputStream = null;\r
@@ -105,7 +106,7 @@ public class InputFileTranslator{
                out.println();\r
                out.println("unsigned char * inputFileArrays[]= {");\r
                for(int i = 0; i < sourcefiles.size(); i++) {\r
-                   String arrayname = sourcefiles.elementAt(i);\r
+                   String arrayname = sourcefiles.elementAt(i).replaceAll("\\.", "_");\r
                    \r
                    if(i > 0) {\r
                        out.println(',');\r
@@ -142,6 +143,7 @@ public class InputFileTranslator{
                    out.println("  }");\r
                    out.println();\r
                }\r
+               out.println("  return -1;");\r
                out.println("}");\r
                \r
                out.println();\r
@@ -149,35 +151,35 @@ public class InputFileTranslator{
                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("     *pos=*pos+1;");\r
                out.println("    }");\r
-               out.println("    int value = 0;");\r
+               out.println("    unsigned int value = 0;");\r
                out.println("    bool isNeg=false;");\r
-               out.println("    int radix = 10;");\r
+               out.println("    unsigned int radix = 10;");\r
                out.println();\r
                out.println("    if (filearray[*pos]==\'-\') {");\r
                out.println("      isNeg=true;");\r
-               out.println("      *pos++;");\r
+               out.println("      *pos=*pos+1;");\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("      unsigned char b=filearray[*pos];");\r
+               out.println("      unsigned 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=*pos+1;");\r
+               out.println("      }");\r
                out.println("    }while(cont);");\r
                out.println("    if (isNeg)");\r
                out.println("     value=-value;");\r
@@ -190,11 +192,106 @@ public class InputFileTranslator{
                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("     *pos=*pos+1;");\r
                out.println("    }");\r
-               out.println("    double value = 0.0;");\r
-               out.println("//TODO");\r
-               out.println("    return value;");\r
+               out.println("    double result=0.0;");\r
+               out.println("    unsigned int value=0;");\r
+               out.println("    unsigned int maxvalue=((unsigned int)(1<<32)-1)/10;");\r
+               out.println("    bool isNeg=false;");\r
+               out.println("    bool isDiv=false;");\r
+               out.println("    unsigned int radix = 10;");\r
+               out.println();\r
+               out.println("    if (filearray[*pos]=='-') {");\r
+               out.println("      isNeg=true;");\r
+               out.println("      *pos=*pos+1;");\r
+               out.println("    }");\r
+               out.println("    bool cont=true;");\r
+               out.println("    bool exp=false;");\r
+               out.println("    bool decimal=false;");\r
+               out.println("    bool compute=true;");\r
+               out.println("    bool omit=false;");\r
+               out.println("    unsigned int dcount=0;");\r
+               out.println("    // compute the base");\r
+               out.println("    do {");\r
+               out.println("      unsigned char b=filearray[*pos];");\r
+               out.println("      unsigned int val;");\r
+               out.println("      if (b>='0'&&b<='9') {");\r
+               out.println("        if (!omit) {");\r
+               out.println("          val=b-'0';");\r
+               out.println("          if(decimal) {");\r
+               out.println("            dcount++;");\r
+               out.println("          }");\r
+               out.println("        }");\r
+               out.println("      } else if (b=='.') {");\r
+               out.println("        decimal=true;");\r
+               out.println("        compute=false;");\r
+               out.println("      } else if (b=='E'||b=='e') {");\r
+               out.println("        exp=true;");\r
+               out.println("        cont=false;");\r
+               out.println("        *pos=*pos+1;");\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 nextDouble(): val >= radix\");");\r
+               out.println("        if(compute) {");\r
+               out.println("          if(value<maxvalue) {");\r
+               out.println("            value=value*radix+val;");\r
+               out.println("          } else {");\r
+               out.println("            omit=true;");\r
+               out.println("            compute=false;");\r
+               out.println("            dcount--;");\r
+               out.println("          }");\r
+               out.println("        } else if(!omit) {");\r
+               out.println("          compute=true;");\r
+               out.println("        }");\r
+               out.println("        *pos=*pos+1;");\r
+               out.println("      }");\r
+               out.println("    }while(cont);");\r
+               out.println("    if(exp) {");\r
+               out.println("      // compute the power index");\r
+               out.println("      cont=true;");\r
+               out.println("      unsigned int n=0;");\r
+               out.println("      if (filearray[*pos]=='-') {");\r
+               out.println("        isDiv=true;");\r
+               out.println("        *pos=*pos+1;");\r
+               out.println("      } else if (filearray[*pos]=='+') {");\r
+               out.println("        *pos=*pos+1;");\r
+               out.println("      }");\r
+               out.println("      do {");\r
+               out.println("        unsigned char b=filearray[*pos];");\r
+               out.println("        unsigned int val;");\r
+               out.println("        if (b>='0'&&b<='9') {");\r
+               out.println("          val=b-'0';");\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 nextDouble(): val >= radix\");");\r
+               out.println("          n=n*10+val;");\r
+               out.println("          *pos=*pos+1;");\r
+               out.println("        }");\r
+               out.println("      }while(cont);");\r
+               out.println("      if(isDiv) {");\r
+               out.println("        result = (double)value/pow(radix, n+dcount);");\r
+               out.println("      } else {");\r
+               out.println("        if(n>dcount) {");\r
+               out.println("          result = (double)value*pow(radix, n-dcount);");\r
+               out.println("        } else if(n<dcount) {");\r
+               out.println("          result = (double)value/pow(radix, dcount-n);");\r
+               out.println("        } else {");\r
+               out.println("          result = (double)value;");\r
+               out.println("        }");\r
+               out.println("      }");\r
+               out.println("    } else {");\r
+               out.println("      result = (double)value/pow(radix, dcount);");\r
+               out.println("    }");\r
+               out.println("    if (isNeg)");\r
+               out.println("      result=-result;");\r
+               out.println();\r
+               out.println("return result;");\r
                out.println("  }");\r
                out.println();\r
 \r
index ddf8cdb..7c54d9c 100755 (executable)
@@ -983,6 +983,7 @@ fi
 
 if $INPUTFILEFLAG
 then
+./ourjavac -cp ../cup:.:$(CLASSPATH) Util/InputFileTranslator.java
 if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx${COMPILER_HEAP_SIZE}m -classpath $ROBUSTROOT Util.InputFileTranslator \
        -dir $BUILDDIR $INPUTFILES
     then exit $?