No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gen_assembleur.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef GEN_ASSEMBLEUR_H
  2. #define GEN_ASSEMBLEUR_H
  3. #define INSTRUCTION_TABLE_SIZE 1000
  4. #include "table_symboles.h"
  5. enum operation{ADD, SOU, MUL, DIV, COP, AFC, RET, JMF, JMP, EQ, NEQ, LT, GT, LTE, GTE, AND, OR, NOT, PRI};
  6. typedef struct instruction{
  7. enum operation operation;
  8. int reg1;
  9. int reg2;
  10. int reg3;
  11. }instruction;
  12. //table des instructions
  13. typedef struct instructions_array{
  14. instruction array[INSTRUCTION_TABLE_SIZE];
  15. int index;
  16. } instructions_array;
  17. /**
  18. *
  19. * @param op operation
  20. * @return returns the string that corresponds to the enum operation op
  21. */
  22. char * operationName(enum operation op);
  23. /**
  24. * Initialises the instructions array
  25. * @param array
  26. */
  27. void initialise_asm(instructions_array * array);
  28. //renvoie l'index (ou valeur?) de la premiere @ dispo
  29. /**
  30. * Fetch address of a temporary variable
  31. * @param table
  32. * @return first available temp address
  33. */
  34. int new_temp(Table_Symboles * table);
  35. /**
  36. * Adds intruction to instruction array
  37. * @param array
  38. * @param intru
  39. * @return 0 if instruction was added successfully, -1 if not
  40. */
  41. int add_instruction(instructions_array * array, instruction * intru);
  42. /**
  43. * Generates intruction with one parameter
  44. * @param array
  45. * @param op
  46. * @param arg1
  47. * @return
  48. */
  49. int generate_instruction_1(instructions_array * array, enum operation op, int arg1);
  50. /**
  51. * Generates intruction with two parameters
  52. * @param array
  53. * @param op
  54. * @param arg1
  55. * @param arg2
  56. * @return
  57. */
  58. int generate_instruction_2(instructions_array * array, enum operation op, int arg1, int arg2);
  59. /**
  60. * Generates intruction with three parameters
  61. * @param array
  62. * @param op
  63. * @param arg1
  64. * @param arg2
  65. * @param arg3
  66. * @return
  67. */
  68. int generate_instruction_3(instructions_array * array, enum operation op, int arg1, int arg2, int arg3);
  69. /**
  70. * Updates the JMF instruction with the correct jump destination address
  71. * @param array
  72. * @param instru_index
  73. * @param adr_jmp
  74. */
  75. void update_jmf(instructions_array * array, int instru_index, int adr_jmp);
  76. void exportInstructions(instructions_array * array);
  77. /*
  78. void gen_arithmetique(instructions_array * array, enum operation op, int arg1, int arg2);
  79. int gen_var(Table_Symboles * table, instructions_array * array, char * varName);
  80. int gen_entier(Table_Symboles * table, instructions_array * array, int entier);
  81. int gen_return(Table_Symboles * table, instructions_array * array, int adr);
  82. int gen_jmpf(Table_Symboles * table, instructions_array * array, int cond, int dest);
  83. int gen_condition(Table_Symboles * table, instructions_array * array, enum operation op, int arg1, int arg2);
  84. int gen_print(Table_Symboles * table, instructions_array * array, int arg1);
  85. */
  86. #endif