Some changes to enable SPECjbb for MGC version. Enable the compilation for 1. class...
authorjzhou <jzhou>
Mon, 24 Jan 2011 22:14:25 +0000 (22:14 +0000)
committerjzhou <jzhou>
Mon, 24 Jan 2011 22:14:25 +0000 (22:14 +0000)
Robust/src/ClassLibrary/FileOutputStream.java
Robust/src/ClassLibrary/String.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/ClassTypeNode.java [new file with mode: 0644]
Robust/src/IR/Tree/Kind.java
Robust/src/IR/Tree/Modifiers.java
Robust/src/Parse/java14.cup

index 297cd482072c8e84201d553b3941841d6fde66c4..07658f10bf230238398f78976ce4884ab4d8e196 100644 (file)
@@ -1,3 +1,5 @@
+import java.io.FileDescriptor;
+
 public class FileOutputStream extends OutputStream {
   private int fd;
 
@@ -26,6 +28,10 @@ public class FileOutputStream extends OutputStream {
   public FileOutputStreamOpen(String pathname) {
     fd = nativeOpen(pathname.getBytes());
   }
+  
+  public FileOutputStream(FileDescriptor fdObj) {
+    fd = nativeOpen(fdObj.channel.getBytes());
+  }
 
   private static native int nativeOpen(byte[] filename);
   private static native int nativeAppend(byte[] filename);
index 52147045afce4e7c0cbcc7479784b9da30c5ed39..e306e742c7798a482c34ddce1e938806bad1eeca 100644 (file)
@@ -41,6 +41,29 @@ public class String {
     this.count=length;
     this.offset=0;
   }
+  
+  public String(byte str[], String encoding) {
+    int length = this.count;
+    if (length>(str.length))
+      length=str.length;
+    char charstr[]=new char[length];
+    for(int i=0; i<length; i++)
+      charstr[i]=(char)str[i];
+    this.value=charstr;
+    this.count=length;
+    this.offset=0;
+  }
+  
+  public String(char str[], int offset, int length) {
+    if (length>(str.length-offset))
+      length=str.length-offset;
+    char charstr[]=new char[length];
+    for(int i=0; i<length; i++)
+      charstr[i]=str[i+offset];
+    this.value=charstr;
+    this.count=length;
+    this.offset=0;
+  }
 
   public String(String str) {
     this.value=str.value;
@@ -228,6 +251,19 @@ public class String {
       str[i]=(byte)value[i+offset];
     return str;
   }
+  
+  public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
+    if((srcBegin < 0) || (srcEnd > count) || (srcBegin > srcEnd)) {
+      // FIXME
+      System.printString("Index error: "+srcBegin+" "+srcEnd+" "+count+"\n"+this);
+      System.exit(-1);
+    }
+    int len = srcEnd - srcBegin;
+    int j = dstBegin;
+    for(int i=srcBegin; i<srcEnd; i++)
+      dst[j++]=value[i+offset];
+    return;
+  }
 
   public int length() {
     return count;
index e8a3396208a57a88fa7f5fed4310dc5e031a74f3..c0ee0ec6806d4430ab8362a702cf19e50140fa34 100644 (file)
@@ -736,6 +736,17 @@ public class BuildIR {
        con.addArgument((ExpressionNode)args.get(i));
       }
       return con;
+    } if (isNode(pn,"createarray2") && state.MGC) {
+      TypeDescriptor td=parseTypeDescriptor(pn);
+      int num=0;
+      if (pn.getChild("dims_opt").getLiteral()!=null)
+    num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
+      for(int i=0; i<num; i++)
+    td=td.makeArray(state);
+      CreateObjectNode con=new CreateObjectNode(td, false, null);
+      // TODO array initializers
+      pn.getChild("initializer");
+      return con;
     } else if (isNode(pn,"name")) {
       NameDescriptor nd=parseName(pn);
       return new NameNode(nd);
@@ -795,10 +806,16 @@ public class BuildIR {
       return new InstanceOfNode(exp,t);
     } else if (isNode(pn, "array_initializer")) {
       System.out.println( "Array initializers not implemented yet." );
-      throw new Error();
+      return null; // TODO MGC
+      //throw new Error();
       //TypeDescriptor td=parseTypeDescriptor(pn);      
       //Vector initializers=parseVariableInitializerList(pn);
       //return new ArrayInitializerNode(td, initializers);
+    } else if (isNode(pn, "class_type") && state.MGC) {
+      TypeDescriptor td=parseTypeDescriptor(pn);
+      return new ClassTypeNode(td);
+    } else if (isNode(pn, "empty") && state.MGC) {
+      return null;
     } else {
       System.out.println("---------------------");
       System.out.println(pn.PPrint(3,true));
@@ -1097,6 +1114,9 @@ public class BuildIR {
         BlockNode fbn=parseBlockHelper(fpn);
         blockstatements.add(new SubBlockNode(fbn));
       }
+    } else if (isNode(pn, "throwstatement")) {
+      // TODO Simply return here
+      blockstatements.add(new ReturnNode());
     } else if (isNode(pn,"taskexit")) {
       Vector vfe=null;
       if (pn.getChild("flag_effects_list")!=null)
@@ -1249,6 +1269,8 @@ public class BuildIR {
       m.addModifier(Modifiers.ABSTRACT);
     else if (isNode(modn,"volatile"))
       m.addModifier(Modifiers.VOLATILE);
+    else if (isNode(modn,"transient"))
+      m.addModifier(Modifiers.TRANSIENT);
        else throw new Error("Unrecognized Modifier");
       }
     }
diff --git a/Robust/src/IR/Tree/ClassTypeNode.java b/Robust/src/IR/Tree/ClassTypeNode.java
new file mode 100644 (file)
index 0000000..18a7b00
--- /dev/null
@@ -0,0 +1,31 @@
+package IR.Tree;
+
+import IR.TypeDescriptor;
+
+public class ClassTypeNode extends ExpressionNode {
+  TypeDescriptor td;
+
+  public ClassTypeNode(TypeDescriptor td) {
+    this.td=td;
+  }
+  
+  public TypeDescriptor getTypeDesc() {
+    return this.td;
+  }
+  
+  public void setTypeDesc(TypeDescriptor td) {
+    this.td = td;
+  }
+
+  public TypeDescriptor getType() {
+    return td;
+  }
+
+  public String printNode(int indent) {
+    return td.toString();
+  }
+
+  public int kind() {
+    return Kind.ClassTypeNode;
+  }
+}
index 38edb43ed782fe820d4aa66f4b40dd43e0a979af..6887303ea68cd1e1803a9924eb1f3fa6f1304d3b 100644 (file)
@@ -33,4 +33,5 @@ public class Kind {
   public final static int SwitchStatementNode=30;
   public final static int SwitchLabelNode=31;
   public final static int SwitchBlockNode=32;
+  public final static int ClassTypeNode=33;
 }
index 709d46a9b27fc69c6555117b7b9f7fa1567cd663..c49c35d2409998bb02a3a00a93ae142f7c6ec7f9 100644 (file)
@@ -9,7 +9,7 @@ public class Modifiers {
   public static final int FINAL=32;
   public static final int NATIVE=64;
   public static final int SYNCHRONIZED=128;
-//     TRANSIENT=256
+  public static final int TRANSIENT=256;
   public static final int VOLATILE=512;
 //     STRICTFP=1024
   public static final int ATOMIC=2048;
@@ -58,6 +58,10 @@ public class Modifiers {
   public boolean isVolatile() {
     return ((value&VOLATILE)!= 0);
   }
+  
+  public boolean isTransient() {
+    return ((value & TRANSIENT) != 0);
+  }
 
   public String toString() {
     String st="";
@@ -81,6 +85,8 @@ public class Modifiers {
       st+="abstract ";
     if((value&VOLATILE)!=0)
       st += "volatile ";
+    if((value&TRANSIENT)!=0)
+      st += "transient ";
     return st;
   }
 }
index d0482858a33130298d2392a2a0f96ce8effbe799..6f489a676b7987a0aaccb1b61e842e80297df94b 100644 (file)
@@ -146,9 +146,9 @@ non terminal ParseNode variable_initializer;
 non terminal ParseNode method_declaration, method_header, method_declarator;
 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
 non terminal ParseNode formal_parameter;
-//non terminal ParseNode throws_opt;
-//non terminal ParseNode throws;
-//non terminal ParseNode class_type_list;
+non terminal ParseNode throws_opt;
+non terminal ParseNode throws;
+non terminal ParseNode class_type_list;
 non terminal ParseNode method_body;
 // 19.8.4) Static Initializers
 non terminal ParseNode static_initializer;
@@ -190,7 +190,7 @@ non terminal ParseNode statement_expression_list;
 //non terminal ParseNode identifier_opt;
 non terminal ParseNode break_statement, continue_statement;
 non terminal ParseNode return_statement;
-//non terminal ParseNode throw_statement;
+non terminal ParseNode throw_statement;
 non terminal ParseNode synchronized_statement;
 non terminal ParseNode try_statement;
 non terminal ParseNode catches_opt;
@@ -203,7 +203,7 @@ non terminal ParseNode primary, primary_no_new_array;
 non terminal ParseNode class_instance_creation_expression;
 non terminal ParseNode cons_argument_list_opt, cons_argument_list;
 non terminal ParseNode argument_list_opt, argument_list;
-//non terminal ParseNode array_creation_init;
+non terminal ParseNode array_creation_init;
 non terminal ParseNode array_creation_uninit;
 non terminal ParseNode dim_exprs, dim_expr;
 non terminal Integer dims_opt, dims;
@@ -733,8 +733,8 @@ modifier ::=
        NATIVE {: RESULT=new ParseNode("native"); :} |
        SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :} |
        ATOMIC {: RESULT=new ParseNode("atomic"); :} |
-       VOLATILE {: RESULT=new ParseNode("volatile"); :}
-//     TRANSIENT | 
+       VOLATILE {: RESULT=new ParseNode("volatile"); :} |
+       TRANSIENT {: RESULT=new ParseNode("transient"); :} 
 
 //     STRICTFP // note that semantic analysis must check that the
                         // context of the modifier allows strictfp.
@@ -967,7 +967,7 @@ variable_declarator_id ::=
        ;
 variable_initializer ::=
                expression:exp {: RESULT=exp; :}
-       |       array_initializer {: RESULT=new ParseNode("array_initializer"); :}
+       |       array_initializer:ai {: RESULT=(new ParseNode("array_initializer")).addChild(ai).getRoot(); :}
        ;
 
 // 19.8.3) Method Declarations
@@ -980,18 +980,20 @@ method_declaration ::=
        :}
        ;
 method_header ::=
-               modifiers_opt:mo type:type method_declarator:decl //throws_opt 
+               modifiers_opt:mo type:type method_declarator:decl throws_opt:to 
        {:
                ParseNode pn=new ParseNode("method_header");
                pn.addChild("modifiers").addChild(mo);
                pn.addChild("returntype").addChild(type);
+               pn.addChild("throws").addChild(to);
                pn.addChild(decl);
                RESULT=pn;
        :}
-       |       modifiers_opt:mo VOID method_declarator:decl //throws_opt
+       |       modifiers_opt:mo VOID method_declarator:decl throws_opt:to
        {:
                ParseNode pn=new ParseNode("method_header");
                pn.addChild("modifiers").addChild(mo);
+               pn.addChild("throws").addChild(to);
                pn.addChild(decl);
                RESULT=pn;
        :}
@@ -1043,15 +1045,27 @@ formal_parameter ::=
                RESULT=pn;
        :}
        ;
-//throws_opt ::=       
-//     |       throws
-//     ;
-//throws ::=   THROWS class_type_list
-//     ;
-//class_type_list ::=
-//             class_type
-//     |       class_type_list COMMA class_type
-//     ;
+throws_opt ::= 
+        {: RESULT=new ParseNode("empty"); :}
+       |       throws:trs
+           {: RESULT=trs; :}
+       ;
+throws ::=     THROWS class_type_list:ctl
+        {: RESULT=(new ParseNode("throw_list")).addChild(ctl).getRoot(); :}
+       ;
+class_type_list ::=
+               class_type:ct
+               {: 
+               ParseNode pn=new ParseNode("class_type_list");
+               pn.addChild(ct);
+               RESULT=pn; 
+               :}
+       |       class_type_list:ctl COMMA class_type:ct
+           {: 
+           ctl.addChild(ct);
+           RESULT=ctl; 
+           :}
+       ;
 method_body ::=        block:block {: 
                RESULT=block;
        :}
@@ -1069,21 +1083,21 @@ static_initializer ::=
 
 // 19.8.5) Constructor Declarations
 constructor_declaration ::=
-               modifiers_opt:mo constructor_declarator:cd
-//throws_opt 
+               modifiers_opt:mo constructor_declarator:cd throws_opt:to 
                        constructor_body:body   {:
                ParseNode pn=new ParseNode("constructor_declaration");
                pn.addChild("modifiers").addChild(mo);
+               pn.addChild("throws").addChild(to);
                pn.addChild(cd);
                pn.addChild("body").addChild(body);
                RESULT=pn;
        :} |
-               modifiers_opt:mo GLOBAL constructor_declarator:cd
-//throws_opt 
+               modifiers_opt:mo GLOBAL constructor_declarator:cd throws_opt:to 
                        constructor_body:body   {:
                ParseNode pn=new ParseNode("constructor_declaration");
                pn.addChild("global");
                pn.addChild("modifiers").addChild(mo);
+               pn.addChild("throws").addChild(to);
                pn.addChild(cd);
                pn.addChild("body").addChild(body);
                RESULT=pn;
@@ -1338,7 +1352,7 @@ statement_without_trailing_substatement ::=
        |       sese_statement:st {: RESULT=st; :}
        |       synchronized_statement:st {: RESULT=st; :}
        |       genreach_statement:st {: RESULT=st; :}
-//     |       throw_statement
+       |       throw_statement:st {: RESULT=st; :}
        |       try_statement:st {: RESULT=st; :}
 //     |       assert_statement
        ;
@@ -1564,9 +1578,11 @@ return_statement ::=
                RETURN expression_opt:exp SEMICOLON {: 
        RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
        ;
-//throw_statement ::=
-//             THROW expression SEMICOLON
-//     ;
+throw_statement ::=
+               THROW expression:exp SEMICOLON {:
+               RESULT=(new ParseNode("throwstatement")).addChild(exp).getRoot();
+               :}
+       ;
 synchronized_statement ::=
                SYNCHRONIZED LPAREN expression:e RPAREN block:b {: 
                ParseNode pn=new ParseNode("synchronized");
@@ -1660,9 +1676,9 @@ finally ::=       FINALLY block:bk
 // 19.12) Expressions
 primary ::=    primary_no_new_array:st {: 
                RESULT=st; :}
-//     |       array_creation_init:st {: 
-//             RESULT=st;
-//     :}
+       |       array_creation_init:st {: 
+               RESULT=st;
+       :}
        |       array_creation_uninit:st {:
                RESULT=st;
        :}
@@ -1680,10 +1696,22 @@ primary_no_new_array ::=
                pn.addChild(id);
                RESULT=pn;
        :}
-//     |       primitive_type DOT CLASS
+       |       primitive_type:pt DOT CLASS {:
+           ParseNode pn=new ParseNode("class_type");
+           pn.addChild(pt);
+           RESULT=pn;
+       :}
 //     |       VOID DOT CLASS
-//     |       array_type DOT CLASS
-//     |       name DOT CLASS
+       |       array_type:at DOT CLASS {:
+           ParseNode pn=new ParseNode("class_type");
+           pn.addChild(at);
+           RESULT=pn;
+       :}
+       |       name:name DOT CLASS {:
+           ParseNode pn=new ParseNode("class_type");
+           pn.addChild("type").addChild("class").addChild(name);
+           RESULT=pn;
+       :}
 //     |       name DOT THIS
        ;
 class_instance_creation_expression ::=
@@ -1850,10 +1878,22 @@ array_creation_uninit ::=
                RESULT=pn;
                :}
        ;
-//array_creation_init ::=
-//             NEW primitive_type dims array_initializer
-//     |       NEW class_or_interface_type dims array_initializer
-//     ;
+array_creation_init ::=
+               NEW primitive_type:type dims:dims array_initializer:ai {: 
+               ParseNode pn=new ParseNode("createarray2");
+               pn.addChild(type);
+               pn.addChild("dims_opt").setLiteral(dims);
+               pn.addChild("initializer").addChild(ai);
+               RESULT=pn;
+               :}
+       |       NEW class_or_interface_type:type dims:dims array_initializer:ai {: 
+               ParseNode pn=new ParseNode("createarray2");
+               pn.addChild(type);
+               pn.addChild("dims_opt").setLiteral(dims);
+               pn.addChild("initializer").addChild(ai);
+               RESULT=pn;
+               :}
+       ;
 dim_exprs ::=  dim_expr:exp {: 
                ParseNode pn=new ParseNode("dim_exprs");
                pn.addChild(exp);
@@ -1992,7 +2032,19 @@ else {
                RESULT=pn;
 
        :}
-//     |       LPAREN name dims RPAREN unary_expression_not_plus_minus
+       |       LPAREN name:name dims:dims RPAREN unary_expression_not_plus_minus:exp {: 
+               ParseNode pn=new ParseNode("cast1");
+if (dims.intValue()==0)
+               pn.addChild("type").addChild("class").addChild(name);
+else {
+               ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
+               arrayt.addChild("basetype").addChild("type").addChild("class").addChild(name);
+               arrayt.addChild("dims").setLiteral(dims);
+}
+               pn.addChild("exp").addChild(exp);
+               RESULT=pn;
+
+       :}
        ;
 multiplicative_expression ::=
                unary_expression:exp {: