Skip to content
This repository has been archived by the owner on Aug 16, 2018. It is now read-only.

Commit

Permalink
have initial validator kernels building, but not actual
Browse files Browse the repository at this point in the history
  • Loading branch information
robertleeplummerjr committed May 5, 2017
1 parent 5b74db9 commit 62591e3
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 190 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ gulp.task('build', function() {
.bundle()
.pipe(source('gpu.js'))
.pipe(buffer())
.pipe(header(fs.readFileSync('./src/wrapper/prefix.js', 'utf8'), { pkg : pkg } ))
.pipe(header(fs.readFileSync('./src/wrapper/prefix.js', 'utf8'), { pkg : pkg }))
.pipe(gulp.dest('bin'));
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"devDependencies": {
"babel-plugin-syntax-async-functions": "^6.5.0",
"browser-sync": "^2.18.2",
"browserify": "^14.3.0",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.0",
"gulp-header": "^1.7.1",
Expand Down
20 changes: 8 additions & 12 deletions src/backend/base-function-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = class BaseFunctionBuilder {
///
/// Returns:
/// {[String,...]} Returning list of function names that is traced. Including itself.
traceFunctionCalls(functionName, retList, opt) {
traceFunctionCalls(functionName, retList) {
functionName = functionName || 'kernel';
retList = retList || [];

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

fNode.getFunctionString(opt); //ensure JS trace is done
fNode.getFunctionString(); //ensure JS trace is done
for(let i = 0; i < fNode.calledFunctions.length; ++i) {
this.traceFunctionCalls(fNode.calledFunctions[i], retList, opt);
this.traceFunctionCalls(fNode.calledFunctions[i], retList);
}
}
}
Expand All @@ -93,12 +93,12 @@ module.exports = class BaseFunctionBuilder {
/// Returns:
/// {String} The full webgl string, of all the various functions. Trace optimized if functionName given
///
webGlStringFromFunctionNames(functionList, opt) {
webGlStringFromFunctionNames(functionList) {
const ret = [];
for(let i = 0; i < functionList.length; ++i) {
const node = this.nodeMap[functionList[i]];
if(node) {
ret.push(this.nodeMap[functionList[i]].getFunctionString(opt));
ret.push(this.nodeMap[functionList[i]].getFunctionString());
}
}
return ret.join('\n');
Expand Down Expand Up @@ -144,15 +144,11 @@ module.exports = class BaseFunctionBuilder {
/// Returns:
/// {String} The full webgl string, of all the various functions. Trace optimized if functionName given
///
webGlPrototypeString(functionName, opt) {
if (opt === undefined) {
opt = {};
}

webGlPrototypeString(functionName) {
if(functionName) {
return this.webGlPrototypeStringFromFunctionNames(this.traceFunctionCalls(functionName, [], opt).reverse(), opt);
return this.webGlPrototypeStringFromFunctionNames(this.traceFunctionCalls(functionName, []).reverse());
}
return this.webGlPrototypeStringFromFunctionNames(Object.keys(this.nodeMap), opt);
return this.webGlPrototypeStringFromFunctionNames(Object.keys(this.nodeMap));
}

//---------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/backend/base-function-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = class BaseFunctionNode {
//
// Missing jsFunction object exception
//
if(jsFunction == null) {
if(jsFunction === null) {
throw 'jsFunction, parameter is null';
}

Expand Down Expand Up @@ -88,7 +88,7 @@ module.exports = class BaseFunctionNode {
//
this.paramNames = utils.getParamNamesFromString(this.jsFunctionString);
if(paramTypeArray != null) {
if(paramTypeArray.length != this.paramNames.length) {
if(paramTypeArray.length !== this.paramNames.length) {
throw 'Invalid argument type array length, against function length -> ('+
paramTypeArray.length+','+
this.paramNames.length+
Expand Down Expand Up @@ -176,9 +176,9 @@ module.exports = class BaseFunctionNode {
/// Returns the converted webgl shader function equivalent of the JS function
///
/// Returns:
/// {String} webgl function string, result is cached under this.webglFunctionString
/// {String} webgl function string, result is cached under this.webGlFunctionString
///
getFunctionString(opt) {
getFunctionString() {
return this.functionString;
}

Expand Down
100 changes: 46 additions & 54 deletions src/backend/gpu/gpu-function-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const localPrefix = 'this.';
const constantsPrefix = 'this.constants.';

function isIdentifierKernelParam(paramName, ast, funcParam) {
return funcParam.paramNames.indexOf(paramName) != -1;
return funcParam.paramNames.indexOf(paramName) !== -1;
}

function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
Expand All @@ -27,7 +27,7 @@ function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
throw 'Error unexpected identifier ' + paramName + ' on line ' + start.line;
} else {
const actualType = funcParam.paramType[funcParam.paramNames.indexOf(paramName)];
if (actualType != expectedType) {
if (actualType !== expectedType) {
throw 'Error unexpected identifier ' + paramName + ' on line ' + start.line;
}
}
Expand Down Expand Up @@ -69,31 +69,27 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
super(functionName, jsFunction, paramTypeArray, returnType);
this.gpu = null;
this.opt = null;
this.jsFunctionString = null;
this.webGlFunctionPrototypeString = null;
}

generate(inNode, _opt) {
this.gpu = inNode.gpu;
generate(_opt) {
const opt = this.opt = _opt || {};
if (opt.debug) {
console.log(inNode);
console.log(this);
}
this.jsFunctionString = inNode.jsFunctionString;
if (opt.prototypeOnly) {
return GPUFunctionNode.astFunctionPrototype(inNode.getJsAST(), [], inNode).join('').trim();
return GPUFunctionNode.astFunctionPrototype(this.getJsAST(), [], this).join('').trim();
} else {
inNode.functionStringArray = this.astGeneric(inNode.getJsAST(), [], inNode);
this.functionStringArray = this.astGeneric(this.getJsAST(), [], this);
}
inNode.functionString = webGlRegexOptimize(
inNode.functionStringArray.join('').trim()
);
return inNode.functionString;
this.functionString = webGlRegexOptimize(
this.functionStringArray.join('').trim()
);
return this.functionString;
}

isIdentifierConstant(paramName) {
if (!this.opt.constants) return false;
return this.opt.constants.indexOf(paramName) != -1;
return this.opt.constants.indexOf(paramName) !== -1;
}

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

if (ast.operator == '%') {
if (ast.operator === '%') {
retArr.push('mod(');
this.astGeneric(ast.left, retArr, funcParam);
retArr.push(',');
this.astGeneric(ast.right, retArr, funcParam);
retArr.push(')');
} else if (ast.operator == '===') {
} else if (ast.operator === '===') {
this.astGeneric(ast.left, retArr, funcParam);
retArr.push('==');
this.astGeneric(ast.right, retArr, funcParam);
} else if (ast.operator == '!==') {
} else if (ast.operator === '!==') {
this.astGeneric(ast.left, retArr, funcParam);
retArr.push('!=');
this.astGeneric(ast.right, retArr, funcParam);
Expand All @@ -380,24 +376,24 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
///
/// @returns the append retArr
astIdentifierExpression(idtNode, retArr, funcParam) {
if (idtNode.type != 'Identifier') {
if (idtNode.type !== 'Identifier') {
throw astErrorOutput(
'IdentifierExpression - not an Identifier',
ast, funcParam
);
}

if (idtNode.name == 'gpu_threadX') {
if (idtNode.name === 'gpu_threadX') {
retArr.push('threadId.x');
} else if (idtNode.name == 'gpu_threadY') {
} else if (idtNode.name === 'gpu_threadY') {
retArr.push('threadId.y');
} else if (idtNode.name == 'gpu_threadZ') {
} else if (idtNode.name === 'gpu_threadZ') {
retArr.push('threadId.z');
} else if (idtNode.name == 'gpu_dimensionsX') {
} else if (idtNode.name === 'gpu_dimensionsX') {
retArr.push('uOutputDim.x');
} else if (idtNode.name == 'gpu_dimensionsY') {
} else if (idtNode.name === 'gpu_dimensionsY') {
retArr.push('uOutputDim.y');
} else if (idtNode.name == 'gpu_dimensionsZ') {
} else if (idtNode.name === 'gpu_dimensionsZ') {
retArr.push('uOutputDim.z');
} else {
retArr.push('user_'+idtNode.name);
Expand All @@ -412,16 +408,16 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
///
/// @returns the prased openclgl string
astForStatement(forNode, retArr, funcParam) {
if (forNode.type != 'ForStatement') {
if (forNode.type !== 'ForStatement') {
throw astErrorOutput(
'Invalid for statment',
ast, funcParam
);
}

if (forNode.test && forNode.test.type == 'BinaryExpression') {
if (forNode.test.right.type == 'Identifier'
&& forNode.test.operator == '<'
if (forNode.test && forNode.test.type === 'BinaryExpression') {
if (forNode.test.right.type === 'Identifier'
&& forNode.test.operator === '<'
&& this.isIdentifierConstant(forNode.test.right.name) == false) {

if (this.opt.loopMaxIterations === undefined) {
Expand All @@ -445,8 +441,8 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
retArr.push(forNode.test.operator);
this.astGeneric(forNode.test.right, retArr, funcParam);
retArr.push(') {\n');
if (forNode.body.type == 'BlockStatement') {
for (var i = 0; i < forNode.body.body.length; i++) {
if (forNode.body.type === 'BlockStatement') {
for (let i = 0; i < forNode.body.body.length; i++) {
this.astGeneric(forNode.body.body[i], retArr, funcParam);
}
} else {
Expand Down Expand Up @@ -483,7 +479,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
///
/// @returns the prased openclgl string
astWhileStatement(whileNode, retArr, funcParam) {
if (whileNode.type != 'WhileStatement') {
if (whileNode.type !== 'WhileStatement') {
throw astErrorOutput(
'Invalid while statment',
ast, funcParam
Expand All @@ -504,7 +500,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
}

astAssignmentExpression(assNode, retArr, funcParam) {
if (assNode.operator == '%=') {
if (assNode.operator === '%=') {
this.astGeneric(assNode.left, retArr, funcParam);
retArr.push('=');
retArr.push('mod(');
Expand Down Expand Up @@ -566,7 +562,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
retArr.push('if (');
this.astGeneric(ifNode.test, retArr, funcParam);
retArr.push(')');
if (ifNode.consequent.type == 'BlockStatement') {
if (ifNode.consequent.type === 'BlockStatement') {
this.astGeneric(ifNode.consequent, retArr, funcParam);
} else {
retArr.push(' {\n');
Expand All @@ -576,7 +572,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {

if (ifNode.alternate) {
retArr.push('else ');
if (ifNode.alternate.type == 'BlockStatement') {
if (ifNode.alternate.type === 'BlockStatement') {
this.astGeneric(ifNode.alternate, retArr, funcParam);
} else {
retArr.push(' {\n');
Expand Down Expand Up @@ -639,16 +635,16 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {

astMemberExpression(mNode, retArr, funcParam) {
if (mNode.computed) {
if (mNode.object.type == 'Identifier') {
if (mNode.object.type === 'Identifier') {
// Working logger
const reqName = mNode.object.name;
const funcName = funcParam.funcName || 'kernel';
let assumeNotTexture = false;

// Possibly an array request - handle it as such
if (funcParam != 'kernel' && funcParam.paramNames) {
if (funcParam !== 'kernel' && funcParam.paramNames) {
var idx = funcParam.paramNames.indexOf(reqName);
if (idx >= 0 && funcParam.paramType[idx] == 'float') {
if (idx >= 0 && funcParam.paramType[idx] === 'float') {
assumeNotTexture = true;
}
}
Expand Down Expand Up @@ -701,17 +697,17 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
unrolled = 'constants_'+unrolled.slice(constantsPrefix.length);
}

if (unrolled_lc == 'this.thread.x') {
if (unrolled_lc === 'this.thread.x') {
retArr.push('threadId.x');
} else if (unrolled_lc == 'this.thread.y') {
} else if (unrolled_lc === 'this.thread.y') {
retArr.push('threadId.y');
} else if (unrolled_lc == 'this.thread.z') {
} else if (unrolled_lc === 'this.thread.z') {
retArr.push('threadId.z');
} else if (unrolled_lc == 'this.dimensions.x') {
} else if (unrolled_lc === 'this.dimensions.x') {
retArr.push('uOutputDim.x');
} else if (unrolled_lc == 'this.dimensions.y') {
} else if (unrolled_lc === 'this.dimensions.y') {
retArr.push('uOutputDim.y');
} else if (unrolled_lc == 'this.dimensions.z') {
} else if (unrolled_lc === 'this.dimensions.z') {
retArr.push('uOutputDim.z');
} else {
retArr.push(unrolled);
Expand All @@ -738,13 +734,13 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
///
/// @returns {String} the function namespace call, unrolled
astMemberExpressionUnroll(ast, funcParam) {
if (ast.type == 'Identifier') {
if (ast.type === 'Identifier') {
return ast.name;
} else if (ast.type == 'ThisExpression') {
} else if (ast.type === 'ThisExpression') {
return 'this';
}

if (ast.type == 'MemberExpression') {
if (ast.type === 'MemberExpression') {
if (ast.object && ast.property) {
return (
this.astMemberExpressionUnroll(ast.object, funcParam) +
Expand Down Expand Up @@ -855,14 +851,10 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
/// Returns:
/// {String} webgl function string, result is cached under this.getFunctionPrototypeString
///
getFunctionPrototypeString(opt) {
opt = opt || {};
getFunctionPrototypeString(isRootKernel, options) {
if(this.webGlFunctionPrototypeString) {
return this.webGlFunctionPrototypeString;
}
return this.functionPrototypeString = new FunctionNodeWebGl(this, {
prototypeOnly: true,
isRootKernel: opt.isRootKernel
});
return this.functionPrototypeString = this.generate(options);
}
}
};
Loading

0 comments on commit 62591e3

Please sign in to comment.