<!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>[204484] trunk/Source</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/204484">204484</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2016-08-15 14:35:07 -0700 (Mon, 15 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement WASM Parser and B3 IR generator
https://bugs.webkit.org/show_bug.cgi?id=160681

Reviewed by Benjamin Poulain.

Source/JavaScriptCore:

This patch adds the skeleton for a WebAssembly pipeline. The
pipeline is designed in order to make it easy to have as much of
the compilation process threaded as possible. The flow of the
pipeline roughly goes as follows:

1) Create a WASMPlan with the VM and a Vector of the
assembly. Currently the plan will process all the work
synchronously, however, in the future this can be offloaded to
other threads.

2) The plan will run the WASMModuleParser, which collates all the
information needed to compile each module function
independently. Since, we are still in the early phases, the only
information is the starting and ending byte of the function's
body. The module parser, however, still scans both and
semi-validates the type and the function sections.

3) Each function is decoded and compiled. In the future this
should also include a opcode validation phase. The
WASMFunctionParser is templatized so that a validator should be
able to use most of the same code the B3 IR generator does.

4) When the plan has finished it will fill a Vector of
B3::Compilation objects that correspond to the respective function
in the WASM module.

The current testing plan for the modules is to inline the the
binary generated by the spec's OCaml prototype. The inlined binary
is passed to a WASMPlan then invoked to check the result of the
function. In the future we should add a more robust testing
infrastructure.

* JavaScriptCore.xcodeproj/project.pbxproj:
* testWASM.cpp:
(printUsageStatement):
(CommandLine::parseArguments):
(invoke):
(runWASMTests):
(main):
* wasm/JSWASMModule.h:
(JSC::JSWASMModule::globalVariableTypes):
* wasm/WASMB3IRGenerator.cpp: Added.
(JSC::WASM::B3IRGenerator::B3IRGenerator):
(JSC::WASM::B3IRGenerator::addLocal):
(JSC::WASM::B3IRGenerator::binaryOp):
(JSC::WASM::B3IRGenerator::addConstant):
(JSC::WASM::B3IRGenerator::addBlock):
(JSC::WASM::B3IRGenerator::endBlock):
(JSC::WASM::B3IRGenerator::addReturn):
(JSC::WASM::B3IRGenerator::unify):
(JSC::WASM::B3IRGenerator::initializeIncommingTypes):
(JSC::WASM::B3IRGenerator::unifyValuesWithLevel):
(JSC::WASM::B3IRGenerator::stackForControlLevel):
(JSC::WASM::B3IRGenerator::blockForControlLevel):
(JSC::WASM::parseAndCompile):
* wasm/WASMB3IRGenerator.h: Copied from Source/WTF/wtf/DataLog.h.
* wasm/WASMFormat.h:
* wasm/WASMFunctionParser.h: Added.
(JSC::WASM::WASMFunctionParser&lt;Context&gt;::WASMFunctionParser):
(JSC::WASM::WASMFunctionParser&lt;Context&gt;::parse):
(JSC::WASM::WASMFunctionParser&lt;Context&gt;::parseBlock):
(JSC::WASM::WASMFunctionParser&lt;Context&gt;::parseExpression):
* wasm/WASMModuleParser.cpp: Added.
(JSC::WASM::WASMModuleParser::parse):
(JSC::WASM::WASMModuleParser::parseFunctionTypes):
(JSC::WASM::WASMModuleParser::parseFunctionSignatures):
(JSC::WASM::WASMModuleParser::parseFunctionDefinitions):
* wasm/WASMModuleParser.h: Copied from Source/WTF/wtf/DataLog.h.
(JSC::WASM::WASMModuleParser::WASMModuleParser):
(JSC::WASM::WASMModuleParser::functionInformation):
* wasm/WASMOps.h: Copied from Source/WTF/wtf/DataLog.h.
* wasm/WASMParser.h: Added.
(JSC::WASM::WASMParser::parseVarUInt32):
(JSC::WASM::WASMParser::WASMParser):
(JSC::WASM::WASMParser::consumeCharacter):
(JSC::WASM::WASMParser::consumeString):
(JSC::WASM::WASMParser::parseUInt32):
(JSC::WASM::WASMParser::parseUInt7):
(JSC::WASM::WASMParser::parseVarUInt1):
(JSC::WASM::WASMParser::parseValueType):
* wasm/WASMPlan.cpp: Copied from Source/WTF/wtf/DataLog.h.
(JSC::WASM::Plan::Plan):
* wasm/WASMPlan.h: Copied from Source/WTF/wtf/DataLog.h.
* wasm/WASMSections.cpp: Copied from Source/WTF/wtf/DataLog.h.
(JSC::WASM::WASMSections::lookup):
* wasm/WASMSections.h: Copied from Source/WTF/wtf/DataLog.h.
(JSC::WASM::WASMSections::validateOrder):

Source/WTF:

