homepage: http://bellard.org/tcc/
download: libtcc.zip
Joshy
Code: Select all
#ifndef TCC_DYNAMIC_BI
#define TCC_DYNAMIC_BI
type TCCState as any
type TCC_OUTPUT as long
#define TCC_RELOCATE_AUTO cptr(any ptr,1)
const as TCC_OUTPUT TCC_OUTPUT_MEMORY = 0 ' output will be run in memory (default)
const as TCC_OUTPUT TCC_OUTPUT_EXE = 1 ' executable file
const as TCC_OUTPUT TCC_OUTPUT_DLL = 2 ' dynamic library
const as TCC_OUTPUT TCC_OUTPUT_OBJ = 3 ' object file
type error_func as sub cdecl (byval opaque as any ptr, byval msg as const zstring ptr)
type TCC_DYNAMIC
declare constructor
declare destructor
declare function IsAvailable as boolean
' create a new TCC compilation context
tcc_new as function cdecl () as TCCState ptr
' free a TCC compilation context
tcc_delete as sub cdecl (byval s as TCCState ptr)
' set CONFIG_TCCDIR at runtime
tcc_set_lib_path as sub cdecl (byval s as TCCState ptr, _
byval path as const zstring ptr)
' set error/warning display callback
tcc_set_error_func as sub cdecl (byval s as TCCState ptr, _
byval error_opaque as any ptr, _
byval cb as error_func)
' set options as from command line (multiple supported)
tcc_set_options as function cdecl (byval s as TCCState ptr, _
byval options as const zstring ptr) as long
' preprocessor
' add include path
tcc_add_include_path as function cdecl (byval s as TCCState ptr, _
byval pathname as const zstring ptr) as long
' add in system include path
tcc_add_sysinclude_path as function cdecl (byval s as TCCState ptr, _
byval pathname as const zstring ptr) as long
' define preprocessor symbol 'sym'. Can put optional value */
tcc_define_symbol as sub cdecl (byval s as TCCState ptr, _
byval sym as const zstring ptr, _
byval value as const zstring ptr)
' undefine preprocess symbol 'sym'
tcc_undefine_symbol as sub cdecl (byval s as TCCState ptr, _
byval sym as const zstring ptr)
' compiling
' add a file (C file, dll, object, library, ld script). Return -1 if error.
tcc_add_file as function cdecl (byval s as TCCState ptr, _
byval filename as const zstring ptr) as long
' compile a string containing a C source. Return -1 if error.
tcc_compile_string as function cdecl (byval s as TCCState ptr, _
byval buf as const zstring ptr) as long
' linking commands
' set output type. MUST BE CALLED before any compilation
tcc_set_output_type as function cdecl(byval s as TCCState ptr, _
byval output_type as TCC_OUTPUT) as long
' equivalent to -Lpath option
tcc_add_library_path as function cdecl(byval s as TCCState ptr, _
byval pathname as const zstring ptr) as long
' the library name is the same as the argument of the '-l' option
tcc_add_library as function cdecl(byval s as TCCState ptr, _
byval libraryname as const zstring ptr) as long
' add a symbol to the compiled program
tcc_add_symbol as function cdecl(byval s as TCCState ptr, _
byval name_ as const zstring ptr, byval value as const zstring ptr) as long
' output an executable, library or object file. DO NOT call tcc_relocate() before.
tcc_output_file as function cdecl(byval s as TCCState ptr, _
byval filename as const zstring ptr) as long
' link and run main() function and return its value. DO NOT call tcc_relocate() before.
tcc_run as function cdecl(byval s as TCCState ptr, _
byval argc as long, _
byval argv as zstring ptr ptr) as long
'* do all relocations (needed before using tcc_get_symbol())
' possible values for 'p': TCC_RELOCATE_AUTO : Allocate and manage memory internally
' NULL : return required memory size for the step below
' memory address : copy code to memory passed by the caller
' returns -1 if error.
tcc_relocate as function cdecl(byval s as TCCState ptr, _
byval p as any ptr) as long
' return symbol value or NULL if not found
tcc_get_symbol as function cdecl(byval s as TCCState ptr, _
byval name_ as const zstring ptr) as any ptr
as TCCState ptr state
private:
as any ptr hLib
end type
constructor TCC_DYNAMIC
var oldPath = CurDir()
ChDir(ExePath())
#ifdef __FB_WIN32__
#ifndef __FB_64BIT__
var libfolder ="lib\win32"
#else
var libfolder = "lib\win64"
#endif
#else
#ifndef __FB_64BIT__
var libfolder = "lib/lin32"
#else
var libfolder = "lib/lin64"
#endif
#endif
ChDir(libfolder)
#ifdef __FB_WIN32__
hLib = DyLibLoad("libtcc") ' libtcc.dll
#else
hLib = DyLibLoad("tcc") ' libtcc.so
#endif
if hLib then
tcc_new = DyLibSymbol(hLib,"tcc_new")
tcc_delete = DyLibSymbol(hLib,"tcc_delete")
tcc_set_lib_path = DyLibSymbol(hLib,"tcc_set_lib_path")
tcc_set_error_func = DyLibSymbol(hLib,"tcc_set_error_func")
tcc_set_options = DyLibSymbol(hLib,"tcc_set_options")
tcc_add_include_path = DyLibSymbol(hLib,"tcc_add_include_path")
tcc_add_sysinclude_path = DyLibSymbol(hLib,"tcc_add_sysinclude_path")
tcc_define_symbol = DyLibSymbol(hLib,"tcc_define_symbol")
tcc_undefine_symbol = DyLibSymbol(hLib,"tcc_undefine_symbol")
tcc_add_file = DyLibSymbol(hLib,"tcc_add_file")
tcc_compile_string = DyLibSymbol(hLib,"tcc_compile_string")
tcc_set_output_type = DyLibSymbol(hLib,"tcc_set_output_type")
tcc_add_library_path = DyLibSymbol(hLib,"tcc_add_library_path")
tcc_add_library = DyLibSymbol(hLib,"tcc_add_library")
tcc_add_symbol = DyLibSymbol(hLib,"tcc_add_symbol")
tcc_output_file = DyLibSymbol(hLib,"tcc_output_file")
tcc_run = DyLibSymbol(hLib,"tcc_run")
tcc_relocate = DyLibSymbol(hLib,"tcc_relocate")
tcc_get_symbol = DyLibSymbol(hLib,"tcc_get_symbol")
if tcc_new then state=tcc_new()
if state=0 then
DyLibFree hLib
hLib = 0
else
tcc_add_library_path(state,libfolder)
end if
end if
ChDir(oldPath)
end constructor
destructor TCC_DYNAMIC
if state then
tcc_delete(state)
end if
end destructor
function TCC_DYNAMIC.IsAvailable as boolean
return iif(state<>0,true,false)
end function
#endif ' TCC_DYNAMIC_BI