| 70 | } |
| 71 | |
| 72 | void nullcInitCustomAlloc(void* (NCDECL *allocFunc)(int), void (NCDECL *deallocFunc)(void*), const char* importPath) |
| 73 | { |
| 74 | using namespace NULLC; |
| 75 | if(initialized) |
| 76 | { |
| 77 | nullcLastError = "ERROR: NULLC is already initialized"; |
| 78 | return; |
| 79 | } |
| 80 | nullcLastError = ""; |
| 81 | |
| 82 | NULLC::alloc = allocFunc ? allocFunc : NULLC::defaultAlloc; |
| 83 | NULLC::dealloc = deallocFunc ? deallocFunc : NULLC::defaultDealloc; |
| 84 | NULLC::fileLoad = NULLC::defaultFileLoad; |
| 85 | |
| 86 | CodeInfo::funcInfo.reserve(256); |
| 87 | CodeInfo::varInfo.reserve(256); |
| 88 | CodeInfo::typeInfo.reserve(256); |
| 89 | CodeInfo::typeArrays.reserve(64); |
| 90 | CodeInfo::typeFunctions.reserve(128); |
| 91 | CodeInfo::cmdList.reserve(2048); |
| 92 | CodeInfo::nodeList.reserve(1024); |
| 93 | CodeInfo::funcDefList.reserve(64); |
| 94 | CodeInfo::namespaceInfo.reserve(64); |
| 95 | CodeInfo::classMap.init(); |
| 96 | |
| 97 | compiler = NULLC::construct<Compiler>(); |
| 98 | #ifndef NULLC_NO_EXECUTOR |
| 99 | linker = NULLC::construct<Linker>(); |
| 100 | executor = new(NULLC::alloc(sizeof(Executor))) Executor(linker); |
| 101 | NULLC::SetGlobalLimit(NULLC_DEFAULT_GLOBAL_MEMORY_LIMIT); |
| 102 | #endif |
| 103 | #ifdef NULLC_BUILD_X86_JIT |
| 104 | executorX86 = new(NULLC::alloc(sizeof(ExecutorX86))) ExecutorX86(linker); |
| 105 | bool initx86 = executorX86->Initialize(); |
| 106 | assert(initx86); |
| 107 | (void)initx86; |
| 108 | #endif |
| 109 | #if defined(NULLC_LLVM_SUPPORT) && !defined(NULLC_NO_EXECUTOR) |
| 110 | executorLLVM = new(NULLC::alloc(sizeof(ExecutorLLVM))) ExecutorLLVM(linker); |
| 111 | #endif |
| 112 | BinaryCache::Initialize(); |
| 113 | BinaryCache::SetImportPath(importPath); |
| 114 | |
| 115 | argBuf = (char*)NULLC::alloc(64 * 1024); |
| 116 | |
| 117 | #ifndef NULLC_NO_EXECUTOR |
| 118 | nullcInitTypeinfoModuleLinkerOnly(linker); |
| 119 | #endif |
| 120 | |
| 121 | initialized = true; |
| 122 | } |
| 123 | |
| 124 | void nullcSetImportPath(const char* importPath) |
| 125 | { |