tinyc.nim 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2010 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. type
  10. CcState {.pure, final.} = object
  11. PccState* = ptr CcState
  12. ErrorFunc* = proc (opaque: pointer, msg: cstring) {.cdecl.}
  13. {.deprecated: [TccState: CcState, TErrorFunc: ErrorFunc].}
  14. proc openCCState*(): PccState {.importc: "tcc_new", cdecl.}
  15. ## create a new TCC compilation context
  16. proc closeCCState*(s: PccState) {.importc: "tcc_delete", cdecl.}
  17. ## free a TCC compilation context
  18. proc enableDebug*(s: PccState) {.importc: "tcc_enable_debug", cdecl.}
  19. ## add debug information in the generated code
  20. proc setErrorFunc*(s: PccState, errorOpaque: pointer, errorFun: ErrorFunc) {.
  21. cdecl, importc: "tcc_set_error_func".}
  22. ## set error/warning display callback
  23. proc setWarning*(s: PccState, warningName: cstring, value: int) {.cdecl,
  24. importc: "tcc_set_warning".}
  25. ## set/reset a warning
  26. # preprocessor
  27. proc addIncludePath*(s: PccState, pathname: cstring) {.cdecl,
  28. importc: "tcc_add_include_path".}
  29. ## add include path
  30. proc addSysincludePath*(s: PccState, pathname: cstring) {.cdecl,
  31. importc: "tcc_add_sysinclude_path".}
  32. ## add in system include path
  33. proc defineSymbol*(s: PccState, sym, value: cstring) {.cdecl,
  34. importc: "tcc_define_symbol".}
  35. ## define preprocessor symbol 'sym'. Can put optional value
  36. proc undefineSymbol*(s: PccState, sym: cstring) {.cdecl,
  37. importc: "tcc_undefine_symbol".}
  38. ## undefine preprocess symbol 'sym'
  39. # compiling
  40. proc addFile*(s: PccState, filename: cstring): cint {.cdecl,
  41. importc: "tcc_add_file".}
  42. ## add a file (either a C file, dll, an object, a library or an ld
  43. ## script). Return -1 if error.
  44. proc compileString*(s: PccState, buf: cstring): cint {.cdecl,
  45. importc: "tcc_compile_string".}
  46. ## compile a string containing a C source. Return non zero if error.
  47. # linking commands
  48. const
  49. OutputMemory*: cint = 0 ## output will be ran in memory (no
  50. ## output file) (default)
  51. OutputExe*: cint = 1 ## executable file
  52. OutputDll*: cint = 2 ## dynamic library
  53. OutputObj*: cint = 3 ## object file
  54. OutputPreprocess*: cint = 4 ## preprocessed file (used internally)
  55. OutputFormatElf*: cint = 0 ## default output format: ELF
  56. OutputFormatBinary*: cint = 1 ## binary image output
  57. OutputFormatCoff*: cint = 2 ## COFF
  58. proc setOutputType*(s: PCCState, outputType: cint): cint {.cdecl,
  59. importc: "tcc_set_output_type".}
  60. ## set output type. MUST BE CALLED before any compilation
  61. proc addLibraryPath*(s: PccState, pathname: cstring): cint {.cdecl,
  62. importc: "tcc_add_library_path".}
  63. ## equivalent to -Lpath option
  64. proc addLibrary*(s: PCCState, libraryname: cstring): cint {.cdecl,
  65. importc: "tcc_add_library".}
  66. ## the library name is the same as the argument of the '-l' option
  67. proc addSymbol*(s: PccState, name: cstring, val: pointer): cint {.cdecl,
  68. importc: "tcc_add_symbol".}
  69. ## add a symbol to the compiled program
  70. proc outputFile*(s: PccState, filename: cstring): cint {.cdecl,
  71. importc: "tcc_output_file".}
  72. ## output an executable, library or object file. DO NOT call
  73. ## tcc_relocate() before.
  74. proc run*(s: PccState, argc: cint, argv: cstringArray): cint {.cdecl,
  75. importc: "tcc_run".}
  76. ## link and run main() function and return its value. DO NOT call
  77. ## tcc_relocate() before.
  78. proc relocate*(s: PccState, p: pointer): cint {.cdecl,
  79. importc: "tcc_relocate".}
  80. ## copy code into memory passed in by the caller and do all relocations
  81. ## (needed before using tcc_get_symbol()).
  82. ## returns -1 on error and required size if ptr is NULL
  83. proc getSymbol*(s: PccState, name: cstring): pointer {.cdecl,
  84. importc: "tcc_get_symbol".}
  85. ## return symbol value or NULL if not found
  86. proc setLibPath*(s: PccState, path: cstring) {.cdecl,
  87. importc: "tcc_set_lib_path".}
  88. ## set CONFIG_TCCDIR at runtime