Exemplo n.º 1
0
void TypeCycleChecker::PartialOrder(Tuple<Semantic*>& semantic, int start)
{
    type_list.Reset();

    //
    // assert that the "index" of all types that should be checked is initially
    // set to OMEGA
    //
    for (unsigned i = start; i < semantic.Length(); i++)
    {
        Semantic* sem = semantic[i];
        for (unsigned k = 0;
             k < sem -> compilation_unit -> NumTypeDeclarations(); k++)
        {
            AstDeclaredType* declared =
                sem -> compilation_unit -> TypeDeclaration(k);
            if (declared -> EmptyDeclarationCast())
                continue;
            SemanticEnvironment* env =
                declared -> class_body -> semantic_environment;
            if (env) // type was successfully compiled thus far?
            {
                TypeSymbol* type = env -> Type();
                if (type -> index == OMEGA)
                   ProcessSubtypes(type);
            }
        }
    }

    ReverseTypeList();
}
Exemplo n.º 2
0
void TypeDependenceChecker::OutputMake(FILE* outfile, char* output_name,
                                       Tuple<FileSymbol*>& file_list)
{
    assert(outfile);

    for (unsigned i = 0; i < file_list.Length(); i++)
    {
        FileSymbol* file_symbol = file_list[i];
        char* name = file_symbol -> FileName();
        int length = file_symbol -> FileNameLength() -
            (file_symbol -> IsJava() ? FileSymbol::java_suffix_length
             : FileSymbol::class_suffix_length);

        char* class_name = new char[length + FileSymbol::class_suffix_length +
                                   1];
        char* java_name =
            new char[length + FileSymbol::java_suffix_length + 1];

        strncpy(class_name, name, length);
        strcpy(&class_name[length], FileSymbol::class_suffix);
        strncpy(java_name, name, length);
        strcpy(&java_name[length], FileSymbol::java_suffix);

        fprintf(outfile, "%s : %s\n", output_name, java_name);

        if (i > 0) // Not the first file in the list
        {
            fprintf(outfile, "%s : %s\n", output_name, class_name);
        }

        delete [] class_name;
        delete [] java_name;
    }
}
Exemplo n.º 3
0
void Operators::OpLine(Tuple<cp_info *> &constant_pool, const char *hdr,
                       int pc, Opcode opc, const char *name, char *args,
                       const char *desc, int info_kind, int info_index)
{
    // generate line of opcode dump, info is extra info

    Coutput << *hdr;
    Coutput.width(4);
    Coutput << pc;
    Coutput << "\t" << name;
    int len = strlen(name);
    if (strlen(args))
    {
        Coutput << " " << args;
        len += (strlen(args) + 1);
    }
    if (len < 8)
         Coutput << "\t\t\t";
    else if (len < 16)
         Coutput << "\t\t";
    else Coutput << "\t";

    switch (info_kind)
    {
        case INFO_CONST:
             Coutput << " ";
             if (info_index <= 0 || info_index > constant_pool.Length())
                Coutput << "OUT-OF_BOUNDS CONSTANT_POOL-INDEX " << info_index;
            else {
//              constant_pool[info_index] -> describe(constant_pool);
            }
            break;
        case INFO_LOCAL:
            Coutput << " local#" << info_index;
            break;
    }
//
// DS (17 jun) - skip desc for now: it's too long and should only
// be written at user request.
//  Coutput << " " << desc;
//
    Coutput << endl;
}
Exemplo n.º 4
0
void Operators::OpDmp(Tuple<cp_info *> &constant_pool, Tuple<u1> &code)
{
    int pc = 0;
    while (pc < code.Length())
    {
        int info_kind = INFO_NONE; // assume no extra info
        int info_index = 0;
        int pc_start = pc;
        Opcode opc = (Opcode) GetU1(code, pc);
        const char *name, *desc; // set to name (mnemonic) and description of opcode.
        OpDesc((Opcode) code[pc_start], &name, &desc);
        pc++;

        char argdesc[100];
        argdesc[0] = U_NULL; // assume no argument description needed

        unsigned au1;
        int ai1,
            ai2,
            ai4;
        switch (opc)
        {
            case OP_BIPUSH:
                 ai1 = GetI1(code, pc); pc++;
                 sprintf(argdesc, "%d", ai1);
                 break;
            case OP_SIPUSH:
                 ai2 = GetI2(code, pc); pc +=2;
                 sprintf(argdesc, "%d", ai2);
                 break;
            case OP_LDC:
                 info_index = GetU1(code, pc); pc++;
                 sprintf(argdesc,"%d", info_index);
                 info_kind = INFO_CONST;
                 break;
            case OP_LDC_W:
            case OP_LDC2_W:
                 info_index = GetU2(code, pc);pc +=2;
                 sprintf(argdesc, "%u", info_index);
                 info_kind = INFO_CONST;
                 break;
            case OP_ILOAD:
            case OP_LLOAD:
            case OP_FLOAD:
            case OP_DLOAD:
            case OP_ALOAD:
            case OP_ISTORE:
            case OP_LSTORE:
            case OP_FSTORE:
            case OP_DSTORE:
            case OP_ASTORE:
                 info_index = GetU1(code, pc);pc++;
                 sprintf(argdesc, "%u", info_index);
                 info_kind = INFO_LOCAL;
                 break;
            case OP_ILOAD_0:
            case OP_LLOAD_0:
            case OP_FLOAD_0:
            case OP_DLOAD_0:
            case OP_ALOAD_0:
            case OP_ISTORE_0:
            case OP_LSTORE_0:
            case OP_FSTORE_0:
            case OP_DSTORE_0:
            case OP_ASTORE_0:
                 info_kind = INFO_LOCAL;
                 info_index = 0;
                 break;
            case OP_ILOAD_1:
            case OP_LLOAD_1:
            case OP_FLOAD_1:
            case OP_DLOAD_1:
            case OP_ALOAD_1:
            case OP_ISTORE_1:
            case OP_LSTORE_1:
            case OP_FSTORE_1:
            case OP_DSTORE_1:
            case OP_ASTORE_1:
                 info_kind = INFO_LOCAL;
                 info_index = 1;
                 break;
            case OP_ILOAD_2:
            case OP_LLOAD_2:
            case OP_FLOAD_2:
            case OP_DLOAD_2:
            case OP_ALOAD_2:
            case OP_ISTORE_2:
            case OP_LSTORE_2:
            case OP_DSTORE_2:
            case OP_FSTORE_2:
            case OP_ASTORE_2:
                 info_kind = INFO_LOCAL;
                 info_index = 2;
                 break;
            case OP_ILOAD_3:
            case OP_LLOAD_3:
            case OP_FLOAD_3:
            case OP_DLOAD_3:
            case OP_ALOAD_3:
            case OP_ISTORE_3:
            case OP_LSTORE_3:
            case OP_FSTORE_3:
            case OP_DSTORE_3:
            case OP_ASTORE_3:
                 info_kind= INFO_LOCAL;
                 info_index = 3;
                 break;
            case OP_IINC:
                 info_index = GetU1(code, pc); pc++;
                 au1 = GetU1(code, pc); pc++;
                 ai1 = GetI1(code, pc); pc++;
                 info_kind = INFO_LOCAL;
                 sprintf(argdesc, "%d %d", au1, ai1);
                 break;
            case OP_IFEQ:
            case OP_IFNE:
            case OP_IFLT:
            case OP_IFGE:
            case OP_IFGT:
            case OP_IFLE:
            case OP_IF_ICMPEQ:
            case OP_IF_ICMPNE:
            case OP_IF_ICMPLT:
            case OP_IF_ICMPGE:
            case OP_IF_ICMPGT:
            case OP_IF_ICMPLE:
            case OP_IF_ACMPEQ:
            case OP_IF_ACMPNE:
            case OP_GOTO:
            case OP_JSR:
            case OP_IFNULL:
            case OP_IFNONNULL:
                 ai2 = GetI2(code, pc);
                 sprintf(argdesc, "%d", (int) ( ai2+pc_start)); // compute branch target
                 pc +=2;
                 break;
            case OP_RET:
                 au1 = GetU1(code, pc);
                 pc++;
                 sprintf(argdesc, "%d", (int) au1);
                 break;
            case OP_TABLESWITCH:
                 {
                     int def,
                         low,
                         high,
                         len,
                         val,
                         pc_this;
                     Opcode op_this;
                     unsigned iu1;
                     op_this = OP_TABLESWITCH;
                     // account for padding
                     while (pc % 4)
                     {
                         iu1 = GetU1(code, pc);
                         pc++;
                     }
                     def = GetI4(code, pc); pc += 4;
                     low = GetI4(code, pc); pc +=4;
                     high = GetI4(code, pc); pc += 4;
                     sprintf(argdesc, "default:%d low:%d high:%d",
                             def + pc_start, low, high);
                     OpLine(constant_pool, " ", pc_start, opc, name,
                            argdesc, desc, info_kind, info_index);
                     len =  high - low + 1;
                     while (len)
                     {
                         pc_this = pc;
                         val = GetI4(code, pc);
                         sprintf(argdesc, "match:%d offset:%d",
                                 low++, val + pc_start);
                         OpLine(constant_pool,"*",pc_this, op_this, name,
                                argdesc, desc, INFO_NONE, 0);
                         pc += 4;
                         len--;
                     }
                     info_kind = INFO_DONE;
                 }
                 break;
            case OP_LOOKUPSWITCH:
                 {
                     int def,
                         npairs,
                         len,
                         match,
                         offset;
                     Opcode op_this;

                     // account for padding
                     unsigned iu1;
                     op_this = OP_LOOKUPSWITCH;
                     while (pc % 4)
                     {
                         iu1 = GetU1(code, pc);
                         pc++;
                     }
                     def = GetI4(code, pc); pc += 4;
                     npairs = GetI4(code, pc); pc +=4;
                     sprintf(argdesc, "default:%d npairs:%d",
                             def + pc_start, npairs);
                     OpLine(constant_pool, " ", pc_start, op_this, name,
                            argdesc, desc, info_kind, info_index);
                     len = npairs;
                     while (npairs)
                     {
                         int pcb = pc;
                         match = GetI4(code, pc); pc +=4 ;
                         offset = GetI4(code, pc); pc +=4;
                         sprintf(argdesc, "match:%d offset:%d ",
                                 match, offset + pc_start);
                         OpLine(constant_pool, "*", pcb, op_this, name,
                                argdesc, desc, INFO_NONE, 0);
                         npairs--;
                     }
                     info_kind = INFO_DONE;
                 }
                 break;
            case OP_GETSTATIC:
            case OP_PUTSTATIC:
            case OP_GETFIELD:
            case OP_PUTFIELD:
            case OP_INVOKEVIRTUAL:
            case OP_INVOKESPECIAL:
            case OP_INVOKESTATIC:
            case OP_NEW:
            case OP_ANEWARRAY:
            case OP_CHECKCAST:
            case OP_INSTANCEOF:
                 info_index = GetU2(code, pc); pc += 2;
                 sprintf(argdesc, "%d", info_index);
                 info_kind = INFO_CONST;
                 break;
            case OP_INVOKEINTERFACE:
                 {
                     int nargs;
                     info_index = GetU2(code, pc); pc += 2;
                     au1 = GetU1(code, pc); pc++;
                     nargs = au1;
                     au1 = GetU1(code, pc); pc++;

                     assert((! au1) && "...zero byte required in this position");

                     sprintf(argdesc, "%d %d", nargs,info_index);
                     info_kind=INFO_CONST;
                 }
                 break;
            case OP_NEWARRAY:
                 au1 = GetU1(code, pc); pc++;
                 switch (au1)
                 {
                     case 4: sprintf(argdesc, "%s", "BOOLEAN");break;
                     case 5: sprintf(argdesc, "%s", "CHAR");break;
                     case 6: sprintf(argdesc, "%s", "FLOAT");break;
                     case 7: sprintf(argdesc, "%s", "DOUBLE");break;
                     case 8: sprintf(argdesc, "%s", "BYTE");break;
                     case 9: sprintf(argdesc, "%s", "SHORT");break;
                     case 10: sprintf(argdesc, "%s", "INT");break;
                     case 11: sprintf(argdesc, "%s", "LONG");break;
                     default:
                         sprintf(argdesc, "%s", "<UNKNOWN>");break;
                 }
                 break;
            case OP_WIDE:
                 assert(false && "dmp for op_wide not supported yet");
                 break;
            case OP_MULTIANEWARRAY:
                 info_index = GetU2(code, pc); pc += 2;
                 au1 = GetU1(code, pc); pc++;
                 info_kind = INFO_CONST;
                 // au1 gives dimensions
                 sprintf(argdesc, "%u", au1);
                 break;
            case OP_GOTO_W:
            case OP_JSR_W:
                 ai4 = GetI4(code, pc); pc += 4;
                 // ai4 gives offset (wide) of branch target
                 sprintf(argdesc, "%d", pc_start + ai4);
                 break;
            default:
                 break;
        }

        // output first part of description
        if (info_kind != INFO_DONE)
            OpLine(constant_pool, " ", pc_start, opc, name,
                   argdesc, desc, info_kind, info_index);
    }
}