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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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,
  6. GTE, AND, OR, NOT, PRI, LEA, COP_LD, COP_STR, CALL, RET_FUN};
  7. typedef struct instruction{
  8. enum operation operation;
  9. int reg1;
  10. int reg2;
  11. int reg3;
  12. }instruction;
  13. //table des instructions
  14. typedef struct instructions_array{
  15. instruction array[INSTRUCTION_TABLE_SIZE];
  16. int index;
  17. } instructions_array;
  18. /**
  19. *
  20. * @param op operation
  21. * @return returns the string that corresponds to the enum operation op
  22. */
  23. char * operationName(enum operation op);
  24. /**
  25. * Initialises the instructions array
  26. * @param array
  27. */
  28. void initialise_asm(instructions_array * array);
  29. //renvoie l'index (ou valeur?) de la premiere @ dispo
  30. /**
  31. * Fetch address of a temporary variable
  32. * @param table
  33. * @return first available temp address
  34. */
  35. int new_temp(Table_Symboles * table);
  36. /**
  37. * Adds intruction to instruction array
  38. * @param array
  39. * @param intru
  40. * @return 0 if instruction was added successfully, -1 if not
  41. */
  42. int add_instruction(instructions_array * array, instruction * intru);
  43. /**
  44. * Generates intruction with no parameter
  45. * @param array
  46. * @param op
  47. * @return
  48. */
  49. int generate_instruction_0(instructions_array * array, enum operation op);
  50. /**
  51. * Generates intruction with one parameter
  52. * @param array
  53. * @param op
  54. * @param arg1
  55. * @return
  56. */
  57. int generate_instruction_1(instructions_array * array, enum operation op, int arg1);
  58. /**
  59. * Generates intruction with two parameters
  60. * @param array
  61. * @param op
  62. * @param arg1
  63. * @param arg2
  64. * @return
  65. */
  66. int generate_instruction_2(instructions_array * array, enum operation op, int arg1, int arg2);
  67. /**
  68. * Generates intruction with three parameters
  69. * @param array
  70. * @param op
  71. * @param arg1
  72. * @param arg2
  73. * @param arg3
  74. * @return
  75. */
  76. int generate_instruction_3(instructions_array * array, enum operation op, int arg1, int arg2, int arg3);
  77. /**
  78. * Updates the JMF instruction with the correct jump destination address
  79. * @param array
  80. * @param instru_index
  81. * @param adr_jmp
  82. */
  83. void update_jmf(instructions_array * array, int instru_index, int adr_jmp);
  84. void update_jmp(instructions_array * array, int instru_index, int adr_jmp);
  85. void exportInstructions(instructions_array * array);
  86. /*
  87. void gen_arithmetique(instructions_array * array, enum operation op, int arg1, int arg2);
  88. int gen_var(Table_Symboles * table, instructions_array * array, char * varName);
  89. int gen_entier(Table_Symboles * table, instructions_array * array, int entier);
  90. int gen_return(Table_Symboles * table, instructions_array * array, int adr);
  91. int gen_jmpf(Table_Symboles * table, instructions_array * array, int cond, int dest);
  92. int gen_condition(Table_Symboles * table, instructions_array * array, enum operation op, int arg1, int arg2);
  93. int gen_print(Table_Symboles * table, instructions_array * array, int arg1);
  94. */
  95. #endif