Skip to content

Commit 62591e3

Browse files
have initial validator kernels building, but not actual
1 parent 5b74db9 commit 62591e3

11 files changed

Lines changed: 208 additions & 190 deletions

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gulp.task('build', function() {
1717
.bundle()
1818
.pipe(source('gpu.js'))
1919
.pipe(buffer())
20-
.pipe(header(fs.readFileSync('./src/wrapper/prefix.js', 'utf8'), { pkg : pkg } ))
20+
.pipe(header(fs.readFileSync('./src/wrapper/prefix.js', 'utf8'), { pkg : pkg }))
2121
.pipe(gulp.dest('bin'));
2222
});
2323

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"devDependencies": {
1414
"babel-plugin-syntax-async-functions": "^6.5.0",
1515
"browser-sync": "^2.18.2",
16+
"browserify": "^14.3.0",
1617
"gulp": "^3.9.1",
1718
"gulp-concat": "^2.6.0",
1819
"gulp-header": "^1.7.1",

src/backend/base-function-builder.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module.exports = class BaseFunctionBuilder {
6262
///
6363
/// Returns:
6464
/// {[String,...]} Returning list of function names that is traced. Including itself.
65-
traceFunctionCalls(functionName, retList, opt) {
65+
traceFunctionCalls(functionName, retList) {
6666
functionName = functionName || 'kernel';
6767
retList = retList || [];
6868

@@ -74,9 +74,9 @@ module.exports = class BaseFunctionBuilder {
7474
} else {
7575
retList.push(functionName);
7676

77-
fNode.getFunctionString(opt); //ensure JS trace is done
77+
fNode.getFunctionString(); //ensure JS trace is done
7878
for(let i = 0; i < fNode.calledFunctions.length; ++i) {
79-
this.traceFunctionCalls(fNode.calledFunctions[i], retList, opt);
79+
this.traceFunctionCalls(fNode.calledFunctions[i], retList);
8080
}
8181
}
8282
}
@@ -93,12 +93,12 @@ module.exports = class BaseFunctionBuilder {
9393
/// Returns:
9494
/// {String} The full webgl string, of all the various functions. Trace optimized if functionName given
9595
///
96-
webGlStringFromFunctionNames(functionList, opt) {
96+
webGlStringFromFunctionNames(functionList) {
9797
const ret = [];
9898
for(let i = 0; i < functionList.length; ++i) {
9999
const node = this.nodeMap[functionList[i]];
100100
if(node) {
101-
ret.push(this.nodeMap[functionList[i]].getFunctionString(opt));
101+
ret.push(this.nodeMap[functionList[i]].getFunctionString());
102102
}
103103
}
104104
return ret.join('\n');
@@ -144,15 +144,11 @@ module.exports = class BaseFunctionBuilder {
144144
/// Returns:
145145
/// {String} The full webgl string, of all the various functions. Trace optimized if functionName given
146146
///
147-
webGlPrototypeString(functionName, opt) {
148-
if (opt === undefined) {
149-
opt = {};
150-
}
151-
147+
webGlPrototypeString(functionName) {
152148
if(functionName) {
153-
return this.webGlPrototypeStringFromFunctionNames(this.traceFunctionCalls(functionName, [], opt).reverse(), opt);
149+
return this.webGlPrototypeStringFromFunctionNames(this.traceFunctionCalls(functionName, []).reverse());
154150
}
155-
return this.webGlPrototypeStringFromFunctionNames(Object.keys(this.nodeMap), opt);
151+
return this.webGlPrototypeStringFromFunctionNames(Object.keys(this.nodeMap));
156152
}
157153

158154
//---------------------------------------------------------

src/backend/base-function-node.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = class BaseFunctionNode {
5252
//
5353
// Missing jsFunction object exception
5454
//
55-
if(jsFunction == null) {
55+
if(jsFunction === null) {
5656
throw 'jsFunction, parameter is null';
5757
}
5858

@@ -88,7 +88,7 @@ module.exports = class BaseFunctionNode {
8888
//
8989
this.paramNames = utils.getParamNamesFromString(this.jsFunctionString);
9090
if(paramTypeArray != null) {
91-
if(paramTypeArray.length != this.paramNames.length) {
91+
if(paramTypeArray.length !== this.paramNames.length) {
9292
throw 'Invalid argument type array length, against function length -> ('+
9393
paramTypeArray.length+','+
9494
this.paramNames.length+
@@ -176,9 +176,9 @@ module.exports = class BaseFunctionNode {
176176
/// Returns the converted webgl shader function equivalent of the JS function
177177
///
178178
/// Returns:
179-
/// {String} webgl function string, result is cached under this.webglFunctionString
179+
/// {String} webgl function string, result is cached under this.webGlFunctionString
180180
///
181-
getFunctionString(opt) {
181+
getFunctionString() {
182182
return this.functionString;
183183
}
184184

src/backend/gpu/gpu-function-node.js

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const localPrefix = 'this.';
1717
const constantsPrefix = 'this.constants.';
1818

1919
function isIdentifierKernelParam(paramName, ast, funcParam) {
20-
return funcParam.paramNames.indexOf(paramName) != -1;
20+
return funcParam.paramNames.indexOf(paramName) !== -1;
2121
}
2222

2323
function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
@@ -27,7 +27,7 @@ function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
2727
throw 'Error unexpected identifier ' + paramName + ' on line ' + start.line;
2828
} else {
2929
const actualType = funcParam.paramType[funcParam.paramNames.indexOf(paramName)];
30-
if (actualType != expectedType) {
30+
if (actualType !== expectedType) {
3131
throw 'Error unexpected identifier ' + paramName + ' on line ' + start.line;
3232
}
3333
}
@@ -69,31 +69,27 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
6969
super(functionName, jsFunction, paramTypeArray, returnType);
7070
this.gpu = null;
7171
this.opt = null;
72-
this.jsFunctionString = null;
73-
this.webGlFunctionPrototypeString = null;
7472
}
7573

76-
generate(inNode, _opt) {
77-
this.gpu = inNode.gpu;
74+
generate(_opt) {
7875
const opt = this.opt = _opt || {};
7976
if (opt.debug) {
80-
console.log(inNode);
77+
console.log(this);
8178
}
82-
this.jsFunctionString = inNode.jsFunctionString;
8379
if (opt.prototypeOnly) {
84-
return GPUFunctionNode.astFunctionPrototype(inNode.getJsAST(), [], inNode).join('').trim();
80+
return GPUFunctionNode.astFunctionPrototype(this.getJsAST(), [], this).join('').trim();
8581
} else {
86-
inNode.functionStringArray = this.astGeneric(inNode.getJsAST(), [], inNode);
82+
this.functionStringArray = this.astGeneric(this.getJsAST(), [], this);
8783
}
88-
inNode.functionString = webGlRegexOptimize(
89-
inNode.functionStringArray.join('').trim()
90-
);
91-
return inNode.functionString;
84+
this.functionString = webGlRegexOptimize(
85+
this.functionStringArray.join('').trim()
86+
);
87+
return this.functionString;
9288
}
9389

9490
isIdentifierConstant(paramName) {
9591
if (!this.opt.constants) return false;
96-
return this.opt.constants.indexOf(paramName) != -1;
92+
return this.opt.constants.indexOf(paramName) !== -1;
9793
}
9894

9995
/// Prases the abstract syntax tree, genericially to its respective function
@@ -347,17 +343,17 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
347343
astBinaryExpression(ast, retArr, funcParam) {
348344
retArr.push('(');
349345

350-
if (ast.operator == '%') {
346+
if (ast.operator === '%') {
351347
retArr.push('mod(');
352348
this.astGeneric(ast.left, retArr, funcParam);
353349
retArr.push(',');
354350
this.astGeneric(ast.right, retArr, funcParam);
355351
retArr.push(')');
356-
} else if (ast.operator == '===') {
352+
} else if (ast.operator === '===') {
357353
this.astGeneric(ast.left, retArr, funcParam);
358354
retArr.push('==');
359355
this.astGeneric(ast.right, retArr, funcParam);
360-
} else if (ast.operator == '!==') {
356+
} else if (ast.operator === '!==') {
361357
this.astGeneric(ast.left, retArr, funcParam);
362358
retArr.push('!=');
363359
this.astGeneric(ast.right, retArr, funcParam);
@@ -380,24 +376,24 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
380376
///
381377
/// @returns the append retArr
382378
astIdentifierExpression(idtNode, retArr, funcParam) {
383-
if (idtNode.type != 'Identifier') {
379+
if (idtNode.type !== 'Identifier') {
384380
throw astErrorOutput(
385381
'IdentifierExpression - not an Identifier',
386382
ast, funcParam
387383
);
388384
}
389385

390-
if (idtNode.name == 'gpu_threadX') {
386+
if (idtNode.name === 'gpu_threadX') {
391387
retArr.push('threadId.x');
392-
} else if (idtNode.name == 'gpu_threadY') {
388+
} else if (idtNode.name === 'gpu_threadY') {
393389
retArr.push('threadId.y');
394-
} else if (idtNode.name == 'gpu_threadZ') {
390+
} else if (idtNode.name === 'gpu_threadZ') {
395391
retArr.push('threadId.z');
396-
} else if (idtNode.name == 'gpu_dimensionsX') {
392+
} else if (idtNode.name === 'gpu_dimensionsX') {
397393
retArr.push('uOutputDim.x');
398-
} else if (idtNode.name == 'gpu_dimensionsY') {
394+
} else if (idtNode.name === 'gpu_dimensionsY') {
399395
retArr.push('uOutputDim.y');
400-
} else if (idtNode.name == 'gpu_dimensionsZ') {
396+
} else if (idtNode.name === 'gpu_dimensionsZ') {
401397
retArr.push('uOutputDim.z');
402398
} else {
403399
retArr.push('user_'+idtNode.name);
@@ -412,16 +408,16 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
412408
///
413409
/// @returns the prased openclgl string
414410
astForStatement(forNode, retArr, funcParam) {
415-
if (forNode.type != 'ForStatement') {
411+
if (forNode.type !== 'ForStatement') {
416412
throw astErrorOutput(
417413
'Invalid for statment',
418414
ast, funcParam
419415
);
420416
}
421417

422-
if (forNode.test && forNode.test.type == 'BinaryExpression') {
423-
if (forNode.test.right.type == 'Identifier'
424-
&& forNode.test.operator == '<'
418+
if (forNode.test && forNode.test.type === 'BinaryExpression') {
419+
if (forNode.test.right.type === 'Identifier'
420+
&& forNode.test.operator === '<'
425421
&& this.isIdentifierConstant(forNode.test.right.name) == false) {
426422

427423
if (this.opt.loopMaxIterations === undefined) {
@@ -445,8 +441,8 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
445441
retArr.push(forNode.test.operator);
446442
this.astGeneric(forNode.test.right, retArr, funcParam);
447443
retArr.push(') {\n');
448-
if (forNode.body.type == 'BlockStatement') {
449-
for (var i = 0; i < forNode.body.body.length; i++) {
444+
if (forNode.body.type === 'BlockStatement') {
445+
for (let i = 0; i < forNode.body.body.length; i++) {
450446
this.astGeneric(forNode.body.body[i], retArr, funcParam);
451447
}
452448
} else {
@@ -483,7 +479,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
483479
///
484480
/// @returns the prased openclgl string
485481
astWhileStatement(whileNode, retArr, funcParam) {
486-
if (whileNode.type != 'WhileStatement') {
482+
if (whileNode.type !== 'WhileStatement') {
487483
throw astErrorOutput(
488484
'Invalid while statment',
489485
ast, funcParam
@@ -504,7 +500,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
504500
}
505501

506502
astAssignmentExpression(assNode, retArr, funcParam) {
507-
if (assNode.operator == '%=') {
503+
if (assNode.operator === '%=') {
508504
this.astGeneric(assNode.left, retArr, funcParam);
509505
retArr.push('=');
510506
retArr.push('mod(');
@@ -566,7 +562,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
566562
retArr.push('if (');
567563
this.astGeneric(ifNode.test, retArr, funcParam);
568564
retArr.push(')');
569-
if (ifNode.consequent.type == 'BlockStatement') {
565+
if (ifNode.consequent.type === 'BlockStatement') {
570566
this.astGeneric(ifNode.consequent, retArr, funcParam);
571567
} else {
572568
retArr.push(' {\n');
@@ -576,7 +572,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
576572

577573
if (ifNode.alternate) {
578574
retArr.push('else ');
579-
if (ifNode.alternate.type == 'BlockStatement') {
575+
if (ifNode.alternate.type === 'BlockStatement') {
580576
this.astGeneric(ifNode.alternate, retArr, funcParam);
581577
} else {
582578
retArr.push(' {\n');
@@ -639,16 +635,16 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
639635

640636
astMemberExpression(mNode, retArr, funcParam) {
641637
if (mNode.computed) {
642-
if (mNode.object.type == 'Identifier') {
638+
if (mNode.object.type === 'Identifier') {
643639
// Working logger
644640
const reqName = mNode.object.name;
645641
const funcName = funcParam.funcName || 'kernel';
646642
let assumeNotTexture = false;
647643

648644
// Possibly an array request - handle it as such
649-
if (funcParam != 'kernel' && funcParam.paramNames) {
645+
if (funcParam !== 'kernel' && funcParam.paramNames) {
650646
var idx = funcParam.paramNames.indexOf(reqName);
651-
if (idx >= 0 && funcParam.paramType[idx] == 'float') {
647+
if (idx >= 0 && funcParam.paramType[idx] === 'float') {
652648
assumeNotTexture = true;
653649
}
654650
}
@@ -701,17 +697,17 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
701697
unrolled = 'constants_'+unrolled.slice(constantsPrefix.length);
702698
}
703699

704-
if (unrolled_lc == 'this.thread.x') {
700+
if (unrolled_lc === 'this.thread.x') {
705701
retArr.push('threadId.x');
706-
} else if (unrolled_lc == 'this.thread.y') {
702+
} else if (unrolled_lc === 'this.thread.y') {
707703
retArr.push('threadId.y');
708-
} else if (unrolled_lc == 'this.thread.z') {
704+
} else if (unrolled_lc === 'this.thread.z') {
709705
retArr.push('threadId.z');
710-
} else if (unrolled_lc == 'this.dimensions.x') {
706+
} else if (unrolled_lc === 'this.dimensions.x') {
711707
retArr.push('uOutputDim.x');
712-
} else if (unrolled_lc == 'this.dimensions.y') {
708+
} else if (unrolled_lc === 'this.dimensions.y') {
713709
retArr.push('uOutputDim.y');
714-
} else if (unrolled_lc == 'this.dimensions.z') {
710+
} else if (unrolled_lc === 'this.dimensions.z') {
715711
retArr.push('uOutputDim.z');
716712
} else {
717713
retArr.push(unrolled);
@@ -738,13 +734,13 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
738734
///
739735
/// @returns {String} the function namespace call, unrolled
740736
astMemberExpressionUnroll(ast, funcParam) {
741-
if (ast.type == 'Identifier') {
737+
if (ast.type === 'Identifier') {
742738
return ast.name;
743-
} else if (ast.type == 'ThisExpression') {
739+
} else if (ast.type === 'ThisExpression') {
744740
return 'this';
745741
}
746742

747-
if (ast.type == 'MemberExpression') {
743+
if (ast.type === 'MemberExpression') {
748744
if (ast.object && ast.property) {
749745
return (
750746
this.astMemberExpressionUnroll(ast.object, funcParam) +
@@ -855,14 +851,10 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
855851
/// Returns:
856852
/// {String} webgl function string, result is cached under this.getFunctionPrototypeString
857853
///
858-
getFunctionPrototypeString(opt) {
859-
opt = opt || {};
854+
getFunctionPrototypeString(isRootKernel, options) {
860855
if(this.webGlFunctionPrototypeString) {
861856
return this.webGlFunctionPrototypeString;
862857
}
863-
return this.functionPrototypeString = new FunctionNodeWebGl(this, {
864-
prototypeOnly: true,
865-
isRootKernel: opt.isRootKernel
866-
});
858+
return this.functionPrototypeString = this.generate(options);
867859
}
868-
}
860+
};

0 commit comments

Comments
 (0)