Implement WASM Parser and B3 IR generator
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Aug 2016 21:35:07 +0000 (21:35 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Aug 2016 21:35:07 +0000 (21:35 +0000)
commitcc619f11704dd893f01424de54dd65f66602ca0c
tree96e876cea8387faa7bbd27be540610b3e383d1b7
parentd4d98b30006e38aad1358529a33dacbeb61b1015
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<Context>::WASMFunctionParser):
(JSC::WASM::WASMFunctionParser<Context>::parse):
(JSC::WASM::WASMFunctionParser<Context>::parseBlock):
(JSC::WASM::WASMFunctionParser<Context>::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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204484 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/testWASM.cpp
Source/JavaScriptCore/wasm/JSWASMModule.h
Source/JavaScriptCore/wasm/WASMB3IRGenerator.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMB3IRGenerator.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMFormat.h
Source/JavaScriptCore/wasm/WASMFunctionParser.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMModuleParser.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMModuleParser.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMOps.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMParser.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMPlan.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMPlan.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMSections.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/WASMSections.h [new file with mode: 0644]
Source/WTF/ChangeLog
Source/WTF/wtf/DataLog.h
Source/WTF/wtf/LEBDecoder.h