tinycc.g 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # This file is part of asmc, a bootstrapping OS with minimal seed
  2. # Copyright (C) 2018 Giovanni Mascellani <gio@debian.org>
  3. # https://gitlab.com/giomasce/asmc
  4. # This program 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. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. const TINYCC_LOAD_TOKENS 0
  15. fun compile_tinycc 0 {
  16. $filename
  17. @filename "/disk1/run_tcc.c" = ;
  18. # Preprocessing
  19. $ctx
  20. @ctx ppctx_init = ;
  21. $tokens
  22. if TINYCC_LOAD_TOKENS {
  23. @tokens load_token_list_from_diskfs = ;
  24. } else {
  25. "Preprocessing tinycc...\n" log ;
  26. ctx "__ASMC_COMP__" "1" ppctx_define ;
  27. ctx filename ppctx_set_base_filename ;
  28. ctx "/disk1/tinycc/" ppctx_add_include_path ;
  29. ctx "/disk1/tinycc-aux/" ppctx_add_include_path ;
  30. ctx "/disk1/tinycc/softfloat/" ppctx_add_include_path ;
  31. ctx "/disk1/tinycc/softfloat/include/" ppctx_add_include_path ;
  32. ctx "/disk1/tinycc/softfloat/8086/" ppctx_add_include_path ;
  33. ctx PPCTX_VERBOSE take_addr 1 = ;
  34. @tokens 4 vector_init = ;
  35. tokens ctx filename preproc_file ;
  36. @tokens tokens remove_whites = ;
  37. @tokens tokens collapse_strings = ;
  38. "Finished preprocessing tinycc!\n" log ;
  39. #tokens dump_token_list_to_debugfs ;
  40. }
  41. # Compilation
  42. $cctx
  43. @cctx tokens cctx_init = ;
  44. cctx CCTX_VERBOSE take_addr 1 = ;
  45. cctx CCTX_DEBUG take_addr 0 = ;
  46. #cctx CCTX_DEBUG_AFTER take_addr 1000 "..................................................................................................................................................................................." strlen 1 - * = ;
  47. "Compiling tinycc...\n" log ;
  48. cctx cctx_compile ;
  49. "Finished compiling tinycc!\n" log ;
  50. cctx cctx_print_stats ;
  51. # Try to execute the code
  52. "Executing compiled tinycc...\n" log ;
  53. $main_global
  54. @main_global cctx "_start" cctx_get_global = ;
  55. $main_addr
  56. @main_addr main_global GLOBAL_LOC take = ;
  57. $arg
  58. @arg "_main" = ;
  59. $res
  60. @res @arg 1 main_addr \2 = ;
  61. "tinycc returned " log ;
  62. res itoa log ;
  63. "\n" log ;
  64. # Dump some test file
  65. # "/ram/ipxe/main.o" "main.o" debugfs_copy_file ;
  66. # "/ram/ipxe/main.o" dump_debug ;
  67. # "/ram/ipxe/init.o" dump_debug ;
  68. # "/ram/ipxe/vsprintf.o" dump_debug ;
  69. # "/ram/ipxe/ipxe.o" dump_debug ;
  70. tokens free_vect_of_ptrs ;
  71. cctx cctx_destroy ;
  72. ctx ppctx_destroy ;
  73. }