예제 #1
0
파일: cs311.c 프로젝트: heejongahn/MIPS
void load_program(char *program_filename) {
    FILE *prog;
    int ii, word;
    char buffer[33];
    //to notifying data & text segment size
    int flag = 0;
    int text_index = 0;
    int data_index = 0;

    /* Open program file. */
    prog = fopen(program_filename, "r");
    if (prog == NULL) {
        printf("Error: Can't open program file %s\n", program_filename);
        exit(-1);
    }

    /* Read in the program. */
    ii = 0;

    //read 32bits + '\0' = 33
    while (fgets(buffer,33,prog) != NULL)
    {
        if(flag == 0)
        {
            //check text segment size
            text_size = fromBinary(buffer);
            NUM_INST = text_size/4;
            //initial memory allocation of text segment
            INST_INFO = malloc(sizeof(instruction)*NUM_INST);
            init_inst_info(NUM_INST);
        }

        else if(flag == 1)
        {
            //check data segment size
            data_size = fromBinary(buffer);
        }

        else
        {
            if(ii < text_size){
                INST_INFO[text_index++] = parsing_instr(buffer, ii);
            }
            else if(ii < text_size + data_size){
                parsing_data(buffer, ii-text_size);
            }
            else
            {
                //Do not enter this case
                //assert(0);
                //However, there is a newline in the input file
            }
            ii += 4;
        }
        flag++;
    }
    CURRENT_STATE.PC = MEM_TEXT_START;
    //printf("Read %d words from program into memory.\n\n", ii/4);
}
void tst_QDBusXmlParser::parsingWithDoctype_data()
{
    parsing_data();
}