Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FILE_GENERIQUE ajouter_instruction(FILE_GENERIQUE* Collection,FILE_GENERIQUE file_lexeme, Def_Instruction* definition, unsigned int* adresse, unsigned int* adresse_save){
- Lexeme* Lex = NULL;
- Lexeme* Lex2 = NULL;
- Lex = file_lexeme->val;
- Lex2 = file_lexeme->suiv->suiv->suiv->val;
- int verif_nb_op = 0;
- int op;
- Instruction* Instr = NULL;
- Instr = calloc(1, sizeof(*Instr));
- if(Instr == NULL) {printf("Erreur allocation d'une instruction. (ligne %d)\n", Lex->ligne); return NULL;}
- Instr->tab_op = calloc(definition->nb_op, sizeof(*Instr->tab_op));
- if(Instr->tab_op == NULL) {printf("Erreur allocation de la table d'opérandes d'une instruction. (ligne %d)\n", Lex->ligne); return NULL;}
- if(!strcmp(Lex->val,"lw") && Lex2->type == SYMBOLE) {
- Instruction* Instr2 = NULL;
- Instr2 = calloc(1, sizeof(*Instr2));
- if(Instr2 == NULL) {printf("Erreur allocation d'une instruction. (ligne %d)\n", Lex->ligne); return NULL;}
- Instr2->tab_op = calloc(definition->nb_op, sizeof(*Instr2->tab_op));
- if(Instr2->tab_op == NULL) {printf("Erreur allocation de la table d'opérandes d'une instruction. (ligne %d)\n", Lex->ligne); return NULL;}
- file_lexeme = file_lexeme->suiv;
- Lex = file_lexeme->val;
- /*Def_Instruction* def_save = definition;*/
- definition->val = "lui";
- definition->type = "I";
- definition->nb_op = 2;
- Instr->definition = definition;
- Instr->ligne = Lex->ligne;
- Instr->adresse = *adresse;
- *adresse_save = *adresse;
- *adresse += 4;
- Lexeme* Lex_reg_at = NULL;
- Lex_reg_at=calloc(1, sizeof(*Lex_reg_at));
- if(Lex_reg_at==NULL){perror("Erreur allocation Lexeme"); exit(1);}
- Lex_reg_at->ligne = Lex->ligne;
- Lex_reg_at->type = REGISTRE;
- Lex_reg_at->val = "$at";
- Instr->tab_op[0] = enfiler(Lex_reg_at, Instr->tab_op[0]);
- Instr->tab_op[1] = enfiler(Lex2, Instr->tab_op[1]);
- (*Collection) = enfiler(Instr,*Collection);
- definition->val = "lw";
- Instr2->definition = definition;
- Instr2->ligne = Lex->ligne;
- Instr2->adresse = *adresse;
- *adresse_save = *adresse;
- *adresse += 4;
- Instr2->tab_op[0] = enfiler(Lex, Instr2->tab_op[0]);
- file_lexeme = file_lexeme->suiv;
- Lex = file_lexeme->val;
- if(Lex->type != VIRGULE){ printf("Erreur : Argument ligne %d, instruction %s.\n", Lex->ligne, definition->val); return NULL;}
- file_lexeme = file_lexeme->suiv;
- Lex = file_lexeme->val;
- Instr2->tab_op[1] = enfiler(Lex2, Instr2->tab_op[1]);
- Lexeme* Lex_reg_par_ouv = NULL;
- Lex_reg_par_ouv=calloc(1, sizeof(*Lex_reg_par_ouv));
- if(Lex_reg_par_ouv==NULL){perror("Erreur allocation Lexeme"); exit(1);}
- Lex_reg_par_ouv->ligne = Lex->ligne;
- Lex_reg_par_ouv->type = PAR_OUV;
- Lex_reg_par_ouv->val = "(";
- Instr2->tab_op[1] = enfiler(Lex_reg_par_ouv, Instr2->tab_op[1]);
- Instr2->tab_op[1] = enfiler(Lex_reg_at, Instr2->tab_op[1]);
- Lexeme* Lex_reg_par_fer = NULL;
- Lex_reg_par_fer=calloc(1, sizeof(*Lex_reg_par_fer));
- if(Lex_reg_par_fer==NULL){perror("Erreur allocation Lexeme"); exit(1);}
- Lex_reg_par_fer->ligne = Lex->ligne;
- Lex_reg_par_fer->type = PAR_FER;
- Lex_reg_par_fer->val = ")";
- Instr2->tab_op[1] = enfiler(Lex_reg_par_fer, Instr2->tab_op[1]);
- (*Collection) = enfiler(Instr2,*Collection);
- file_lexeme = file_lexeme->suiv;
- /*ajouter opérandes et instruction2*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement