axe_utils.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Andrea Di Biagio
  3. * Politecnico di Milano, 2007
  4. *
  5. * axe_utils.h
  6. * Formal Languages & Compilers Machine, 2007/2008
  7. *
  8. */
  9. #ifndef _AXE_UTILS_H
  10. #define _AXE_UTILS_H
  11. #include "axe_engine.h"
  12. #include "axe_struct.h"
  13. #include "axe_constants.h"
  14. #include "collections.h"
  15. /* create a variable for each `t_axe_declaration' inside
  16. * the list `variables'. Each new variable will be of type
  17. * `varType'. */
  18. extern void set_new_variables(t_program_infos *program
  19. , int varType, t_list *variables);
  20. /* Given a variable/symbol identifier (ID) this function
  21. * returns a register location where the value is stored
  22. * (the value of the variable identified by `ID').
  23. * If the variable/symbol has never been loaded from memory
  24. * to a register, first this function searches
  25. * for a free register, then it assign the variable with the given
  26. * ID to the register just found.
  27. * Once computed, the location (a register identifier) is returned
  28. * as output to the caller.
  29. * This function generates a LOAD instruction
  30. * only if the flag `genLoad' is set to 1; otherwise it simply reserve
  31. * a register location for a new variable in the symbol table.
  32. * If an error occurs, get_symbol_location returns a REG_INVALID errorcode */
  33. extern int get_symbol_location(t_program_infos *program
  34. , char *ID, int genLoad);
  35. /* Generate the instruction to load an `immediate' value into a new register.
  36. * It returns the new register identifier or REG_INVALID if an error occurs */
  37. extern int gen_load_immediate(t_program_infos *program, int immediate);
  38. /* Generate the instruction to move an `immediate' value into a register. */
  39. extern void gen_move_immediate(t_program_infos *program, int dest, int imm);
  40. /* Notify the end of the program. This function is directly called
  41. * from the parser when the parsing process is ended */
  42. extern void set_end_Program(t_program_infos *program);
  43. /* Once called, this function destroys all the data structures
  44. * associated with the compiler (program, RA, etc.). This function
  45. * is typically automatically called before exiting from the main
  46. * or when the compiler encounters some error. */
  47. extern void shutdownCompiler();
  48. /* Once called, this function initialize all the data structures
  49. * associated with the compiler (program, RA etc..) and all the
  50. * global variables in the system. This function
  51. * is typically automatically called at the beginning of the main
  52. * and should NEVER be called from the user code */
  53. extern void init_compiler(int argc, char **argv);
  54. /* Check whether an immediate is representable as a 16-bit signed integer. */
  55. extern int is_int16(int immediate);
  56. /* Check whether an immediate is representable as a 20-bit signed integer. */
  57. extern int is_int20(int immediate);
  58. #endif