30 #ifndef TCC_BINDINGS_H
31 #define TCC_BINDINGS_H
37 #ifndef TCC_STATIC_LINK
38 #include <cpl/CModule.h>
40 #include <cpl/Utility.h>
48 class CompilerAccess : cpl::Utility::CNoncopyable
52 CompilerAccess() : bindings(instance()), compilerLock(bindings.compilerMutex) {}
54 bool isLinked() const noexcept {
return bindings.linkedCorrectly; }
56 TCCState *
createState()
const {
return bindings.newState(); }
57 void deleteState(TCCState * s)
const {
return bindings.deleteState(s); }
58 void setLibPath(TCCState * s,
const char *path)
const {
return bindings.setLibPath(s, path); }
59 bool addLibPath(TCCState * s,
const char *path)
const {
return bindings.addLibPath(s, path) != -1; }
60 void setErrorFunc(TCCState * s,
void * errorOpaque,
void (*errorFunction)(
void*,
const char*) )
const
62 return bindings.setErrorFunc(s, errorOpaque, errorFunction);
64 void addIncludePath(TCCState * s,
const char * pathName)
const { bindings.addIncludePath(s, pathName); }
65 void defineSymbol(TCCState * s,
const char * symbol,
const char * value)
const {
return bindings.defineSymbol(s, symbol, value); }
66 bool compileString(TCCState * s,
const char * buffer)
const {
return bindings.compileString(s, buffer) != -1; }
67 int setOutputType(TCCState * s,
int outputType)
const {
return bindings.setOutputType(s, outputType); }
68 int relocate(TCCState * s,
void * options)
const {
return bindings.relocate(s, options); }
69 void *
getSymbol(TCCState * s,
const char * name)
const {
return bindings.getSymbol(s, name); }
70 void addSymbol(TCCState * s,
const char * name,
const void * value)
const { bindings.addSymbol(s, name, value); }
71 void setOptions(TCCState * s,
const char * commands)
const {
return bindings.setOptions(s, commands); }
72 bool addFile(TCCState * s,
const char * file)
const {
return bindings.addFile(s, file) != -1; }
73 bool outputFile(TCCState * s,
const char * ofile)
const {
return bindings.outputFile(s, ofile) != -1; }
77 TCCBindings & bindings;
78 std::lock_guard<std::recursive_mutex> compilerLock;
85 #ifdef TCC_STATIC_LINK
87 setLibPath = tcc_set_lib_path;
88 addLibPath = tcc_add_library_path;
89 addIncludePath = tcc_add_include_path;
90 setOutputType = tcc_set_output_type;
91 setErrorFunc = tcc_set_error_func;
92 compileString = tcc_compile_string;
93 deleteState = tcc_delete;
94 relocate = tcc_relocate;
95 addSymbol = tcc_add_symbol;
96 getSymbol = tcc_get_symbol;
97 defineSymbol = tcc_define_symbol;
98 setOptions = tcc_set_options;
99 addFile = tcc_add_file;
100 outputFile = tcc_output_file;
102 if (!tccDLib.load(cpl::Misc::DirectoryPath() +
"/libtcc.dll"))
104 newState = (decltype(newState))tccDLib.getFuncAddress(
"tcc_new");
105 setLibPath = (decltype(setLibPath))tccDLib.getFuncAddress(
"tcc_set_lib_path");
106 addLibPath = (decltype(addLibPath))tccDLib.getFuncAddress(
"tcc_add_library_path");
107 addIncludePath = (decltype(addIncludePath))tccDLib.getFuncAddress(
"tcc_add_include_path");
108 setOutputType = (decltype(setOutputType))tccDLib.getFuncAddress(
"tcc_set_output_type");
109 setErrorFunc = (decltype(setErrorFunc))tccDLib.getFuncAddress(
"tcc_set_error_func");
110 compileString = (decltype(compileString))tccDLib.getFuncAddress(
"tcc_compile_string");
111 deleteState = (decltype(deleteState))tccDLib.getFuncAddress(
"tcc_delete");
112 relocate = (decltype(relocate))tccDLib.getFuncAddress(
"tcc_relocate");
113 getSymbol = (decltype(getSymbol))tccDLib.getFuncAddress(
"tcc_get_symbol");
114 addSymbol = (decltype(addSymbol))tccDLib.getFuncAddress(
"tcc_add_symbol");
115 defineSymbol = (decltype(defineSymbol))tccDLib.getFuncAddress(
"tcc_define_symbol");
116 setOptions = (decltype(setOptions))tccDLib.getFuncAddress(
"tcc_set_options");
117 addFile = (decltype(addFile))tccDLib.getFuncAddress(
"tcc_add_file");
118 outputFile = (decltype(outputFile))tccDLib.getFuncAddress(
"tcc_output_file");
123 linkedCorrectly = newState && setLibPath && addSymbol && addLibPath && addIncludePath && setOutputType && setErrorFunc
124 && compileString && deleteState && relocate && getSymbol && defineSymbol && setOptions
125 && addFile && outputFile;
134 decltype(tcc_new) * newState;
135 decltype(tcc_delete) * deleteState;
136 decltype(tcc_set_lib_path) * setLibPath;
137 decltype(tcc_add_library_path) * addLibPath;
138 decltype(tcc_set_error_func) * setErrorFunc;
139 decltype(tcc_add_include_path) * addIncludePath;
140 decltype(tcc_define_symbol) * defineSymbol;
141 decltype(tcc_add_symbol) * addSymbol;
142 decltype(tcc_compile_string) * compileString;
143 decltype(tcc_set_output_type) * setOutputType;
144 decltype(tcc_relocate) * relocate;
145 decltype(tcc_get_symbol) * getSymbol;
146 decltype(tcc_set_options) * setOptions;
147 decltype(tcc_add_file) * addFile;
148 decltype(tcc_output_file) * outputFile;
150 #ifndef TCC_STATIC_LINK
151 cpl::CModule tccDLib;
156 bool linkedCorrectly;
157 std::recursive_mutex compilerMutex;
164 typedef std::unique_ptr<TCCState, TCCDeleter>
UniqueTCC;