libtcc.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef LIBTCC_H
  2. #define LIBTCC_H
  3. #ifdef LIBTCC_AS_DLL
  4. #define LIBTCCAPI __declspec(dllexport)
  5. #else
  6. #define LIBTCCAPI
  7. #endif
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. struct TCCState;
  12. typedef struct TCCState TCCState;
  13. /* create a new TCC compilation context */
  14. LIBTCCAPI TCCState *tcc_new(void);
  15. /* free a TCC compilation context */
  16. LIBTCCAPI void tcc_delete(TCCState *s);
  17. /* add debug information in the generated code */
  18. LIBTCCAPI void tcc_enable_debug(TCCState *s);
  19. /* set error/warning display callback */
  20. LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
  21. void (*error_func)(void *opaque, const char *msg));
  22. /* set/reset a warning */
  23. LIBTCCAPI int tcc_set_warning(TCCState *s, const char *warning_name, int value);
  24. /*****************************/
  25. /* preprocessor */
  26. /* add include path */
  27. LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
  28. /* add in system include path */
  29. LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
  30. /* define preprocessor symbol 'sym'. Can put optional value */
  31. LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
  32. /* undefine preprocess symbol 'sym' */
  33. LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
  34. /*****************************/
  35. /* compiling */
  36. /* add a file (either a C file, dll, an object, a library or an ld
  37. script). Return -1 if error. */
  38. LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
  39. /* compile a string containing a C source. Return non zero if
  40. error. */
  41. LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
  42. /*****************************/
  43. /* linking commands */
  44. /* set output type. MUST BE CALLED before any compilation */
  45. #define TCC_OUTPUT_MEMORY 0 /* output will be ran in memory (no
  46. output file) (default) */
  47. #define TCC_OUTPUT_EXE 1 /* executable file */
  48. #define TCC_OUTPUT_DLL 2 /* dynamic library */
  49. #define TCC_OUTPUT_OBJ 3 /* object file */
  50. #define TCC_OUTPUT_PREPROCESS 4 /* preprocessed file (used internally) */
  51. LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
  52. #define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
  53. #define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
  54. #define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
  55. /* equivalent to -Lpath option */
  56. LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
  57. /* the library name is the same as the argument of the '-l' option */
  58. LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
  59. /* add a symbol to the compiled program */
  60. LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, void *val);
  61. /* output an executable, library or object file. DO NOT call
  62. tcc_relocate() before. */
  63. LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
  64. /* link and run main() function and return its value. DO NOT call
  65. tcc_relocate() before. */
  66. LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
  67. /* copy code into memory passed in by the caller and do all relocations
  68. (needed before using tcc_get_symbol()).
  69. returns -1 on error and required size if ptr is NULL */
  70. LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
  71. /* return symbol value or NULL if not found */
  72. LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
  73. /* set CONFIG_TCCDIR at runtime */
  74. LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif