tinyc.nim 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. proc openCCState*(): PccState {.importc: "tcc_new", cdecl.}
  14. ## create a new TCC compilation context
  15. proc closeCCState*(s: PccState) {.importc: "tcc_delete", cdecl.}
  16. ## free a TCC compilation context
  17. proc setErrorFunc*(s: PccState, errorOpaque: pointer, errorFun: ErrorFunc) {.
  18. cdecl, importc: "tcc_set_error_func".}
  19. ## set error/warning display callback
  20. proc setOptions*(s: PccState, options: cstring) {.cdecl, importc: "tcc_set_options".}
  21. ## set a options
  22. # preprocessor
  23. proc addIncludePath*(s: PccState, pathname: cstring) {.cdecl,
  24. importc: "tcc_add_include_path".}
  25. ## add include path
  26. proc addSysincludePath*(s: PccState, pathname: cstring) {.cdecl,
  27. importc: "tcc_add_sysinclude_path".}
  28. ## add in system include path
  29. proc defineSymbol*(s: PccState, sym, value: cstring) {.cdecl,
  30. importc: "tcc_define_symbol".}
  31. ## define preprocessor symbol 'sym'. Can put optional value
  32. proc undefineSymbol*(s: PccState, sym: cstring) {.cdecl,
  33. importc: "tcc_undefine_symbol".}
  34. ## undefine preprocess symbol 'sym'
  35. # compiling
  36. proc addFile*(s: PccState, filename: cstring): cint {.cdecl,
  37. importc: "tcc_add_file".}
  38. ## add a file (either a C file, dll, an object, a library or an ld
  39. ## script). Return -1 if error.
  40. proc compileString*(s: PccState, buf: cstring): cint {.cdecl,
  41. importc: "tcc_compile_string".}
  42. ## compile a string containing a C source. Return non zero if error.
  43. # linking commands
  44. const
  45. OutputMemory*: cint = 1 ## output will be ran in memory (no
  46. ## output file) (default)
  47. OutputExe*: cint = 2 ## executable file
  48. OutputDll*: cint = 3 ## dynamic library
  49. OutputObj*: cint = 4 ## object file
  50. OutputPreprocess*: cint = 5 ## preprocessed file (used internally)
  51. proc setOutputType*(s: PCCState, outputType: cint): cint {.cdecl,
  52. importc: "tcc_set_output_type".}
  53. ## set output type. MUST BE CALLED before any compilation
  54. proc addLibraryPath*(s: PccState, pathname: cstring): cint {.cdecl,
  55. importc: "tcc_add_library_path".}
  56. ## equivalent to -Lpath option
  57. proc addLibrary*(s: PCCState, libraryname: cstring): cint {.cdecl,
  58. importc: "tcc_add_library".}
  59. ## the library name is the same as the argument of the '-l' option
  60. proc addSymbol*(s: PccState, name: cstring, val: pointer): cint {.cdecl,
  61. importc: "tcc_add_symbol".}
  62. ## add a symbol to the compiled program
  63. proc outputFile*(s: PccState, filename: cstring): cint {.cdecl,
  64. importc: "tcc_output_file".}
  65. ## output an executable, library or object file. DO NOT call
  66. ## tcc_relocate() before.
  67. proc run*(s: PccState, argc: cint, argv: cstringArray): cint {.cdecl,
  68. importc: "tcc_run".}
  69. ## link and run main() function and return its value. DO NOT call
  70. ## tcc_relocate() before.
  71. proc relocate*(s: PccState, p: pointer): cint {.cdecl,
  72. importc: "tcc_relocate".}
  73. ## copy code into memory passed in by the caller and do all relocations
  74. ## (needed before using tcc_get_symbol()).
  75. ## returns -1 on error and required size if ptr is NULL
  76. proc getSymbol*(s: PccState, name: cstring): pointer {.cdecl,
  77. importc: "tcc_get_symbol".}
  78. ## return symbol value or NULL if not found
  79. proc setLibPath*(s: PccState, path: cstring) {.cdecl,
  80. importc: "tcc_set_lib_path".}
  81. ## set CONFIG_TCCDIR at runtime