libtcc.h 3.2 KB

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