Changeset 3914
- Timestamp:
- 07/02/09 05:12:38 (5 months ago)
- Location:
- trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen
- Files:
-
- 3 modified
-
CodeGen.java (modified) (8 diffs)
-
CodeGenClassWriter.java (modified) (1 diff)
-
CodeGenMethodVisitor.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGen.java
r3912 r3914 145 145 mv.visitVarInsn(Opcodes.ALOAD, mv.getLocalVariable("instance")); 146 146 147 System.out.println("Creating local variable " + task);148 147 mv.visitVarInsn(Opcodes.ASTORE, mv.createLocalVariable(task)); 149 148 … … 828 827 } 829 828 829 private void generatePrintArgs(CodeGen cg) { 830 cg.mv.visitVarInsn(Opcodes.ALOAD, 1); 831 cg.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NamingCzar.internalFortressZZ32, 832 "getValue", "()I"); 833 cg.mv.visitMethodInsn(Opcodes.INVOKESTATIC,"com/sun/fortress/nativeHelpers/simplePrintArgs", 834 "nativePrintZZ32", "(I)V"); 835 } 836 837 830 838 // This sets up the parallel task construct. 831 839 // Caveats: We assume that everything has a ZZ32 result … … 833 841 public String delegate(ASTNode x) { 834 842 String className = NamingCzar.gensymTaskName(packageAndClassName); 835 debug("delegate creating class " + className );843 debug("delegate creating class " + className + " node = " + x); 836 844 // Create a new environment 837 845 CodeGen cg = new CodeGen(this); … … 850 858 "(" + NamingCzar.descFortressZZ32 + ")V", null, null); 851 859 cg.mv.visitCode(); 852 cg.mv.visitVarInsn(Opcodes.ALOAD, 0);860 cg.mv.visitVarInsn(Opcodes.ALOAD, cg.mv.getLocalVariable("instance")); 853 861 cg.mv.visitMethodInsn(Opcodes.INVOKESPECIAL, NamingCzar.fortressBaseTask, 854 862 "<init>", NamingCzar.voidToVoid); 855 856 cg.mv.visitVarInsn(Opcodes.ALOAD, 0); 863 cg.mv.visitVarInsn(Opcodes.ALOAD, cg.mv.getLocalVariable("instance")); 857 864 cg.mv.visitVarInsn(Opcodes.ALOAD, 1); 858 865 cg.mv.visitFieldInsn(Opcodes.PUTFIELD, className, "n", NamingCzar.descFortressZZ32); 859 // cg.mv.visitVarInsn(Opcodes.ALOAD, 1);860 // cg.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NamingCzar.internalFortressZZ32,861 // "getValue", "()I");862 // cg.mv.visitMethodInsn(Opcodes.INVOKESTATIC,"com/sun/fortress/nativeHelpers/simplePrintArgs",863 // "nativePrintZZ32", "(I)V");864 866 865 867 cg.mv.visitInsn(Opcodes.RETURN); … … 890 892 } 891 893 894 private void generatePrintResult(CodeGen cg) { 895 mv.visitInsn(Opcodes.DUP); 896 mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NamingCzar.internalFortressZZ32, 897 "getValue", "()I"); 898 mv.visitMethodInsn(Opcodes.INVOKESTATIC,"com/sun/fortress/nativeHelpers/simplePrintResult", 899 "nativePrintZZ32", "(I)V"); 900 } 901 892 902 public void forOpExpr(OpExpr x) { 893 903 debug("forOpExpr ", x, " op = ", x.getOp(), … … 902 912 mv.visitVarInsn(Opcodes.ASTORE, mv.createLocalVariable("TaskArray", "java/util/ArrayList")); 903 913 904 System.out.println("RRRRRRR:" + pa + " SSSSSS " + x);905 914 if (pa.worthParallelizing(x)) { 906 915 for (int i = 0; i < args.size(); i++) { … … 926 935 mv.visitVarInsn(Opcodes.ALOAD, mv.getLocalVariable(tasks.get(i))); 927 936 mv.visitFieldInsn(Opcodes.GETFIELD, tasks.get(i), "result", NamingCzar.descFortressZZ32); 928 // mv.visitInsn(Opcodes.DUP);929 // mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NamingCzar.internalFortressZZ32,930 // "getValue", "()I");931 // mv.visitMethodInsn(Opcodes.INVOKESTATIC,"com/sun/fortress/nativeHelpers/simplePrintResult",932 // "nativePrintZZ32", "(I)V");933 934 937 } 935 938 } else { … … 1126 1129 List<Expr> exprs = targ.getExprs(); 1127 1130 for (Expr expr : exprs) { 1128 System.out.println("args = " + expr);1129 1131 expr.accept(this); 1130 1132 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGenClassWriter.java
r3912 r3914 35 35 } 36 36 37 // When we can reliably parse type descriptors, this will go away.38 39 public CodeGenMethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions, String[] argTypes, String resultType) {40 return new CodeGenMethodVisitor(access, name, desc, signature, exceptions,41 super.visitMethod(access, name, desc, signature, exceptions),42 argTypes, resultType);43 }44 45 37 } 46 38 -
trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGenMethodVisitor.java
r3912 r3914 39 39 private String signature; 40 40 private String[] exceptions; 41 private String[] arguments;41 private List<String> argumentTypes; 42 42 private String resultType; 43 int localVariableCount; 43 44 45 static void error(String s) {throw new RuntimeException("Bad Signature " + s);} 46 47 private void parseDescriptor(String desc) { 48 argumentTypes = new ArrayList<String>(); 49 50 System.out.println("parseDescriptor: " + desc); 51 52 if (desc.charAt(0) != '(') error(desc); 53 int i = 1; 54 int start = 0; 55 int ch = desc.charAt(i); 56 57 58 while (ch != ')') { 59 System.out.println("parseDescriptor: desc = " + desc + 60 " i = " + i + " argumentTypes = " + argumentTypes); 61 62 switch(ch) { 63 case 'B': 64 case 'S': 65 case 'F': 66 case 'D': 67 case 'C': 68 case 'I': 69 case 'J': 70 case 'Z': 71 argumentTypes.add(Character.toString(desc.charAt(i))); ch = desc.charAt(++i); break; 72 case '[': 73 case 'L': 74 start = i; 75 while (ch != ';') { 76 ch = desc.charAt(++i); 77 } 78 argumentTypes.add(desc.substring(start, ++i)); 79 ch = desc.charAt(i); 80 break; 81 default: error(desc); 82 } 83 } 84 ch = desc.charAt(++i); 85 86 switch(ch) { 87 case 'B': 88 case 'S': 89 case 'F': 90 case 'D': 91 case 'C': 92 case 'I': 93 case 'J': 94 case 'Z': 95 case 'V': 96 resultType = Character.toString(desc.charAt(i)); break; 97 case '[': 98 start = i; 99 while (ch != ']') { 100 ch = desc.charAt(++i); 101 } 102 resultType = new String(desc.substring(start, ++i)); 103 break; 104 case 'L': 105 start = i; 106 while (ch != ';') { 107 ch = desc.charAt(++i); 108 } 109 resultType = new String(desc.substring(start, ++i)); 110 break; 111 default: error(desc); 112 } 113 System.out.println("parseDescriptor: desc = " + desc + 114 " i = " + i + " argumentTypes = " + argumentTypes + 115 " resultType = " + resultType); 116 } 44 117 45 118 public CodeGenMethodVisitor(int access, String name, String desc, … … 56 129 this.localVariableTypeTable = new HashMap<String, String>(); 57 130 this.localVariableCount = 0; 58 createLocalVariable("instance");59 createLocalVariable("result");60 131 61 } 132 if ((access & Opcodes.ACC_STATIC) != Opcodes.ACC_STATIC) { 133 createLocalVariable("instance", name); 134 } 62 135 63 public CodeGenMethodVisitor(int access, String name, String desc, 64 String signature, String[] exceptions, 65 MethodVisitor mvisitor, String argTypes[], 66 String resultType) { 67 super(mvisitor); 68 this.access = access; 69 this.name = name; 70 this.desc = desc; 71 this.signature = signature; 72 this.exceptions = exceptions; 73 this.arguments = argTypes; 74 this.resultType = resultType; 136 parseDescriptor(desc); 137 138 System.out.println("MethodVisitor: name = " + name + " desc = " + desc + 139 " argumentTypes = " + argumentTypes + " resultType " + resultType); 75 140 76 this.localVariableTable = new HashMap<String, Integer>(); 77 this.localVariableTypeTable = new HashMap<String, String>(); 78 this.localVariableCount = 0; 141 int i = 0; 79 142 80 createLocalVariable("instance"); 81 82 int ind = 0; 83 for (String arg : arguments) { 84 createLocalVariable("arg" + ind, arguments[ind++]); 143 for (String argumentType : argumentTypes) { 144 createLocalVariable("arg" + i++, argumentType); 85 145 } 86 146 87 147 createLocalVariable("result", resultType); 148 88 149 } 89 150 … … 96 157 Debug.debug(Debug.Type.CODEGEN, 1, getText()); 97 158 } 98 99 // We need to be smarter about this.100 public int localVariableCount;101 159 102 160 public int createLocalVariable(String name) {

