Changeset 3914

Show
Ignore:
Timestamp:
07/02/09 05:12:38 (5 months ago)
Author:
chf
Message:

parse descriptors

Location:
trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGen.java

    r3912 r3914  
    145145        mv.visitVarInsn(Opcodes.ALOAD, mv.getLocalVariable("instance")); 
    146146 
    147         System.out.println("Creating local variable " + task); 
    148147        mv.visitVarInsn(Opcodes.ASTORE, mv.createLocalVariable(task)); 
    149148         
     
    828827    } 
    829828 
     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 
    830838    // This sets up the parallel task construct. 
    831839    // Caveats: We assume that everything has a ZZ32 result 
     
    833841    public String delegate(ASTNode x) { 
    834842        String className = NamingCzar.gensymTaskName(packageAndClassName); 
    835         debug("delegate creating class " + className); 
     843        debug("delegate creating class " + className + " node = " + x); 
    836844        // Create a new environment 
    837845        CodeGen cg = new CodeGen(this); 
     
    850858                                  "(" + NamingCzar.descFortressZZ32 + ")V", null, null); 
    851859        cg.mv.visitCode(); 
    852         cg.mv.visitVarInsn(Opcodes.ALOAD, 0); 
     860        cg.mv.visitVarInsn(Opcodes.ALOAD, cg.mv.getLocalVariable("instance")); 
    853861        cg.mv.visitMethodInsn(Opcodes.INVOKESPECIAL, NamingCzar.fortressBaseTask,  
    854862                              "<init>", NamingCzar.voidToVoid); 
    855  
    856         cg.mv.visitVarInsn(Opcodes.ALOAD, 0); 
     863        cg.mv.visitVarInsn(Opcodes.ALOAD, cg.mv.getLocalVariable("instance")); 
    857864        cg.mv.visitVarInsn(Opcodes.ALOAD, 1); 
    858865        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"); 
    864866 
    865867        cg.mv.visitInsn(Opcodes.RETURN); 
     
    890892    } 
    891893 
     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 
    892902    public void forOpExpr(OpExpr x) { 
    893903        debug("forOpExpr ", x, " op = ", x.getOp(), 
     
    902912        mv.visitVarInsn(Opcodes.ASTORE, mv.createLocalVariable("TaskArray", "java/util/ArrayList")); 
    903913     
    904         System.out.println("RRRRRRR:" + pa + " SSSSSS " + x); 
    905914        if (pa.worthParallelizing(x)) { 
    906915            for (int i = 0; i < args.size(); i++) { 
     
    926935                mv.visitVarInsn(Opcodes.ALOAD, mv.getLocalVariable(tasks.get(i))); 
    927936                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                  
    934937            } 
    935938        } else { 
     
    11261129                List<Expr> exprs = targ.getExprs(); 
    11271130                for (Expr expr : exprs) { 
    1128                     System.out.println("args = " + expr); 
    11291131                    expr.accept(this); 
    11301132                } 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGenClassWriter.java

    r3912 r3914  
    3535    } 
    3636 
    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  
    4537} 
    4638             
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGenMethodVisitor.java

    r3912 r3914  
    3939    private String signature; 
    4040    private String[] exceptions; 
    41     private String[] arguments; 
     41    private List<String> argumentTypes; 
    4242    private String resultType; 
     43    int localVariableCount; 
    4344 
     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    } 
    44117 
    45118    public CodeGenMethodVisitor(int access, String name, String desc,  
     
    56129        this.localVariableTypeTable = new HashMap<String, String>(); 
    57130        this.localVariableCount = 0; 
    58         createLocalVariable("instance"); 
    59         createLocalVariable("result"); 
    60131 
    61     } 
     132        if ((access & Opcodes.ACC_STATIC) != Opcodes.ACC_STATIC) { 
     133            createLocalVariable("instance", name);             
     134        } 
    62135 
    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); 
    75140         
    76         this.localVariableTable = new HashMap<String, Integer>(); 
    77         this.localVariableTypeTable = new HashMap<String, String>(); 
    78         this.localVariableCount = 0; 
     141        int i = 0; 
    79142 
    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); 
    85145        } 
    86146         
    87147        createLocalVariable("result", resultType); 
     148 
    88149    } 
    89150 
     
    96157        Debug.debug(Debug.Type.CODEGEN, 1, getText()); 
    97158    } 
    98  
    99     // We need to be smarter about this. 
    100     public int localVariableCount; 
    101159 
    102160    public int createLocalVariable(String name) {