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.

table_fonctions.c 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "table_fonctions.h"
  2. #include <string.h>
  3. #include <stdio.h>
  4. void initialise_function_table(Table_Fonctions * table){
  5. table->depth = 1;
  6. }
  7. void add_function(Table_Fonctions * table, char * function_name, enum Return_Type return_type, int start_addr){
  8. Fonction fonction;
  9. strcpy(fonction.function_name,function_name);
  10. fonction.start_addr = start_addr;
  11. fonction.type = return_type;
  12. fonction.function_depth = table->depth;
  13. table->array[table->depth] = fonction;
  14. table->depth++;
  15. }
  16. void print_function(Fonction * fonction){
  17. char * function_name = fonction->function_name;
  18. int start_addr = fonction->start_addr;
  19. int depth = fonction->function_depth;
  20. int return_type = fonction->type;
  21. char typeStr[20];
  22. if (return_type == RET_INT){
  23. strcpy(typeStr, "INT");
  24. } else if (return_type == RET_INT_PTR){
  25. strcpy(typeStr, "INT_PTR");
  26. }
  27. printf("%-20s\t\t %-12s\t\t %-12d\t %-12d\n", function_name, typeStr, start_addr, depth);
  28. }
  29. void print_fonction_table(Table_Fonctions * table) {
  30. printf("%-20s\t\t %-12s\t\t %-12s\t %-20s\n", "Function Name", "Return Type", "Start Address", "Depth");
  31. Fonction fonction;
  32. for (int i = 1; i < table->depth; i++) {
  33. fonction = table->array[i];
  34. print_function(&fonction);
  35. }
  36. }
  37. int function_exists(Table_Fonctions * table, char * func_name){
  38. for (int i = 0; i < table->depth; i++){
  39. if (strcmp(table->array[i].function_name, func_name) == 0){
  40. return i;
  41. }
  42. }
  43. return -1;
  44. }
  45. /*
  46. int main(){
  47. Table_Fonctions table;
  48. initialise_function_table(&table);
  49. add_function(&table, "Fonction1", 0, 7);
  50. add_function(&table, "Fonction2", 1, 23);
  51. print_fonction_table(&table);
  52. return 1;
  53. }*/