Diff
Modified: trunk/Tools/ChangeLog (221449 => 221450)
--- trunk/Tools/ChangeLog 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/ChangeLog 2017-08-31 23:00:22 UTC (rev 221450)
@@ -1,5 +1,48 @@
2017-08-31 Filip Pizlo <[email protected]>
+ WSL should support dereference (^)
+ https://bugs.webkit.org/show_bug.cgi?id=176192
+
+ Reviewed by Myles Maxfield.
+
+ This implements DereferenceExpression.
+
+ It also renames Evaluator.prototype.visitFunctionBody, because that name confusingly implies
+ that there is a class named FunctionBody. It's now called runBody.
+
+ I made the check to see if a type is a pointer type be the isPtr method, so that we can have
+ other pointer types that are implemented via something other than PtrType. We might want it if
+ for example we wanted a pointer type that is generic over address space.
+
+ * WebGPUShadingLanguageRI/All.js:
+ * WebGPUShadingLanguageRI/CallFunction.js:
+ (callFunction):
+ * WebGPUShadingLanguageRI/Checker.js:
+ (Checker.prototype.visitProtocolDecl.set throw):
+ * WebGPUShadingLanguageRI/DereferenceExpression.js: Added.
+ (DereferenceExpression):
+ (DereferenceExpression.prototype.get ptr):
+ (DereferenceExpression.prototype.toString):
+ * WebGPUShadingLanguageRI/Evaluator.js:
+ (Evaluator.prototype.visitFunctionLikeBlock):
+ (Evaluator.prototype._dereference):
+ (Evaluator.prototype.visitDereferenceExpression):
+ (Evaluator.prototype.visitFunctionBody): Deleted.
+ * WebGPUShadingLanguageRI/PtrType.js:
+ (PtrType.prototype.get isPtr):
+ (PtrType.prototype.populateDefaultValue):
+ * WebGPUShadingLanguageRI/Rewriter.js:
+ (Rewriter.prototype.visitAssignment):
+ (Rewriter.prototype.visitDereferenceExpression):
+ * WebGPUShadingLanguageRI/Test.js:
+ (TEST_simpleDereference):
+ * WebGPUShadingLanguageRI/Type.js:
+ (Type.prototype.get isPtr):
+ * WebGPUShadingLanguageRI/Visitor.js:
+ (Visitor.prototype.visitDereferenceExpression):
+
+2017-08-31 Filip Pizlo <[email protected]>
+
There should only be one callFunction API in WSL
https://bugs.webkit.org/show_bug.cgi?id=176189
Modified: trunk/Tools/WebGPUShadingLanguageRI/All.js (221449 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/All.js 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/WebGPUShadingLanguageRI/All.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -44,6 +44,7 @@
load("Checker.js");
load("CommaExpression.js");
load("ConstexprTypeParameter.js");
+load("DereferenceExpression.js");
load("EBuffer.js");
load("EBufferBuilder.js");
load("EPtr.js");
Modified: trunk/Tools/WebGPUShadingLanguageRI/CallFunction.js (221449 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/CallFunction.js 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/WebGPUShadingLanguageRI/CallFunction.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -33,7 +33,7 @@
throw new WTypeError("<callFunction>", "Cannot resolve function call " + name + "<" + typeArguments + ">(" + argumentList + ")");
for (let i = 0; i < func.parameters.length; ++i)
func.parameters[i].ePtr.copyFrom(argumentList[i].ePtr, argumentTypes[i].size);
- let result = new Evaluator(program).visitFunctionBody(func.body);
+ let result = new Evaluator(program).runBody(func.body);
return new TypedValue(func.returnType, result);
}
Modified: trunk/Tools/WebGPUShadingLanguageRI/Checker.js (221449 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/Checker.js 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/WebGPUShadingLanguageRI/Checker.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -132,6 +132,15 @@
return lhsType;
}
+ visitDereferenceExpression(node)
+ {
+ let type = node.ptr.visit(this).unifyNode;
+ if (!type.isPtr)
+ throw new WTypeError(node.origin.originString, "Type passed to dereference is not a pointer: " + type);
+ node.type = type.elementType;
+ return node.type;
+ }
+
visitVariableRef(node)
{
return node.variable.type;
Added: trunk/Tools/WebGPUShadingLanguageRI/DereferenceExpression.js (0 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/DereferenceExpression.js (rev 0)
+++ trunk/Tools/WebGPUShadingLanguageRI/DereferenceExpression.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+"use strict";
+
+class DereferenceExpression extends _expression_ {
+ constructor(origin, ptr)
+ {
+ super(origin);
+ this._ptr = ptr;
+ }
+
+ get ptr() { return this._ptr; }
+
+ toString()
+ {
+ return "^(" + this.ptr + ")";
+ }
+}
Modified: trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js (221449 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -32,7 +32,7 @@
this._program = program;
}
- visitFunctionBody(block)
+ runBody(block)
{
try {
block.visit(this);
@@ -55,7 +55,7 @@
node.argumentList[i].visit(this),
node.parameters[i].type.size);
}
- return this.visitFunctionBody(node.body);
+ return this.runBody(node.body);
}
visitReturn(node)
@@ -79,6 +79,19 @@
return result;
}
+ _dereference(ptr, type)
+ {
+ let size = type.size;
+ let result = new EPtr(new EBuffer(size), 0);
+ result.copyFrom(ptr.loadValue(), size);
+ return result;
+ }
+
+ visitDereferenceExpression(node)
+ {
+ return this._dereference(node.ptr.visit(this), node.type);
+ }
+
visitCommaExpression(node)
{
let result;
Modified: trunk/Tools/WebGPUShadingLanguageRI/PtrType.js (221449 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/PtrType.js 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/WebGPUShadingLanguageRI/PtrType.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -25,6 +25,13 @@
"use strict";
class PtrType extends ReferenceType {
+ get isPtr() { return true; }
+
+ populateDefaultValue(buffer, offset)
+ {
+ buffer.set(offset, null);
+ }
+
unifyImpl(unificationContext, other)
{
if (!(other instanceof PtrType))
Modified: trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js (221449 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -139,10 +139,17 @@
visitAssignment(node)
{
let result = new Assignment(node.origin, node.lhs.visit(this), node.rhs.visit(this));
- result.type = node.type.visit(this);
+ result.type = node.type ? node.type.visit(this) : null;
return result;
}
+ visitDereferenceExpression(node)
+ {
+ let result = new DereferenceExpression(node.origin, node.ptr.visit(this));
+ result.type = node.type ? node.type.visit(this) : null;
+ return result;
+ }
+
visitVariableRef(node)
{
node.variable = this._getMapping(node.variable);
Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (221449 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/Test.js 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -111,6 +111,18 @@
checkInt(program, callFunction(program, "foo", [], []), 0);
}
+function TEST_simpleDereference()
+{
+ let program = doPrep(`
+ int foo(device int^ p)
+ {
+ return ^p;
+ }`);
+ let buffer = new EBuffer(1);
+ buffer.set(0, 13);
+ checkInt(program, callFunction(program, "foo", [], [TypedValue.box(new PtrType(null, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 13);
+}
+
let before = preciseTime();
let filter = /.*/; // run everything by default
Modified: trunk/Tools/WebGPUShadingLanguageRI/Type.js (221449 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/Type.js 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/WebGPUShadingLanguageRI/Type.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -27,6 +27,7 @@
class Type extends Node {
get typeParameters() { return []; }
get kind() { return Type; }
+ get isPtr() { return false; }
inherits(protocol)
{
Modified: trunk/Tools/WebGPUShadingLanguageRI/Visitor.js (221449 => 221450)
--- trunk/Tools/WebGPUShadingLanguageRI/Visitor.js 2017-08-31 22:22:59 UTC (rev 221449)
+++ trunk/Tools/WebGPUShadingLanguageRI/Visitor.js 2017-08-31 23:00:22 UTC (rev 221450)
@@ -153,6 +153,11 @@
node.rhs.visit(this);
}
+ visitDereferenceExpression(node)
+ {
+ node.ptr.visit(this);
+ }
+
visitVariableRef(node)
{
}