* wtf/DataLog.h:
(WTF::dataLogLn): Add a new dataLog function, dataLogLn that
automagically includes a new line at the end of the print.
* wtf/LEBDecoder.h:
(decodeUInt32):
(decodeInt32): Change the LEBDecoder to take a pointer and length
rather than a Vector.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceJavaScriptCoretestWASMcpp">trunk/Source/JavaScriptCore/testWASM.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmJSWASMModuleh">trunk/Source/JavaScriptCore/wasm/JSWASMModule.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFormath">trunk/Source/JavaScriptCore/wasm/WASMFormat.h</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfDataLogh">trunk/Source/WTF/wtf/DataLog.h</a></li>
<li><a href="#trunkSourceWTFwtfLEBDecoderh">trunk/Source/WTF/wtf/LEBDecoder.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCorewasmWASMB3IRGeneratorcpp">trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMB3IRGeneratorh">trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionParserh">trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.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="#trunkSourceJavaScriptCorewasmWASMOpsh">trunk/Source/JavaScriptCore/wasm/WASMOps.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMParserh">trunk/Source/JavaScriptCore/wasm/WASMParser.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMPlancpp">trunk/Source/JavaScriptCore/wasm/WASMPlan.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMPlanh">trunk/Source/JavaScriptCore/wasm/WASMPlan.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMSectionscpp">trunk/Source/JavaScriptCore/wasm/WASMSections.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMSectionsh">trunk/Source/JavaScriptCore/wasm/WASMSections.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (204483 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-08-15 21:23:32 UTC (rev 204483)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -1,3 +1,99 @@
</span><ins>+2016-08-15  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        Implement WASM Parser and B3 IR generator
+        https://bugs.webkit.org/show_bug.cgi?id=160681
+
+        Reviewed by Benjamin Poulain.
+
+        This patch adds the skeleton for a WebAssembly pipeline. The
+        pipeline is designed in order to make it easy to have as much of
+        the compilation process threaded as possible. The flow of the
+        pipeline roughly goes as follows:
+
+        1) Create a WASMPlan with the VM and a Vector of the
+        assembly. Currently the plan will process all the work
+        synchronously, however, in the future this can be offloaded to
+        other threads.
+
+        2) The plan will run the WASMModuleParser, which collates all the
+        information needed to compile each module function
+        independently. Since, we are still in the early phases, the only
+        information is the starting and ending byte of the function's
+        body. The module parser, however, still scans both and
+        semi-validates the type and the function sections.
+
+        3) Each function is decoded and compiled. In the future this
+        should also include a opcode validation phase. The
+        WASMFunctionParser is templatized so that a validator should be
+        able to use most of the same code the B3 IR generator does.
+
+        4) When the plan has finished it will fill a Vector of
+        B3::Compilation objects that correspond to the respective function
+        in the WASM module.
+
+
+        The current testing plan for the modules is to inline the the
+        binary generated by the spec's OCaml prototype. The inlined binary
+        is passed to a WASMPlan then invoked to check the result of the
+        function. In the future we should add a more robust testing
+        infrastructure.
+
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * testWASM.cpp:
+        (printUsageStatement):
+        (CommandLine::parseArguments):
+        (invoke):
+        (runWASMTests):
+        (main):
+        * wasm/JSWASMModule.h:
+        (JSC::JSWASMModule::globalVariableTypes):
+        * wasm/WASMB3IRGenerator.cpp: Added.
+        (JSC::WASM::B3IRGenerator::B3IRGenerator):
+        (JSC::WASM::B3IRGenerator::addLocal):
+        (JSC::WASM::B3IRGenerator::binaryOp):
+        (JSC::WASM::B3IRGenerator::addConstant):
+        (JSC::WASM::B3IRGenerator::addBlock):
+        (JSC::WASM::B3IRGenerator::endBlock):
+        (JSC::WASM::B3IRGenerator::addReturn):
+        (JSC::WASM::B3IRGenerator::unify):
+        (JSC::WASM::B3IRGenerator::initializeIncommingTypes):
+        (JSC::WASM::B3IRGenerator::unifyValuesWithLevel):
+        (JSC::WASM::B3IRGenerator::stackForControlLevel):
+        (JSC::WASM::B3IRGenerator::blockForControlLevel):
+        (JSC::WASM::parseAndCompile):
+        * wasm/WASMB3IRGenerator.h: Copied from Source/WTF/wtf/DataLog.h.
+        * wasm/WASMFormat.h:
+        * wasm/WASMFunctionParser.h: Added.
+        (JSC::WASM::WASMFunctionParser&lt;Context&gt;::WASMFunctionParser):
+        (JSC::WASM::WASMFunctionParser&lt;Context&gt;::parse):
+        (JSC::WASM::WASMFunctionParser&lt;Context&gt;::parseBlock):
+        (JSC::WASM::WASMFunctionParser&lt;Context&gt;::parseExpression):
+        * wasm/WASMModuleParser.cpp: Added.
+        (JSC::WASM::WASMModuleParser::parse):
+        (JSC::WASM::WASMModuleParser::parseFunctionTypes):
+        (JSC::WASM::WASMModuleParser::parseFunctionSignatures):
+        (JSC::WASM::WASMModuleParser::parseFunctionDefinitions):
+        * wasm/WASMModuleParser.h: Copied from Source/WTF/wtf/DataLog.h.
+        (JSC::WASM::WASMModuleParser::WASMModuleParser):
+        (JSC::WASM::WASMModuleParser::functionInformation):
+        * wasm/WASMOps.h: Copied from Source/WTF/wtf/DataLog.h.
+        * wasm/WASMParser.h: Added.
+        (JSC::WASM::WASMParser::parseVarUInt32):
+        (JSC::WASM::WASMParser::WASMParser):
+        (JSC::WASM::WASMParser::consumeCharacter):
+        (JSC::WASM::WASMParser::consumeString):
+        (JSC::WASM::WASMParser::parseUInt32):
+        (JSC::WASM::WASMParser::parseUInt7):
+        (JSC::WASM::WASMParser::parseVarUInt1):
+        (JSC::WASM::WASMParser::parseValueType):
+        * wasm/WASMPlan.cpp: Copied from Source/WTF/wtf/DataLog.h.
+        (JSC::WASM::Plan::Plan):
+        * wasm/WASMPlan.h: Copied from Source/WTF/wtf/DataLog.h.
+        * wasm/WASMSections.cpp: Copied from Source/WTF/wtf/DataLog.h.
+        (JSC::WASM::WASMSections::lookup):
+        * wasm/WASMSections.h: Copied from Source/WTF/wtf/DataLog.h.
+        (JSC::WASM::WASMSections::validateOrder):
+
</ins><span class="cx"> 2016-08-15  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [JSC] B3 Neg opcode should support float
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (204483 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2016-08-15 21:23:32 UTC (rev 204483)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -1178,6 +1178,8 @@
</span><span class="cx">                 52C0611F1AA51E1C00B4ADBA /* RuntimeType.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 52C952B719A289850069B386 /* TypeProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C952B619A289850069B386 /* TypeProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 52C952B919A28A1C0069B386 /* TypeProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */; };
</span><ins>+                531374BD1D5CE67600AF7A0B /* WASMPlan.h in Headers */ = {isa = PBXBuildFile; fileRef = 531374BC1D5CE67600AF7A0B /* WASMPlan.h */; };
+                531374BF1D5CE95000AF7A0B /* WASMPlan.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */; };
</ins><span class="cx">                 53486BB71C1795C300F6F3AF /* JSTypedArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 53486BB61C1795C300F6F3AF /* JSTypedArray.h */; settings = {ATTRIBUTES = (Public, ); }; };
</span><span class="cx">                 53486BBB1C18E84500F6F3AF /* JSTypedArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */; };
</span><span class="cx">                 534902851C7276B70012BCB8 /* TypedArrayCTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */; };
</span><span class="lines">@@ -1191,6 +1193,15 @@
</span><span class="cx">                 539EB07A1D55607000C82EF7 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932F5BD90822A1C700736975 /* JavaScriptCore.framework */; };
</span><span class="cx">                 539EB0811D55608A00C82EF7 /* testWASM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539EB0711D553DF800C82EF7 /* testWASM.cpp */; };
</span><span class="cx">                 539FB8BA1C99DA7C00940FA1 /* JSArrayInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */; };
</span><ins>+                53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E841D58F9770099A1B6 /* WASMSections.h */; };
+                53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */; };
+                53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */; };
+                53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8C1D5901F20099A1B6 /* WASMParser.h */; };
+                53F40E8F1D5902820099A1B6 /* WASMB3IRGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */; };
+                53F40E911D5903020099A1B6 /* WASMOps.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E901D5903020099A1B6 /* WASMOps.h */; };
+                53F40E931D5A4AB30099A1B6 /* WASMB3IRGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */; };
+                53F40E951D5A7AEF0099A1B6 /* WASMModuleParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */; };
+                53F40E971D5A7BEC0099A1B6 /* WASMModuleParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */; };
</ins><span class="cx">                 53F6BF6D1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 53FA2AE11CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 53FA2AE31CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FA2AE21CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp */; };
</span><span class="lines">@@ -3353,6 +3364,8 @@
</span><span class="cx">                 52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeType.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 52C952B619A289850069B386 /* TypeProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeProfiler.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                531374BC1D5CE67600AF7A0B /* WASMPlan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMPlan.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMPlan.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 53486BB61C1795C300F6F3AF /* JSTypedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArray.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArray.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TypedArrayCTest.cpp; path = API/tests/TypedArrayCTest.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -3370,6 +3383,15 @@
</span><span class="cx">                 539EB0801D55607000C82EF7 /* testWASM */ = {isa = PBXFileReference; explicitFileType = &quot;compiled.mach-o.executable&quot;; includeInIndex = 0; path = testWASM; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">                 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSArrayInlines.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArrayViewPrototype.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                53F40E841D58F9770099A1B6 /* WASMSections.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMSections.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                53F40E861D58F9D60099A1B6 /* WASMSections.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMSections.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMFunctionParser.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                53F40E8C1D5901F20099A1B6 /* WASMParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMParser.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMB3IRGenerator.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                53F40E901D5903020099A1B6 /* WASMOps.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMOps.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMB3IRGenerator.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMModuleParser.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMModuleParser.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InternalFunctionAllocationProfile.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LLIntPrototypeLoadAdaptiveStructureWatchpoint.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 53FA2AE21CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -5539,7 +5561,18 @@
</span><span class="cx">                         children = (
</span><span class="cx">                                 7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */,
</span><span class="cx">                                 7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */,
</span><ins>+                                53F40E901D5903020099A1B6 /* WASMOps.h */,
</ins><span class="cx">                                 7BC547D21B69599B00959B58 /* WASMFormat.h */,
</span><ins>+                                53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */,
+                                53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */,
+                                53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */,
+                                53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */,
+                                53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */,
+                                531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */,
+                                531374BC1D5CE67600AF7A0B /* WASMPlan.h */,
+                                53F40E8C1D5901F20099A1B6 /* WASMParser.h */,
+                                53F40E861D58F9D60099A1B6 /* WASMSections.cpp */,
+                                53F40E841D58F9770099A1B6 /* WASMSections.h */,
</ins><span class="cx">                         );
</span><span class="cx">                         path = wasm;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="lines">@@ -7211,6 +7244,7 @@
</span><span class="cx">                                 0F4C91661C29F4F2004341A6 /* B3OriginDump.h in Headers */,
</span><span class="cx">                                 C2FCAE1317A9C24E0034C735 /* BytecodeLivenessAnalysis.h in Headers */,
</span><span class="cx">                                 0F666EC0183566F900D017F1 /* BytecodeLivenessAnalysisInlines.h in Headers */,
</span><ins>+                                53F40E951D5A7AEF0099A1B6 /* WASMModuleParser.h in Headers */,
</ins><span class="cx">                                 6514F21918B3E1670098FF8B /* Bytecodes.h in Headers */,
</span><span class="cx">                                 0F885E111849A3BE00F1E3FA /* BytecodeUseDef.h in Headers */,
</span><span class="cx">                                 0F8023EA1613832B00A0BA45 /* ByValInfo.h in Headers */,
</span><span class="lines">@@ -7296,6 +7330,7 @@
</span><span class="cx">                                 BC18C3FB0E16F5CD00B34460 /* DebuggerCallFrame.h in Headers */,
</span><span class="cx">                                 6AD2CB4D19B9140100065719 /* DebuggerEvalEnabler.h in Headers */,
</span><span class="cx">                                 FEA08621182B7A0400F6D851 /* DebuggerPrimitives.h in Headers */,
</span><ins>+                                53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */,
</ins><span class="cx">                                 DC9A0C1F1D2D9CB10085124E /* B3CaseCollectionInlines.h in Headers */,
</span><span class="cx">                                 0F2D4DDE19832D34007D4B19 /* DebuggerScope.h in Headers */,
</span><span class="cx">                                 0F136D4D174AD69E0075B354 /* DeferGC.h in Headers */,
</span><span class="lines">@@ -7442,6 +7477,7 @@
</span><span class="cx">                                 0F7025AA1714B0FC00382C0E /* DFGOSRExitCompilerCommon.h in Headers */,
</span><span class="cx">                                 0F392C8A1B46188400844728 /* DFGOSRExitFuzz.h in Headers */,
</span><span class="cx">                                 0FEFC9AB1681A3B600567F53 /* DFGOSRExitJumpPlaceholder.h in Headers */,
</span><ins>+                                53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */,
</ins><span class="cx">                                 0F40E4A81C497F7400A577FA /* AirOpcodeGenerated.h in Headers */,
</span><span class="cx">                                 0F235BEE17178E7300690C7F /* DFGOSRExitPreparation.h in Headers */,
</span><span class="cx">                                 0F6237981AE45CA700D402EA /* DFGPhantomInsertionPhase.h in Headers */,
</span><span class="lines">@@ -7596,6 +7632,7 @@
</span><span class="cx">                                 0F2B66AD17B6B54500A7AE3F /* GCIncomingRefCountedInlines.h in Headers */,
</span><span class="cx">                                 0F2B66AE17B6B54500A7AE3F /* GCIncomingRefCountedSet.h in Headers */,
</span><span class="cx">                                 0F2B66AF17B6B54500A7AE3F /* GCIncomingRefCountedSetInlines.h in Headers */,
</span><ins>+                                531374BD1D5CE67600AF7A0B /* WASMPlan.h in Headers */,
</ins><span class="cx">                                 2AABCDE718EF294200002096 /* GCLogging.h in Headers */,
</span><span class="cx">                                 0F2BBD981C5FF3F50023EF23 /* B3Variable.h in Headers */,
</span><span class="cx">                                 A54E8EB018BFFBBB00556D28 /* GCSegmentedArray.h in Headers */,
</span><span class="lines">@@ -7807,6 +7844,7 @@
</span><span class="cx">                                 0F2B66F617B6B5AB00A7AE3F /* JSGenericTypedArrayViewPrototypeInlines.h in Headers */,
</span><span class="cx">                                 797E07AA1B8FCFB9008400BA /* JSGlobalLexicalEnvironment.h in Headers */,
</span><span class="cx">                                 BC18C4210E16F5CD00B34460 /* JSGlobalObject.h in Headers */,
</span><ins>+                                53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */,
</ins><span class="cx">                                 996B731D1BDA08EF00331B84 /* JSGlobalObject.lut.h in Headers */,
</span><span class="cx">                                 A5FD0086189B1B7E00633231 /* JSGlobalObjectConsoleAgent.h in Headers */,
</span><span class="cx">                                 A5C3A1A618C0490200C9593A /* JSGlobalObjectConsoleClient.h in Headers */,
</span><span class="lines">@@ -7866,6 +7904,7 @@
</span><span class="cx">                                 A7C0C4AC168103020017011D /* JSScriptRefPrivate.h in Headers */,
</span><span class="cx">                                 FE1220271BE7F58C0039E6F2 /* JITAddGenerator.h in Headers */,
</span><span class="cx">                                 0F919D11157F332C004A4E7D /* JSSegmentedVariableObject.h in Headers */,
</span><ins>+                                53F40E911D5903020099A1B6 /* WASMOps.h in Headers */,
</ins><span class="cx">                                 A7299D9E17D12837005F5FF9 /* JSSet.h in Headers */,
</span><span class="cx">                                 A790DD70182F499700588807 /* JSSetIterator.h in Headers */,
</span><span class="cx">                                 BC18C45E0E16F5CD00B34460 /* CLoopStack.h in Headers */,
</span><span class="lines">@@ -7914,6 +7953,7 @@
</span><span class="cx">                                 0FB5467714F59B5C002C2989 /* LazyOperandValueProfile.h in Headers */,
</span><span class="cx">                                 99DA00B01BD5994E00F4575C /* lazywriter.py in Headers */,
</span><span class="cx">                                 BC18C4310E16F5CD00B34460 /* Lexer.h in Headers */,
</span><ins>+                                53F40E931D5A4AB30099A1B6 /* WASMB3IRGenerator.h in Headers */,
</ins><span class="cx">                                 BC18C52E0E16FCE100B34460 /* Lexer.lut.h in Headers */,
</span><span class="cx">                                 DCF3D56B1CD29472003D5C65 /* LazyClassStructureInlines.h in Headers */,
</span><span class="cx">                                 FE187A021BFBE5610038BBCA /* JITMulGenerator.h in Headers */,
</span><span class="lines">@@ -8947,6 +8987,7 @@
</span><span class="cx">                                 0FBE0F7216C1DB030082C5E8 /* DFGCPSRethreadingPhase.cpp in Sources */,
</span><span class="cx">                                 A7D89CF517A0B8CC00773AD8 /* DFGCriticalEdgeBreakingPhase.cpp in Sources */,
</span><span class="cx">                                 0F6183291C45BF070072450B /* AirCCallingConvention.cpp in Sources */,
</span><ins>+                                53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */,
</ins><span class="cx">                                 0FFFC95914EF90A600C72532 /* DFGCSEPhase.cpp in Sources */,
</span><span class="cx">                                 0F2FC77216E12F710038D976 /* DFGDCEPhase.cpp in Sources */,
</span><span class="cx">                                 0F338E121BF0276C0013C88F /* B3OpaqueByproducts.cpp in Sources */,
</span><span class="lines">@@ -9160,6 +9201,7 @@
</span><span class="cx">                                 9E729407190F01A5001A91B5 /* InitializeThreading.cpp in Sources */,
</span><span class="cx">                                 A513E5B7185B8BD3007E95AD /* InjectedScript.cpp in Sources */,
</span><span class="cx">                                 A514B2C2185A684400F3C7CB /* InjectedScriptBase.cpp in Sources */,
</span><ins>+                                531374BF1D5CE95000AF7A0B /* WASMPlan.cpp in Sources */,
</ins><span class="cx">                                 A58E35911860DECF001F24FE /* InjectedScriptHost.cpp in Sources */,
</span><span class="cx">                                 A513E5CA185F9624007E95AD /* InjectedScriptManager.cpp in Sources */,
</span><span class="cx">                                 A5840E20187B7B8600843B10 /* InjectedScriptModule.cpp in Sources */,
</span><span class="lines">@@ -9536,6 +9578,7 @@
</span><span class="cx">                                 E18E3A590DF9278C00D90B34 /* VM.cpp in Sources */,
</span><span class="cx">                                 FE5932A7183C5A2600A1ECCC /* VMEntryScope.cpp in Sources */,
</span><span class="cx">                                 FE187A011BFBE55E0038BBCA /* JITMulGenerator.cpp in Sources */,
</span><ins>+                                53F40E8F1D5902820099A1B6 /* WASMB3IRGenerator.cpp in Sources */,
</ins><span class="cx">                                 26718BA41BE99F780052017B /* AirIteratedRegisterCoalescing.cpp in Sources */,
</span><span class="cx">                                 FED94F2E171E3E2300BE77A4 /* Watchdog.cpp in Sources */,
</span><span class="cx">                                 0F919D2515853CE0004A4E7D /* Watchpoint.cpp in Sources */,
</span><span class="lines">@@ -9545,6 +9588,7 @@
</span><span class="cx">                                 A7CA3AE317DA41AE006538AF /* WeakMapConstructor.cpp in Sources */,
</span><span class="cx">                                 0F338DF91BE96AA80013C88F /* B3CCallValue.cpp in Sources */,
</span><span class="cx">                                 A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */,
</span><ins>+                                53F40E971D5A7BEC0099A1B6 /* WASMModuleParser.cpp in Sources */,
</ins><span class="cx">                                 A7CA3AE517DA41AE006538AF /* WeakMapPrototype.cpp in Sources */,
</span><span class="cx">                                 14E84FA014EE1ACC00D6D5D4 /* WeakSet.cpp in Sources */,
</span><span class="cx">                                 709FB8691AE335C60039D069 /* WeakSetConstructor.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestWASMcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/testWASM.cpp (204483 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/testWASM.cpp        2016-08-15 21:23:32 UTC (rev 204483)
+++ trunk/Source/JavaScriptCore/testWASM.cpp        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -25,7 +25,11 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> 
</span><ins>+#include &quot;B3Compilation.h&quot;
+#include &quot;InitializeThreading.h&quot;
</ins><span class="cx"> #include &quot;JSString.h&quot;
</span><ins>+#include &quot;VM.h&quot;
+#include &quot;WASMPlan.h&quot;
</ins><span class="cx"> #include &lt;wtf/DataLog.h&gt;
</span><span class="cx"> #include &lt;wtf/LEBDecoder.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -38,6 +42,7 @@
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;String&gt; m_arguments;
</span><span class="cx">     bool m_runLEBTests { false };
</span><ins>+    bool m_runWASMTests { false };
</ins><span class="cx"> 
</span><span class="cx">     void parseArguments(int, char**);
</span><span class="cx"> };
</span><span class="lines">@@ -47,6 +52,7 @@
</span><span class="cx">     fprintf(stderr, &quot;Usage: testWASM [options]\n&quot;);
</span><span class="cx">     fprintf(stderr, &quot;  -h|--help  Prints this help message\n&quot;);
</span><span class="cx">     fprintf(stderr, &quot;  -l|--leb   Runs the LEB decoder tests\n&quot;);
</span><ins>+    fprintf(stderr, &quot;  -w|--web   Run the WASM tests\n&quot;);
</ins><span class="cx">     fprintf(stderr, &quot;\n&quot;);
</span><span class="cx"> 
</span><span class="cx">     exit(help ? EXIT_SUCCESS : EXIT_FAILURE);
</span><span class="lines">@@ -63,6 +69,9 @@
</span><span class="cx"> 
</span><span class="cx">         if (!strcmp(arg, &quot;-l&quot;) || !strcmp(arg, &quot;--leb&quot;))
</span><span class="cx">             m_runLEBTests = true;
</span><ins>+
+        if (!strcmp(arg, &quot;-w&quot;) || !strcmp(arg, &quot;--web&quot;))
+            m_runWASMTests = true;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (; i &lt; argc; ++i)
</span><span class="lines">@@ -109,7 +118,7 @@
</span><span class="cx">         Vector&lt;uint8_t&gt; vector = Vector&lt;uint8_t&gt; init; \
</span><span class="cx">         size_t offset = startOffset; \
</span><span class="cx">         uint32_t result; \
</span><del>-        bool status = decodeUInt32(vector, offset, result); \
</del><ins>+        bool status = decodeUInt32(vector.data(), vector.size(), offset, result); \
</ins><span class="cx">         RELEASE_ASSERT(status == expectedStatus); \
</span><span class="cx">         if (expectedStatus) { \
</span><span class="cx">             RELEASE_ASSERT(result == expectedResult); \
</span><span class="lines">@@ -157,7 +166,7 @@
</span><span class="cx">         Vector&lt;uint8_t&gt; vector = Vector&lt;uint8_t&gt; init; \
</span><span class="cx">         size_t offset = startOffset; \
</span><span class="cx">         int32_t result; \
</span><del>-        bool status = decodeInt32(vector, offset, result); \
</del><ins>+        bool status = decodeInt32(vector.data(), vector.size(), offset, result); \
</ins><span class="cx">         RELEASE_ASSERT(status == expectedStatus); \
</span><span class="cx">         if (expectedStatus) { \
</span><span class="cx">             int32_t expected = expectedResult; \
</span><span class="lines">@@ -173,7 +182,118 @@
</span><span class="cx">     FOR_EACH_SIGNED_LEB_TEST(TEST_SIGNED_LEB_DECODE)
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(WEBASSEMBLY)
</ins><span class="cx"> 
</span><ins>+static JSC::VM* vm;
+
+using namespace JSC;
+using namespace WASM;
+using namespace B3;
+
+template&lt;typename T, typename... Arguments&gt;
+T invoke(MacroAssemblerCodePtr ptr, Arguments... arguments)
+{
+    T (*function)(Arguments...) = bitwise_cast&lt;T(*)(Arguments...)&gt;(ptr.executableAddress());
+    return function(arguments...);
+}
+
+template&lt;typename T, typename... Arguments&gt;
+T invoke(const Compilation&amp; code, Arguments... arguments)
+{
+    return invoke&lt;T&gt;(code.code(), arguments...);
+}
+
+// For now we inline the test files.
+static void runWASMTests()
+{
+    {
+        // Generated from: (module (func &quot;return-i32&quot; (result i32) (return (i32.const 5))) )
+        Vector&lt;uint8_t&gt; vector = {
+            0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80,
+            0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82,
+            0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00,
+            0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f,
+            0x64, 0x65, 0x8b, 0x80, 0x80, 0x00, 0x01, 0x86, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x09, 0x01,
+            0x0f
+        };
+
+        Plan plan(*vm, vector);
+        if (plan.result.size() != 1 || !plan.result[0]) {
+            dataLogLn(&quot;Module failed to compile correctly.&quot;);
+            CRASH();
+        }
+
+        // Test this doesn't crash.
+        RELEASE_ASSERT(invoke&lt;int&gt;(*plan.result[0]) == 5);
+    }
+
+
+    {
+        // Generated from: (module (func &quot;return-i32&quot; (result i32) (return (i32.add (i32.const 5) (i32.const 6)))) )
+        Vector&lt;uint8_t&gt; vector = {
+            0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80,
+            0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82,
+            0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00,
+            0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f,
+            0x64, 0x65, 0x8e, 0x80, 0x80, 0x00, 0x01, 0x89, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x10, 0x06,
+            0x40, 0x09, 0x01, 0x0f
+        };
+
+        Plan plan(*vm, vector);
+        if (plan.result.size() != 1 || !plan.result[0]) {
+            dataLogLn(&quot;Module failed to compile correctly.&quot;);
+            CRASH();
+        }
+
+        // Test this doesn't crash.
+        RELEASE_ASSERT(invoke&lt;int&gt;(*plan.result[0]) == 11);
+    }
+    
+    {
+        // Generated from: (module (func &quot;return-i32&quot; (result i32) (return (i32.add (i32.add (i32.const 5) (i32.const 3)) (i32.const 3)))) )
+        Vector&lt;uint8_t&gt; vector = {
+            0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80,
+            0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82,
+            0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00,
+            0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f,
+            0x64, 0x65, 0x91, 0x80, 0x80, 0x00, 0x01, 0x8c, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x10, 0x03,
+            0x40, 0x10, 0x03, 0x40, 0x09, 0x01, 0x0f
+        };
+
+        Plan plan(*vm, vector);
+        if (plan.result.size() != 1 || !plan.result[0]) {
+            dataLogLn(&quot;Module failed to compile correctly.&quot;);
+            CRASH();
+        }
+
+        // Test this doesn't crash.
+        RELEASE_ASSERT(invoke&lt;int&gt;(*plan.result[0]) == 11);
+    }
+
+    {
+        // Generated from: (module (func &quot;return-i32&quot; (result i32) (block (return (i32.add (i32.add (i32.const 5) (i32.const 3)) (i32.const 3))))) )
+        Vector&lt;uint8_t&gt; vector = {
+            0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80,
+            0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82,
+            0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00,
+            0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f,
+            0x64, 0x65, 0x93, 0x80, 0x80, 0x00, 0x01, 0x8e, 0x80, 0x80, 0x00, 0x00, 0x01, 0x10, 0x05, 0x10,
+            0x03, 0x40, 0x10, 0x03, 0x40, 0x09, 0x01, 0x0f, 0x0f
+        };
+
+        Plan plan(*vm, vector);
+        if (plan.result.size() != 1 || !plan.result[0]) {
+            dataLogLn(&quot;Module failed to compile correctly.&quot;);
+            CRASH();
+        }
+
+        // Test this doesn't crash.
+        RELEASE_ASSERT(invoke&lt;int&gt;(*plan.result[0]) == 11);
+    }
+}
+
+#endif // ENABLE(WEBASSEMBLY)
+
</ins><span class="cx"> int main(int argc, char** argv)
</span><span class="cx"> {
</span><span class="cx">     CommandLine options(argc, argv);
</span><span class="lines">@@ -181,6 +301,18 @@
</span><span class="cx">     if (options.m_runLEBTests)
</span><span class="cx">         runLEBTests();
</span><span class="cx"> 
</span><ins>+
+    if (options.m_runWASMTests) {
+#if ENABLE(WEBASSEMBLY)
+        JSC::initializeThreading();
+        vm = &amp;JSC::VM::create(JSC::LargeHeap).leakRef();
+        runWASMTests();
+#else
+        dataLogLn(&quot;WASM is not enabled!&quot;);
+        return EXIT_FAILURE;
+#endif // ENABLE(WEBASSEMBLY)
+    }
+
</ins><span class="cx">     return EXIT_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmJSWASMModuleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/JSWASMModule.h (204483 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/JSWASMModule.h        2016-08-15 21:23:32 UTC (rev 204483)
+++ trunk/Source/JavaScriptCore/wasm/JSWASMModule.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -79,7 +79,7 @@
</span><span class="cx">     Vector&lt;WASMSignature&gt;&amp; signatures() { return m_signatures; }
</span><span class="cx">     Vector&lt;WASMFunctionImport&gt;&amp; functionImports() { return m_functionImports; }
</span><span class="cx">     Vector&lt;WASMFunctionImportSignature&gt;&amp; functionImportSignatures() { return m_functionImportSignatures; }
</span><del>-    Vector&lt;WASMType&gt;&amp; globalVariableTypes() { return m_globalVariableTypes; }
</del><ins>+    Vector&lt;WASMValueType&gt;&amp; globalVariableTypes() { return m_globalVariableTypes; }
</ins><span class="cx">     Vector&lt;WASMFunctionDeclaration&gt;&amp; functionDeclarations() { return m_functionDeclarations; }
</span><span class="cx">     Vector&lt;WASMFunctionPointerTable&gt;&amp; functionPointerTables() { return m_functionPointerTables; }
</span><span class="cx"> 
</span><span class="lines">@@ -99,7 +99,7 @@
</span><span class="cx">     Vector&lt;WASMSignature&gt; m_signatures;
</span><span class="cx">     Vector&lt;WASMFunctionImport&gt; m_functionImports;
</span><span class="cx">     Vector&lt;WASMFunctionImportSignature&gt; m_functionImportSignatures;
</span><del>-    Vector&lt;WASMType&gt; m_globalVariableTypes;
</del><ins>+    Vector&lt;WASMValueType&gt; m_globalVariableTypes;
</ins><span class="cx">     Vector&lt;WASMFunctionDeclaration&gt; m_functionDeclarations;
</span><span class="cx">     Vector&lt;WASMFunctionPointerTable&gt; m_functionPointerTables;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMB3IRGeneratorcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.cpp (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.cpp                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.cpp        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,201 @@
</span><ins>+/*
+ * Copyright (C) 2016 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 &quot;config.h&quot;
+#include &quot;WASMB3IRGenerator.h&quot;
+
+#include &quot;B3BasicBlockInlines.h&quot;
+#include &quot;B3ValueInlines.h&quot;
+#include &quot;B3Variable.h&quot;
+#include &quot;B3VariableValue.h&quot;
+#include &quot;WASMFunctionParser.h&quot;
+#include &lt;wtf/Optional.h&gt;
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+using namespace B3;
+
+class B3IRGenerator {
+public:
+    typedef Value* ExpressionType;
+
+    B3IRGenerator(Procedure&amp;);
+
+    void addLocal(WASMValueType, uint32_t);
+    ExpressionType addConstant(WASMValueType, uint64_t);
+
+    bool WARN_UNUSED_RETURN binaryOp(WASMBinaryOpType, ExpressionType left, ExpressionType right, ExpressionType&amp; result);
+
+    bool WARN_UNUSED_RETURN addBlock();
+    bool WARN_UNUSED_RETURN endBlock(Vector&lt;ExpressionType&gt;&amp; expressionStack);
+    bool WARN_UNUSED_RETURN addReturn(const Vector&lt;ExpressionType, 1&gt;&amp; returnValues);
+
+private:
+    Optional&lt;Vector&lt;Variable*&gt;&gt;&amp; stackForControlLevel(unsigned);
+    BasicBlock* blockForControlLevel(unsigned);
+    void unify(Variable* target, const ExpressionType source);
+    Vector&lt;Variable*&gt; initializeIncommingTypes(BasicBlock*, const Vector&lt;ExpressionType&gt;&amp;);
+    void unifyValuesWithLevel(const Vector&lt;ExpressionType&gt;&amp; resultStack, unsigned);
+
+    Procedure&amp; m_proc;
+    BasicBlock* m_currentBlock;
+    // This is a pair of the continuation and the types expected on the stack for that continuation.
+    Vector&lt;std::pair&lt;BasicBlock*, Optional&lt;Vector&lt;Variable*&gt;&gt;&gt;&gt; m_controlStack;
+};
+
+B3IRGenerator::B3IRGenerator(Procedure&amp; procedure)
+    : m_proc(procedure)
+{
+    m_currentBlock = m_proc.addBlock();
+}
+
+void B3IRGenerator::addLocal(WASMValueType, uint32_t)
+{
+    // TODO: Add locals.
+}
+
+bool B3IRGenerator::binaryOp(WASMBinaryOpType op, ExpressionType left, ExpressionType right, ExpressionType&amp; result)
+{
+    switch (op) {
+    case WASMBinaryOpType::I32Add: {
+        ASSERT(left-&gt;type() == B3::Int32 &amp;&amp; right-&gt;type() == B3::Int32);
+        result = m_currentBlock-&gt;appendNew&lt;Value&gt;(m_proc, Add, Origin(), left, right);
+        return true;
+    }
+    }
+}
+
+B3IRGenerator::ExpressionType B3IRGenerator::addConstant(WASMValueType type, uint64_t value)
+{
+    switch (type) {
+    case WASMValueType::I32:
+        return m_currentBlock-&gt;appendNew&lt;Const32Value&gt;(m_proc, Origin(), static_cast&lt;int32_t&gt;(value));
+    case WASMValueType::I64:
+        return m_currentBlock-&gt;appendNew&lt;Const64Value&gt;(m_proc, Origin(), value);
+    case WASMValueType::F32:
+        return m_currentBlock-&gt;appendNew&lt;ConstFloatValue&gt;(m_proc, Origin(), bitwise_cast&lt;float&gt;(static_cast&lt;int32_t&gt;(value)));
+    case WASMValueType::F64:
+        return m_currentBlock-&gt;appendNew&lt;ConstDoubleValue&gt;(m_proc, Origin(), bitwise_cast&lt;double&gt;(value));
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
+        return nullptr;
+    }
+}
+
+bool B3IRGenerator::addBlock()
+{
+    m_controlStack.append(std::make_pair(m_proc.addBlock(), Nullopt));
+    return true;
+}
+
+bool B3IRGenerator::endBlock(Vector&lt;ExpressionType&gt;&amp; expressionStack)
+{
+    // This means that we are exiting the function.
+    if (!m_controlStack.size()) {
+        // FIXME: Should this require the stack is empty? It's not clear from the current spec.
+        return !expressionStack.size();
+    }
+
+    unifyValuesWithLevel(expressionStack, 0);
+
+    m_currentBlock = m_controlStack.takeLast().first;
+    return true;
+}
+
+bool B3IRGenerator::addReturn(const Vector&lt;ExpressionType, 1&gt;&amp; returnValues)
+{
+    ASSERT(returnValues.size() &lt;= 1);
+    if (returnValues.size())
+        m_currentBlock-&gt;appendNewControlValue(m_proc, B3::Return, Origin(), returnValues[0]);
+    else
+        m_currentBlock-&gt;appendNewControlValue(m_proc, B3::Return, Origin());
+    return true;
+}
+
+void B3IRGenerator::unify(Variable* variable, ExpressionType source)
+{
+    m_currentBlock-&gt;appendNew&lt;VariableValue&gt;(m_proc, Set, Origin(), variable, source);
+}
+
+Vector&lt;Variable*&gt; B3IRGenerator::initializeIncommingTypes(BasicBlock* block, const Vector&lt;ExpressionType&gt;&amp; source)
+{
+    Vector&lt;Variable*&gt; result;
+    result.reserveInitialCapacity(source.size());
+    for (ExpressionType expr : source) {
+        ASSERT(expr-&gt;type() != Void);
+        Variable* var = m_proc.addVariable(expr-&gt;type());
+        result.append(var);
+        block-&gt;appendNew&lt;VariableValue&gt;(m_proc, B3::Get, Origin(), var);
+    }
+
+    return result;
+}
+
+void B3IRGenerator::unifyValuesWithLevel(const Vector&lt;ExpressionType&gt;&amp; resultStack, unsigned level)
+{
+    ASSERT(level &lt; m_controlStack.size());
+
+    Optional&lt;Vector&lt;Variable*&gt;&gt;&amp; expectedStack = stackForControlLevel(level);
+    if (!expectedStack) {
+        expectedStack = initializeIncommingTypes(blockForControlLevel(level), resultStack);
+        return;
+    }
+
+    ASSERT(expectedStack.value().size() != resultStack.size());
+
+    for (size_t i = 0; i &lt; resultStack.size(); ++i)
+        unify(expectedStack.value()[i], resultStack[i]);
+}
+    
+Optional&lt;Vector&lt;Variable*&gt;&gt;&amp; B3IRGenerator::stackForControlLevel(unsigned level)
+{
+    return m_controlStack[m_controlStack.size() - 1 - level].second;
+}
+
+BasicBlock* B3IRGenerator::blockForControlLevel(unsigned level)
+{
+    return m_controlStack[m_controlStack.size() - 1 - level].first;
+}
+
+std::unique_ptr&lt;Compilation&gt; parseAndCompile(VM&amp; vm, Vector&lt;uint8_t&gt;&amp; source, WASMFunctionInformation info, unsigned optLevel)
+{
+    Procedure procedure;
+    B3IRGenerator context(procedure);
+    WASMFunctionParser&lt;B3IRGenerator&gt; parser(context, source, info);
+    if (!parser.parse())
+        RELEASE_ASSERT_NOT_REACHED();
+
+    return std::make_unique&lt;Compilation&gt;(vm, procedure, optLevel);
+}
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMB3IRGeneratorhfromrev204483trunkSourceWTFwtfDataLogh"></a>
<div class="copfile"><h4>Copied: trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.h (from rev 204483, trunk/Source/WTF/wtf/DataLog.h) (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,44 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#include &quot;B3Compilation.h&quot;
+#include &quot;VM.h&quot;
+#include &quot;WASMFormat.h&quot;
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+std::unique_ptr&lt;B3::Compilation&gt; parseAndCompile(VM&amp;, Vector&lt;uint8_t&gt;&amp;, WASMFunctionInformation, unsigned optLevel = 1);
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFormath"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFormat.h (204483 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFormat.h        2016-08-15 21:23:32 UTC (rev 204483)
+++ trunk/Source/JavaScriptCore/wasm/WASMFormat.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -52,15 +52,17 @@
</span><span class="cx"> 
</span><span class="cx"> class JSFunction;
</span><span class="cx"> 
</span><del>-enum class WASMType : uint8_t {
</del><ins>+enum class WASMValueType : uint8_t {
</ins><span class="cx">     I32,
</span><ins>+    I64,
</ins><span class="cx">     F32,
</span><span class="cx">     F64,
</span><span class="cx">     NumberOfTypes
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-enum class WASMExpressionType : uint8_t {
</del><ins>+enum class WASMFunctionReturnType : uint8_t {
</ins><span class="cx">     I32,
</span><ins>+    I64,
</ins><span class="cx">     F32,
</span><span class="cx">     F64,
</span><span class="cx">     Void,
</span><span class="lines">@@ -68,8 +70,8 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> struct WASMSignature {
</span><del>-    WASMExpressionType returnType;
-    Vector&lt;WASMType&gt; arguments;
</del><ins>+    WASMFunctionReturnType returnType;
+    Vector&lt;WASMValueType&gt; arguments;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> struct WASMFunctionImport {
</span><span class="lines">@@ -91,6 +93,11 @@
</span><span class="cx">     Vector&lt;JSFunction*&gt; functions;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+struct WASMFunctionInformation {
+    size_t start;
+    size_t end;
+};
+
</ins><span class="cx"> } // namespace JSC
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(WEBASSEMBLY)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionParserh"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,163 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#include &quot;WASMParser.h&quot;
+#include &lt;wtf/DataLog.h&gt;
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+template&lt;typename Context&gt;
+class WASMFunctionParser : public WASMParser {
+public:
+    typedef typename Context::ExpressionType ExpressionType;
+
+    WASMFunctionParser(Context&amp;, const Vector&lt;uint8_t&gt;&amp; sourceBuffer, const WASMFunctionInformation&amp;);
+
+    bool WARN_UNUSED_RETURN parse();
+
+private:
+    static const bool verbose = false;
+
+    bool WARN_UNUSED_RETURN parseBlock();
+    bool WARN_UNUSED_RETURN parseExpression(WASMOpType);
+    bool WARN_UNUSED_RETURN unifyControl(Vector&lt;ExpressionType&gt;&amp;, unsigned level);
+
+    Optional&lt;Vector&lt;ExpressionType&gt;&gt;&amp; stackForControlLevel(unsigned level);
+
+    Context&amp; m_context;
+    Vector&lt;ExpressionType&gt; m_expressionStack;
+};
+
+template&lt;typename Context&gt;
+WASMFunctionParser&lt;Context&gt;::WASMFunctionParser(Context&amp; context, const Vector&lt;uint8_t&gt;&amp; sourceBuffer, const WASMFunctionInformation&amp; info)
+    : WASMParser(sourceBuffer, info.start, info.end)
+    , m_context(context)
+{
+}
+
+template&lt;typename Context&gt;
+bool WASMFunctionParser&lt;Context&gt;::parse()
+{
+    uint32_t localCount;
+    if (!parseVarUInt32(localCount))
+        return false;
+
+    for (uint32_t i = 0; i &lt; localCount; ++i) {
+        uint32_t numberOfLocalsWithType;
+        if (!parseUInt32(numberOfLocalsWithType))
+            return false;
+
+        WASMValueType typeOfLocal;
+        if (!parseValueType(typeOfLocal))
+            return false;
+
+        m_context.addLocal(typeOfLocal, numberOfLocalsWithType);
+    }
+
+    return parseBlock();
+}
+
+template&lt;typename Context&gt;
+bool WASMFunctionParser&lt;Context&gt;::parseBlock()
+{
+    while (true) {
+        uint8_t op;
+        if (!parseUInt7(op))
+            return false;
+
+        if (!parseExpression(static_cast&lt;WASMOpType&gt;(op))) {
+            if (verbose)
+                dataLogLn(&quot;failed to process op:&quot;, op);
+            return false;
+        }
+
+        if (op == WASMOpType::End)
+            break;
+    }
+
+    return true;
+}
+
+template&lt;typename Context&gt;
+bool WASMFunctionParser&lt;Context&gt;::parseExpression(WASMOpType op)
+{
+    switch (op) {
+#define CREATE_CASE(name, value) case name:
+    FOR_EACH_WASM_BINARY_OP(CREATE_CASE) {
+#undef CREATE_CASE
+        ExpressionType left = m_expressionStack.takeLast();
+        ExpressionType right = m_expressionStack.takeLast();
+        ExpressionType result;
+        if (!m_context.binaryOp(static_cast&lt;WASMBinaryOpType&gt;(op), left, right, result))
+            return false;
+        m_expressionStack.append(result);
+        return true;
+    }
+
+    case WASMOpType::I32Const: {
+        uint32_t constant;
+        if (!parseVarUInt32(constant))
+            return false;
+        m_expressionStack.append(m_context.addConstant(WASMValueType::I32, constant));
+        return true;
+    }
+
+    case WASMOpType::Block: {
+        if (!m_context.addBlock())
+            return false;
+        return parseBlock();
+    }
+
+    case WASMOpType::Return: {
+        uint8_t returnCount;
+        if (!parseVarUInt1(returnCount))
+            return false;
+        Vector&lt;ExpressionType, 1&gt; returnValues;
+        if (returnCount)
+            returnValues.append(m_expressionStack.takeLast());
+
+        return m_context.addReturn(returnValues);
+    }
+
+    case WASMOpType::End:
+        return m_context.endBlock(m_expressionStack);
+
+    }
+
+    // Unknown opcode.
+    return false;
+}
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMModuleParsercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,231 @@
</span><ins>+/*
+ * Copyright (C) 2016 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 &quot;config.h&quot;
+#include &quot;WASMModuleParser.h&quot;
+
+#include &quot;WASMFormat.h&quot;
+#include &quot;WASMOps.h&quot;
+#include &quot;WASMSections.h&quot;
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+static const bool verbose = false;
+
+bool WASMModuleParser::parse()
+{
+    if (m_sourceLength &lt; 8)
+        return false;
+    if (!consumeCharacter(0))
+        return false;
+    if (!consumeString(&quot;asm&quot;))
+        return false;
+
+    // Skip the version number for now since we don't do anything with it.
+    uint32_t versionNumber;
+    if (!parseUInt32(versionNumber))
+        return false;
+
+    if (versionNumber != magicNumber)
+        return false;
+
+
+    if (verbose)
+        dataLogLn(&quot;Passed processing header.&quot;);
+
+    WASMSections::Section previousSection = WASMSections::Section::Unknown;
+    while (m_offset &lt; m_sourceLength) {
+        if (verbose)
+            dataLogLn(&quot;Starting to parse next section at offset: &quot;, m_offset);
+        uint32_t sectionNameLength;
+        if (!parseVarUInt32(sectionNameLength))
+            return false;
+
+        // Make sure we can read up to the section's size.
+        if (m_offset + sectionNameLength + maxLEBByteLength &gt;= m_sourceLength)
+            return false;
+
+        WASMSections::Section section = WASMSections::lookup(m_source.data() + m_offset, sectionNameLength);
+        if (!WASMSections::validateOrder(previousSection, section))
+            return false;
+        m_offset += sectionNameLength;
+
+        uint32_t sectionLength;
+        if (!parseVarUInt32(sectionLength))
+            return false;
+
+        unsigned end = m_offset + sectionLength;
+
+        switch (section) {
+        case WASMSections::Section::End:
+            return true;
+
+        case WASMSections::Section::FunctionTypes: {
+            if (verbose)
+                dataLogLn(&quot;Parsing types.&quot;);
+            if (!parseFunctionTypes())
+                return false;
+            break;
+        }
+
+        case WASMSections::Section::Signatures: {
+            if (verbose)
+                dataLogLn(&quot;Parsing function signatures.&quot;);
+            if (!parseFunctionSignatures())
+                return false;
+            break;
+        }
+
+        case WASMSections::Section::Definitions: {
+            if (verbose)
+                dataLogLn(&quot;Parsing function definitions.&quot;);
+            if (!parseFunctionDefinitions())
+                return false;
+            break;
+        }
+
+        case WASMSections::Section::Unknown: {
+            if (verbose)
+                dataLogLn(&quot;Unknown section, skipping.&quot;);
+            m_offset += sectionLength;
+            break;
+        }
+        }
+
+        if (verbose)
+            dataLogLn(&quot;Finished parsing section.&quot;);
+
+        if (end != m_offset)
+            return false;
+
+        previousSection = section;
+    }
+
+    // TODO
+    return true;
+}
+
+bool WASMModuleParser::parseFunctionTypes()
+{
+    uint32_t count;
+    if (!parseVarUInt32(count))
+        return false;
+
+    if (verbose)
+        dataLogLn(&quot;count: &quot;, count);
+
+    for (uint32_t i = 0; i &lt; count; ++i) {
+        uint8_t type;
+        if (!parseUInt7(type))
+            return false;
+        if (type != 0x40) // Function type constant.
+            return false;
+
+        if (verbose)
+            dataLogLn(&quot;Got function type.&quot;);
+
+        uint32_t argumentCount;
+        if (!parseVarUInt32(argumentCount))
+            return false;
+
+        if (verbose)
+            dataLogLn(&quot;argumentCount: &quot;, argumentCount);
+
+        Vector&lt;WASMValueType&gt; argumentTypes;
+        for (unsigned i = 0; i &lt; argumentCount; ++i) {
+            if (!parseUInt7(type) || type &gt;= static_cast&lt;uint8_t&gt;(WASMValueType::NumberOfTypes))
+                return false;
+            argumentTypes.append(static_cast&lt;WASMValueType&gt;(type));
+        }
+
+        if (!parseVarUInt1(type))
+            return false;
+        WASMFunctionReturnType returnType;
+
+        if (verbose)
+            dataLogLn(type);
+
+        if (type) {
+            WASMValueType value;
+            if (!parseValueType(value))
+                return false;
+            returnType = static_cast&lt;WASMFunctionReturnType&gt;(value);
+        } else
+            returnType = WASMFunctionReturnType::Void;
+
+        // TODO: Actually do something with this data...
+    }
+    return true;
+}
+
+bool WASMModuleParser::parseFunctionSignatures()
+{
+    uint32_t count;
+    if (!parseVarUInt32(count))
+        return false;
+
+    m_functions.resize(count);
+
+    for (uint32_t i = 0; i &lt; count; ++i) {
+        uint32_t typeNumber;
+        if (!parseVarUInt32(typeNumber))
+            return false;
+    }
+
+    return true;
+}
+
+bool WASMModuleParser::parseFunctionDefinitions()
+{
+    uint32_t count;
+    if (!parseVarUInt32(count))
+        return false;
+
+    if (count != m_functions.size())
+        return false;
+
+    for (uint32_t i = 0; i &lt; count; ++i) {
+        uint32_t functionSize;
+        if (!parseVarUInt32(functionSize))
+            return false;
+
+        WASMFunctionInformation&amp; info = m_functions[i];
+        info.start = m_offset;
+        info.end = m_offset + functionSize;
+        m_offset = info.end;
+    }
+
+    return true;
+}
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMModuleParserhfromrev204483trunkSourceWTFwtfDataLogh"></a>
<div class="copfile"><h4>Copied: trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h (from rev 204483, trunk/Source/WTF/wtf/DataLog.h) (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,67 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#include &quot;WASMOps.h&quot;
+#include &quot;WASMParser.h&quot;
+#include &lt;wtf/Vector.h&gt;
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+class WASMModuleParser : public WASMParser {
+public:
+
+    static const unsigned magicNumber = 0xc;
+
+    WASMModuleParser(const Vector&lt;uint8_t&gt;&amp; sourceBuffer)
+        : WASMParser(sourceBuffer, 0, sourceBuffer.size())
+    {
+    }
+
+    bool WARN_UNUSED_RETURN parse();
+
+    const Vector&lt;WASMFunctionInformation&gt;&amp; functionInformation() { return m_functions; }
+
+private:
+    bool WARN_UNUSED_RETURN parseFunctionTypes();
+    bool WARN_UNUSED_RETURN parseFunctionSignatures();
+    bool WARN_UNUSED_RETURN parseFunctionDefinitions();
+    bool WARN_UNUSED_RETURN parseFunctionDefinition(uint32_t number);
+    bool WARN_UNUSED_RETURN parseBlock();
+    bool WARN_UNUSED_RETURN parseExpression(WASMOpType);
+
+    Vector&lt;WASMFunctionInformation&gt; m_functions;
+};
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMOpshfromrev204483trunkSourceWTFwtfDataLogh"></a>
<div class="copfile"><h4>Copied: trunk/Source/JavaScriptCore/wasm/WASMOps.h (from rev 204483, trunk/Source/WTF/wtf/DataLog.h) (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMOps.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMOps.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,71 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+#define FOR_EACH_WASM_SPECIAL_OP(macro) \
+    macro(I32Const, 0x10)
+
+#define FOR_EACH_WASM_CONTROL_FLOW_OP(macro) \
+    macro(Block, 0x01) \
+    macro(Return, 0x09) \
+    macro(End, 0x0f)
+
+#define FOR_EACH_WASM_UNARY_OP(macro)
+
+#define FOR_EACH_WASM_BINARY_OP(macro) \
+    macro(I32Add, 0x40)
+
+#define FOR_EACH_WASM_OP(macro) \
+    FOR_EACH_WASM_SPECIAL_OP(macro) \
+    FOR_EACH_WASM_CONTROL_FLOW_OP(macro) \
+    FOR_EACH_WASM_UNARY_OP(macro) \
+    FOR_EACH_WASM_BINARY_OP(macro)
+
+#define CREATE_ENUM_VALUE(name, id) name = id,
+
+enum WASMOpType : uint8_t {
+    FOR_EACH_WASM_OP(CREATE_ENUM_VALUE)
+};
+
+
+
+enum class WASMBinaryOpType : uint8_t {
+    FOR_EACH_WASM_BINARY_OP(CREATE_ENUM_VALUE)
+};
+
+} // namespace WASM
+
+} // namespace JSC
+
+#undef CREATE_ENUM_VALUE
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMParserh"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/wasm/WASMParser.h (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMParser.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMParser.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,134 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#include &quot;B3Compilation.h&quot;
+#include &quot;B3Procedure.h&quot;
+#include &quot;WASMFormat.h&quot;
+#include &quot;WASMOps.h&quot;
+#include &quot;WASMSections.h&quot;
+#include &lt;wtf/LEBDecoder.h&gt;
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+class WASMParser {
+protected:
+    WASMParser(const Vector&lt;uint8_t&gt;&amp;, size_t start, size_t end);
+
+    bool WARN_UNUSED_RETURN consumeCharacter(char);
+    bool WARN_UNUSED_RETURN consumeString(const char*);
+
+    bool WARN_UNUSED_RETURN parseVarUInt1(uint8_t&amp; result);
+    bool WARN_UNUSED_RETURN parseUInt7(uint8_t&amp; result);
+    bool WARN_UNUSED_RETURN parseUInt32(uint32_t&amp; result);
+    bool WARN_UNUSED_RETURN parseVarUInt32(uint32_t&amp; result) { return decodeUInt32(m_source.data(), m_sourceLength, m_offset, result); }
+
+
+    bool WARN_UNUSED_RETURN parseValueType(WASMValueType&amp; result);
+
+    const Vector&lt;uint8_t&gt;&amp; m_source;
+    size_t m_sourceLength;
+    size_t m_offset;
+};
+
+ALWAYS_INLINE WASMParser::WASMParser(const Vector&lt;uint8_t&gt;&amp; sourceBuffer, size_t start, size_t end)
+    : m_source(sourceBuffer)
+    , m_sourceLength(end)
+    , m_offset(start)
+{
+    ASSERT(end &lt;= sourceBuffer.size());
+    ASSERT(start &lt; end);
+}
+
+ALWAYS_INLINE bool WASMParser::consumeCharacter(char c)
+{
+    if (m_offset &gt;= m_sourceLength)
+        return false;
+    if (c == m_source[m_offset]) {
+        m_offset++;
+        return true;
+    }
+    return false;
+}
+
+ALWAYS_INLINE bool WASMParser::consumeString(const char* str)
+{
+    unsigned start = m_offset;
+    for (unsigned i = 0; str[i]; i++) {
+        if (!consumeCharacter(str[i])) {
+            m_offset = start;
+            return false;
+        }
+    }
+    return true;
+}
+
+ALWAYS_INLINE bool WASMParser::parseUInt32(uint32_t&amp; result)
+{
+    if (m_offset + 4 &gt;= m_sourceLength)
+        return false;
+    result = *reinterpret_cast&lt;const uint32_t*&gt;(m_source.data() + m_offset);
+    m_offset += 4;
+    return true;
+}
+
+ALWAYS_INLINE bool WASMParser::parseUInt7(uint8_t&amp; result)
+{
+    if (m_offset &gt;= m_sourceLength)
+        return false;
+    result = m_source[m_offset++];
+    return result &lt; 0x80;
+}
+
+ALWAYS_INLINE bool WASMParser::parseVarUInt1(uint8_t&amp; result)
+{
+    uint32_t temp;
+    if (!parseVarUInt32(temp))
+        return false;
+    result = static_cast&lt;uint8_t&gt;(temp);
+    return temp &lt;= 1;
+}
+
+ALWAYS_INLINE bool WASMParser::parseValueType(WASMValueType&amp; result)
+{
+    uint8_t value;
+    if (!parseUInt7(value))
+        return false;
+    if (value &gt;= static_cast&lt;uint8_t&gt;(WASMValueType::NumberOfTypes))
+        return false;
+    result = static_cast&lt;WASMValueType&gt;(value);
+    return true;
+}
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMPlancppfromrev204483trunkSourceWTFwtfDataLogh"></a>
<div class="copfile"><h4>Copied: trunk/Source/JavaScriptCore/wasm/WASMPlan.cpp (from rev 204483, trunk/Source/WTF/wtf/DataLog.h) (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMPlan.cpp                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMPlan.cpp        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,66 @@
</span><ins>+/*
+ * Copyright (C) 2016 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 &quot;config.h&quot;
+#include &quot;WASMPlan.h&quot;
+
+#include &quot;B3Compilation.h&quot;
+#include &quot;WASMB3IRGenerator.h&quot;
+#include &quot;WASMModuleParser.h&quot;
+#include &lt;wtf/DataLog.h&gt;
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+static const bool verbose = false;
+
+Plan::Plan(VM&amp; vm, Vector&lt;uint8_t&gt; source)
+{
+    if (verbose)
+        dataLogLn(&quot;Starting plan.&quot;);
+    WASMModuleParser moduleParser(source);
+    if (!moduleParser.parse()) {
+        dataLogLn(&quot;Parsing module failed.&quot;);
+        return;
+    }
+
+    if (verbose)
+        dataLogLn(&quot;Parsed module.&quot;);
+
+    for (const WASMFunctionInformation&amp; info : moduleParser.functionInformation()) {
+        if (verbose)
+            dataLogLn(&quot;Processing funcion starting at: &quot;, info.start, &quot; and ending at: &quot;, info.end);
+        result.append(parseAndCompile(vm, source, info));
+    }
+}
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMPlanhfromrev204483trunkSourceWTFwtfDataLogh"></a>
<div class="copfile"><h4>Copied: trunk/Source/JavaScriptCore/wasm/WASMPlan.h (from rev 204483, trunk/Source/WTF/wtf/DataLog.h) (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMPlan.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMPlan.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,55 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#include &quot;CompilationResult.h&quot;
+#include &quot;VM.h&quot;
+#include &lt;wtf/ThreadSafeRefCounted.h&gt;
+#include &lt;wtf/Vector.h&gt;
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace B3 {
+class Compilation;
+} // namespace B3
+
+namespace WASM {
+
+// TODO: This should create a WASM Module not a list of functions.
+class Plan {
+public:
+    JS_EXPORT_PRIVATE Plan(VM&amp;, Vector&lt;uint8_t&gt; source);
+
+    Vector&lt;std::unique_ptr&lt;B3::Compilation&gt;&gt; result;
+};
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMSectionscppfromrev204483trunkSourceWTFwtfDataLogh"></a>
<div class="copfile"><h4>Copied: trunk/Source/JavaScriptCore/wasm/WASMSections.cpp (from rev 204483, trunk/Source/WTF/wtf/DataLog.h) (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMSections.cpp                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMSections.cpp        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,69 @@
</span><ins>+/*
+ * Copyright (C) 2016 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 &quot;config.h&quot;
+#include &quot;WASMSections.h&quot;
+
+#include &lt;wtf/DataLog.h&gt;
+#include &lt;wtf/text/WTFString.h&gt;
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+struct SectionData {
+    unsigned length;
+    const char* name;
+};
+
+static const bool verbose = false;
+
+static const unsigned sectionDataLength = static_cast&lt;unsigned&gt;(WASMSections::Section::Unknown);
+static const SectionData sectionData[sectionDataLength] {
+#define CREATE_SECTION_DATA(name, str) { sizeof(str) - 1, str },
+    FOR_EACH_WASM_SECTION_TYPE(CREATE_SECTION_DATA)
+#undef CREATE_SECTION_DATA
+};
+
+WASMSections::Section WASMSections::lookup(const uint8_t* name, unsigned length)
+{
+    if (verbose)
+        dataLogLn(&quot;Decoding section with name: &quot;, String(name, length));
+    for (unsigned i = 0; i &lt; sectionDataLength; ++i) {
+        if (sectionData[i].length != length)
+            continue;
+        if (!memcmp(name, sectionData[i].name, length))
+            return static_cast&lt;WASMSections::Section&gt;(i);
+    }
+    return WASMSections::Section::Unknown;
+}
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMSectionshfromrev204483trunkSourceWTFwtfDataLogh"></a>
<div class="copfile"><h4>Copied: trunk/Source/JavaScriptCore/wasm/WASMSections.h (from rev 204483, trunk/Source/WTF/wtf/DataLog.h) (0 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMSections.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/WASMSections.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -0,0 +1,63 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC {
+
+namespace WASM {
+
+// These should be in the order that we expect them to be in the binary.
+#define FOR_EACH_WASM_SECTION_TYPE(macro) \
+    macro(FunctionTypes, &quot;type&quot;) \
+    macro(Signatures, &quot;function&quot;) \
+    macro(Definitions, &quot;code&quot;) \
+    macro(End, &quot;end&quot;)
+
+struct WASMSections {
+    enum class Section {
+#define CREATE_SECTION_ENUM(name, str) name,
+        FOR_EACH_WASM_SECTION_TYPE(CREATE_SECTION_ENUM)
+#undef CREATE_SECTION_ENUM
+        Unknown
+    };
+    static Section lookup(const uint8_t*, unsigned);
+    static bool validateOrder(Section previous, Section next)
+    {
+        // This allows unknown sections after End, which I doubt will ever be supported but
+        // there is no reason to potentially break backwards compatability.
+        if (previous == Section::Unknown)
+            return true;
+        return previous &lt; next;
+    }
+};
+
+} // namespace WASM
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
</ins></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (204483 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-08-15 21:23:32 UTC (rev 204483)
+++ trunk/Source/WTF/ChangeLog        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2016-08-15  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        Implement WASM Parser and B3 IR generator
+        https://bugs.webkit.org/show_bug.cgi?id=160681
+
+        Reviewed by Benjamin Poulain.
+
+        * wtf/DataLog.h:
+        (WTF::dataLogLn): Add a new dataLog function, dataLogLn that
+        automagically includes a new line at the end of the print.
+        * wtf/LEBDecoder.h:
+        (decodeUInt32):
+        (decodeInt32): Change the LEBDecoder to take a pointer and length
+        rather than a Vector.
+
</ins><span class="cx"> 2016-08-15  Keith Rollin  &lt;krollin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Rename LOG_ALWAYS
</span></span></pre></div>
<a id="trunkSourceWTFwtfDataLogh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/DataLog.h (204483 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/DataLog.h        2016-08-15 21:23:32 UTC (rev 204483)
+++ trunk/Source/WTF/wtf/DataLog.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -45,9 +45,16 @@
</span><span class="cx">     dataFile().print(values...);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template&lt;typename... Types&gt;
+void dataLogLn(const Types&amp;... values)
+{
+    dataFile().print(values..., &quot;\n&quot;);
+}
+
</ins><span class="cx"> } // namespace WTF
</span><span class="cx"> 
</span><span class="cx"> using WTF::dataLog;
</span><ins>+using WTF::dataLogLn;
</ins><span class="cx"> using WTF::dataLogF;
</span><span class="cx"> using WTF::dataLogFString;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWTFwtfLEBDecoderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/LEBDecoder.h (204483 => 204484)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/LEBDecoder.h        2016-08-15 21:23:32 UTC (rev 204483)
+++ trunk/Source/WTF/wtf/LEBDecoder.h        2016-08-15 21:35:07 UTC (rev 204484)
</span><span class="lines">@@ -26,11 +26,8 @@
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><span class="cx"> #include &quot;Compiler.h&quot;
</span><del>-#include &quot;Vector.h&quot;
</del><span class="cx"> #include &lt;algorithm&gt;
</span><span class="cx"> 
</span><del>-#include &quot;DataLog.h&quot;
-
</del><span class="cx"> // This file contains a bunch of helper functions for decoding LEB numbers.
</span><span class="cx"> // See https://en.wikipedia.org/wiki/LEB128 for more information about the
</span><span class="cx"> // LEB format.
</span><span class="lines">@@ -37,12 +34,12 @@
</span><span class="cx"> 
</span><span class="cx"> const size_t maxLEBByteLength = 5;
</span><span class="cx"> 
</span><del>-inline bool WARN_UNUSED_RETURN decodeUInt32(const Vector&lt;uint8_t&gt;&amp; bytes, size_t&amp; offset, uint32_t&amp; result)
</del><ins>+inline bool WARN_UNUSED_RETURN decodeUInt32(const uint8_t* bytes, size_t length, size_t&amp; offset, uint32_t&amp; result)
</ins><span class="cx"> {
</span><del>-    ASSERT(bytes.size() &gt; offset);
</del><ins>+    ASSERT(length &gt; offset);
</ins><span class="cx">     result = 0;
</span><span class="cx">     unsigned shift = 0;
</span><del>-    size_t last = std::min(maxLEBByteLength, bytes.size() - offset - 1);
</del><ins>+    size_t last = std::min(maxLEBByteLength, length - offset - 1);
</ins><span class="cx">     for (unsigned i = 0; true; ++i) {
</span><span class="cx">         uint8_t byte = bytes[offset++];
</span><span class="cx">         result |= (byte &amp; 0x7f) &lt;&lt; shift;
</span><span class="lines">@@ -56,12 +53,12 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline bool WARN_UNUSED_RETURN decodeInt32(const Vector&lt;uint8_t&gt;&amp; bytes, size_t&amp; offset, int32_t&amp; result)
</del><ins>+inline bool WARN_UNUSED_RETURN decodeInt32(const uint8_t* bytes, size_t length, size_t&amp; offset, int32_t&amp; result)
</ins><span class="cx"> {
</span><del>-    ASSERT(bytes.size() &gt; offset);
</del><ins>+    ASSERT(length &gt; offset);
</ins><span class="cx">     result = 0;
</span><span class="cx">     unsigned shift = 0;
</span><del>-    size_t last = std::min(maxLEBByteLength, bytes.size() - offset - 1);
</del><ins>+    size_t last = std::min(maxLEBByteLength, length - offset - 1);
</ins><span class="cx">     uint8_t byte;
</span><span class="cx">     for (unsigned i = 0; true; ++i) {
</span><span class="cx">         byte = bytes[offset++];
</span></span></pre>
</div>
</div>

</body>
</html>