1
0

run_tcc.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* This file is part of asmc, a bootstrapping OS with minimal seed
  2. Copyright (C) 2019 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. #ifndef __RUN_TCC_H
  15. #define __RUN_TCC_H
  16. // Allow the same code to be ran on the host machine, which is
  17. // supposed to be x86_64
  18. #ifdef __x86_64__
  19. #define _GNU_SOURCE
  20. #include <dlfcn.h>
  21. //#define TCC_TARGET_I386
  22. #define TCC_TARGET_X86_64 1
  23. //#define CONFIG_TRIPLET "x86_64-linux-gnu"
  24. #define ASMC_PREFIX "./diskfs"
  25. int __get_handles() {
  26. return 0;
  27. }
  28. #else
  29. #define TCC_TARGET_I386 1
  30. // Need this, otherwise tcc does not believe it can run natively
  31. #define __i386__ 1
  32. #define ASMC_PREFIX "/disk1"
  33. #endif
  34. #include <stdio.h>
  35. #include "libtcc.h"
  36. int run_tinycc(TCCState *state, int file_num, const char **files, int include_path_num, const char **include_paths) {
  37. int res;
  38. tcc_set_options(state, "-nostdlib -nostdinc");
  39. tcc_set_output_type(state, TCC_OUTPUT_MEMORY);
  40. while (include_path_num--) {
  41. res = tcc_add_include_path(state, *include_paths++);
  42. if (res) {
  43. printf("tcc_add_include_path() failed...\n");
  44. return 1;
  45. }
  46. }
  47. while (file_num--) {
  48. res = tcc_add_file(state, *files++);
  49. if (res) {
  50. printf("tcc_add_file() failed...\n");
  51. return 1;
  52. }
  53. }
  54. res = tcc_relocate(state, TCC_RELOCATE_AUTO);
  55. if (res) {
  56. printf("tcc_relocate() failed...\n");
  57. return 1;
  58. }
  59. return 0;
  60. }
  61. #endif