<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[188778] trunk/Source/JavaScriptCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/188778">188778</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-08-21 14:46:22 -0700 (Fri, 21 Aug 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Implement WebAssembly function parser
https://bugs.webkit.org/show_bug.cgi?id=147738
Patch by Sukolsak Sakshuwong <sukolsak@gmail.com> on 2015-08-21
Reviewed by Filip Pizlo.
Implement WebAssembly function parser for WebAssembly files produced by pack-asmjs
<https://github.com/WebAssembly/polyfill-prototype-1>. This patch parses only
some instructions on statements and int32 expressions. Parsing of the rest
will be implemented in subsequent patches. The instruction lists in WASMConstants.h
are slightly modified from
<https://github.com/WebAssembly/polyfill-prototype-1/blob/master/src/shared.h>.
* CMakeLists.txt:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
* JavaScriptCore.xcodeproj/project.pbxproj:
* wasm/WASMConstants.h: Added.
* wasm/WASMFormat.h:
* wasm/WASMFunctionParser.cpp: Added.
(JSC::WASMFunctionParser::checkSyntax):
(JSC::WASMFunctionParser::parseFunction):
(JSC::WASMFunctionParser::parseLocalVariables):
(JSC::WASMFunctionParser::parseStatement):
(JSC::WASMFunctionParser::parseSetLocalStatement):
(JSC::WASMFunctionParser::parseReturnStatement):
(JSC::WASMFunctionParser::parseBlockStatement):
(JSC::WASMFunctionParser::parseExpression):
(JSC::WASMFunctionParser::parseExpressionI32):
(JSC::WASMFunctionParser::parseImmediateExpressionI32):
* wasm/WASMFunctionParser.h: Added.
(JSC::WASMFunctionParser::WASMFunctionParser):
* wasm/WASMFunctionSyntaxChecker.h: Renamed from Source/JavaScriptCore/wasm/WASMMagicNumber.h.
* wasm/WASMModuleParser.cpp:
(JSC::WASMModuleParser::WASMModuleParser):
(JSC::WASMModuleParser::parseFunctionDefinitionSection):
(JSC::WASMModuleParser::parseFunctionDefinition):
* wasm/WASMModuleParser.h:
* wasm/WASMReader.cpp:
(JSC::WASMReader::readType):
(JSC::WASMReader::readExpressionType):
(JSC::WASMReader::readExportFormat):
(JSC::WASMReader::readOpStatement):
(JSC::WASMReader::readOpExpressionI32):
(JSC::WASMReader::readVariableTypes):
(JSC::WASMReader::readOp):
* wasm/WASMReader.h:
(JSC::WASMReader::offset):
(JSC::WASMReader::setOffset):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreCMakeListstxt">trunk/Source/JavaScriptCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorevcxprojJavaScriptCorevcxproj">trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorevcxprojJavaScriptCorevcxprojfilters">trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFormath">trunk/Source/JavaScriptCore/wasm/WASMFormat.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMModuleParsercpp">trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMModuleParserh">trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMReadercpp">trunk/Source/JavaScriptCore/wasm/WASMReader.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMReaderh">trunk/Source/JavaScriptCore/wasm/WASMReader.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCorewasmWASMConstantsh">trunk/Source/JavaScriptCore/wasm/WASMConstants.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionParsercpp">trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionParserh">trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionSyntaxCheckerh">trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCorewasmWASMMagicNumberh">trunk/Source/JavaScriptCore/wasm/WASMMagicNumber.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/CMakeLists.txt (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/CMakeLists.txt        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/CMakeLists.txt        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -423,6 +423,7 @@
</span><span class="cx"> tools/JSDollarVMPrototype.cpp
</span><span class="cx">
</span><span class="cx"> wasm/JSWASMModule.cpp
</span><ins>+ wasm/WASMFunctionParser.cpp
</ins><span class="cx"> wasm/WASMModuleParser.cpp
</span><span class="cx"> wasm/WASMReader.cpp
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -1,3 +1,54 @@
</span><ins>+2015-08-21 Sukolsak Sakshuwong <sukolsak@gmail.com>
+
+ Implement WebAssembly function parser
+ https://bugs.webkit.org/show_bug.cgi?id=147738
+
+ Reviewed by Filip Pizlo.
+
+ Implement WebAssembly function parser for WebAssembly files produced by pack-asmjs
+ <https://github.com/WebAssembly/polyfill-prototype-1>. This patch parses only
+ some instructions on statements and int32 expressions. Parsing of the rest
+ will be implemented in subsequent patches. The instruction lists in WASMConstants.h
+ are slightly modified from
+ <https://github.com/WebAssembly/polyfill-prototype-1/blob/master/src/shared.h>.
+
+ * CMakeLists.txt:
+ * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
+ * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
+ * JavaScriptCore.xcodeproj/project.pbxproj:
+ * wasm/WASMConstants.h: Added.
+ * wasm/WASMFormat.h:
+ * wasm/WASMFunctionParser.cpp: Added.
+ (JSC::WASMFunctionParser::checkSyntax):
+ (JSC::WASMFunctionParser::parseFunction):
+ (JSC::WASMFunctionParser::parseLocalVariables):
+ (JSC::WASMFunctionParser::parseStatement):
+ (JSC::WASMFunctionParser::parseSetLocalStatement):
+ (JSC::WASMFunctionParser::parseReturnStatement):
+ (JSC::WASMFunctionParser::parseBlockStatement):
+ (JSC::WASMFunctionParser::parseExpression):
+ (JSC::WASMFunctionParser::parseExpressionI32):
+ (JSC::WASMFunctionParser::parseImmediateExpressionI32):
+ * wasm/WASMFunctionParser.h: Added.
+ (JSC::WASMFunctionParser::WASMFunctionParser):
+ * wasm/WASMFunctionSyntaxChecker.h: Renamed from Source/JavaScriptCore/wasm/WASMMagicNumber.h.
+ * wasm/WASMModuleParser.cpp:
+ (JSC::WASMModuleParser::WASMModuleParser):
+ (JSC::WASMModuleParser::parseFunctionDefinitionSection):
+ (JSC::WASMModuleParser::parseFunctionDefinition):
+ * wasm/WASMModuleParser.h:
+ * wasm/WASMReader.cpp:
+ (JSC::WASMReader::readType):
+ (JSC::WASMReader::readExpressionType):
+ (JSC::WASMReader::readExportFormat):
+ (JSC::WASMReader::readOpStatement):
+ (JSC::WASMReader::readOpExpressionI32):
+ (JSC::WASMReader::readVariableTypes):
+ (JSC::WASMReader::readOp):
+ * wasm/WASMReader.h:
+ (JSC::WASMReader::offset):
+ (JSC::WASMReader::setOffset):
+
</ins><span class="cx"> 2015-08-21 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> DFG::PutStackSinkingPhase doesn't need to emit KillStack nodes
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorevcxprojJavaScriptCorevcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -892,6 +892,7 @@
</span><span class="cx"> <ClCompile Include="..\tools\JSDollarVM.cpp" />
</span><span class="cx"> <ClCompile Include="..\tools\JSDollarVMPrototype.cpp" />
</span><span class="cx"> <ClCompile Include="..\wasm\JSWASMModule.cpp" />
</span><ins>+ <ClCompile Include="..\wasm\WASMFunctionParser.cpp" />
</ins><span class="cx"> <ClCompile Include="..\wasm\WASMModuleParser.cpp" />
</span><span class="cx"> <ClCompile Include="..\wasm\WASMReader.cpp" />
</span><span class="cx"> <ClCompile Include="..\yarr\RegularExpression.cpp" />
</span><span class="lines">@@ -1786,8 +1787,10 @@
</span><span class="cx"> <ClInclude Include="..\tools\ProfileTreeNode.h" />
</span><span class="cx"> <ClInclude Include="..\tools\TieredMMapArray.h" />
</span><span class="cx"> <ClInclude Include="..\wasm\JSWASMModule.h" />
</span><ins>+ <ClInclude Include="..\wasm\WASMConstants.h" />
</ins><span class="cx"> <ClInclude Include="..\wasm\WASMFormat.h" />
</span><del>- <ClInclude Include="..\wasm\WASMMagicNumber.h" />
</del><ins>+ <ClInclude Include="..\wasm\WASMFunctionParser.h" />
+ <ClInclude Include="..\wasm\WASMFunctionSyntaxChecker.h" />
</ins><span class="cx"> <ClInclude Include="..\wasm\WASMModuleParser.h" />
</span><span class="cx"> <ClInclude Include="..\wasm\WASMReader.h" />
</span><span class="cx"> <ClInclude Include="..\yarr\RegularExpression.h" />
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorevcxprojJavaScriptCorevcxprojfilters"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -1841,6 +1841,9 @@
</span><span class="cx"> <ClCompile Include="..\wasm\JSWASMModule.cpp">
</span><span class="cx"> <Filter>wasm</Filter>
</span><span class="cx"> </ClCompile>
</span><ins>+ <ClCompile Include="..\wasm\WASMFunctionParser.cpp">
+ <Filter>wasm</Filter>
+ </ClCompile>
</ins><span class="cx"> <ClCompile Include="..\wasm\WASMModuleParser.cpp">
</span><span class="cx"> <Filter>wasm</Filter>
</span><span class="cx"> </ClCompile>
</span><span class="lines">@@ -4420,12 +4423,18 @@
</span><span class="cx"> <ClInclude Include="..\wasm\JSWASMModule.h">
</span><span class="cx"> <Filter>wasm</Filter>
</span><span class="cx"> </ClInclude>
</span><ins>+ <ClInclude Include="..\wasm\WASMConstants.h">
+ <Filter>wasm</Filter>
+ </ClInclude>
</ins><span class="cx"> <ClInclude Include="..\wasm\WASMFormat.h">
</span><span class="cx"> <Filter>wasm</Filter>
</span><span class="cx"> </ClInclude>
</span><del>- <ClInclude Include="..\wasm\WASMMagicNumber.h">
</del><ins>+ <ClInclude Include="..\wasm\WASMFunctionParser.h">
</ins><span class="cx"> <Filter>wasm</Filter>
</span><span class="cx"> </ClInclude>
</span><ins>+ <ClInclude Include="..\wasm\WASMFunctionSyntaxChecker.h">
+ <Filter>wasm</Filter>
+ </ClInclude>
</ins><span class="cx"> <ClInclude Include="..\wasm\WASMModuleParser.h">
</span><span class="cx"> <Filter>wasm</Filter>
</span><span class="cx"> </ClInclude>
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -1032,11 +1032,14 @@
</span><span class="cx">                 70ECA6091AFDBEA200449739 /* TemplateRegistryKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 70ECA6041AFDBEA200449739 /* TemplateRegistryKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 79EE0BFF1B4AFB85000385C9 /* VariableEnvironment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79EE0BFD1B4AFB85000385C9 /* VariableEnvironment.cpp */; };
</span><span class="cx">                 79EE0C001B4AFB85000385C9 /* VariableEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = 79EE0BFE1B4AFB85000385C9 /* VariableEnvironment.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                7B0247551B8682DD00542440 /* WASMConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B0247521B8682D500542440 /* WASMConstants.h */; settings = {ATTRIBUTES = (Private, ); }; };
+                7B0247561B8682E100542440 /* WASMFunctionParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B0247531B8682D500542440 /* WASMFunctionParser.cpp */; };
+                7B0247571B8682E400542440 /* WASMFunctionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B0247541B8682D500542440 /* WASMFunctionParser.h */; settings = {ATTRIBUTES = (Private, ); }; };
+                7B0247591B868EB700542440 /* WASMFunctionSyntaxChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B0247581B868EAE00542440 /* WASMFunctionSyntaxChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 7B39F76D1B62DE2E00360FB4 /* WASMModuleParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B39F7691B62DE2200360FB4 /* WASMModuleParser.cpp */; };
</span><span class="cx">                 7B39F76E1B62DE3200360FB4 /* WASMModuleParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B39F76A1B62DE2200360FB4 /* WASMModuleParser.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 7B39F7701B62DE3200360FB4 /* WASMReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B39F76C1B62DE2200360FB4 /* WASMReader.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 7B39F7721B63574D00360FB4 /* WASMReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B39F7711B63574B00360FB4 /* WASMReader.cpp */; };
</span><del>-                7B7A5E271B68288C0027CAD0 /* WASMMagicNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B7A5E261B6828840027CAD0 /* WASMMagicNumber.h */; settings = {ATTRIBUTES = (Private, ); }; };
</del><span class="cx">                 7B98D1361B60CD5F0023B1A4 /* JSWASMModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */; };
</span><span class="cx">                 7B98D1371B60CD620023B1A4 /* JSWASMModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 7BC547D31B6959A100959B58 /* WASMFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC547D21B69599B00959B58 /* WASMFormat.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -2842,11 +2845,14 @@
</span><span class="cx">                 70ECA6041AFDBEA200449739 /* TemplateRegistryKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TemplateRegistryKey.h; sourceTree = "<group>"; };
</span><span class="cx">                 79EE0BFD1B4AFB85000385C9 /* VariableEnvironment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VariableEnvironment.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 79EE0BFE1B4AFB85000385C9 /* VariableEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VariableEnvironment.h; sourceTree = "<group>"; };
</span><ins>+                7B0247521B8682D500542440 /* WASMConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMConstants.h; sourceTree = "<group>"; };
+                7B0247531B8682D500542440 /* WASMFunctionParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMFunctionParser.cpp; sourceTree = "<group>"; };
+                7B0247541B8682D500542440 /* WASMFunctionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMFunctionParser.h; sourceTree = "<group>"; };
+                7B0247581B868EAE00542440 /* WASMFunctionSyntaxChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMFunctionSyntaxChecker.h; sourceTree = "<group>"; };
</ins><span class="cx">                 7B39F7691B62DE2200360FB4 /* WASMModuleParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMModuleParser.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 7B39F76A1B62DE2200360FB4 /* WASMModuleParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMModuleParser.h; sourceTree = "<group>"; };
</span><span class="cx">                 7B39F76C1B62DE2200360FB4 /* WASMReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMReader.h; sourceTree = "<group>"; };
</span><span class="cx">                 7B39F7711B63574B00360FB4 /* WASMReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMReader.cpp; sourceTree = "<group>"; };
</span><del>-                7B7A5E261B6828840027CAD0 /* WASMMagicNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMMagicNumber.h; sourceTree = "<group>"; };
</del><span class="cx">                 7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWASMModule.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWASMModule.h; sourceTree = "<group>"; };
</span><span class="cx">                 7BC547D21B69599B00959B58 /* WASMFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMFormat.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -4444,8 +4450,11 @@
</span><span class="cx">                         children = (
</span><span class="cx">                                 7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */,
</span><span class="cx">                                 7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */,
</span><ins>+                                7B0247521B8682D500542440 /* WASMConstants.h */,
</ins><span class="cx">                                 7BC547D21B69599B00959B58 /* WASMFormat.h */,
</span><del>-                                7B7A5E261B6828840027CAD0 /* WASMMagicNumber.h */,
</del><ins>+                                7B0247531B8682D500542440 /* WASMFunctionParser.cpp */,
+                                7B0247541B8682D500542440 /* WASMFunctionParser.h */,
+                                7B0247581B868EAE00542440 /* WASMFunctionSyntaxChecker.h */,
</ins><span class="cx">                                 7B39F7691B62DE2200360FB4 /* WASMModuleParser.cpp */,
</span><span class="cx">                                 7B39F76A1B62DE2200360FB4 /* WASMModuleParser.h */,
</span><span class="cx">                                 7B39F7711B63574B00360FB4 /* WASMReader.cpp */,
</span><span class="lines">@@ -5971,6 +5980,7 @@
</span><span class="cx">                                 A77F1822164088B200640A47 /* CodeCache.h in Headers */,
</span><span class="cx">                                 86E116B10FE75AC800B512BC /* CodeLocation.h in Headers */,
</span><span class="cx">                                 0FBD7E691447999600481315 /* CodeOrigin.h in Headers */,
</span><ins>+                                7B0247591B868EB700542440 /* WASMFunctionSyntaxChecker.h in Headers */,
</ins><span class="cx">                                 0F21C27D14BE727A00ADC64B /* CodeSpecializationKind.h in Headers */,
</span><span class="cx">                                 0F0B83A714BCF50700885B4F /* CodeType.h in Headers */,
</span><span class="cx">                                 BC18C3F30E16F5CD00B34460 /* CommonIdentifiers.h in Headers */,
</span><span class="lines">@@ -6230,6 +6240,7 @@
</span><span class="cx">                                 0F8F2B96172E04A3007DBDA5 /* FTLLink.h in Headers */,
</span><span class="cx">                                 0FCEFAE0180738C000472CE4 /* FTLLocation.h in Headers */,
</span><span class="cx">                                 A1587D701B4DC14100D69849 /* IntlDateTimeFormatConstructor.h in Headers */,
</span><ins>+                                7B0247571B8682E400542440 /* WASMFunctionParser.h in Headers */,
</ins><span class="cx">                                 0FEA0A10170513DB00BB722C /* FTLLowerDFGToLLVM.h in Headers */,
</span><span class="cx">                                 A7D89D0217A0B90400773AD8 /* FTLLoweredNodeValue.h in Headers */,
</span><span class="cx">                                 0FD8A31C17D51F2200CA2C40 /* FTLOSREntry.h in Headers */,
</span><span class="lines">@@ -6618,6 +6629,7 @@
</span><span class="cx">                                 95CD45770E1C4FDD0085358E /* ProfileGenerator.h in Headers */,
</span><span class="cx">                                 BC18C4510E16F5CD00B34460 /* ProfileNode.h in Headers */,
</span><span class="cx">                                 0FF729A5166AD351000F5BA3 /* ProfilerBytecode.h in Headers */,
</span><ins>+                                7B0247551B8682DD00542440 /* WASMConstants.h in Headers */,
</ins><span class="cx">                                 0FF729B9166AD360000F5BA3 /* ProfilerBytecodes.h in Headers */,
</span><span class="cx">                                 0F13912A16771C36009CCB07 /* ProfilerBytecodeSequence.h in Headers */,
</span><span class="cx">                                 0FF729BA166AD360000F5BA3 /* ProfilerCompilation.h in Headers */,
</span><span class="lines">@@ -6641,7 +6653,6 @@
</span><span class="cx">                                 BC18C4540E16F5CD00B34460 /* PropertyNameArray.h in Headers */,
</span><span class="cx">                                 0FF7168C15A3B235008F5DAA /* PropertyOffset.h in Headers */,
</span><span class="cx">                                 A785F6BC18C553FE00F10626 /* SpillRegistersMode.h in Headers */,
</span><del>-                                7B7A5E271B68288C0027CAD0 /* WASMMagicNumber.h in Headers */,
</del><span class="cx">                                 BC18C4550E16F5CD00B34460 /* PropertySlot.h in Headers */,
</span><span class="cx">                                 0FB7F39C15ED8E4600F167B2 /* PropertyStorage.h in Headers */,
</span><span class="cx">                                 0F6FC751196110A800E1D02D /* ComplexGetStatus.h in Headers */,
</span><span class="lines">@@ -7575,6 +7586,7 @@
</span><span class="cx">                                 0F5A6283188C98D40072C9DF /* FTLValueRange.cpp in Sources */,
</span><span class="cx">                                 E33637A51B63220200EE0840 /* ReflectObject.cpp in Sources */,
</span><span class="cx">                                 147F39CB107EC37600427A48 /* FunctionConstructor.cpp in Sources */,
</span><ins>+                                7B0247561B8682E100542440 /* WASMFunctionParser.cpp in Sources */,
</ins><span class="cx">                                 0FF0F19F16B72A17005DF95B /* FunctionExecutableDump.cpp in Sources */,
</span><span class="cx">                                 52B310FD1974AE870080857C /* FunctionHasExecutedCache.cpp in Sources */,
</span><span class="cx">                                 147F39CC107EC37600427A48 /* FunctionPrototype.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMConstantsh"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/wasm/WASMConstants.h (0 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMConstants.h         (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMConstants.h        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -0,0 +1,203 @@
</span><ins>+/*
+ * Copyright (C) 2015 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.
+ *
+ * =========================================================================
+ *
+ * Copyright (c) 2015 by the repository authors of
+ * WebAssembly/polyfill-prototype-1.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WASMConstants_h
+#define WASMConstants_h
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+static const uint32_t wasmMagicNumber = 0x6d736177;
+
+enum class WASMOpStatement : uint8_t {
+ SetLocal,
+ SetGlobal,
+ I32Store8,
+ I32StoreWithOffset8,
+ I32Store16,
+ I32StoreWithOffset16,
+ I32Store32,
+ I32StoreWithOffset32,
+ F32Store,
+ F32StoreWithOffset,
+ F64Store,
+ F64StoreWithOffset,
+ CallInternal,
+ CallIndirect,
+ CallImport,
+ Return,
+ Block,
+ If,
+ IfElse,
+ While,
+ Do,
+ Label,
+ Break,
+ BreakLabel,
+ Continue,
+ ContinueLabel,
+ Switch,
+ NumberOfWASMOpStatements
+};
+
+enum class WASMOpStatementWithImmediate : uint8_t {
+ SetLocal,
+ SetGlobal,
+ NumberOfWASMOpStatementWithImmediates
+};
+
+enum class WASMOpExpressionI32 : uint8_t {
+ ConstantPoolIndex,
+ Immediate,
+ GetLocal,
+ GetGlobal,
+ SetLocal,
+ SetGlobal,
+ SLoad8,
+ SLoadWithOffset8,
+ ULoad8,
+ ULoadWithOffset8,
+ SLoad16,
+ SLoadWithOffset16,
+ ULoad16,
+ ULoadWithOffset16,
+ Load32,
+ LoadWithOffset32,
+ Store8,
+ StoreWithOffset8,
+ Store16,
+ StoreWithOffset16,
+ Store32,
+ StoreWithOffset32,
+ CallInternal,
+ CallIndirect,
+ CallImport,
+ Conditional,
+ Comma,
+ FromF32,
+ FromF64,
+ Negate,
+ Add,
+ Sub,
+ Mul,
+ SDiv,
+ UDiv,
+ SMod,
+ UMod,
+ BitNot,
+ BitOr,
+ BitAnd,
+ BitXor,
+ LeftShift,
+ ArithmeticRightShift,
+ LogicalRightShift,
+ CountLeadingZeros,
+ LogicalNot,
+ EqualI32,
+ EqualF32,
+ EqualF64,
+ NotEqualI32,
+ NotEqualF32,
+ NotEqualF64,
+ SLessThanI32,
+ ULessThanI32,
+ LessThanF32,
+ LessThanF64,
+ SLessThanOrEqualI32,
+ ULessThanOrEqualI32,
+ LessThanOrEqualF32,
+ LessThanOrEqualF64,
+ SGreaterThanI32,
+ UGreaterThanI32,
+ GreaterThanF32,
+ GreaterThanF64,
+ SGreaterThanOrEqualI32,
+ UGreaterThanOrEqualI32,
+ GreaterThanOrEqualF32,
+ GreaterThanOrEqualF64,
+ SMin,
+ UMin,
+ SMax,
+ UMax,
+ Abs,
+ NumberOfWASMOpExpressionI32s
+};
+
+enum class WASMOpExpressionI32WithImmediate : uint8_t {
+ ConstantPoolIndex,
+ Immediate,
+ GetLocal,
+ NumberOfWASMOpExpressionI32WithImmediates
+};
+
+enum class WASMVariableTypes : uint8_t {
+ I32 = 1 << 0,
+ F32 = 1 << 1,
+ F64 = 1 << 2,
+ NumberOfVariableTypes = 8
+};
+
+enum class WASMVariableTypesWithImmediate : uint8_t {
+ I32,
+ NumberOfVariableTypesWithImmediates
+};
+
+enum class WASMExportFormat : uint8_t {
+ Default,
+ Record,
+ NumberOfExportFormats
+};
+
+static const uint8_t hasImmediateInOpFlag = 0x80;
+
+static const unsigned opWithImmediateBits = 2;
+static const uint32_t opWithImmediateLimit = 1 << opWithImmediateBits;
+
+static const unsigned immediateBits = 5;
+static const uint32_t immediateLimit = 1 << immediateBits;
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
+
+#endif // WASMConstants_h
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFormath"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFormat.h (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFormat.h        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/wasm/WASMFormat.h        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -65,12 +65,6 @@
</span><span class="cx"> NumberOfExpressionTypes
</span><span class="cx"> };
</span><span class="cx">
</span><del>-enum class WASMExportFormat : uint8_t {
- Default,
- Record,
- NumberOfExportFormats
-};
-
</del><span class="cx"> struct WASMSignature {
</span><span class="cx"> WASMExpressionType returnType;
</span><span class="cx"> Vector<WASMType> arguments;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionParsercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp (0 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp         (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -0,0 +1,347 @@
</span><ins>+/*
+ * Copyright (C) 2015 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.
+ */
+
+#include "config.h"
+#include "WASMFunctionParser.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSWASMModule.h"
+#include "WASMFunctionSyntaxChecker.h"
+
+#define PROPAGATE_ERROR() do { if (!m_errorMessage.isNull()) return 0; } while (0)
+#define FAIL_WITH_MESSAGE(errorMessage) do { m_errorMessage = errorMessage; return 0; } while (0)
+#define READ_COMPACT_UINT32_OR_FAIL(result, errorMessage) do { if (!m_reader.readCompactUInt32(result)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
+#define READ_OP_STATEMENT_OR_FAIL(hasImmediate, op, opWithImmediate, immediate, errorMessage) do { if (!m_reader.readOpStatement(hasImmediate, op, opWithImmediate, immediate)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
+#define READ_OP_EXPRESSION_I32_OR_FAIL(hasImmediate, op, opWithImmediate, immediate, errorMessage) do { if (!m_reader.readOpExpressionI32(hasImmediate, op, opWithImmediate, immediate)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
+#define READ_VARIABLE_TYPES_OR_FAIL(hasImmediate, variableTypes, variableTypesWithImmediate, immediate, errorMessage) do { if (!m_reader.readVariableTypes(hasImmediate, variableTypes, variableTypesWithImmediate, immediate)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
+#define FAIL_IF_FALSE(condition, errorMessage) do { if (!(condition)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
+
+#define UNUSED 0
+
+namespace JSC {
+
+bool WASMFunctionParser::checkSyntax(JSWASMModule* module, const SourceCode& source, size_t functionIndex, unsigned startOffsetInSource, unsigned& endOffsetInSource, String& errorMessage)
+{
+ WASMFunctionParser parser(module, source, functionIndex);
+ WASMFunctionSyntaxChecker syntaxChecker;
+ parser.m_reader.setOffset(startOffsetInSource);
+ parser.parseFunction(syntaxChecker);
+ if (!parser.m_errorMessage.isNull()) {
+ errorMessage = parser.m_errorMessage;
+ return false;
+ }
+ endOffsetInSource = parser.m_reader.offset();
+ return true;
+}
+
+template <class Context>
+bool WASMFunctionParser::parseFunction(Context& context)
+{
+ const WASMSignature& signature = m_module->signatures()[m_module->functionDeclarations()[m_functionIndex].signatureIndex];
+
+ m_returnType = signature.returnType;
+
+ parseLocalVariables();
+ PROPAGATE_ERROR();
+
+ const Vector<WASMType>& arguments = signature.arguments;
+ for (size_t i = 0; i < arguments.size(); ++i)
+ m_localTypes.append(arguments[i]);
+ for (uint32_t i = 0; i < m_numberOfI32LocalVariables; ++i)
+ m_localTypes.append(WASMType::I32);
+ for (uint32_t i = 0; i < m_numberOfF32LocalVariables; ++i)
+ m_localTypes.append(WASMType::F32);
+ for (uint32_t i = 0; i < m_numberOfF64LocalVariables; ++i)
+ m_localTypes.append(WASMType::F64);
+
+ parseBlockStatement(context);
+ return true;
+}
+
+bool WASMFunctionParser::parseLocalVariables()
+{
+ m_numberOfI32LocalVariables = 0;
+ m_numberOfF32LocalVariables = 0;
+ m_numberOfF64LocalVariables = 0;
+
+ bool hasImmediate;
+ WASMVariableTypes variableTypes;
+ WASMVariableTypesWithImmediate variableTypesWithImmediate;
+ uint8_t immediate;
+ READ_VARIABLE_TYPES_OR_FAIL(hasImmediate, variableTypes, variableTypesWithImmediate, immediate, "Cannot read the types of local variables.");
+ if (!hasImmediate) {
+ if (static_cast<uint8_t>(variableTypes) & static_cast<uint8_t>(WASMVariableTypes::I32))
+ READ_COMPACT_UINT32_OR_FAIL(m_numberOfI32LocalVariables, "Cannot read the number of int32 local variables.");
+ if (static_cast<uint8_t>(variableTypes) & static_cast<uint8_t>(WASMVariableTypes::F32))
+ READ_COMPACT_UINT32_OR_FAIL(m_numberOfF32LocalVariables, "Cannot read the number of float32 local variables.");
+ if (static_cast<uint8_t>(variableTypes) & static_cast<uint8_t>(WASMVariableTypes::F64))
+ READ_COMPACT_UINT32_OR_FAIL(m_numberOfF64LocalVariables, "Cannot read the number of float64 local variables.");
+ } else
+ m_numberOfI32LocalVariables = immediate;
+ return true;
+}
+
+template <class Context>
+ContextStatement WASMFunctionParser::parseStatement(Context& context)
+{
+ bool hasImmediate;
+ WASMOpStatement op;
+ WASMOpStatementWithImmediate opWithImmediate;
+ uint8_t immediate;
+ READ_OP_STATEMENT_OR_FAIL(hasImmediate, op, opWithImmediate, immediate, "Cannot read the statement opcode.");
+ if (!hasImmediate) {
+ switch (op) {
+ case WASMOpStatement::SetLocal:
+ parseSetLocalStatement(context);
+ break;
+ case WASMOpStatement::Return:
+ parseReturnStatement(context);
+ break;
+ case WASMOpStatement::Block:
+ parseBlockStatement(context);
+ break;
+ case WASMOpStatement::SetGlobal:
+ case WASMOpStatement::If:
+ case WASMOpStatement::IfElse:
+ case WASMOpStatement::While:
+ case WASMOpStatement::Do:
+ case WASMOpStatement::Label:
+ case WASMOpStatement::Break:
+ case WASMOpStatement::BreakLabel:
+ case WASMOpStatement::Continue:
+ case WASMOpStatement::ContinueLabel:
+ case WASMOpStatement::Switch:
+ case WASMOpStatement::I32Store8:
+ case WASMOpStatement::I32StoreWithOffset8:
+ case WASMOpStatement::I32Store16:
+ case WASMOpStatement::I32StoreWithOffset16:
+ case WASMOpStatement::I32Store32:
+ case WASMOpStatement::I32StoreWithOffset32:
+ case WASMOpStatement::F32Store:
+ case WASMOpStatement::F32StoreWithOffset:
+ case WASMOpStatement::F64Store:
+ case WASMOpStatement::F64StoreWithOffset:
+ case WASMOpStatement::CallInternal:
+ case WASMOpStatement::CallIndirect:
+ case WASMOpStatement::CallImport:
+ // FIXME: Implement these instructions.
+ FAIL_WITH_MESSAGE("Unsupported instruction.");
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ } else {
+ switch (opWithImmediate) {
+ case WASMOpStatementWithImmediate::SetLocal:
+ parseSetLocalStatement(context, immediate);
+ break;
+ case WASMOpStatementWithImmediate::SetGlobal:
+ // FIXME: Implement this instruction.
+ FAIL_WITH_MESSAGE("Unsupported instruction.");
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ }
+ return UNUSED;
+}
+
+template <class Context>
+ContextStatement WASMFunctionParser::parseSetLocalStatement(Context& context, uint32_t localIndex)
+{
+ FAIL_IF_FALSE(localIndex < m_localTypes.size(), "The local variable index is incorrect.");
+ WASMType type = m_localTypes[localIndex];
+ parseExpression(context, WASMExpressionType(type));
+ // FIXME: Implement this instruction.
+ return UNUSED;
+}
+
+template <class Context>
+ContextStatement WASMFunctionParser::parseSetLocalStatement(Context& context)
+{
+ uint32_t localIndex;
+ READ_COMPACT_UINT32_OR_FAIL(localIndex, "Cannot read the local index.");
+ return parseSetLocalStatement(context, localIndex);
+}
+
+template <class Context>
+ContextStatement WASMFunctionParser::parseReturnStatement(Context& context)
+{
+ if (m_returnType != WASMExpressionType::Void)
+ parseExpression(context, m_returnType);
+ // FIXME: Implement this instruction.
+ return UNUSED;
+}
+
+template <class Context>
+ContextStatement WASMFunctionParser::parseBlockStatement(Context& context)
+{
+ uint32_t numberOfStatements;
+ READ_COMPACT_UINT32_OR_FAIL(numberOfStatements, "Cannot read the number of statements.");
+ for (uint32_t i = 0; i < numberOfStatements; ++i) {
+ parseStatement(context);
+ PROPAGATE_ERROR();
+ }
+ return UNUSED;
+}
+
+template <class Context>
+ContextExpression WASMFunctionParser::parseExpression(Context& context, WASMExpressionType expressionType)
+{
+ switch (expressionType) {
+ case WASMExpressionType::I32:
+ return parseExpressionI32(context);
+ case WASMExpressionType::F32:
+ case WASMExpressionType::F64:
+ case WASMExpressionType::Void:
+ // FIXME: Implement these instructions.
+ FAIL_WITH_MESSAGE("Unsupported instruction.");
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ return 0;
+}
+
+template <class Context>
+ContextExpression WASMFunctionParser::parseExpressionI32(Context& context)
+{
+ bool hasImmediate;
+ WASMOpExpressionI32 op;
+ WASMOpExpressionI32WithImmediate opWithImmediate;
+ uint8_t immediate;
+ READ_OP_EXPRESSION_I32_OR_FAIL(hasImmediate, op, opWithImmediate, immediate, "Cannot read the int32 expression opcode.");
+ if (!hasImmediate) {
+ switch (op) {
+ case WASMOpExpressionI32::Immediate:
+ return parseImmediateExpressionI32(context);
+ case WASMOpExpressionI32::ConstantPoolIndex:
+ case WASMOpExpressionI32::GetLocal:
+ case WASMOpExpressionI32::GetGlobal:
+ case WASMOpExpressionI32::SetLocal:
+ case WASMOpExpressionI32::SetGlobal:
+ case WASMOpExpressionI32::SLoad8:
+ case WASMOpExpressionI32::SLoadWithOffset8:
+ case WASMOpExpressionI32::ULoad8:
+ case WASMOpExpressionI32::ULoadWithOffset8:
+ case WASMOpExpressionI32::SLoad16:
+ case WASMOpExpressionI32::SLoadWithOffset16:
+ case WASMOpExpressionI32::ULoad16:
+ case WASMOpExpressionI32::ULoadWithOffset16:
+ case WASMOpExpressionI32::Load32:
+ case WASMOpExpressionI32::LoadWithOffset32:
+ case WASMOpExpressionI32::Store8:
+ case WASMOpExpressionI32::StoreWithOffset8:
+ case WASMOpExpressionI32::Store16:
+ case WASMOpExpressionI32::StoreWithOffset16:
+ case WASMOpExpressionI32::Store32:
+ case WASMOpExpressionI32::StoreWithOffset32:
+ case WASMOpExpressionI32::CallInternal:
+ case WASMOpExpressionI32::CallIndirect:
+ case WASMOpExpressionI32::CallImport:
+ case WASMOpExpressionI32::Conditional:
+ case WASMOpExpressionI32::Comma:
+ case WASMOpExpressionI32::FromF32:
+ case WASMOpExpressionI32::FromF64:
+ case WASMOpExpressionI32::Negate:
+ case WASMOpExpressionI32::Add:
+ case WASMOpExpressionI32::Sub:
+ case WASMOpExpressionI32::Mul:
+ case WASMOpExpressionI32::SDiv:
+ case WASMOpExpressionI32::UDiv:
+ case WASMOpExpressionI32::SMod:
+ case WASMOpExpressionI32::UMod:
+ case WASMOpExpressionI32::BitNot:
+ case WASMOpExpressionI32::BitOr:
+ case WASMOpExpressionI32::BitAnd:
+ case WASMOpExpressionI32::BitXor:
+ case WASMOpExpressionI32::LeftShift:
+ case WASMOpExpressionI32::ArithmeticRightShift:
+ case WASMOpExpressionI32::LogicalRightShift:
+ case WASMOpExpressionI32::CountLeadingZeros:
+ case WASMOpExpressionI32::LogicalNot:
+ case WASMOpExpressionI32::EqualI32:
+ case WASMOpExpressionI32::EqualF32:
+ case WASMOpExpressionI32::EqualF64:
+ case WASMOpExpressionI32::NotEqualI32:
+ case WASMOpExpressionI32::NotEqualF32:
+ case WASMOpExpressionI32::NotEqualF64:
+ case WASMOpExpressionI32::SLessThanI32:
+ case WASMOpExpressionI32::ULessThanI32:
+ case WASMOpExpressionI32::LessThanF32:
+ case WASMOpExpressionI32::LessThanF64:
+ case WASMOpExpressionI32::SLessThanOrEqualI32:
+ case WASMOpExpressionI32::ULessThanOrEqualI32:
+ case WASMOpExpressionI32::LessThanOrEqualF32:
+ case WASMOpExpressionI32::LessThanOrEqualF64:
+ case WASMOpExpressionI32::SGreaterThanI32:
+ case WASMOpExpressionI32::UGreaterThanI32:
+ case WASMOpExpressionI32::GreaterThanF32:
+ case WASMOpExpressionI32::GreaterThanF64:
+ case WASMOpExpressionI32::SGreaterThanOrEqualI32:
+ case WASMOpExpressionI32::UGreaterThanOrEqualI32:
+ case WASMOpExpressionI32::GreaterThanOrEqualF32:
+ case WASMOpExpressionI32::GreaterThanOrEqualF64:
+ case WASMOpExpressionI32::SMin:
+ case WASMOpExpressionI32::UMin:
+ case WASMOpExpressionI32::SMax:
+ case WASMOpExpressionI32::UMax:
+ case WASMOpExpressionI32::Abs:
+ // FIXME: Implement these instructions.
+ FAIL_WITH_MESSAGE("Unsupported instruction.");
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ } else {
+ switch (opWithImmediate) {
+ case WASMOpExpressionI32WithImmediate::Immediate:
+ return parseImmediateExpressionI32(context, immediate);
+ case WASMOpExpressionI32WithImmediate::ConstantPoolIndex:
+ case WASMOpExpressionI32WithImmediate::GetLocal:
+ // FIXME: Implement these instructions.
+ FAIL_WITH_MESSAGE("Unsupported instruction.");
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ }
+ return 0;
+}
+
+template <class Context>
+ContextExpression WASMFunctionParser::parseImmediateExpressionI32(Context&, uint32_t)
+{
+ // FIXME: Implement this instruction.
+ return UNUSED;
+}
+
+template <class Context>
+ContextExpression WASMFunctionParser::parseImmediateExpressionI32(Context& context)
+{
+ uint32_t immediate;
+ READ_COMPACT_UINT32_OR_FAIL(immediate, "Cannot read the immediate.");
+ return parseImmediateExpressionI32(context, immediate);
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionParserh"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h (0 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h         (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -0,0 +1,84 @@
</span><ins>+/*
+ * Copyright (C) 2015 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.
+ */
+
+#ifndef WASMFunctionParser_h
+#define WASMFunctionParser_h
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "SourceCode.h"
+#include "WASMReader.h"
+
+#define ContextExpression typename Context::Expression
+#define ContextStatement typename Context::Statement
+
+namespace JSC {
+
+class JSWASMModule;
+
+class WASMFunctionParser {
+public:
+ static bool checkSyntax(JSWASMModule*, const SourceCode&, size_t functionIndex, unsigned startOffsetInSource, unsigned& endOffsetInSource, String& errorMessage);
+
+private:
+ WASMFunctionParser(JSWASMModule* module, const SourceCode& source, size_t functionIndex)
+ : m_module(module)
+ , m_reader(static_cast<WebAssemblySourceProvider*>(source.provider())->data())
+ , m_functionIndex(functionIndex)
+ {
+ }
+
+ template <class Context> bool parseFunction(Context&);
+ bool parseLocalVariables();
+
+ template <class Context> ContextStatement parseStatement(Context&);
+ template <class Context> ContextStatement parseSetLocalStatement(Context&, uint32_t localIndex);
+ template <class Context> ContextStatement parseSetLocalStatement(Context&);
+ template <class Context> ContextStatement parseReturnStatement(Context&);
+ template <class Context> ContextStatement parseBlockStatement(Context&);
+
+ template <class Context> ContextExpression parseExpression(Context&, WASMExpressionType);
+
+ template <class Context> ContextExpression parseExpressionI32(Context&);
+ template <class Context> ContextExpression parseImmediateExpressionI32(Context&, uint32_t immediate);
+ template <class Context> ContextExpression parseImmediateExpressionI32(Context&);
+
+ JSWASMModule* m_module;
+ WASMReader m_reader;
+ size_t m_functionIndex;
+ String m_errorMessage;
+
+ WASMExpressionType m_returnType;
+ Vector<WASMType> m_localTypes;
+ uint32_t m_numberOfI32LocalVariables;
+ uint32_t m_numberOfF32LocalVariables;
+ uint32_t m_numberOfF64LocalVariables;
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
+
+#endif // WASMFunctionParser_h
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionSyntaxCheckerhfromrev188776trunkSourceJavaScriptCorewasmWASMMagicNumberh"></a>
<div class="copfile"><h4>Copied: trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h (from rev 188776, trunk/Source/JavaScriptCore/wasm/WASMMagicNumber.h) (0 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h         (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -0,0 +1,43 @@
</span><ins>+/*
+ * Copyright (C) 2015 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.
+ */
+
+#ifndef WASMFunctionSyntaxChecker_h
+#define WASMFunctionSyntaxChecker_h
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+class WASMFunctionSyntaxChecker {
+public:
+ typedef int Expression;
+ typedef int Statement;
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
+
+#endif // WASMFunctionSyntaxChecker_h
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMMagicNumberh"></a>
<div class="delfile"><h4>Deleted: trunk/Source/JavaScriptCore/wasm/WASMMagicNumber.h (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMMagicNumber.h        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/wasm/WASMMagicNumber.h        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -1,39 +0,0 @@
</span><del>-/*
- * Copyright (C) 2015 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.
- */
-
-#ifndef WASMMagicNumber_h
-#define WASMMagicNumber_h
-
-#if ENABLE(WEBASSEMBLY)
-
-namespace JSC {
-
-static const uint32_t wasmMagicNumber = 0x6d736177;
-
-} // namespace JSC
-
-#endif // ENABLE(WEBASSEMBLY)
-
-#endif // WASMMagicNumber_h
</del></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMModuleParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -31,7 +31,8 @@
</span><span class="cx"> #include "JSCInlines.h"
</span><span class="cx"> #include "JSWASMModule.h"
</span><span class="cx"> #include "StrongInlines.h"
</span><del>-#include "WASMMagicNumber.h"
</del><ins>+#include "WASMConstants.h"
+#include "WASMFunctionParser.h"
</ins><span class="cx"> #include <wtf/MathExtras.h>
</span><span class="cx">
</span><span class="cx"> #define FAIL_WITH_MESSAGE(errorMessage) do { m_errorMessage = errorMessage; return; } while (0)
</span><span class="lines">@@ -49,7 +50,8 @@
</span><span class="cx"> namespace JSC {
</span><span class="cx">
</span><span class="cx"> WASMModuleParser::WASMModuleParser(const SourceCode& source)
</span><del>- : m_reader(static_cast<WebAssemblySourceProvider*>(source.provider())->data())
</del><ins>+ : m_source(source)
+ , m_reader(static_cast<WebAssemblySourceProvider*>(source.provider())->data())
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -247,25 +249,22 @@
</span><span class="cx">
</span><span class="cx"> void WASMModuleParser::parseFunctionDefinitionSection()
</span><span class="cx"> {
</span><del>- for (size_t i = 0; i < m_module->functionDeclarations().size(); ++i) {
- parseFunctionDefinition();
</del><ins>+ for (size_t functionIndex = 0; functionIndex < m_module->functionDeclarations().size(); ++functionIndex) {
+ parseFunctionDefinition(functionIndex);
</ins><span class="cx"> PROPAGATE_ERROR();
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void WASMModuleParser::parseFunctionDefinition()
</del><ins>+void WASMModuleParser::parseFunctionDefinition(size_t functionIndex)
</ins><span class="cx"> {
</span><del>- // FIXME: Support any functions. https://bugs.webkit.org/show_bug.cgi?id=147738
- // Currently, we only support functions that have "return 0;" as their only statement.
- // These functions consist of exactly 4 bytes, i.e.
- // 1. The number of local variables (0) [0x80]
- // 2. The number of statements (1) [0x01]
- // 3. The return statement [0x0f]
- // 4. The immediate expression (0) [0xa0]
- uint32_t functionDefinitionBytes;
- READ_UINT32_OR_FAIL(functionDefinitionBytes, "Cannot read the function definition.");
- FAIL_IF_FALSE(functionDefinitionBytes == 0xa00f0180, "Only functions that have \"return 0;\" "
- "as their only statement are supported at the moment.");
</del><ins>+ unsigned startOffsetInSource = m_reader.offset();
+ unsigned endOffsetInSource;
+ String errorMessage;
+ if (!WASMFunctionParser::checkSyntax(m_module.get(), m_source, functionIndex, startOffsetInSource, endOffsetInSource, errorMessage)) {
+ m_errorMessage = errorMessage;
+ return;
+ }
+ m_reader.setOffset(endOffsetInSource);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void WASMModuleParser::parseExportSection()
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMModuleParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -54,9 +54,10 @@
</span><span class="cx"> void parseFunctionDeclarationSection();
</span><span class="cx"> void parseFunctionPointerTableSection();
</span><span class="cx"> void parseFunctionDefinitionSection();
</span><del>- void parseFunctionDefinition();
</del><ins>+ void parseFunctionDefinition(size_t functionIndex);
</ins><span class="cx"> void parseExportSection();
</span><span class="cx">
</span><ins>+ const SourceCode& m_source;
</ins><span class="cx"> WASMReader m_reader;
</span><span class="cx"> Strong<JSWASMModule> m_module;
</span><span class="cx"> String m_errorMessage;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMReadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMReader.cpp (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMReader.cpp        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/wasm/WASMReader.cpp        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -21,6 +21,23 @@
</span><span class="cx"> * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
</span><span class="cx"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
</span><span class="cx"> * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><ins>+ *
+ * =========================================================================
+ *
+ * Copyright (c) 2015 by the repository authors of
+ * WebAssembly/polyfill-prototype-1.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
</ins><span class="cx"> */
</span><span class="cx">
</span><span class="cx"> #include "config.h"
</span><span class="lines">@@ -113,17 +130,17 @@
</span><span class="cx">
</span><span class="cx"> bool WASMReader::readType(WASMType& result)
</span><span class="cx"> {
</span><del>- return readByte<WASMType>(result, (uint8_t)WASMType::NumberOfTypes);
</del><ins>+ return readByte<WASMType>(result, static_cast<uint8_t>(WASMType::NumberOfTypes));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool WASMReader::readExpressionType(WASMExpressionType& result)
</span><span class="cx"> {
</span><del>- return readByte<WASMExpressionType>(result, (uint8_t)WASMExpressionType::NumberOfExpressionTypes);
</del><ins>+ return readByte<WASMExpressionType>(result, static_cast<uint8_t>(WASMExpressionType::NumberOfExpressionTypes));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool WASMReader::readExportFormat(WASMExportFormat& result)
</span><span class="cx"> {
</span><del>- return readByte<WASMExportFormat>(result, (uint8_t)WASMExportFormat::NumberOfExportFormats);
</del><ins>+ return readByte<WASMExportFormat>(result, static_cast<uint8_t>(WASMExportFormat::NumberOfExportFormats));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template <class T> bool WASMReader::readByte(T& result, uint8_t numberOfValues)
</span><span class="lines">@@ -136,6 +153,50 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+bool WASMReader::readOpStatement(bool& hasImmediate, WASMOpStatement& op, WASMOpStatementWithImmediate& opWithImmediate, uint8_t& immediate)
+{
+ return readOp(hasImmediate, op, opWithImmediate, immediate,
+ static_cast<uint8_t>(WASMOpStatement::NumberOfWASMOpStatements),
+ static_cast<uint8_t>(WASMOpStatementWithImmediate::NumberOfWASMOpStatementWithImmediates));
+}
+
+bool WASMReader::readOpExpressionI32(bool& hasImmediate, WASMOpExpressionI32& op, WASMOpExpressionI32WithImmediate& opWithImmediate, uint8_t& immediate)
+{
+ return readOp(hasImmediate, op, opWithImmediate, immediate,
+ static_cast<uint8_t>(WASMOpExpressionI32::NumberOfWASMOpExpressionI32s),
+ static_cast<uint8_t>(WASMOpExpressionI32WithImmediate::NumberOfWASMOpExpressionI32WithImmediates));
+}
+
+bool WASMReader::readVariableTypes(bool& hasImmediate, WASMVariableTypes& variableTypes, WASMVariableTypesWithImmediate& variableTypesWithImmediate, uint8_t& immediate)
+{
+ return readOp(hasImmediate, variableTypes, variableTypesWithImmediate, immediate,
+ static_cast<uint8_t>(WASMVariableTypes::NumberOfVariableTypes),
+ static_cast<uint8_t>(WASMVariableTypesWithImmediate::NumberOfVariableTypesWithImmediates));
+}
+
+template <class T, class TWithImmediate>
+bool WASMReader::readOp(bool& hasImmediate, T& op, TWithImmediate& opWithImmediate, uint8_t& immediate, uint8_t numberOfValues, uint8_t numberOfValuesWithImmediate)
+{
+ CHECK_READ(1);
+ uint8_t byte = *m_cursor++;
+
+ if (!(byte & hasImmediateInOpFlag)) {
+ if (byte >= numberOfValues)
+ return false;
+ hasImmediate = false;
+ op = T(byte);
+ return true;
+ }
+
+ uint8_t byteWithoutImmediate = (byte >> immediateBits) & (opWithImmediateLimit - 1);
+ if (byteWithoutImmediate >= numberOfValuesWithImmediate)
+ return false;
+ hasImmediate = true;
+ opWithImmediate = TWithImmediate(byteWithoutImmediate);
+ immediate = byte & (immediateLimit - 1);
+ return true;
+}
+
</ins><span class="cx"> } // namespace JSC
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(WEBASSEMBLY)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMReaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMReader.h (188777 => 188778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMReader.h        2015-08-21 21:44:34 UTC (rev 188777)
+++ trunk/Source/JavaScriptCore/wasm/WASMReader.h        2015-08-21 21:46:22 UTC (rev 188778)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(WEBASSEMBLY)
</span><span class="cx">
</span><ins>+#include "WASMConstants.h"
</ins><span class="cx"> #include "WASMFormat.h"
</span><span class="cx"> #include <wtf/Vector.h>
</span><span class="cx">
</span><span class="lines">@@ -41,6 +42,9 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ unsigned offset() const { return m_cursor - m_buffer.data(); }
+ void setOffset(unsigned offset) { m_cursor = m_buffer.data() + offset; }
+
</ins><span class="cx"> bool readUInt32(uint32_t& result);
</span><span class="cx"> bool readFloat(float& result);
</span><span class="cx"> bool readDouble(double& result);
</span><span class="lines">@@ -49,11 +53,15 @@
</span><span class="cx"> bool readType(WASMType& result);
</span><span class="cx"> bool readExpressionType(WASMExpressionType& result);
</span><span class="cx"> bool readExportFormat(WASMExportFormat& result);
</span><ins>+ bool readOpStatement(bool& hasImmediate, WASMOpStatement&, WASMOpStatementWithImmediate&, uint8_t& immediate);
+ bool readOpExpressionI32(bool& hasImmediate, WASMOpExpressionI32&, WASMOpExpressionI32WithImmediate&, uint8_t& immediate);
+ bool readVariableTypes(bool& hasImmediate, WASMVariableTypes&, WASMVariableTypesWithImmediate&, uint8_t& immediate);
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> static const uint32_t firstSevenBitsMask = 0x7f;
</span><span class="cx">
</span><span class="cx"> template <class T> bool readByte(T& result, uint8_t numberOfValues);
</span><ins>+ template <class T, class TWithImmediate> bool readOp(bool& hasImmediate, T&, TWithImmediate&, uint8_t& immediate, uint8_t numberOfValues, uint8_t numberOfValuesWithImmediate);
</ins><span class="cx">
</span><span class="cx"> const Vector<uint8_t>& m_buffer;
</span><span class="cx"> const uint8_t* m_cursor;
</span></span></pre>
</div>
</div>
</body>
</html>