Beispiel #1
0
/**
 * @param argc Number of arguments on the command line.
 * @param argv Value of arguments on the command line.
 * @return Whether this was a success or not.
 * @brief Main entry point for MIPS assembler.
 *
 */
int main ( int argc, char *argv[] ) {

    unsigned int 	nlines 	= 0;
    char         	 *file 	= NULL;


    if ( argc <2 ) {
        print_usage(argv[0]);
        exit( EXIT_FAILURE );
    }


    file  	= argv[argc-1];


    if ( NULL == file ) {
        fprintf( stderr, "Missing ASM source file, aborting.\n" );
        exit( EXIT_FAILURE );
    }

    L_lexem  L = NULL;
    L_lexem  l_etiq = NULL;

    int nb_inst;
    instru_def* dico = load_dico("dico/dico_instr",&nb_inst);

    /* ---------------- do the lexical analysis -------------------*/
    lex_load_file( file, &nlines, &L);
    DEBUG_MSG("source code got %d lines", nlines);
    L_lexem nL = reverse_list_lex(L);
    free_liste(L,1);
    afficher_liste_lex(nL);
    char test[20];
    sprintf(test,"%ld",int_to_int(4096));
    printf("\n%ld %s\n",strlen(test),test);
    printf("\n%ld \n",sizeof(unsigned long));
    verif_gram(nlines, nL, &l_etiq, dico, nb_inst);

    /* ---------------- Free memory and terminate -------------------*/

    /* TODO free everything properly*/

    free_liste(nL,0);
    free_liste(l_etiq,1);
    free_dico(&dico,nb_inst);
    free(dico);
    dico = NULL;
    exit( EXIT_SUCCESS );
}
void InitParser::load(const string& file)
{
	// Check file presence
	FILE * fp = NULL;
	fp = fopen(file.c_str(),"rt");
	if (fp) {
		fclose(fp);
	} else {
		cerr << "ERROR : Can't find config file " << file << endl;
		exit(-1);
	}

	if (dico) free_dico();
	dico = NULL;
	dico = iniparser_load(file.c_str());
	if (!dico) {
		cerr << "ERROR : Couldn't read config file " << file << endl;
		exit(-1);
	}
}
InitParser::~InitParser()
{
	if (dico) free_dico();
	dico = NULL;
}