forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction-builder.js
More file actions
32 lines (29 loc) · 1.11 KB
/
function-builder.js
File metadata and controls
32 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const FunctionBuilderBase = require('../function-builder-base');
const CPUFunctionNode = require('./function-node');
module.exports = class CPUFunctionBuilder extends FunctionBuilderBase {
addFunction(functionName, jsFunction, paramTypes, returnType) {
this.addFunctionNode(
new CPUFunctionNode(functionName, jsFunction, paramTypes, returnType)
.setAddFunction(this.addFunction.bind(this))
);
}
getPrototypeString() {
let ret = '';
for (let p in this.nodeMap) {
if (!this.nodeMap.hasOwnProperty(p)) continue;
const node = this.nodeMap[p];
if (node.isSubKernel) {
ret += `var ${ node.functionName } = ` + node.jsFunctionString.replace('return', `return ${ node.functionName }Result[this.thread.z][this.thread.y][this.thread.x] =`) + '.bind(this);\n';
} else {
ret += `var ${ node.functionName } = ${ node.jsFunctionString };\n`;
}
}
return ret;
}
addSubKernel(jsFunction, paramTypes, returnType) {
const node = new CPUFunctionNode(null, jsFunction, paramTypes, returnType)
.setAddFunction(this.addFunction.bind(this));
node.isSubKernel = true;
this.addFunctionNode(node);
}
};