Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. FILE_GENERIQUE ajouter_instruction(FILE_GENERIQUE* Collection,FILE_GENERIQUE file_lexeme, Def_Instruction* definition, unsigned int* adresse, unsigned int* adresse_save){
  2. Lexeme* Lex = NULL;
  3. Lexeme* Lex2 = NULL;
  4. Lex = file_lexeme->val;
  5.  
  6.  
  7. Lex2 = file_lexeme->suiv->suiv->suiv->val;
  8. int verif_nb_op = 0;
  9. int op;
  10. Instruction* Instr = NULL;
  11. Instr = calloc(1, sizeof(*Instr));
  12. if(Instr == NULL) {printf("Erreur allocation d'une instruction. (ligne %d)\n", Lex->ligne); return NULL;}
  13. Instr->tab_op = calloc(definition->nb_op, sizeof(*Instr->tab_op));
  14. if(Instr->tab_op == NULL) {printf("Erreur allocation de la table d'opérandes d'une instruction. (ligne %d)\n", Lex->ligne); return NULL;}
  15.  
  16.  
  17.  
  18. if(!strcmp(Lex->val,"lw") && Lex2->type == SYMBOLE) {
  19. Instruction* Instr2 = NULL;
  20. Instr2 = calloc(1, sizeof(*Instr2));
  21. if(Instr2 == NULL) {printf("Erreur allocation d'une instruction. (ligne %d)\n", Lex->ligne); return NULL;}
  22. Instr2->tab_op = calloc(definition->nb_op, sizeof(*Instr2->tab_op));
  23. if(Instr2->tab_op == NULL) {printf("Erreur allocation de la table d'opérandes d'une instruction. (ligne %d)\n", Lex->ligne); return NULL;}
  24.  
  25. file_lexeme = file_lexeme->suiv;
  26. Lex = file_lexeme->val;
  27. /*Def_Instruction* def_save = definition;*/
  28. definition->val = "lui";
  29. definition->type = "I";
  30. definition->nb_op = 2;
  31. Instr->definition = definition;
  32. Instr->ligne = Lex->ligne;
  33. Instr->adresse = *adresse;
  34. *adresse_save = *adresse;
  35. *adresse += 4;
  36.  
  37. Lexeme* Lex_reg_at = NULL;
  38. Lex_reg_at=calloc(1, sizeof(*Lex_reg_at));
  39. if(Lex_reg_at==NULL){perror("Erreur allocation Lexeme"); exit(1);}
  40. Lex_reg_at->ligne = Lex->ligne;
  41. Lex_reg_at->type = REGISTRE;
  42. Lex_reg_at->val = "$at";
  43. Instr->tab_op[0] = enfiler(Lex_reg_at, Instr->tab_op[0]);
  44. Instr->tab_op[1] = enfiler(Lex2, Instr->tab_op[1]);
  45. (*Collection) = enfiler(Instr,*Collection);
  46. definition->val = "lw";
  47. Instr2->definition = definition;
  48. Instr2->ligne = Lex->ligne;
  49. Instr2->adresse = *adresse;
  50. *adresse_save = *adresse;
  51. *adresse += 4;
  52. Instr2->tab_op[0] = enfiler(Lex, Instr2->tab_op[0]);
  53. file_lexeme = file_lexeme->suiv;
  54. Lex = file_lexeme->val;
  55. if(Lex->type != VIRGULE){ printf("Erreur : Argument ligne %d, instruction %s.\n", Lex->ligne, definition->val); return NULL;}
  56. file_lexeme = file_lexeme->suiv;
  57. Lex = file_lexeme->val;
  58. Instr2->tab_op[1] = enfiler(Lex2, Instr2->tab_op[1]);
  59. Lexeme* Lex_reg_par_ouv = NULL;
  60. Lex_reg_par_ouv=calloc(1, sizeof(*Lex_reg_par_ouv));
  61. if(Lex_reg_par_ouv==NULL){perror("Erreur allocation Lexeme"); exit(1);}
  62. Lex_reg_par_ouv->ligne = Lex->ligne;
  63. Lex_reg_par_ouv->type = PAR_OUV;
  64. Lex_reg_par_ouv->val = "(";
  65. Instr2->tab_op[1] = enfiler(Lex_reg_par_ouv, Instr2->tab_op[1]);
  66. Instr2->tab_op[1] = enfiler(Lex_reg_at, Instr2->tab_op[1]);
  67. Lexeme* Lex_reg_par_fer = NULL;
  68. Lex_reg_par_fer=calloc(1, sizeof(*Lex_reg_par_fer));
  69. if(Lex_reg_par_fer==NULL){perror("Erreur allocation Lexeme"); exit(1);}
  70. Lex_reg_par_fer->ligne = Lex->ligne;
  71. Lex_reg_par_fer->type = PAR_FER;
  72. Lex_reg_par_fer->val = ")";
  73. Instr2->tab_op[1] = enfiler(Lex_reg_par_fer, Instr2->tab_op[1]);
  74. (*Collection) = enfiler(Instr2,*Collection);
  75. file_lexeme = file_lexeme->suiv;
  76. /*ajouter opérandes et instruction2*/
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement