1 /* 2 * Copyright (C) 2010-2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_BCC_BCC_H 18 #define ANDROID_BCC_BCC_H 19 20 #include <stddef.h> 21 #include <stdint.h> 22 23 /*-------------------------------------------------------------------------*/ 24 25 /* libbcc script opaque type */ 26 typedef struct BCCOpaqueScript *BCCScriptRef; 27 28 29 /* Symbol lookup function type */ 30 typedef void *(*BCCSymbolLookupFn)(void *context, char const *symbolName); 31 32 33 /* llvm::Module (see <llvm>/include/llvm-c/Core.h for details) */ 34 typedef struct LLVMOpaqueModule *LLVMModuleRef; 35 36 37 /*-------------------------------------------------------------------------*/ 38 39 40 #define BCC_NO_ERROR 0x0000 41 #define BCC_INVALID_ENUM 0x0500 42 #define BCC_INVALID_OPERATION 0x0502 43 #define BCC_INVALID_VALUE 0x0501 44 #define BCC_OUT_OF_MEMORY 0x0505 45 46 47 /*-------------------------------------------------------------------------*/ 48 49 50 /* Optional Flags for bccReadBC, bccReadFile, bccLinkBC, bccLinkFile */ 51 #define BCC_SKIP_DEP_SHA1 (1 << 0) 52 53 54 /*-------------------------------------------------------------------------*/ 55 56 /* 57 * Relocation model when prepare object, it provides 1-1 mapping to the enum 58 * llvm::Reloc::Model in llvm/Support/CodeGen.h 59 */ 60 typedef enum bccRelocModelEnum { 61 bccRelocDefault, // Use default target-defined relocation model 62 bccRelocStatic, 63 bccRelocPIC, 64 bccRelocDynamicNoPIC 65 } bccRelocModelEnum; 66 67 /*-------------------------------------------------------------------------*/ 68 69 #ifdef __cplusplus 70 extern "C" { 71 #endif 72 73 BCCScriptRef bccCreateScript(); 74 75 void bccDisposeScript(BCCScriptRef script); 76 77 int bccRegisterSymbolCallback(BCCScriptRef script, 78 BCCSymbolLookupFn pFn, 79 void *pContext); 80 81 int bccGetError(BCCScriptRef script); /* deprecated */ 82 83 84 85 int bccReadBC(BCCScriptRef script, 86 char const *resName, 87 char const *bitcode, 88 size_t bitcodeSize, 89 unsigned long flags); 90 91 int bccReadModule(BCCScriptRef script, 92 char const *resName, 93 LLVMModuleRef module, 94 unsigned long flags); 95 96 int bccReadFile(BCCScriptRef script, 97 char const *path, 98 unsigned long flags); 99 100 int bccLinkBC(BCCScriptRef script, 101 char const *resName, 102 char const *bitcode, 103 size_t bitcodeSize, 104 unsigned long flags); 105 106 int bccLinkFile(BCCScriptRef script, 107 char const *path, 108 unsigned long flags); 109 110 void bccMarkExternalSymbol(BCCScriptRef script, char const *name); 111 112 int bccPrepareRelocatable(BCCScriptRef script, 113 char const *objPath, 114 bccRelocModelEnum RelocModel, 115 unsigned long flags); 116 117 int bccPrepareSharedObject(BCCScriptRef script, 118 char const *objPath, 119 char const *dsoPath, 120 unsigned long flags); 121 122 int bccPrepareExecutable(BCCScriptRef script, 123 char const *cacheDir, 124 char const *cacheName, 125 unsigned long flags); 126 127 void *bccGetFuncAddr(BCCScriptRef script, char const *funcname); 128 129 void bccGetExportVarList(BCCScriptRef script, 130 size_t varListSize, 131 void **varList); 132 133 void bccGetExportFuncList(BCCScriptRef script, 134 size_t funcListSize, 135 void **funcList); 136 137 void bccGetExportForEachList(BCCScriptRef script, 138 size_t forEachListSize, 139 void **forEachList); 140 141 char const *bccGetBuildTime(); 142 143 char const *bccGetBuildRev(); 144 145 char const *bccGetBuildSHA1(); 146 147 #ifdef __cplusplus 148 }; 149 #endif 150 151 /*-------------------------------------------------------------------------*/ 152 153 #endif 154