1 /************************** BEGIN llvm-machine-dsp.h **************************/ 2 /************************************************************************ 3 ************************************************************************ 4 Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU Lesser General Public License as published by 8 the Free Software Foundation; either version 2.1 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 20 ************************************************************************ 21 ************************************************************************/ 22 23 #ifndef LLVM_MACHINE_DSP_H 24 #define LLVM_MACHINE_DSP_H 25 26 #ifdef _WIN32 27 #define DEPRECATED(fun) __declspec(deprecated) fun 28 #else 29 #define DEPRECATED(fun) fun __attribute__ ((deprecated)); 30 #endif 31 32 #include <vector> 33 #include <string> 34 35 #include "faust/dsp/dsp.h" 36 #include "faust/gui/meta.h" 37 38 /*! 39 \addtogroup llvmcpp C++ interface for reading LLVM machine code. 40 @{ 41 */ 42 43 /** 44 * Get the library version. 45 * 46 * @return the library version as a static string. 47 */ 48 extern "C" const char* getCLibFaustVersion(); 49 50 /** 51 * DSP instance class with methods. 52 */ 53 class llvm_dsp : public dsp { 54 55 private: 56 57 // llvm_dsp objects are allocated using llvm_dsp_factory::createDSPInstance(); llvm_dsp()58 llvm_dsp() {} 59 60 public: 61 62 int getNumInputs(); 63 64 int getNumOutputs(); 65 66 void buildUserInterface(UI* ui_interface); 67 68 int getSampleRate(); 69 70 void init(int sample_rate); 71 72 void instanceInit(int sample_rate); 73 74 void instanceConstants(int sample_rate); 75 76 void instanceResetUserInterface(); 77 78 void instanceClear(); 79 80 llvm_dsp* clone(); 81 82 void metadata(Meta* m); 83 84 void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs); 85 86 }; 87 88 /** 89 * DSP factory class. 90 */ 91 92 class llvm_dsp_factory : public dsp_factory { 93 94 public: 95 96 virtual ~llvm_dsp_factory(); 97 98 /** 99 * Return factory name: 100 * either the name declared in DSP with [declare name "foo"] syntax 101 * or 'filename' (if createDSPFactoryFromFile is used) 102 * or 'name_app' (if createDSPFactoryFromString is used) 103 */ 104 std::string getName(); 105 106 /* Return factory LLVM target */ 107 std::string getTarget(); 108 109 /* Return factory SHA key */ 110 std::string getSHAKey(); 111 112 /* Return factory expanded DSP code */ 113 std::string getDSPCode(); 114 115 /* Return factory compile options */ 116 std::string getCompileOptions(); 117 118 /* Get the Faust DSP factory list of library dependancies */ 119 std::vector<std::string> getLibraryList(); 120 121 /* Get the list of all used includes */ 122 std::vector<std::string> getIncludePathnames(); 123 124 /* Create a new DSP instance, to be deleted with C++ 'delete' */ 125 llvm_dsp* createDSPInstance(); 126 127 /* Set a custom memory manager to be used when creating instances */ 128 void setMemoryManager(dsp_memory_manager* manager); 129 130 /* Return the currently set custom memory manager */ 131 dsp_memory_manager* getMemoryManager(); 132 133 }; 134 135 /** 136 * Get the target (triple + CPU) of the machine. 137 * 138 * @return the target as a string. 139 */ 140 std::string getDSPMachineTarget(); 141 142 /** 143 * Get the Faust DSP factory associated with a given SHA key (created from the 'expanded' DSP source), 144 * if already allocated in the factories cache and increment it's reference counter. You will have to explicitly 145 * use deleteDSPFactory to properly decrement reference counter when the factory is no more needed. 146 * 147 * @param sha_key - the SHA key for an already created factory, kept in the factory cache 148 * 149 * @return a DSP factory if one is associated with the SHA key, otherwise a null pointer. 150 */ 151 llvm_dsp_factory* getDSPFactoryFromSHAKey(const std::string& sha_key); 152 153 /** 154 /** 155 * Delete a Faust DSP factory, that is decrements it's reference counter, possibly really deleting the internal pointer. 156 * Possibly also delete DSP pointers associated with this factory, if they were not explicitly deleted with C++ delete. 157 * Beware : all kept factories and DSP pointers (in local variables...) thus become invalid. 158 * 159 * @param factory - the DSP factory 160 * 161 * @return true if the factory internal pointer was really deleted, and false if only 'decremented'. 162 */ 163 bool deleteDSPFactory(llvm_dsp_factory* factory); 164 165 /** 166 * Delete all Faust DSP factories kept in the library cache. Beware : all kept factory and DSP pointers (in local variables...) thus become invalid. 167 * 168 */ 169 void deleteAllDSPFactories(); 170 171 /** 172 * Return Faust DSP factories of the library cache as a vector of their SHA keys. 173 * 174 * @return the Faust DSP factories. 175 */ 176 std::vector<std::string> getAllDSPFactories(); 177 178 /** 179 * Create a Faust DSP factory from a base64 encoded machine code string. Note that the library keeps an internal cache of all 180 * allocated factories so that the compilation of the same DSP code (that is the same machine code string) will return 181 * the same (reference counted) factory pointer. You will have to explicitly use deleteDSPFactory to properly 182 * decrement reference counter when the factory is no more needed. 183 * 184 * @param machine_code - the machine code string 185 * @param target - the LLVM machine target: like 'i386-apple-macosx10.6.0:opteron', 186 * using an empty string takes the current machine settings, 187 * and i386-apple-macosx10.6.0:generic kind of syntax for a generic processor 188 * @param error_msg - the error string to be filled 189 * 190 * @return the DSP factory on success, otherwise a null pointer. 191 */ 192 llvm_dsp_factory* readDSPFactoryFromMachine(const std::string& machine_code, const std::string& target, std::string& error_msg); 193 194 /** 195 * Create a Faust DSP factory from a machine code file. Note that the library keeps an internal cache of all 196 * allocated factories so that the compilation of the same DSP code (that is the same machine code file) will return 197 * the same (reference counted) factory pointer. You will have to explicitly use deleteDSPFactory to properly 198 * decrement reference counter when the factory is no more needed. 199 * 200 * @param machine_code_path - the machine code file pathname 201 * @param target - the LLVM machine target: like 'i386-apple-macosx10.6.0:opteron', 202 * using an empty string takes the current machine settings, 203 * and i386-apple-macosx10.6.0:generic kind of syntax for a generic processor 204 * @param error_msg - the error string to be filled 205 * 206 * @return the DSP factory on success, otherwise a null pointer. 207 */ 208 llvm_dsp_factory* readDSPFactoryFromMachineFile(const std::string& machine_code_path, const std::string& target, std::string& error_msg); 209 210 /*! 211 @} 212 */ 213 214 #endif 215 /************************** END llvm-machine-dsp.h **************************/ 216