* @desc Generates kernel string for this kernel program. * * If sub-kernels are supplied, they are also factored in. * This string can be saved by calling the `toString` method * and then can be reused later. * * @returns {String} result *
()
| 210 | * |
| 211 | */ |
| 212 | getKernelString() { |
| 213 | if (this._kernelString !== null) return this._kernelString; |
| 214 | |
| 215 | let kernelThreadString = null; |
| 216 | let { |
| 217 | translatedSources |
| 218 | } = this; |
| 219 | if (translatedSources.length > 1) { |
| 220 | translatedSources = translatedSources.filter(fn => { |
| 221 | if (/^function/.test(fn)) return fn; |
| 222 | kernelThreadString = fn; |
| 223 | return false; |
| 224 | }); |
| 225 | } else { |
| 226 | kernelThreadString = translatedSources.shift(); |
| 227 | } |
| 228 | return this._kernelString = ` const LOOP_MAX = ${ this._getLoopMaxString() }; |
| 229 | ${ this.injectedNative || '' } |
| 230 | const _this = this; |
| 231 | ${ this._resultKernelHeader() } |
| 232 | ${ this._processConstants() } |
| 233 | return (${ this.argumentNames.map(argumentName => 'user_' + argumentName).join(', ') }) => { |
| 234 | ${ this._prependedString.join('') } |
| 235 | ${ this._earlyThrows() } |
| 236 | ${ this._processArguments() } |
| 237 | ${ this.graphical ? this._graphicalKernelBody(kernelThreadString) : this._resultKernelBody(kernelThreadString) } |
| 238 | ${ translatedSources.length > 0 ? translatedSources.join('\n') : '' } |
| 239 | };`; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * @desc Returns the *pre-compiled* Kernel as a JS Object String, that can be reused. |
no test coverage detected