cc-minimal.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 2016 Jeremiah Orians
  2. * This file is part of M2-Planet.
  3. *
  4. * M2-Planet is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * M2-Planet is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include<stdlib.h>
  18. #include<stdio.h>
  19. #include<string.h>
  20. #include"cc.h"
  21. /* The core functions */
  22. void initialize_types();
  23. struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename);
  24. struct token_list* reverse_list(struct token_list* head);
  25. struct token_list* program();
  26. void recursive_output(struct token_list* i, FILE* out);
  27. int match(char* a, char* b);
  28. char* parse_string(char* string);
  29. int main()
  30. {
  31. MAX_STRING = 4096;
  32. hold_string = calloc(MAX_STRING, sizeof(char));
  33. FILE* in = fopen("tape_01", "r");
  34. FILE* destination_file = fopen("tape_02", "w");
  35. Architecture = KNIGHT_NATIVE;
  36. global_token = read_all_tokens(in, global_token, "tape_01");
  37. fclose(in);
  38. if(NULL == global_token)
  39. {
  40. fputs("Either no input files were given or they were empty\n", stderr);
  41. exit(EXIT_FAILURE);
  42. }
  43. global_token = reverse_list(global_token);
  44. initialize_types();
  45. reset_hold_string();
  46. output_list = NULL;
  47. program();
  48. /* Output the program we have compiled */
  49. fputs("\n# Core program\n", destination_file);
  50. recursive_output(output_list, destination_file);
  51. fputs("\n\n# Program global variables\n", destination_file);
  52. recursive_output(globals_list, destination_file);
  53. fputs("\n# Program strings\n", destination_file);
  54. recursive_output(strings_list, destination_file);
  55. fputs("\n:STACK\n", destination_file);
  56. fclose(destination_file);
  57. return EXIT_SUCCESS;
  58. }