axe_engine.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Andrea Di Biagio
  3. * Politecnico di Milano, 2007
  4. *
  5. * axe_engine.h
  6. * Formal Languages & Compilers Machine, 2007/2008
  7. *
  8. */
  9. #ifndef _AXE_ENGINE_H
  10. #define _AXE_ENGINE_H
  11. #include "axe_struct.h"
  12. #include "axe_labels.h"
  13. #include "collections.h"
  14. #include "symbol_table.h"
  15. typedef struct t_program_infos
  16. {
  17. t_list *variables;
  18. t_list *instructions;
  19. t_list *data;
  20. t_axe_label_manager *lmanager;
  21. t_symbol_table *sy_table;
  22. int current_register;
  23. } t_program_infos;
  24. /* initialize the informations associated with the program. This function is
  25. * called at the beginning of the translation process. This function
  26. * is called once: its only purpouse is to initialize an instance of the struct
  27. * `t_program_infos' that will contain all the informations about the program
  28. * that will be compiled */
  29. extern t_program_infos * allocProgramInfos();
  30. /* add a new instruction to the current program. This function is directly
  31. * called by all the functions defined in `axe_gencode.h' */
  32. extern void addInstruction(t_program_infos *program, t_axe_instruction *instr);
  33. /* reserve a new label identifier and return the identifier to the caller */
  34. extern t_axe_label * newLabel(t_program_infos *program);
  35. /* assign the given label identifier to the next instruction. Returns
  36. * the label assigned; otherwise (an error occurred) LABEL_UNSPECIFIED */
  37. extern t_axe_label * assignLabel(t_program_infos *program, t_axe_label *label);
  38. /* reserve and fix a new label. It returns either the label assigned or the
  39. * value LABEL_UNSPECIFIED if an error occurred */
  40. extern t_axe_label * assignNewLabel(t_program_infos *program);
  41. /* add a variable to the program */
  42. extern void createVariable(t_program_infos *program
  43. , char *ID, int type, int isArray, int arraySize, int init_val);
  44. /* get a previously allocated variable */
  45. extern t_axe_variable * getVariable
  46. (t_program_infos *program, char *ID);
  47. /* get the label that marks the starting address of the variable
  48. * with name "ID" */
  49. extern t_axe_label * getLabelFromVariableID
  50. (t_program_infos *program, char *ID);
  51. /* get a register still not used. This function returns
  52. * the ID of the register found*/
  53. extern int getNewRegister(t_program_infos *program);
  54. /* finalize all the data structures associated with `program' */
  55. extern void finalizeProgramInfos(t_program_infos *program);
  56. /* write the corresponding assembly for the given program */
  57. extern void writeAssembly(t_program_infos *program, char *output_file);
  58. #endif