├── .gitignore ├── AUTHORS ├── LICENSE ├── Makefile ├── README.md ├── jslib ├── load-wasm-worker.js └── load-wasm.js ├── src ├── cashew │ ├── .gitignore │ ├── README.md │ ├── build.sh │ ├── istring.h │ ├── parser.cpp │ ├── parser.h │ ├── samples │ │ ├── 1.js │ │ ├── 1.js.1_0.js │ │ ├── 1.js.txt │ │ ├── 10.js │ │ ├── 10.js.1_0.js │ │ ├── 10.js.txt │ │ ├── 2.js │ │ ├── 2.js.1_0.js │ │ ├── 2.js.txt │ │ ├── 3.js │ │ ├── 3.js.1_0.js │ │ ├── 3.js.txt │ │ ├── 4.js │ │ ├── 4.js.1_0.js │ │ ├── 4.js.txt │ │ ├── 5.js │ │ ├── 5.js.1_0.js │ │ ├── 5.js.txt │ │ ├── 6.js │ │ ├── 6.js.1_0.js │ │ ├── 6.js.txt │ │ ├── 7.js │ │ ├── 7.js.1_0.js │ │ ├── 7.js.txt │ │ ├── 8.js │ │ ├── 8.js.1_0.js │ │ ├── 8.js.txt │ │ ├── 9.js │ │ ├── 9.js.1_0.js │ │ └── 9.js.txt │ ├── simple_ast.cpp │ ├── simple_ast.h │ ├── snprintf.h │ ├── test.cpp │ └── test.py ├── load-wasm-worker.js ├── pack-asmjs.cpp ├── shared.h ├── unpack-asmjs.cpp ├── unpack.cpp └── unpack.h ├── test ├── a01.js ├── a02.js ├── a03.js ├── a04.js ├── a05.js ├── a06.js ├── a07.js ├── a08.js ├── a09.js ├── a10.js ├── a11.js ├── a12.js ├── a13.js ├── a14.js ├── a15.js └── a16.js └── vs ├── .gitignore ├── pack-asmjs.vcxproj ├── polyfill-prototype-1.sln └── unpack-asmjs.vcxproj /.gitignore: -------------------------------------------------------------------------------- 1 | tools/* 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | The following authors have all licensed their contributions to this 2 | repository under the licensing terms detailed in LICENSE. 3 | 4 | (Authors keep copyright of their contributions, of course; they just grant 5 | a license to everyone to use it as detailed in LICENSE.) 6 | 7 | * Luke Wagner (copyright owned by Mozilla Foundation) 8 | * Alon Zakai (copyright owned by Mozilla Foundation) 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright (c) 2015 repository authors, see AUTHORS file. 190 | 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Patches welcome to actually make this portable 2 | 3 | default: tools/pack-asmjs tools/unpack-asmjs jslib/load-wasm-worker.js 4 | 5 | tools/pack-asmjs: src/pack-asmjs.cpp src/unpack.cpp src/unpack.h src/shared.h src/cashew/parser.h src/cashew/parser.cpp src/cashew/istring.h 6 | mkdir -p tools 7 | c++ -O3 -g -std=c++11 -DCHECKED_OUTPUT_SIZE -Wall -pedantic \ 8 | src/pack-asmjs.cpp src/unpack.cpp src/cashew/parser.cpp \ 9 | -o tools/pack-asmjs 10 | 11 | tools/unpack-asmjs: src/unpack-asmjs.cpp src/unpack.cpp src/unpack.h src/shared.h 12 | mkdir -p tools 13 | c++ -DNDEBUG -O3 -std=c++11 -Wall -pedantic \ 14 | src/unpack-asmjs.cpp src/unpack.cpp \ 15 | -o tools/unpack-asmjs 16 | 17 | jslib/load-wasm-worker.js: src/unpack.cpp src/unpack.h src/shared.h src/load-wasm-worker.js 18 | emcc -DNDEBUG -O3 -std=c++11 -Wall -pedantic \ 19 | --memory-init-file 0 --llvm-lto 1 -s TOTAL_MEMORY=67108864 \ 20 | src/unpack.cpp \ 21 | -o jslib/load-wasm-worker.js 22 | cat src/load-wasm-worker.js >> jslib/load-wasm-worker.js 23 | 24 | .PHONY: test 25 | test: tools/pack-asmjs tools/unpack-asmjs 26 | mkdir -p /tmp/test 27 | for tjs in test/*.js; do \ 28 | t=$${tjs%.js}; \ 29 | ( tools/pack-asmjs $$t.js /tmp/$$t.wasm || \ 30 | ( echo "Failure running: tools/pack-asmjs $$t.js /tmp/$$t.wasm" && false) ) && \ 31 | \ 32 | ( tools/unpack-asmjs /tmp/$$t.wasm /tmp/$$t.js || \ 33 | ( echo "Failure running: tools/unpack-asmjs /tmp/$$t.wasm /tmp/$$t.js" && false) ) && \ 34 | \ 35 | ( diff $$t.js /tmp/$$t.js || \ 36 | ( echo "Failure running: diff $$t.js /tmp/$$t.js" && false) ); \ 37 | \ 38 | true; \ 39 | done 40 | 41 | .PHONY: clean 42 | clean: 43 | rm -f tools/pack-asmjs tools/unpack-asmjs 44 | rmdir tools 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebAssembly Polyfill (prototype) 2 | 3 | **This repo contains a prototype built to demonstrate the 4 | viability of a WebAssembly polyfill. Work is ongoing in other repos to design 5 | the actual standard binary format. This prototype also makes no attempt to call 6 | native browser decoding and so it is not, technically, a polyfill but rather a 7 | pure JS library.** 8 | 9 | ## Demos 10 | 11 | See [FAQ entry](https://github.com/WebAssembly/design/blob/master/FAQ.md#can-the-polyfill-really-be-efficient). 12 | 13 | ## How it (currently) works 14 | 15 | A real (non-prototype) polyfill would hook into an [ES6 Module loader 16 | polyfill](https://github.com/ModuleLoader/es6-module-loader) so that loading a 17 | WebAssembly module will Just Work. The scheme described here is just a proof of 18 | concept for how the polyfill can avoid massive copying, string manipulation and 19 | garbage. 20 | 21 | 1. On the main thread, the client kicks off a load of a URL by calling 22 | [`loadWebAssembly`](https://github.com/WebAssembly/polyfill-prototype-1/blob/master/jslib/load-wasm.js#L6) 23 | and receives a `Promise`. 24 | 2. The polyfill library starts up a worker containing asm.js code compiled from 25 | [`unpack.cpp`](https://github.com/WebAssembly/polyfill-prototype-1/blob/master/src/unpack.cpp) 26 | concatenated with the glue code in 27 | [`load-wasm-worker.js`](https://github.com/WebAssembly/polyfill-prototype-1/blob/master/src/load-wasm-worker.js). 28 | 2. The worker glue code fetches the binary via XHR then copies the result into the asm.js heap. 29 | 3. The asm.js code decodes the binary into asm.js in the form of UTF8 bytes in a separate region of the asm.js heap. 30 | 4. The worker glue code creates a `Blob` (a read-only copy) from a view of just the asm.js UTF8 bytes. 31 | 5. The `Blob` is `postMessage()`ed back to the main thread (a non-copying 32 | operation) where it is loaded as a script element with `script.src = URL.getObjectURL(blob)`. 33 | 6. When the asm.js script is executed, it passes the asm.js module function 34 | object to a callback which resolves the promise in step 1. 35 | 36 | ## Build instructions 37 | 38 | The library in `jslib/` should be ready to use, just copy both files and call `loadWebAssembly()`. 39 | 40 | Running `make` compiles the C++ implementation into the JS files in `jslib/` and 41 | into native executables in `tools/`. (The Makefile is currently super-unportable. 42 | Sorry! Patches welcome.) 43 | 44 | ## Packing asm.js into the binary format 45 | 46 | The polyfill also comes with a tool (`tools/pack-asmjs`) that compiles a single JS 47 | file (containing only asm.js) into the (experimental) WebAssembly format decoded by 48 | the library. Given an existing asm.js application, one can experiment with this 49 | polyfill (perform direct size/load-time comparisons) by following the steps: 50 | 1. Separate the asm.js module out into a separate file. 51 | 2. Run `tools/pack-asmjs` to produce a `.wasm` file. 52 | 3. Refactor the code that called the asm.js module to instead call `loadWebAssembly()` 53 | (which returns a promise that resolves to the unlinked asm.js module function). 54 | 55 | ## Future work 56 | 57 | * Decode while downloading (using HTTP `Range` requests or splitting into separate files) 58 | * Perform generic compression on top of the `.wasm` file (e.g., 59 | [lzham](https://github.com/richgel999/lzham_codec) gives a further 24% boost over `gzip`). 60 | -------------------------------------------------------------------------------- /jslib/load-wasm.js: -------------------------------------------------------------------------------- 1 | // This file implements a browser utility function to asychronously fetch, 2 | // decode and compile a given WebAssembly module. The caller passes in the url 3 | // of the .wasm file and the returned promise resolves to a compiled (but 4 | // unlinked) module. 5 | 6 | var loadWebAssembly = (function() { 7 | var globalNameCounter = 0; 8 | return function(packedURL, workerURL) { 9 | workerURL = workerURL || 'load-wasm-worker.js'; 10 | 11 | return new Promise(function(resolve, reject) { 12 | var callbackName = ""; 13 | do { 14 | callbackName = "onFinishLoadWebAssembly_" + globalNameCounter++; 15 | } while (Object.prototype.hasOwnProperty.call(window, callbackName)); 16 | window[callbackName] = function(asmModule) { 17 | delete window[callbackName]; 18 | resolve(asmModule); 19 | } 20 | 21 | var worker = new Worker(workerURL); 22 | worker.postMessage({url:packedURL, callbackName:callbackName}); 23 | worker.onmessage = function (e) { 24 | if (!(e.data instanceof Blob)) { 25 | reject("load-wasm-worker.js failed with: " + e.data); 26 | return; 27 | } 28 | 29 | var script = document.createElement('script'); 30 | var url = URL.createObjectURL(e.data); 31 | script.onload = script.onerror = function() { URL.revokeObjectURL(url) } 32 | script.src = url; 33 | document.body.appendChild(script); 34 | } 35 | }); 36 | } 37 | })(); 38 | -------------------------------------------------------------------------------- /src/cashew/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.gch 3 | a.out 4 | 5 | -------------------------------------------------------------------------------- /src/cashew/README.md: -------------------------------------------------------------------------------- 1 | cashew 2 | ====== 3 | 4 | Cashew is an asm.js parser written in C++. 5 | 6 | * Cashew has a parser which does not mandate any particular 7 | AST. You can plug in your AST builder methods. 8 | * Cashew comes with a simple AST that is similar to Uglify's 9 | AST. You can either use that, or consider it an example. 10 | * Cashew parses ASCII input. 11 | * Cashew is built for speed. 12 | * Cashew does not do much in terms of error checking. 13 | 14 | The main use case for Cashew is to quickly parse known-valid asm.js, 15 | in order to then process it. 16 | 17 | usage 18 | ----- 19 | 20 | `istring.h` and `cpp` implement an always-interned string class. This 21 | makes parsing much more efficient. 22 | 23 | `parser.h` and `cpp` implement the parser. It is templated on the AST 24 | pointer type, and a class that provides methods to build the 25 | various things necessary. 26 | 27 | `simple_ast.h` and `cpp` implement an AST using Cashew, and provide 28 | a builder, see ValueBuilder in the header. 29 | 30 | `test.cpp` is a simple example of using Cashew and the simple AST. It 31 | is used by `test.py`, which runs the test suite. 32 | 33 | -------------------------------------------------------------------------------- /src/cashew/build.sh: -------------------------------------------------------------------------------- 1 | ~/Dev/fastcomp/build/Release+Asserts/bin/clang++ -std=c++11 parser.cpp simple_ast.cpp test.cpp -g 2 | 3 | -------------------------------------------------------------------------------- /src/cashew/istring.h: -------------------------------------------------------------------------------- 1 | // Interned String type, 100% interned on creation. Comparisons are always just a pointer comparison 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace cashew { 13 | 14 | struct IString { 15 | const char *str; 16 | 17 | static size_t hash_c(const char *str) { // see http://www.cse.yorku.ca/~oz/hash.html 18 | unsigned int hash = 5381; 19 | int c; 20 | while ((c = *str++)) { 21 | hash = ((hash << 5) + hash) ^ c; 22 | } 23 | return (size_t)hash; 24 | } 25 | 26 | class CStringHash : public std::hash { 27 | public: 28 | size_t operator()(const char *str) const { 29 | return IString::hash_c(str); 30 | } 31 | }; 32 | class CStringEqual : public std::equal_to { 33 | public: 34 | bool operator()(const char *x, const char *y) const { 35 | return strcmp(x, y) == 0; 36 | } 37 | }; 38 | 39 | IString() : str(nullptr) {} 40 | IString(const char *s, bool reuse=true) { // if reuse=true, then input is assumed to remain alive; not copied 41 | set(s, reuse); 42 | } 43 | 44 | void set(const char *s, bool reuse=true) { 45 | typedef std::unordered_set StringSet; 46 | static StringSet* strings = new StringSet(); 47 | 48 | if (reuse) { 49 | auto result = strings->insert(s); // if already present, does nothing 50 | str = *(result.first); 51 | } else { 52 | auto existing = strings->find(s); 53 | if (existing == strings->end()) { 54 | char *copy = (char*)malloc(strlen(s)+1); // XXX leaked 55 | strcpy(copy, s); 56 | s = copy; 57 | } else { 58 | s = *existing; 59 | } 60 | strings->insert(s); 61 | str = s; 62 | } 63 | } 64 | 65 | void set(const IString &s) { 66 | str = s.str; 67 | } 68 | 69 | bool operator==(const IString& other) const { 70 | //assert((str == other.str) == !strcmp(str, other.str)); 71 | return str == other.str; // fast! 72 | } 73 | bool operator!=(const IString& other) const { 74 | //assert((str == other.str) == !strcmp(str, other.str)); 75 | return str != other.str; // fast! 76 | } 77 | bool operator<(const IString& other) const { 78 | return strcmp(str ? str : "", other.str ? other.str : "") < 0; 79 | } 80 | 81 | char operator[](int x) const { 82 | return str[x]; 83 | } 84 | 85 | bool operator!() const { // no string, or empty string 86 | return !str || str[0] == 0; 87 | } 88 | 89 | const char *c_str() const { return str; } 90 | bool equals(const char *other) const { return !strcmp(str, other); } 91 | 92 | bool isNull() { return str == nullptr; } 93 | }; 94 | 95 | } // namespace cashew 96 | 97 | // Utilities for creating hashmaps/sets over IStrings 98 | 99 | namespace std { 100 | 101 | template <> struct hash : public unary_function { 102 | size_t operator()(const cashew::IString& str) const { 103 | size_t hash = size_t(str.str); 104 | return hash = ((hash << 5) + hash) ^ 5381; /* (hash * 33) ^ c */ 105 | } 106 | }; 107 | 108 | template <> struct equal_to : public binary_function { 109 | bool operator()(const cashew::IString& x, const cashew::IString& y) const { 110 | return x == y; 111 | } 112 | }; 113 | 114 | } // namespace std 115 | 116 | namespace cashew { 117 | 118 | // IStringSet 119 | 120 | class IStringSet : public std::unordered_set { 121 | public: 122 | IStringSet() {} 123 | IStringSet(const char *init) { // comma-delimited list 124 | int size = strlen(init); 125 | char *curr = new char[size+1]; // leaked! 126 | strcpy(curr, init); 127 | while (1) { 128 | char *end = strchr(curr, ' '); 129 | if (end) *end = 0; 130 | insert(curr); 131 | if (!end) break; 132 | curr = end + 1; 133 | } 134 | } 135 | 136 | bool has(const IString& str) { 137 | return count(str) > 0; 138 | } 139 | }; 140 | 141 | } // namespace cashew 142 | 143 | -------------------------------------------------------------------------------- /src/cashew/parser.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "parser.h" 3 | 4 | namespace cashew { 5 | 6 | // common strings 7 | 8 | IString TOPLEVEL("toplevel"), 9 | DEFUN("defun"), 10 | BLOCK("block"), 11 | STAT("stat"), 12 | ASSIGN("assign"), 13 | NAME("name"), 14 | VAR("var"), 15 | CONST("const"), 16 | CONDITIONAL("conditional"), 17 | BINARY("binary"), 18 | RETURN("return"), 19 | IF("if"), 20 | ELSE("else"), 21 | WHILE("while"), 22 | DO("do"), 23 | FOR("for"), 24 | SEQ("seq"), 25 | SUB("sub"), 26 | CALL("call"), 27 | NUM("num"), 28 | LABEL("label"), 29 | BREAK("break"), 30 | CONTINUE("continue"), 31 | SWITCH("switch"), 32 | STRING("string"), 33 | INF("inf"), 34 | NaN("nan"), 35 | TEMP_RET0("tempRet0"), 36 | UNARY_PREFIX("unary-prefix"), 37 | UNARY_POSTFIX("unary-postfix"), 38 | MATH_FROUND("Math_fround"), 39 | SIMD_FLOAT32X4("SIMD_float32x4"), 40 | SIMD_INT32X4("SIMD_int32x4"), 41 | PLUS("+"), 42 | MINUS("-"), 43 | OR("|"), 44 | AND("&"), 45 | XOR("^"), 46 | L_NOT("!"), 47 | B_NOT("~"), 48 | LT("<"), 49 | GE(">="), 50 | LE("<="), 51 | GT(">"), 52 | EQ("=="), 53 | NE("!="), 54 | DIV("/"), 55 | MOD("%"), 56 | MUL("*"), 57 | RSHIFT(">>"), 58 | LSHIFT("<<"), 59 | TRSHIFT(">>>"), 60 | TEMP_DOUBLE_PTR("tempDoublePtr"), 61 | HEAP8("HEAP8"), 62 | HEAP16("HEAP16"), 63 | HEAP32("HEAP32"), 64 | HEAPF32("HEAPF32"), 65 | HEAPU8("HEAPU8"), 66 | HEAPU16("HEAPU16"), 67 | HEAPU32("HEAPU32"), 68 | HEAPF64("HEAPF64"), 69 | F0("f0"), 70 | EMPTY(""), 71 | FUNCTION("function"), 72 | OPEN_PAREN("("), 73 | OPEN_BRACE("["), 74 | OPEN_CURLY("{"), 75 | CLOSE_CURLY("}"), 76 | COMMA(","), 77 | QUESTION("?"), 78 | COLON(":"), 79 | CASE("case"), 80 | DEFAULT("default"), 81 | DOT("dot"), 82 | PERIOD("."), 83 | NEW("new"), 84 | ARRAY("array"), 85 | OBJECT("object"), 86 | THROW("throw"), 87 | SET("="); 88 | 89 | IStringSet keywords("var const function if else do while for break continue return switch case default throw try catch finally true false null new"); 90 | 91 | const char *OPERATOR_INITS = "+-*/%<>&^|~=!,?:.", 92 | *SEPARATORS = "([;{}"; 93 | 94 | int MAX_OPERATOR_SIZE = 3; 95 | 96 | std::vector operatorClasses; 97 | 98 | static std::vector> precedences; // op, type => prec 99 | 100 | struct Init { 101 | Init() { 102 | // operators, rtl, type 103 | operatorClasses.push_back(OperatorClass(".", false, OperatorClass::Binary)); 104 | operatorClasses.push_back(OperatorClass("! ~ + -", true, OperatorClass::Prefix)); 105 | operatorClasses.push_back(OperatorClass("* / %", false, OperatorClass::Binary)); 106 | operatorClasses.push_back(OperatorClass("+ -", false, OperatorClass::Binary)); 107 | operatorClasses.push_back(OperatorClass("<< >> >>>", false, OperatorClass::Binary)); 108 | operatorClasses.push_back(OperatorClass("< <= > >=", false, OperatorClass::Binary)); 109 | operatorClasses.push_back(OperatorClass("== !=", false, OperatorClass::Binary)); 110 | operatorClasses.push_back(OperatorClass("&", false, OperatorClass::Binary)); 111 | operatorClasses.push_back(OperatorClass("^", false, OperatorClass::Binary)); 112 | operatorClasses.push_back(OperatorClass("|", false, OperatorClass::Binary)); 113 | operatorClasses.push_back(OperatorClass("? :", true, OperatorClass::Tertiary)); 114 | operatorClasses.push_back(OperatorClass("=", true, OperatorClass::Binary)); 115 | operatorClasses.push_back(OperatorClass(",", true, OperatorClass::Binary)); 116 | 117 | precedences.resize(OperatorClass::Tertiary + 1); 118 | 119 | for (size_t prec = 0; prec < operatorClasses.size(); prec++) { 120 | for (auto curr : operatorClasses[prec].ops) { 121 | precedences[operatorClasses[prec].type][curr] = prec; 122 | } 123 | } 124 | } 125 | }; 126 | 127 | Init init; 128 | 129 | int OperatorClass::getPrecedence(Type type, IString op) { 130 | return precedences[type][op]; 131 | } 132 | 133 | bool OperatorClass::getRtl(int prec) { 134 | return operatorClasses[prec].rtl; 135 | } 136 | 137 | bool isIdentInit(char x) { return (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') || x == '_' || x == '$'; } 138 | bool isIdentPart(char x) { return isIdentInit(x) || (x >= '0' && x <= '9'); } 139 | 140 | } // namespace cashew 141 | 142 | -------------------------------------------------------------------------------- /src/cashew/samples/1.js: -------------------------------------------------------------------------------- 1 | print('hello world') 2 | 3 | -------------------------------------------------------------------------------- /src/cashew/samples/1.js.1_0.js: -------------------------------------------------------------------------------- 1 | print("hello world") 2 | -------------------------------------------------------------------------------- /src/cashew/samples/1.js.txt: -------------------------------------------------------------------------------- 1 | [ 2 | "toplevel", 3 | [ 4 | [ 5 | "call", 6 | [ 7 | "name", 8 | "print" 9 | ], 10 | [ 11 | [ 12 | "string", 13 | "hello world" 14 | ] 15 | ] 16 | ] 17 | ] 18 | ] 19 | -------------------------------------------------------------------------------- /src/cashew/samples/10.js: -------------------------------------------------------------------------------- 1 | function mymodule(stdlib, foreign, heap) { 2 | "use asm"; 3 | 4 | // ------------------------------------------------------------------------- 5 | // SECTION 1: globals 6 | 7 | var H32 = new stdlib.Int32Array(heap); 8 | var HU32 = new stdlib.Uint32Array(heap); 9 | var log = foreign.consoleDotLog; 10 | 11 | var g_i = 0; // int global 12 | var g_f = 0.0; // double global 13 | 14 | // ------------------------------------------------------------------------- 15 | // SECTION 2: functions 16 | 17 | function f(x, y) { 18 | // SECTION A: parameter type declarations 19 | x = x|0; // int parameter 20 | y = +y; // double parameter 21 | 22 | // SECTION B: function body 23 | log(x|0); // call into FFI -- must force the sign 24 | log(y); // call into FFI -- already know it's a double 25 | x = (x+3)|0; // signed addition 26 | 27 | // SECTION C: unconditional return 28 | return ((((x+1)|0)>>>0)/(x>>>0))|0; // compound expression 29 | } 30 | 31 | function g() { 32 | g_f = +(g_i|0); // read/write globals 33 | return; 34 | } 35 | 36 | function g2() { 37 | return; 38 | } 39 | 40 | function h(i, x) { 41 | i = i|0; 42 | x = x|0; 43 | H32[i>>2] = x; // shifted by log2(byte count) 44 | ftable_2[(x-2)&1](); // dynamic call of functions in table 2 45 | 46 | // no return necessary when return type is void 47 | } 48 | 49 | // ------------------------------------------------------------------------- 50 | // SECTION 3: function tables 51 | 52 | var ftable_1 = [f]; 53 | var ftable_2 = [g, g2]; // all of the same type 54 | 55 | // ------------------------------------------------------------------------- 56 | // SECTION 4: exports 57 | 58 | return { f_export: f, goop: g }; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/cashew/samples/10.js.1_0.js: -------------------------------------------------------------------------------- 1 | function mymodule(stdlib, foreign, heap) { 2 | "use asm"; 3 | var H32 = new stdlib.Int32Array(heap); 4 | var HU32 = new stdlib.Uint32Array(heap); 5 | var log = foreign.consoleDotLog; 6 | var g_i = 0; 7 | var g_f = 0; 8 | function f(x, y) { 9 | x = x | 0; 10 | y = +y; 11 | log(x | 0); 12 | log(y); 13 | x = x + 3 | 0; 14 | return ((x + 1 | 0) >>> 0) / (x >>> 0) | 0; 15 | } 16 | 17 | function g() { 18 | g_f = +(g_i | 0); 19 | return; 20 | } 21 | 22 | function g2() { 23 | return; 24 | } 25 | 26 | function h(i, x) { 27 | i = i | 0; 28 | x = x | 0; 29 | H32[i >> 2] = x; 30 | ftable_2[x - 2 & 1](); 31 | } 32 | 33 | var ftable_1 = [f]; 34 | var ftable_2 = [g, g2]; 35 | return { 36 | "f_export": f, 37 | "goop": g 38 | }; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/cashew/samples/10.js.txt: -------------------------------------------------------------------------------- 1 | [ 2 | "toplevel", 3 | [ 4 | [ 5 | "defun", 6 | "mymodule", 7 | [ 8 | "stdlib", 9 | "foreign", 10 | "heap" 11 | ], 12 | [ 13 | [ 14 | "stat", 15 | [ 16 | "string", 17 | "use asm" 18 | ] 19 | ], 20 | [ 21 | "var", 22 | [ 23 | [ 24 | "H32", 25 | [ 26 | "new", 27 | [ 28 | "call", 29 | [ 30 | "dot", 31 | [ 32 | "name", 33 | "stdlib" 34 | ], 35 | "Int32Array" 36 | ], 37 | [ 38 | [ 39 | "name", 40 | "heap" 41 | ] 42 | ] 43 | ] 44 | ] 45 | ] 46 | ] 47 | ], 48 | [ 49 | "var", 50 | [ 51 | [ 52 | "HU32", 53 | [ 54 | "new", 55 | [ 56 | "call", 57 | [ 58 | "dot", 59 | [ 60 | "name", 61 | "stdlib" 62 | ], 63 | "Uint32Array" 64 | ], 65 | [ 66 | [ 67 | "name", 68 | "heap" 69 | ] 70 | ] 71 | ] 72 | ] 73 | ] 74 | ] 75 | ], 76 | [ 77 | "var", 78 | [ 79 | [ 80 | "log", 81 | [ 82 | "dot", 83 | [ 84 | "name", 85 | "foreign" 86 | ], 87 | "consoleDotLog" 88 | ] 89 | ] 90 | ] 91 | ], 92 | [ 93 | "var", 94 | [ 95 | [ 96 | "g_i", 97 | [ 98 | "num", 99 | 0 100 | ] 101 | ] 102 | ] 103 | ], 104 | [ 105 | "var", 106 | [ 107 | [ 108 | "g_f", 109 | [ 110 | "num", 111 | 0 112 | ] 113 | ] 114 | ] 115 | ], 116 | [ 117 | "defun", 118 | "f", 119 | [ 120 | "x", 121 | "y" 122 | ], 123 | [ 124 | [ 125 | "stat", 126 | [ 127 | "assign", 128 | true, 129 | [ 130 | "name", 131 | "x" 132 | ], 133 | [ 134 | "binary", 135 | "|", 136 | [ 137 | "name", 138 | "x" 139 | ], 140 | [ 141 | "num", 142 | 0 143 | ] 144 | ] 145 | ] 146 | ], 147 | [ 148 | "stat", 149 | [ 150 | "assign", 151 | true, 152 | [ 153 | "name", 154 | "y" 155 | ], 156 | [ 157 | "unary-prefix", 158 | "+", 159 | [ 160 | "name", 161 | "y" 162 | ] 163 | ] 164 | ] 165 | ], 166 | [ 167 | "stat", 168 | [ 169 | "call", 170 | [ 171 | "name", 172 | "log" 173 | ], 174 | [ 175 | [ 176 | "binary", 177 | "|", 178 | [ 179 | "name", 180 | "x" 181 | ], 182 | [ 183 | "num", 184 | 0 185 | ] 186 | ] 187 | ] 188 | ] 189 | ], 190 | [ 191 | "stat", 192 | [ 193 | "call", 194 | [ 195 | "name", 196 | "log" 197 | ], 198 | [ 199 | [ 200 | "name", 201 | "y" 202 | ] 203 | ] 204 | ] 205 | ], 206 | [ 207 | "stat", 208 | [ 209 | "assign", 210 | true, 211 | [ 212 | "name", 213 | "x" 214 | ], 215 | [ 216 | "binary", 217 | "|", 218 | [ 219 | "binary", 220 | "+", 221 | [ 222 | "name", 223 | "x" 224 | ], 225 | [ 226 | "num", 227 | 3 228 | ] 229 | ], 230 | [ 231 | "num", 232 | 0 233 | ] 234 | ] 235 | ] 236 | ], 237 | [ 238 | "return", 239 | [ 240 | "binary", 241 | "|", 242 | [ 243 | "binary", 244 | "/", 245 | [ 246 | "binary", 247 | ">>>", 248 | [ 249 | "binary", 250 | "|", 251 | [ 252 | "binary", 253 | "+", 254 | [ 255 | "name", 256 | "x" 257 | ], 258 | [ 259 | "num", 260 | 1 261 | ] 262 | ], 263 | [ 264 | "num", 265 | 0 266 | ] 267 | ], 268 | [ 269 | "num", 270 | 0 271 | ] 272 | ], 273 | [ 274 | "binary", 275 | ">>>", 276 | [ 277 | "name", 278 | "x" 279 | ], 280 | [ 281 | "num", 282 | 0 283 | ] 284 | ] 285 | ], 286 | [ 287 | "num", 288 | 0 289 | ] 290 | ] 291 | ] 292 | ] 293 | ], 294 | [ 295 | "defun", 296 | "g", 297 | [], 298 | [ 299 | [ 300 | "stat", 301 | [ 302 | "assign", 303 | true, 304 | [ 305 | "name", 306 | "g_f" 307 | ], 308 | [ 309 | "unary-prefix", 310 | "+", 311 | [ 312 | "binary", 313 | "|", 314 | [ 315 | "name", 316 | "g_i" 317 | ], 318 | [ 319 | "num", 320 | 0 321 | ] 322 | ] 323 | ] 324 | ] 325 | ], 326 | [ 327 | "return", 328 | null 329 | ] 330 | ] 331 | ], 332 | [ 333 | "defun", 334 | "g2", 335 | [], 336 | [ 337 | [ 338 | "return", 339 | null 340 | ] 341 | ] 342 | ], 343 | [ 344 | "defun", 345 | "h", 346 | [ 347 | "i", 348 | "x" 349 | ], 350 | [ 351 | [ 352 | "stat", 353 | [ 354 | "assign", 355 | true, 356 | [ 357 | "name", 358 | "i" 359 | ], 360 | [ 361 | "binary", 362 | "|", 363 | [ 364 | "name", 365 | "i" 366 | ], 367 | [ 368 | "num", 369 | 0 370 | ] 371 | ] 372 | ] 373 | ], 374 | [ 375 | "stat", 376 | [ 377 | "assign", 378 | true, 379 | [ 380 | "name", 381 | "x" 382 | ], 383 | [ 384 | "binary", 385 | "|", 386 | [ 387 | "name", 388 | "x" 389 | ], 390 | [ 391 | "num", 392 | 0 393 | ] 394 | ] 395 | ] 396 | ], 397 | [ 398 | "stat", 399 | [ 400 | "assign", 401 | true, 402 | [ 403 | "sub", 404 | [ 405 | "name", 406 | "H32" 407 | ], 408 | [ 409 | "binary", 410 | ">>", 411 | [ 412 | "name", 413 | "i" 414 | ], 415 | [ 416 | "num", 417 | 2 418 | ] 419 | ] 420 | ], 421 | [ 422 | "name", 423 | "x" 424 | ] 425 | ] 426 | ], 427 | [ 428 | "stat", 429 | [ 430 | "call", 431 | [ 432 | "sub", 433 | [ 434 | "name", 435 | "ftable_2" 436 | ], 437 | [ 438 | "binary", 439 | "&", 440 | [ 441 | "binary", 442 | "-", 443 | [ 444 | "name", 445 | "x" 446 | ], 447 | [ 448 | "num", 449 | 2 450 | ] 451 | ], 452 | [ 453 | "num", 454 | 1 455 | ] 456 | ] 457 | ], 458 | [] 459 | ] 460 | ] 461 | ] 462 | ], 463 | [ 464 | "var", 465 | [ 466 | [ 467 | "ftable_1", 468 | [ 469 | "array", 470 | [ 471 | [ 472 | "name", 473 | "f" 474 | ] 475 | ] 476 | ] 477 | ] 478 | ] 479 | ], 480 | [ 481 | "var", 482 | [ 483 | [ 484 | "ftable_2", 485 | [ 486 | "array", 487 | [ 488 | [ 489 | "name", 490 | "g" 491 | ], 492 | [ 493 | "name", 494 | "g2" 495 | ] 496 | ] 497 | ] 498 | ] 499 | ] 500 | ], 501 | [ 502 | "return", 503 | [ 504 | "object", 505 | [ 506 | [ 507 | "f_export", 508 | [ 509 | "name", 510 | "f" 511 | ] 512 | ], 513 | [ 514 | "goop", 515 | [ 516 | "name", 517 | "g" 518 | ] 519 | ] 520 | ] 521 | ] 522 | ] 523 | ] 524 | ] 525 | ] 526 | ] 527 | -------------------------------------------------------------------------------- /src/cashew/samples/2.js: -------------------------------------------------------------------------------- 1 | print('hello world'); 2 | print('hello world'); 3 | 4 | -------------------------------------------------------------------------------- /src/cashew/samples/2.js.1_0.js: -------------------------------------------------------------------------------- 1 | print("hello world"); 2 | print("hello world"); 3 | -------------------------------------------------------------------------------- /src/cashew/samples/2.js.txt: -------------------------------------------------------------------------------- 1 | [ 2 | "toplevel", 3 | [ 4 | [ 5 | "stat", 6 | [ 7 | "call", 8 | [ 9 | "name", 10 | "print" 11 | ], 12 | [ 13 | [ 14 | "string", 15 | "hello world" 16 | ] 17 | ] 18 | ] 19 | ], 20 | [ 21 | "stat", 22 | [ 23 | "call", 24 | [ 25 | "name", 26 | "print" 27 | ], 28 | [ 29 | [ 30 | "string", 31 | "hello world" 32 | ] 33 | ] 34 | ] 35 | ] 36 | ] 37 | ] 38 | -------------------------------------------------------------------------------- /src/cashew/samples/3.js: -------------------------------------------------------------------------------- 1 | print(10) 2 | 3 | -------------------------------------------------------------------------------- /src/cashew/samples/3.js.1_0.js: -------------------------------------------------------------------------------- 1 | print(10) 2 | -------------------------------------------------------------------------------- /src/cashew/samples/3.js.txt: -------------------------------------------------------------------------------- 1 | [ 2 | "toplevel", 3 | [ 4 | [ 5 | "call", 6 | [ 7 | "name", 8 | "print" 9 | ], 10 | [ 11 | [ 12 | "num", 13 | 10 14 | ] 15 | ] 16 | ] 17 | ] 18 | ] 19 | -------------------------------------------------------------------------------- /src/cashew/samples/4.js: -------------------------------------------------------------------------------- 1 | print(10, "hello", 'world', cheez); 2 | 3 | -------------------------------------------------------------------------------- /src/cashew/samples/4.js.1_0.js: -------------------------------------------------------------------------------- 1 | print(10, "hello", "world", cheez); 2 | -------------------------------------------------------------------------------- /src/cashew/samples/4.js.txt: -------------------------------------------------------------------------------- 1 | [ 2 | "toplevel", 3 | [ 4 | [ 5 | "stat", 6 | [ 7 | "call", 8 | [ 9 | "name", 10 | "print" 11 | ], 12 | [ 13 | [ 14 | "num", 15 | 10 16 | ], 17 | [ 18 | "string", 19 | "hello" 20 | ], 21 | [ 22 | "string", 23 | "world" 24 | ], 25 | [ 26 | "name", 27 | "cheez" 28 | ] 29 | ] 30 | ] 31 | ] 32 | ] 33 | ] 34 | -------------------------------------------------------------------------------- /src/cashew/samples/5.js: -------------------------------------------------------------------------------- 1 | x = 10; 2 | x = y = 20; 3 | x = y + 5; 4 | x = y + 5 | 0; 5 | x = 0 | y + 5; 6 | x = f(y + 5); 7 | x = (y = 10, y); 8 | 9 | -------------------------------------------------------------------------------- /src/cashew/samples/5.js.1_0.js: -------------------------------------------------------------------------------- 1 | x = 10; 2 | x = y = 20; 3 | x = y + 5; 4 | x = y + 5 | 0; 5 | x = 0 | y + 5; 6 | x = f(y + 5); 7 | x = (y = 10, y); 8 | -------------------------------------------------------------------------------- /src/cashew/samples/5.js.txt: -------------------------------------------------------------------------------- 1 | [ 2 | "toplevel", 3 | [ 4 | [ 5 | "stat", 6 | [ 7 | "assign", 8 | true, 9 | [ 10 | "name", 11 | "x" 12 | ], 13 | [ 14 | "num", 15 | 10 16 | ] 17 | ] 18 | ], 19 | [ 20 | "stat", 21 | [ 22 | "assign", 23 | true, 24 | [ 25 | "name", 26 | "x" 27 | ], 28 | [ 29 | "assign", 30 | true, 31 | [ 32 | "name", 33 | "y" 34 | ], 35 | [ 36 | "num", 37 | 20 38 | ] 39 | ] 40 | ] 41 | ], 42 | [ 43 | "stat", 44 | [ 45 | "assign", 46 | true, 47 | [ 48 | "name", 49 | "x" 50 | ], 51 | [ 52 | "binary", 53 | "+", 54 | [ 55 | "name", 56 | "y" 57 | ], 58 | [ 59 | "num", 60 | 5 61 | ] 62 | ] 63 | ] 64 | ], 65 | [ 66 | "stat", 67 | [ 68 | "assign", 69 | true, 70 | [ 71 | "name", 72 | "x" 73 | ], 74 | [ 75 | "binary", 76 | "|", 77 | [ 78 | "binary", 79 | "+", 80 | [ 81 | "name", 82 | "y" 83 | ], 84 | [ 85 | "num", 86 | 5 87 | ] 88 | ], 89 | [ 90 | "num", 91 | 0 92 | ] 93 | ] 94 | ] 95 | ], 96 | [ 97 | "stat", 98 | [ 99 | "assign", 100 | true, 101 | [ 102 | "name", 103 | "x" 104 | ], 105 | [ 106 | "binary", 107 | "|", 108 | [ 109 | "num", 110 | 0 111 | ], 112 | [ 113 | "binary", 114 | "+", 115 | [ 116 | "name", 117 | "y" 118 | ], 119 | [ 120 | "num", 121 | 5 122 | ] 123 | ] 124 | ] 125 | ] 126 | ], 127 | [ 128 | "stat", 129 | [ 130 | "assign", 131 | true, 132 | [ 133 | "name", 134 | "x" 135 | ], 136 | [ 137 | "call", 138 | [ 139 | "name", 140 | "f" 141 | ], 142 | [ 143 | [ 144 | "binary", 145 | "+", 146 | [ 147 | "name", 148 | "y" 149 | ], 150 | [ 151 | "num", 152 | 5 153 | ] 154 | ] 155 | ] 156 | ] 157 | ] 158 | ], 159 | [ 160 | "stat", 161 | [ 162 | "assign", 163 | true, 164 | [ 165 | "name", 166 | "x" 167 | ], 168 | [ 169 | "seq", 170 | [ 171 | "assign", 172 | true, 173 | [ 174 | "name", 175 | "y" 176 | ], 177 | [ 178 | "num", 179 | 10 180 | ] 181 | ], 182 | [ 183 | "name", 184 | "y" 185 | ] 186 | ] 187 | ] 188 | ] 189 | ] 190 | ] 191 | -------------------------------------------------------------------------------- /src/cashew/samples/6.js: -------------------------------------------------------------------------------- 1 | function func() { 2 | print(10); 3 | } 4 | function another(x, y) { 5 | func(); 6 | return; 7 | } 8 | // hello 9 | /* 10 | world 11 | */ 12 | 13 | function varr() { 14 | var x; 15 | var a = 5, b, c = func(a, b), d; 16 | return 20; 17 | } 18 | function sub() { 19 | x[10]; 20 | x[y + 20]; 21 | x[30](); 22 | x[40] = 50; 23 | ;a; 24 | } 25 | function frac() { 26 | print(2.2250738585072014e-308); 27 | } 28 | function doIf() { 29 | do if ((N | 0) > -1) if ((O | 0) > (2147483647 - N | 0)) { 30 | c[(Ya() | 0) >> 2] = 75; 31 | R = -1; 32 | break; 33 | } else { 34 | R = O + N | 0; 35 | break; 36 | } else R = N; while (0); 37 | $7 = 5 >= +1 ? $5 > +0 ? 5 : 5 >>> 0 : 0; 38 | print(1.0E+22); 39 | $call126 = SIMD_float32x4(Math_fround(Math_fround(+-9)),Math_fround(Math_fround(+0)),Math_fround(Math_fround(+4)),Math_fround(Math_fround(+9))).signMaskPolyfill; 40 | switch (x) { 41 | case 5: break; 42 | default: break; 43 | } 44 | } 45 | function labeledBlock() { 46 | a:{ break a; } 47 | } 48 | if (waka) { y() } else ; 49 | if (waka) ; else { y() } 50 | 51 | -------------------------------------------------------------------------------- /src/cashew/samples/6.js.1_0.js: -------------------------------------------------------------------------------- 1 | function func() { 2 | print(10); 3 | } 4 | 5 | function another(x, y) { 6 | func(); 7 | return; 8 | } 9 | 10 | function varr() { 11 | var x; 12 | var a = 5, b, c = func(a, b), d; 13 | return 20; 14 | } 15 | 16 | function sub() { 17 | x[10]; 18 | x[y + 20]; 19 | x[30](); 20 | x[40] = 50; 21 | a; 22 | } 23 | 24 | function frac() { 25 | print(2.2250738585072014e-308); 26 | } 27 | 28 | function doIf() { 29 | do if ((N | 0) > -1) if ((O | 0) > (2147483647 - N | 0)) { 30 | c[(Ya() | 0) >> 2] = 75; 31 | R = -1; 32 | break; 33 | } else { 34 | R = O + N | 0; 35 | break; 36 | } else R = N; while (0); 37 | $7 = 5 >= +1 ? ($5 > +0 ? 5 : 5 >>> 0) : 0; 38 | print(1e22); 39 | $call126 = SIMD_float32x4(Math_fround(Math_fround(+-9)), Math_fround(Math_fround(+0)), Math_fround(Math_fround(+4)), Math_fround(Math_fround(+9))).signMaskPolyfill; 40 | switch (x) { 41 | case 5: 42 | break; 43 | default: 44 | break; 45 | } 46 | } 47 | 48 | function labeledBlock() { 49 | a : { 50 | break a; 51 | } 52 | } 53 | 54 | if (waka) { 55 | y() 56 | } else {} 57 | if (waka) {} else { 58 | y() 59 | } 60 | -------------------------------------------------------------------------------- /src/cashew/samples/6.js.txt: -------------------------------------------------------------------------------- 1 | [ 2 | "toplevel", 3 | [ 4 | [ 5 | "defun", 6 | "func", 7 | [], 8 | [ 9 | [ 10 | "stat", 11 | [ 12 | "call", 13 | [ 14 | "name", 15 | "print" 16 | ], 17 | [ 18 | [ 19 | "num", 20 | 10 21 | ] 22 | ] 23 | ] 24 | ] 25 | ] 26 | ], 27 | [ 28 | "defun", 29 | "another", 30 | [ 31 | "x", 32 | "y" 33 | ], 34 | [ 35 | [ 36 | "stat", 37 | [ 38 | "call", 39 | [ 40 | "name", 41 | "func" 42 | ], 43 | [] 44 | ] 45 | ], 46 | [ 47 | "return", 48 | null 49 | ] 50 | ] 51 | ], 52 | [ 53 | "defun", 54 | "varr", 55 | [], 56 | [ 57 | [ 58 | "var", 59 | [ 60 | [ 61 | "x" 62 | ] 63 | ] 64 | ], 65 | [ 66 | "var", 67 | [ 68 | [ 69 | "a", 70 | [ 71 | "num", 72 | 5 73 | ] 74 | ], 75 | [ 76 | "b" 77 | ], 78 | [ 79 | "c", 80 | [ 81 | "call", 82 | [ 83 | "name", 84 | "func" 85 | ], 86 | [ 87 | [ 88 | "name", 89 | "a" 90 | ], 91 | [ 92 | "name", 93 | "b" 94 | ] 95 | ] 96 | ] 97 | ], 98 | [ 99 | "d" 100 | ] 101 | ] 102 | ], 103 | [ 104 | "return", 105 | [ 106 | "num", 107 | 20 108 | ] 109 | ] 110 | ] 111 | ], 112 | [ 113 | "defun", 114 | "sub", 115 | [], 116 | [ 117 | [ 118 | "stat", 119 | [ 120 | "sub", 121 | [ 122 | "name", 123 | "x" 124 | ], 125 | [ 126 | "num", 127 | 10 128 | ] 129 | ] 130 | ], 131 | [ 132 | "stat", 133 | [ 134 | "sub", 135 | [ 136 | "name", 137 | "x" 138 | ], 139 | [ 140 | "binary", 141 | "+", 142 | [ 143 | "name", 144 | "y" 145 | ], 146 | [ 147 | "num", 148 | 20 149 | ] 150 | ] 151 | ] 152 | ], 153 | [ 154 | "stat", 155 | [ 156 | "call", 157 | [ 158 | "sub", 159 | [ 160 | "name", 161 | "x" 162 | ], 163 | [ 164 | "num", 165 | 30 166 | ] 167 | ], 168 | [] 169 | ] 170 | ], 171 | [ 172 | "stat", 173 | [ 174 | "assign", 175 | true, 176 | [ 177 | "sub", 178 | [ 179 | "name", 180 | "x" 181 | ], 182 | [ 183 | "num", 184 | 40 185 | ] 186 | ], 187 | [ 188 | "num", 189 | 50 190 | ] 191 | ] 192 | ], 193 | [ 194 | "stat", 195 | [ 196 | "name", 197 | "a" 198 | ] 199 | ] 200 | ] 201 | ], 202 | [ 203 | "defun", 204 | "frac", 205 | [], 206 | [ 207 | [ 208 | "stat", 209 | [ 210 | "call", 211 | [ 212 | "name", 213 | "print" 214 | ], 215 | [ 216 | [ 217 | "num", 218 | 2.2250738585072014e-308 219 | ] 220 | ] 221 | ] 222 | ] 223 | ] 224 | ], 225 | [ 226 | "defun", 227 | "doIf", 228 | [], 229 | [ 230 | [ 231 | "do", 232 | [ 233 | "num", 234 | 0 235 | ], 236 | [ 237 | "if", 238 | [ 239 | "binary", 240 | ">", 241 | [ 242 | "binary", 243 | "|", 244 | [ 245 | "name", 246 | "N" 247 | ], 248 | [ 249 | "num", 250 | 0 251 | ] 252 | ], 253 | [ 254 | "unary-prefix", 255 | "-", 256 | [ 257 | "num", 258 | 1 259 | ] 260 | ] 261 | ], 262 | [ 263 | "if", 264 | [ 265 | "binary", 266 | ">", 267 | [ 268 | "binary", 269 | "|", 270 | [ 271 | "name", 272 | "O" 273 | ], 274 | [ 275 | "num", 276 | 0 277 | ] 278 | ], 279 | [ 280 | "binary", 281 | "|", 282 | [ 283 | "binary", 284 | "-", 285 | [ 286 | "num", 287 | 2147483647 288 | ], 289 | [ 290 | "name", 291 | "N" 292 | ] 293 | ], 294 | [ 295 | "num", 296 | 0 297 | ] 298 | ] 299 | ], 300 | [ 301 | "block", 302 | [ 303 | [ 304 | "stat", 305 | [ 306 | "assign", 307 | true, 308 | [ 309 | "sub", 310 | [ 311 | "name", 312 | "c" 313 | ], 314 | [ 315 | "binary", 316 | ">>", 317 | [ 318 | "binary", 319 | "|", 320 | [ 321 | "call", 322 | [ 323 | "name", 324 | "Ya" 325 | ], 326 | [] 327 | ], 328 | [ 329 | "num", 330 | 0 331 | ] 332 | ], 333 | [ 334 | "num", 335 | 2 336 | ] 337 | ] 338 | ], 339 | [ 340 | "num", 341 | 75 342 | ] 343 | ] 344 | ], 345 | [ 346 | "stat", 347 | [ 348 | "assign", 349 | true, 350 | [ 351 | "name", 352 | "R" 353 | ], 354 | [ 355 | "unary-prefix", 356 | "-", 357 | [ 358 | "num", 359 | 1 360 | ] 361 | ] 362 | ] 363 | ], 364 | [ 365 | "break", 366 | null 367 | ] 368 | ] 369 | ], 370 | [ 371 | "block", 372 | [ 373 | [ 374 | "stat", 375 | [ 376 | "assign", 377 | true, 378 | [ 379 | "name", 380 | "R" 381 | ], 382 | [ 383 | "binary", 384 | "|", 385 | [ 386 | "binary", 387 | "+", 388 | [ 389 | "name", 390 | "O" 391 | ], 392 | [ 393 | "name", 394 | "N" 395 | ] 396 | ], 397 | [ 398 | "num", 399 | 0 400 | ] 401 | ] 402 | ] 403 | ], 404 | [ 405 | "break", 406 | null 407 | ] 408 | ] 409 | ] 410 | ], 411 | [ 412 | "stat", 413 | [ 414 | "assign", 415 | true, 416 | [ 417 | "name", 418 | "R" 419 | ], 420 | [ 421 | "name", 422 | "N" 423 | ] 424 | ] 425 | ] 426 | ] 427 | ], 428 | [ 429 | "stat", 430 | [ 431 | "assign", 432 | true, 433 | [ 434 | "name", 435 | "$7" 436 | ], 437 | [ 438 | "conditional", 439 | [ 440 | "binary", 441 | ">=", 442 | [ 443 | "num", 444 | 5 445 | ], 446 | [ 447 | "unary-prefix", 448 | "+", 449 | [ 450 | "num", 451 | 1 452 | ] 453 | ] 454 | ], 455 | [ 456 | "conditional", 457 | [ 458 | "binary", 459 | ">", 460 | [ 461 | "name", 462 | "$5" 463 | ], 464 | [ 465 | "unary-prefix", 466 | "+", 467 | [ 468 | "num", 469 | 0 470 | ] 471 | ] 472 | ], 473 | [ 474 | "num", 475 | 5 476 | ], 477 | [ 478 | "binary", 479 | ">>>", 480 | [ 481 | "num", 482 | 5 483 | ], 484 | [ 485 | "num", 486 | 0 487 | ] 488 | ] 489 | ], 490 | [ 491 | "num", 492 | 0 493 | ] 494 | ] 495 | ] 496 | ], 497 | [ 498 | "stat", 499 | [ 500 | "call", 501 | [ 502 | "name", 503 | "print" 504 | ], 505 | [ 506 | [ 507 | "num", 508 | 1e+22 509 | ] 510 | ] 511 | ] 512 | ], 513 | [ 514 | "stat", 515 | [ 516 | "assign", 517 | true, 518 | [ 519 | "name", 520 | "$call126" 521 | ], 522 | [ 523 | "dot", 524 | [ 525 | "call", 526 | [ 527 | "name", 528 | "SIMD_float32x4" 529 | ], 530 | [ 531 | [ 532 | "call", 533 | [ 534 | "name", 535 | "Math_fround" 536 | ], 537 | [ 538 | [ 539 | "call", 540 | [ 541 | "name", 542 | "Math_fround" 543 | ], 544 | [ 545 | [ 546 | "unary-prefix", 547 | "+", 548 | [ 549 | "unary-prefix", 550 | "-", 551 | [ 552 | "num", 553 | 9 554 | ] 555 | ] 556 | ] 557 | ] 558 | ] 559 | ] 560 | ], 561 | [ 562 | "call", 563 | [ 564 | "name", 565 | "Math_fround" 566 | ], 567 | [ 568 | [ 569 | "call", 570 | [ 571 | "name", 572 | "Math_fround" 573 | ], 574 | [ 575 | [ 576 | "unary-prefix", 577 | "+", 578 | [ 579 | "num", 580 | 0 581 | ] 582 | ] 583 | ] 584 | ] 585 | ] 586 | ], 587 | [ 588 | "call", 589 | [ 590 | "name", 591 | "Math_fround" 592 | ], 593 | [ 594 | [ 595 | "call", 596 | [ 597 | "name", 598 | "Math_fround" 599 | ], 600 | [ 601 | [ 602 | "unary-prefix", 603 | "+", 604 | [ 605 | "num", 606 | 4 607 | ] 608 | ] 609 | ] 610 | ] 611 | ] 612 | ], 613 | [ 614 | "call", 615 | [ 616 | "name", 617 | "Math_fround" 618 | ], 619 | [ 620 | [ 621 | "call", 622 | [ 623 | "name", 624 | "Math_fround" 625 | ], 626 | [ 627 | [ 628 | "unary-prefix", 629 | "+", 630 | [ 631 | "num", 632 | 9 633 | ] 634 | ] 635 | ] 636 | ] 637 | ] 638 | ] 639 | ] 640 | ], 641 | "signMaskPolyfill" 642 | ] 643 | ] 644 | ], 645 | [ 646 | "switch", 647 | [ 648 | "name", 649 | "x" 650 | ], 651 | [ 652 | [ 653 | [ 654 | "num", 655 | 5 656 | ], 657 | [ 658 | [ 659 | "break", 660 | null 661 | ] 662 | ] 663 | ], 664 | [ 665 | null, 666 | [ 667 | [ 668 | "break", 669 | null 670 | ] 671 | ] 672 | ] 673 | ] 674 | ] 675 | ] 676 | ], 677 | [ 678 | "defun", 679 | "labeledBlock", 680 | [], 681 | [ 682 | [ 683 | "label", 684 | "a", 685 | [ 686 | "block", 687 | [ 688 | [ 689 | "break", 690 | "a" 691 | ] 692 | ] 693 | ] 694 | ] 695 | ] 696 | ], 697 | [ 698 | "if", 699 | [ 700 | "name", 701 | "waka" 702 | ], 703 | [ 704 | "block", 705 | [ 706 | [ 707 | "call", 708 | [ 709 | "name", 710 | "y" 711 | ], 712 | [] 713 | ] 714 | ] 715 | ], 716 | [ 717 | "block", 718 | [] 719 | ] 720 | ], 721 | [ 722 | "if", 723 | [ 724 | "name", 725 | "waka" 726 | ], 727 | [ 728 | "block", 729 | [] 730 | ], 731 | [ 732 | "block", 733 | [ 734 | [ 735 | "call", 736 | [ 737 | "name", 738 | "y" 739 | ], 740 | [] 741 | ] 742 | ] 743 | ] 744 | ] 745 | ] 746 | ] 747 | -------------------------------------------------------------------------------- /src/cashew/samples/7.js: -------------------------------------------------------------------------------- 1 | function badf() { 2 | var $9 = Math_fround(0); 3 | $9 = (HEAP32[tempDoublePtr>>2]=$8,Math_fround(HEAPF32[tempDoublePtr>>2])); 4 | HEAPF32[$gep23_asptr>>2] = $9; 5 | } 6 | function badf2() { 7 | var $9 = 0; 8 | $9 = (HEAPF32[tempDoublePtr>>2]=$8,HEAP32[tempDoublePtr>>2]|0); 9 | HEAP32[$gep23_asptr>>2] = $9; 10 | } 11 | function dupe() { 12 | x = Math_fround(x); 13 | x = Math_fround(Math_fround(x)); 14 | x = Math_fround(Math_fround(Math_fround(x))); 15 | x = Math_fround(Math_fround(Math_fround(Math_fround(x)))); 16 | } 17 | function zeros(x) { 18 | x = Math_fround(x); 19 | var y = Math_fround(0); 20 | print(Math_fround(y) + Math_fround(0)); 21 | return Math_fround(0); // return needs to stay as is 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/cashew/samples/7.js.1_0.js: -------------------------------------------------------------------------------- 1 | function badf() { 2 | var $9 = Math_fround(0); 3 | $9 = (HEAP32[tempDoublePtr >> 2] = $8, Math_fround(HEAPF32[tempDoublePtr >> 2])); 4 | HEAPF32[$gep23_asptr >> 2] = $9; 5 | } 6 | 7 | function badf2() { 8 | var $9 = 0; 9 | $9 = (HEAPF32[tempDoublePtr >> 2] = $8, HEAP32[tempDoublePtr >> 2] | 0); 10 | HEAP32[$gep23_asptr >> 2] = $9; 11 | } 12 | 13 | function dupe() { 14 | x = Math_fround(x); 15 | x = Math_fround(Math_fround(x)); 16 | x = Math_fround(Math_fround(Math_fround(x))); 17 | x = Math_fround(Math_fround(Math_fround(Math_fround(x)))); 18 | } 19 | 20 | function zeros(x) { 21 | x = Math_fround(x); 22 | var y = Math_fround(0); 23 | print(Math_fround(y) + Math_fround(0)); 24 | return Math_fround(0); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/cashew/samples/7.js.txt: -------------------------------------------------------------------------------- 1 | [ 2 | "toplevel", 3 | [ 4 | [ 5 | "defun", 6 | "badf", 7 | [], 8 | [ 9 | [ 10 | "var", 11 | [ 12 | [ 13 | "$9", 14 | [ 15 | "call", 16 | [ 17 | "name", 18 | "Math_fround" 19 | ], 20 | [ 21 | [ 22 | "num", 23 | 0 24 | ] 25 | ] 26 | ] 27 | ] 28 | ] 29 | ], 30 | [ 31 | "stat", 32 | [ 33 | "assign", 34 | true, 35 | [ 36 | "name", 37 | "$9" 38 | ], 39 | [ 40 | "seq", 41 | [ 42 | "assign", 43 | true, 44 | [ 45 | "sub", 46 | [ 47 | "name", 48 | "HEAP32" 49 | ], 50 | [ 51 | "binary", 52 | ">>", 53 | [ 54 | "name", 55 | "tempDoublePtr" 56 | ], 57 | [ 58 | "num", 59 | 2 60 | ] 61 | ] 62 | ], 63 | [ 64 | "name", 65 | "$8" 66 | ] 67 | ], 68 | [ 69 | "call", 70 | [ 71 | "name", 72 | "Math_fround" 73 | ], 74 | [ 75 | [ 76 | "sub", 77 | [ 78 | "name", 79 | "HEAPF32" 80 | ], 81 | [ 82 | "binary", 83 | ">>", 84 | [ 85 | "name", 86 | "tempDoublePtr" 87 | ], 88 | [ 89 | "num", 90 | 2 91 | ] 92 | ] 93 | ] 94 | ] 95 | ] 96 | ] 97 | ] 98 | ], 99 | [ 100 | "stat", 101 | [ 102 | "assign", 103 | true, 104 | [ 105 | "sub", 106 | [ 107 | "name", 108 | "HEAPF32" 109 | ], 110 | [ 111 | "binary", 112 | ">>", 113 | [ 114 | "name", 115 | "$gep23_asptr" 116 | ], 117 | [ 118 | "num", 119 | 2 120 | ] 121 | ] 122 | ], 123 | [ 124 | "name", 125 | "$9" 126 | ] 127 | ] 128 | ] 129 | ] 130 | ], 131 | [ 132 | "defun", 133 | "badf2", 134 | [], 135 | [ 136 | [ 137 | "var", 138 | [ 139 | [ 140 | "$9", 141 | [ 142 | "num", 143 | 0 144 | ] 145 | ] 146 | ] 147 | ], 148 | [ 149 | "stat", 150 | [ 151 | "assign", 152 | true, 153 | [ 154 | "name", 155 | "$9" 156 | ], 157 | [ 158 | "seq", 159 | [ 160 | "assign", 161 | true, 162 | [ 163 | "sub", 164 | [ 165 | "name", 166 | "HEAPF32" 167 | ], 168 | [ 169 | "binary", 170 | ">>", 171 | [ 172 | "name", 173 | "tempDoublePtr" 174 | ], 175 | [ 176 | "num", 177 | 2 178 | ] 179 | ] 180 | ], 181 | [ 182 | "name", 183 | "$8" 184 | ] 185 | ], 186 | [ 187 | "binary", 188 | "|", 189 | [ 190 | "sub", 191 | [ 192 | "name", 193 | "HEAP32" 194 | ], 195 | [ 196 | "binary", 197 | ">>", 198 | [ 199 | "name", 200 | "tempDoublePtr" 201 | ], 202 | [ 203 | "num", 204 | 2 205 | ] 206 | ] 207 | ], 208 | [ 209 | "num", 210 | 0 211 | ] 212 | ] 213 | ] 214 | ] 215 | ], 216 | [ 217 | "stat", 218 | [ 219 | "assign", 220 | true, 221 | [ 222 | "sub", 223 | [ 224 | "name", 225 | "HEAP32" 226 | ], 227 | [ 228 | "binary", 229 | ">>", 230 | [ 231 | "name", 232 | "$gep23_asptr" 233 | ], 234 | [ 235 | "num", 236 | 2 237 | ] 238 | ] 239 | ], 240 | [ 241 | "name", 242 | "$9" 243 | ] 244 | ] 245 | ] 246 | ] 247 | ], 248 | [ 249 | "defun", 250 | "dupe", 251 | [], 252 | [ 253 | [ 254 | "stat", 255 | [ 256 | "assign", 257 | true, 258 | [ 259 | "name", 260 | "x" 261 | ], 262 | [ 263 | "call", 264 | [ 265 | "name", 266 | "Math_fround" 267 | ], 268 | [ 269 | [ 270 | "name", 271 | "x" 272 | ] 273 | ] 274 | ] 275 | ] 276 | ], 277 | [ 278 | "stat", 279 | [ 280 | "assign", 281 | true, 282 | [ 283 | "name", 284 | "x" 285 | ], 286 | [ 287 | "call", 288 | [ 289 | "name", 290 | "Math_fround" 291 | ], 292 | [ 293 | [ 294 | "call", 295 | [ 296 | "name", 297 | "Math_fround" 298 | ], 299 | [ 300 | [ 301 | "name", 302 | "x" 303 | ] 304 | ] 305 | ] 306 | ] 307 | ] 308 | ] 309 | ], 310 | [ 311 | "stat", 312 | [ 313 | "assign", 314 | true, 315 | [ 316 | "name", 317 | "x" 318 | ], 319 | [ 320 | "call", 321 | [ 322 | "name", 323 | "Math_fround" 324 | ], 325 | [ 326 | [ 327 | "call", 328 | [ 329 | "name", 330 | "Math_fround" 331 | ], 332 | [ 333 | [ 334 | "call", 335 | [ 336 | "name", 337 | "Math_fround" 338 | ], 339 | [ 340 | [ 341 | "name", 342 | "x" 343 | ] 344 | ] 345 | ] 346 | ] 347 | ] 348 | ] 349 | ] 350 | ] 351 | ], 352 | [ 353 | "stat", 354 | [ 355 | "assign", 356 | true, 357 | [ 358 | "name", 359 | "x" 360 | ], 361 | [ 362 | "call", 363 | [ 364 | "name", 365 | "Math_fround" 366 | ], 367 | [ 368 | [ 369 | "call", 370 | [ 371 | "name", 372 | "Math_fround" 373 | ], 374 | [ 375 | [ 376 | "call", 377 | [ 378 | "name", 379 | "Math_fround" 380 | ], 381 | [ 382 | [ 383 | "call", 384 | [ 385 | "name", 386 | "Math_fround" 387 | ], 388 | [ 389 | [ 390 | "name", 391 | "x" 392 | ] 393 | ] 394 | ] 395 | ] 396 | ] 397 | ] 398 | ] 399 | ] 400 | ] 401 | ] 402 | ] 403 | ] 404 | ], 405 | [ 406 | "defun", 407 | "zeros", 408 | [ 409 | "x" 410 | ], 411 | [ 412 | [ 413 | "stat", 414 | [ 415 | "assign", 416 | true, 417 | [ 418 | "name", 419 | "x" 420 | ], 421 | [ 422 | "call", 423 | [ 424 | "name", 425 | "Math_fround" 426 | ], 427 | [ 428 | [ 429 | "name", 430 | "x" 431 | ] 432 | ] 433 | ] 434 | ] 435 | ], 436 | [ 437 | "var", 438 | [ 439 | [ 440 | "y", 441 | [ 442 | "call", 443 | [ 444 | "name", 445 | "Math_fround" 446 | ], 447 | [ 448 | [ 449 | "num", 450 | 0 451 | ] 452 | ] 453 | ] 454 | ] 455 | ] 456 | ], 457 | [ 458 | "stat", 459 | [ 460 | "call", 461 | [ 462 | "name", 463 | "print" 464 | ], 465 | [ 466 | [ 467 | "binary", 468 | "+", 469 | [ 470 | "call", 471 | [ 472 | "name", 473 | "Math_fround" 474 | ], 475 | [ 476 | [ 477 | "name", 478 | "y" 479 | ] 480 | ] 481 | ], 482 | [ 483 | "call", 484 | [ 485 | "name", 486 | "Math_fround" 487 | ], 488 | [ 489 | [ 490 | "num", 491 | 0 492 | ] 493 | ] 494 | ] 495 | ] 496 | ] 497 | ] 498 | ], 499 | [ 500 | "return", 501 | [ 502 | "call", 503 | [ 504 | "name", 505 | "Math_fround" 506 | ], 507 | [ 508 | [ 509 | "num", 510 | 0 511 | ] 512 | ] 513 | ] 514 | ] 515 | ] 516 | ] 517 | ] 518 | ] 519 | -------------------------------------------------------------------------------- /src/cashew/samples/8.js: -------------------------------------------------------------------------------- 1 | function a() { 2 | f((HEAPU8[10202] | 0) + 5 | 0); 3 | f((HEAPU8[10202] | 0) | 0); 4 | f(347 | 0); 5 | f(347 | 12); 6 | f(347 & 12); 7 | HEAP[4096 >> 2] = 5; 8 | HEAP[(4096 & 8191) >> 2] = 5; 9 | whee(12, 13) | 0; 10 | +whee(12, 13); 11 | f((g = t(), (g+g)|0)|0); 12 | // always coerce function calls in asm 13 | f() | 0; 14 | f((h() | 0) + 5 | 0); 15 | f(((x + y) | 0) + z | 0); 16 | +f(); 17 | f(+(+h() + 5)); 18 | $140 = $p_3_i + (-$mantSize_0_i | 0) | 0; 19 | f(g() | 0 | 0); 20 | f(g() | 0 & -1); 21 | f((g() | 0) >> 2); 22 | $56 = (_fcntl() | 0) | 1; 23 | FUNCTION_TABLE_ii[55 & 127]() | 0; 24 | } 25 | function b($this, $__n) { 26 | $this = $this | 0; 27 | $__n = $__n | 0; 28 | var $4 = 0, $5 = 0, $10 = 0, $13 = 0, $14 = 0, $15 = 0, $23 = 0, $30 = 0, $38 = 0, $40 = 0; 29 | if (($__n | 0) == 0) { 30 | return; 31 | } 32 | $4 = $this; 33 | $5 = HEAP8[$4 & 16777215] | 0; 34 | if (($5 & 1) << 24 >> 24 == 0) { 35 | $14 = 10; 36 | $13 = $5; 37 | } else { 38 | $10 = HEAP32[(($this | 0) & 16777215) >> 2] | 0; 39 | $14 = ($10 & -2) - 1 | 0; 40 | $13 = $10 & 255; 41 | } 42 | $15 = $13 & 255; 43 | if (($15 & 1 | 0) == 0) { 44 | $23 = $15 >>> 1; 45 | } else { 46 | $23 = HEAP32[(($this + 4 | 0) & 16777215) >> 2] | 0; 47 | } 48 | if (($14 - $23 | 0) >>> 0 < $__n >>> 0) { 49 | __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEjjjjjj($this, $14, ($__n - $14 | 0) + $23 | 0, $23, $23); 50 | $30 = HEAP8[$4 & 16777215] | 0; 51 | } else { 52 | $30 = $13; 53 | } 54 | if (($30 & 1) << 24 >> 24 == 0) { 55 | $38 = $this + 1 | 0; 56 | } else { 57 | $38 = HEAP32[(($this + 8 | 0) & 16777215) >> 2] | 0; 58 | } 59 | _memset($38 + $23 | 0 | 0 | 0, 0 | 0 | 0, $__n | 0 | 0, 1 | 0 | 0, 1213141516); 60 | $40 = $23 + $__n | 0; 61 | if (((HEAP8[$4 & 16777215] | 0) & 1) << 24 >> 24 == 0) { 62 | HEAP8[$4 & 16777215] = $40 << 1 & 255; 63 | } else { 64 | HEAP32[(($this + 4 | 0) & 16777215) >> 2] = $40; 65 | } 66 | HEAP8[($38 + $40 | 0) & 16777215] = 0; 67 | // Eliminate the |0. 68 | HEAP32[$4] = ((~(HEAP32[$5]|0))|0); 69 | // Eliminate the &255 70 | HEAP8[$4] = HEAP32[$5]&255; 71 | // Eliminate the &65535 72 | HEAP16[$4] = HEAP32[$5]&65535; 73 | // Rewrite to ~. 74 | HEAP32[$4] = HEAP32[$5]^-1; 75 | // Rewrite to ~ and eliminate the |0. 76 | HEAP32[$4] = ((HEAP32[$5]|0)^-1)|0; 77 | h((~~g) ^ -1); // do NOT convert this, as it would lead to ~~~ which is confusing in asm, given the role of ~~ 78 | return; 79 | } 80 | function i32_8() { 81 | if (((HEAP8[$4 & 16777215] | 0) << 24 >> 24) == 0) { 82 | print(5); 83 | } 84 | if ((HEAP8[$5 & 16777215] << 24 >> 24) == 0) { 85 | print(5); 86 | } 87 | if (((HEAPU8[$6 & 16777215] | 0) << 24 >> 24) == 0) { 88 | print(5); 89 | } 90 | if ((HEAPU8[$7 & 16777215] << 24 >> 24) == 0) { 91 | print(5); 92 | } 93 | // non-valid 94 | if ((HEAPU8[$8 & 16777215] << 24 >> 16) == 0) { 95 | print(5); 96 | } 97 | if ((HEAPU8[$9 & 16777215] << 16 >> 16) == 0) { 98 | print(5); 99 | } 100 | } 101 | function sign_extension_simplification() { 102 | if ((HEAP8[$4 & 16777215] & 127) << 24 >> 24 == 0) { 103 | print(5); 104 | } 105 | if ((HEAP8[$4 & 16777215] & 128) << 24 >> 24 == 0) { 106 | print(5); 107 | } 108 | if ((HEAP32[$5 & 16777215] & 32767) << 16 >> 16 == 0) { 109 | print(5); 110 | } 111 | if ((HEAP32[$5 & 16777215] & 32768) << 16 >> 16 == 0) { 112 | print(5); 113 | } 114 | } 115 | function compare_result_simplification() { 116 | f(((a > b)&1) + 1 | 0); 117 | f(((a > b)&1) | z); 118 | f(((a > b)&1) | (c > d & 1)); 119 | // Don't eliminate these '&1's. 120 | HEAP32[$4] = (HEAP32[$5] < HEAP32[$6]) & 1; 121 | var x = (HEAP32[$5] != HEAP32[$6]) & 1; 122 | } 123 | function tempDoublePtr($45, $14, $28, $42) { 124 | $45 = $45 | 0; 125 | $14 = $14 | 0; 126 | $28 = $28 | 0; 127 | $42 = $42 | 0; 128 | var unelim = 0; // only used as assign to int heap, so can avoid bitcast in definition 129 | var bad = 0; 130 | var unelim2 = 0; // opposite types 131 | unelim = (HEAPF32[tempDoublePtr >> 2] = 127.5 * +$14, HEAP32[tempDoublePtr >> 2] | 0); 132 | HEAP32[$45 >> 2] = 0 | (HEAPF32[tempDoublePtr >> 2] = ($14 < $28 ? $14 : $28) - $42, HEAP32[tempDoublePtr >> 2] | 0); 133 | HEAP32[$world + 102916 >> 2] = _malloc(192) | 0; 134 | f((HEAP32[tempDoublePtr >> 2] = HEAP32[$45 >> 2], +HEAPF32[tempDoublePtr >> 2])); 135 | g((HEAPF32[tempDoublePtr >> 2] = HEAPF32[$14 >> 2], HEAP32[tempDoublePtr >> 2] | 0)); 136 | $42 = (HEAP32[tempDoublePtr >> 2] = HEAP32[$42 >> 2] | 0, +HEAPF32[tempDoublePtr >> 2]); 137 | ch($42); 138 | HEAP32[$45 >> 2] = unelim; 139 | moar(); 140 | bad = (HEAPF32[tempDoublePtr >> 2] = 127.5 * +$14, HEAP32[tempDoublePtr >> 2] | 0); 141 | func(); 142 | HEAP32[4] = bad; 143 | HEAP32[5] = (bad + 1) | 0; 144 | moar(); 145 | unelim2 = (HEAP32[tempDoublePtr >> 2] = 127 + $14, +HEAPF32[tempDoublePtr >> 2]); 146 | func(); 147 | HEAPF32[4] = unelim2; 148 | barrier(); 149 | $f163 = (HEAP32[tempDoublePtr >> 2] = HEAP32[$f165 >> 2], HEAP32[tempDoublePtr + 4 >> 2] = HEAP32[$f165 + 4 >> 2], +HEAPF64[tempDoublePtr >> 3]); 150 | } 151 | function boxx($this, $aabb, $xf, $childIndex) { 152 | $this = $this | 0; 153 | $aabb = $aabb | 0; 154 | $xf = $xf | 0; 155 | $childIndex = $childIndex | 0; 156 | var $2 = +0, $4 = +0, $7 = +0, $9 = +0, $13 = +0, $14 = +0, $19 = +0, $20 = +0, $22 = +0, $25 = +0, $28 = +0, $32 = +0, $42 = +0, $45 = 0, $_sroa_06_0_insert_insert$1 = 0, $51 = 0, $_sroa_0_0_insert_insert$1 = 0; 157 | $2 = +HEAPF32[$xf + 12 >> 2]; 158 | $4 = +HEAPF32[$this + 12 >> 2]; 159 | $7 = +HEAPF32[$xf + 8 >> 2]; 160 | $9 = +HEAPF32[$this + 16 >> 2]; 161 | $13 = +HEAPF32[$xf >> 2]; 162 | $14 = $13 + ($2 * $4 - $7 * $9); 163 | $19 = +HEAPF32[$xf + 4 >> 2]; 164 | $20 = $4 * $7 + $2 * $9 + $19; 165 | $22 = +HEAPF32[$this + 20 >> 2]; 166 | $25 = +HEAPF32[$this + 24 >> 2]; 167 | $28 = $13 + ($2 * $22 - $7 * $25); 168 | $32 = $19 + ($7 * $22 + $2 * $25); 169 | $42 = +HEAPF32[$this + 8 >> 2]; 170 | $45 = $aabb; 171 | $_sroa_06_0_insert_insert$1 = (HEAPF32[tempDoublePtr >> 2] = ($20 < $32 ? $20 : $32) - $42, HEAP32[tempDoublePtr >> 2] | 0) | 0; 172 | HEAPF32[$45 >> 2] = ($14 < $28 ? $14 : $28) - $42; 173 | HEAP32[$45 + 4 >> 2] = $_sroa_06_0_insert_insert$1; 174 | $51 = $aabb + 8 | 0; 175 | $_sroa_0_0_insert_insert$1 = (HEAPF32[tempDoublePtr >> 2] = $42 + ($20 > $32 ? $20 : $32), HEAP32[tempDoublePtr >> 2] | 0) | 0; 176 | HEAPF32[$51 >> 2] = $42 + ($14 > $28 ? $14 : $28); 177 | HEAP32[$51 + 4 >> 2] = $_sroa_0_0_insert_insert$1; 178 | return; 179 | } 180 | function _main($argc, $argv) { 181 | $argc = $argc | 0; 182 | $argv = $argv | 0; 183 | var $def_i21 = 0, $def_i = 0, $world = 0, $bd = 0, $shape = 0, $shape1 = 0, $bd2 = 0, $result = 0, $6 = 0, $WARMUP_0 = 0, $14 = 0, $15 = 0, $17 = 0, $i_09_i_i = 0, $j_08_i_i = 0, $34 = 0, $j_1_i_i = 0, $38 = 0, $46 = 0, $48 = 0, $50 = 0, $54 = 0, $i_05_i_i_i = 0, $56 = 0, $62 = 0, $_lcssa_i_i_i = 0, $87 = 0, $96 = 0, $97 = 0, $98 = 0, $112 = 0, $115 = 0, $116 = 0, $118 = 0, $121 = 0, $126 = 0, $135 = 0, $137 = 0, $174 = 0, $176 = 0, $177 = 0, $178 = 0, $179 = 0, $180 = 0, $181 = 0, $182 = 0, $183 = 0, $185 = 0, $186 = 0, $188 = 0, $189 = 0, $190 = 0, $191 = 0, $192 = 0, $193 = 0, $194 = 0, $195 = 0, $196 = 0, $i_057 = 0, $x_sroa_0_0_load303656 = +0, $x_sroa_1_4_load313755 = +0, $j_052 = 0, $y_sroa_0_0_load283451 = +0, $y_sroa_1_4_load293550 = +0, $y_sroa_0_0_insert_insert$1 = 0, $205 = 0, $208 = 0, $209 = 0, $213 = 0, $223 = 0, $236 = 0, $i3_042 = 0, $241 = 0, $242 = 0, $243 = 0, $i4_038 = 0, $245 = 0, $260 = +0, $_0 = 0, label = 0, __stackBase__ = 0; 184 | __stackBase__ = STACKTOP; 185 | STACKTOP = STACKTOP + 103416 | 0; 186 | $def_i21 = __stackBase__ | 0; 187 | $def_i = __stackBase__ + 32 | 0; 188 | $world = __stackBase__ + 64 | 0; 189 | $bd = __stackBase__ + 103096 | 0; 190 | $shape = __stackBase__ + 103152 | 0; 191 | $shape1 = __stackBase__ + 103200 | 0; 192 | $bd2 = __stackBase__ + 103352 | 0; 193 | $result = __stackBase__ + 103408 | 0; 194 | do { 195 | if (($argc | 0) > 1) { 196 | $6 = (HEAP8[HEAP32[($argv + 4 | 0) >> 2] | 0] | 0) << 24 >> 24; 197 | if (($6 | 0 | 0) == (49 | 0)) { 198 | HEAP32[9656 >> 2] = 35; 199 | $WARMUP_0 = 5; 200 | break; 201 | } else if (($6 | 0 | 0) == (50 | 0)) { 202 | HEAP32[9656 >> 2] = 161; 203 | $WARMUP_0 = 32; 204 | break; 205 | } else if (($6 | 0 | 0) == (51 | 0)) { 206 | label = 43; 207 | break; 208 | } else if (($6 | 0 | 0) == (52 | 0)) { 209 | HEAP32[9656 >> 2] = 2331; 210 | $WARMUP_0 = 320; 211 | break; 212 | } else if (($6 | 0 | 0) == (53 | 0)) { 213 | HEAP32[9656 >> 2] = 5661; 214 | $WARMUP_0 = 640; 215 | break; 216 | } else if (($6 | 0 | 0) == (48 | 0)) { 217 | $_0 = 0; 218 | STACKTOP = __stackBase__; 219 | return $_0 | 0; 220 | } else { 221 | _printf(3512 | 0 | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[tempInt >> 2] = $6 - 48 | 0, tempInt) | 0) | 0; 222 | $_0 = -1; 223 | STACKTOP = __stackBase__; 224 | return $_0 | 0; 225 | } 226 | } else { 227 | label = 43; 228 | } 229 | } while (0); 230 | if ((label | 0) == 43) { 231 | HEAP32[9656 >> 2] = 333; 232 | $WARMUP_0 = 64; 233 | } 234 | $14 = $world | 0; 235 | $15 = $world + 8 | 0; 236 | HEAP32[$15 >> 2] = 128; 237 | HEAP32[($world + 4 | 0) >> 2] = 0; 238 | $17 = _malloc(1024) | 0; 239 | HEAP32[($world | 0) >> 2] = $17; 240 | _memset($17 | 0 | 0, 0 | 0 | 0, (HEAP32[$15 >> 2] | 0) << 3 | 0 | 0); 241 | _memset($world + 12 | 0 | 0 | 0, 0 | 0 | 0, 56 | 0 | 0); 242 | $j_08_i_i = 0; 243 | $i_09_i_i = 1; 244 | while (1) { 245 | if (!(($j_08_i_i | 0) < 14)) { 246 | label = 49; 247 | break; 248 | } 249 | if (($i_09_i_i | 0) > (HEAP32[(9600 + ($j_08_i_i << 2) | 0) >> 2] | 0 | 0)) { 250 | $34 = $j_08_i_i + 1 | 0; 251 | HEAP8[$i_09_i_i + 8952 | 0] = $34 & 255; 252 | $j_1_i_i = $34; 253 | } else { 254 | HEAP8[$i_09_i_i + 8952 | 0] = $j_08_i_i & 255; 255 | $j_1_i_i = $j_08_i_i; 256 | } 257 | $38 = $i_09_i_i + 1 | 0; 258 | if (($38 | 0) < 641) { 259 | $j_08_i_i = $j_1_i_i; 260 | $i_09_i_i = $38; 261 | } else { 262 | break; 263 | } 264 | } 265 | if ((label | 0) == 49) { 266 | ___assert_func(3248 | 0 | 0, 73 | 0, 6448 | 0 | 0, 3360 | 0 | 0); 267 | return 0 | 0; 268 | } 269 | HEAP32[($world + 102468 | 0) >> 2] = 0; 270 | HEAP32[($world + 102472 | 0) >> 2] = 0; 271 | HEAP32[($world + 102476 | 0) >> 2] = 0; 272 | HEAP32[($world + 102864 | 0) >> 2] = 0; 273 | HEAP32[($world + 102872 | 0) >> 2] = -1; 274 | $46 = $world + 102884 | 0; 275 | HEAP32[$46 >> 2] = 16; 276 | HEAP32[($world + 102880 | 0) >> 2] = 0; 277 | $48 = _malloc(576) | 0; 278 | $50 = $world + 102876 | 0; 279 | HEAP32[$50 >> 2] = $48; 280 | _memset($48 | 0 | 0, 0 | 0 | 0, (HEAP32[$46 >> 2] | 0) * 36 & -1 | 0 | 0); 281 | $54 = (HEAP32[$46 >> 2] | 0) - 1 | 0; 282 | if (($54 | 0) > 0) { 283 | $i_05_i_i_i = 0; 284 | while (1) { 285 | $56 = $i_05_i_i_i + 1 | 0; 286 | HEAP32[((HEAP32[$50 >> 2] | 0) + ($i_05_i_i_i * 36 & -1) + 20 | 0) >> 2] = $56; 287 | HEAP32[((HEAP32[$50 >> 2] | 0) + ($i_05_i_i_i * 36 & -1) + 32 | 0) >> 2] = -1; 288 | $62 = (HEAP32[$46 >> 2] | 0) - 1 | 0; 289 | if (($56 | 0) < ($62 | 0)) { 290 | $i_05_i_i_i = $56; 291 | } else { 292 | $_lcssa_i_i_i = $62; 293 | break; 294 | } 295 | } 296 | } else { 297 | $_lcssa_i_i_i = $54; 298 | } 299 | HEAP32[((HEAP32[$50 >> 2] | 0) + ($_lcssa_i_i_i * 36 & -1) + 20 | 0) >> 2] = -1; 300 | HEAP32[((HEAP32[$50 >> 2] | 0) + (((HEAP32[$46 >> 2] | 0) - 1 | 0) * 36 & -1) + 32 | 0) >> 2] = -1; 301 | _memset($world + 102888 | 0 | 0 | 0, 0 | 0 | 0, 16 | 0 | 0); 302 | HEAP32[($world + 102920 | 0) >> 2] = 16; 303 | HEAP32[($world + 102924 | 0) >> 2] = 0; 304 | HEAP32[($world + 102916 | 0) >> 2] = _malloc(192) | 0; 305 | HEAP32[($world + 102908 | 0) >> 2] = 16; 306 | HEAP32[($world + 102912 | 0) >> 2] = 0; 307 | HEAP32[($world + 102904 | 0) >> 2] = _malloc(64) | 0; 308 | HEAP32[($world + 102932 | 0) >> 2] = 0; 309 | HEAP32[($world + 102936 | 0) >> 2] = 0; 310 | HEAP32[($world + 102940 | 0) >> 2] = 104; 311 | HEAP32[($world + 102944 | 0) >> 2] = 96; 312 | $87 = $world + 102948 | 0; 313 | HEAP32[($world + 102980 | 0) >> 2] = 0; 314 | HEAP32[($world + 102984 | 0) >> 2] = 0; 315 | _memset($87 | 0 | 0, 0 | 0 | 0, 20 | 0 | 0); 316 | HEAP8[$world + 102992 | 0] = 1; 317 | HEAP8[$world + 102993 | 0] = 1; 318 | HEAP8[$world + 102994 | 0] = 0; 319 | HEAP8[$world + 102995 | 0] = 1; 320 | $96 = $world + 102976 | 0; 321 | HEAP8[$96] = 1; 322 | $97 = $world + 102968 | 0; 323 | HEAP32[($97 | 0) >> 2] = 0; 324 | HEAP32[($97 + 4 | 0) >> 2] = -1054867456; 325 | $98 = $world + 102868 | 0; 326 | HEAP32[$98 >> 2] = 4; 327 | HEAPF32[($world + 102988 | 0) >> 2] = +0; 328 | HEAP32[$87 >> 2] = $14; 329 | _memset($world + 102996 | 0 | 0 | 0, 0 | 0 | 0, 32 | 0 | 0); 330 | HEAP8[$96] = 0; 331 | HEAP32[($bd + 44 | 0) >> 2] = 0; 332 | _memset($bd + 4 | 0 | 0 | 0, 0 | 0 | 0, 32 | 0 | 0); 333 | HEAP8[$bd + 36 | 0] = 1; 334 | HEAP8[$bd + 37 | 0] = 1; 335 | HEAP8[$bd + 38 | 0] = 0; 336 | HEAP8[$bd + 39 | 0] = 0; 337 | HEAP32[($bd | 0) >> 2] = 0; 338 | HEAP8[$bd + 40 | 0] = 1; 339 | HEAPF32[($bd + 48 | 0) >> 2] = +1; 340 | $112 = __ZN16b2BlockAllocator8AllocateEi($14, 152) | 0; 341 | if (($112 | 0) == 0) { 342 | $116 = 0; 343 | } else { 344 | $115 = $112; 345 | __ZN6b2BodyC2EPK9b2BodyDefP7b2World($115, $bd, $world); 346 | $116 = $115; 347 | } 348 | HEAP32[($116 + 92 | 0) >> 2] = 0; 349 | $118 = $world + 102952 | 0; 350 | HEAP32[($116 + 96 | 0) >> 2] = HEAP32[$118 >> 2] | 0; 351 | $121 = HEAP32[$118 >> 2] | 0; 352 | if (!(($121 | 0) == 0)) { 353 | HEAP32[($121 + 92 | 0) >> 2] = $116; 354 | } 355 | HEAP32[$118 >> 2] = $116; 356 | $126 = $world + 102960 | 0; 357 | HEAP32[$126 >> 2] = (HEAP32[$126 >> 2] | 0) + 1 | 0; 358 | HEAP32[($shape | 0) >> 2] = 8016 | 0; 359 | HEAP32[($shape + 4 | 0) >> 2] = 1; 360 | HEAPF32[($shape + 8 | 0) >> 2] = +.009999999776482582; 361 | _memset($shape + 28 | 0 | 0 | 0, 0 | 0 | 0, 18 | 0 | 0); 362 | $135 = $shape + 12 | 0; 363 | HEAP32[($135 | 0) >> 2] = -1038090240; 364 | HEAP32[($135 + 4 | 0) >> 2] = 0; 365 | $137 = $shape + 20 | 0; 366 | HEAP32[($137 | 0) >> 2] = 1109393408; 367 | HEAP32[($137 + 4 | 0) >> 2] = 0; 368 | HEAP8[$shape + 44 | 0] = 0; 369 | HEAP8[$shape + 45 | 0] = 0; 370 | HEAP16[($def_i + 22 | 0) >> 1] = 1; 371 | HEAP16[($def_i + 24 | 0) >> 1] = -1; 372 | HEAP16[($def_i + 26 | 0) >> 1] = 0; 373 | HEAP32[($def_i + 4 | 0) >> 2] = 0; 374 | HEAPF32[($def_i + 8 | 0) >> 2] = +.20000000298023224; 375 | HEAPF32[($def_i + 12 | 0) >> 2] = +0; 376 | HEAP8[$def_i + 20 | 0] = 0; 377 | HEAP32[($def_i | 0) >> 2] = $shape | 0; 378 | HEAPF32[($def_i + 16 | 0) >> 2] = +0; 379 | __ZN6b2Body13CreateFixtureEPK12b2FixtureDef($116, $def_i); 380 | HEAP32[($shape1 | 0) >> 2] = 7968 | 0; 381 | HEAP32[($shape1 + 4 | 0) >> 2] = 2; 382 | HEAPF32[($shape1 + 8 | 0) >> 2] = +.009999999776482582; 383 | HEAP32[($shape1 + 148 | 0) >> 2] = 4; 384 | HEAPF32[($shape1 + 20 | 0) >> 2] = +-.5; 385 | HEAPF32[($shape1 + 24 | 0) >> 2] = +-.5; 386 | HEAPF32[($shape1 + 28 | 0) >> 2] = +.5; 387 | HEAPF32[($shape1 + 32 | 0) >> 2] = +-.5; 388 | HEAPF32[($shape1 + 36 | 0) >> 2] = +.5; 389 | HEAPF32[($shape1 + 40 | 0) >> 2] = +.5; 390 | HEAPF32[($shape1 + 44 | 0) >> 2] = +-.5; 391 | HEAPF32[($shape1 + 48 | 0) >> 2] = +.5; 392 | HEAPF32[($shape1 + 84 | 0) >> 2] = +0; 393 | HEAPF32[($shape1 + 88 | 0) >> 2] = +-1; 394 | HEAPF32[($shape1 + 92 | 0) >> 2] = +1; 395 | HEAPF32[($shape1 + 96 | 0) >> 2] = +0; 396 | HEAPF32[($shape1 + 100 | 0) >> 2] = +0; 397 | HEAPF32[($shape1 + 104 | 0) >> 2] = +1; 398 | HEAPF32[($shape1 + 108 | 0) >> 2] = +-1; 399 | HEAPF32[($shape1 + 112 | 0) >> 2] = +0; 400 | HEAPF32[($shape1 + 12 | 0) >> 2] = +0; 401 | HEAPF32[($shape1 + 16 | 0) >> 2] = +0; 402 | $174 = $bd2 + 44 | 0; 403 | $176 = $bd2 + 36 | 0; 404 | $177 = $bd2 + 4 | 0; 405 | $178 = $bd2 + 37 | 0; 406 | $179 = $bd2 + 38 | 0; 407 | $180 = $bd2 + 39 | 0; 408 | $181 = $bd2 | 0; 409 | $182 = $bd2 + 40 | 0; 410 | $183 = $bd2 + 48 | 0; 411 | $185 = $bd2 + 4 | 0; 412 | $186 = $shape1 | 0; 413 | $188 = $def_i21 + 22 | 0; 414 | $189 = $def_i21 + 24 | 0; 415 | $190 = $def_i21 + 26 | 0; 416 | $191 = $def_i21 | 0; 417 | $192 = $def_i21 + 4 | 0; 418 | $193 = $def_i21 + 8 | 0; 419 | $194 = $def_i21 + 12 | 0; 420 | $195 = $def_i21 + 16 | 0; 421 | $196 = $def_i21 + 20 | 0; 422 | $x_sroa_1_4_load313755 = +.75; 423 | $x_sroa_0_0_load303656 = +-7; 424 | $i_057 = 0; 425 | L82 : while (1) { 426 | $y_sroa_1_4_load293550 = $x_sroa_1_4_load313755; 427 | $y_sroa_0_0_load283451 = $x_sroa_0_0_load303656; 428 | $j_052 = $i_057; 429 | while (1) { 430 | HEAP32[$174 >> 2] = 0; 431 | _memset($177 | 0 | 0, 0 | 0 | 0, 32 | 0 | 0); 432 | HEAP8[$176] = 1; 433 | HEAP8[$178] = 1; 434 | HEAP8[$179] = 0; 435 | HEAP8[$180] = 0; 436 | HEAP8[$182] = 1; 437 | HEAPF32[$183 >> 2] = +1; 438 | HEAP32[$181 >> 2] = 2; 439 | $y_sroa_0_0_insert_insert$1 = (HEAPF32[tempDoublePtr >> 2] = $y_sroa_1_4_load293550, HEAP32[tempDoublePtr >> 2] | 0) | 0; 440 | HEAP32[($185 | 0) >> 2] = 0 | (HEAPF32[tempDoublePtr >> 2] = $y_sroa_0_0_load283451, HEAP32[tempDoublePtr >> 2] | 0); 441 | HEAP32[($185 + 4 | 0) >> 2] = $y_sroa_0_0_insert_insert$1; 442 | if (!(((HEAP32[$98 >> 2] | 0) & 2 | 0) == 0)) { 443 | label = 65; 444 | break L82; 445 | } 446 | $205 = __ZN16b2BlockAllocator8AllocateEi($14, 152) | 0; 447 | if (($205 | 0) == 0) { 448 | $209 = 0; 449 | } else { 450 | $208 = $205; 451 | __ZN6b2BodyC2EPK9b2BodyDefP7b2World($208, $bd2, $world); 452 | $209 = $208; 453 | } 454 | HEAP32[($209 + 92 | 0) >> 2] = 0; 455 | HEAP32[($209 + 96 | 0) >> 2] = HEAP32[$118 >> 2] | 0; 456 | $213 = HEAP32[$118 >> 2] | 0; 457 | if (!(($213 | 0) == 0)) { 458 | HEAP32[($213 + 92 | 0) >> 2] = $209; 459 | } 460 | HEAP32[$118 >> 2] = $209; 461 | HEAP32[$126 >> 2] = (HEAP32[$126 >> 2] | 0) + 1 | 0; 462 | HEAP16[$188 >> 1] = 1; 463 | HEAP16[$189 >> 1] = -1; 464 | HEAP16[$190 >> 1] = 0; 465 | HEAP32[$192 >> 2] = 0; 466 | HEAPF32[$193 >> 2] = +.20000000298023224; 467 | HEAPF32[$194 >> 2] = +0; 468 | HEAP8[$196] = 0; 469 | HEAP32[$191 >> 2] = $186; 470 | HEAPF32[$195 >> 2] = +5; 471 | __ZN6b2Body13CreateFixtureEPK12b2FixtureDef($209, $def_i21); 472 | $223 = $j_052 + 1 | 0; 473 | if (($223 | 0) < 40) { 474 | $y_sroa_1_4_load293550 = $y_sroa_1_4_load293550 + +0; 475 | $y_sroa_0_0_load283451 = $y_sroa_0_0_load283451 + 1.125; 476 | $j_052 = $223; 477 | } else { 478 | break; 479 | } 480 | } 481 | $236 = $i_057 + 1 | 0; 482 | if (($236 | 0) < 40) { 483 | $x_sroa_1_4_load313755 = $x_sroa_1_4_load313755 + +1; 484 | $x_sroa_0_0_load303656 = $x_sroa_0_0_load303656 + +.5625; 485 | $i_057 = $236; 486 | } else { 487 | $i3_042 = 0; 488 | break; 489 | } 490 | } 491 | if ((label | 0) == 65) { 492 | ___assert_func(112 | 0 | 0, 109 | 0, 5328 | 0 | 0, 2520 | 0 | 0); 493 | return 0 | 0; 494 | } 495 | while (1) { 496 | __ZN7b2World4StepEfii($world); 497 | $i3_042 = $i3_042 + 1 | 0; 498 | if (($i3_042 | 0) >= ($WARMUP_0 | 0)) { 499 | break; 500 | } 501 | } 502 | $241 = HEAP32[9656 >> 2] | 0; 503 | $242 = _llvm_stacksave() | 0; 504 | $243 = STACKTOP; 505 | STACKTOP = STACKTOP + ($241 * 4 & -1) | 0; 506 | STACKTOP = STACKTOP + 7 >> 3 << 3; 507 | if (($241 | 0) > 0) { 508 | $i4_038 = 0; 509 | while (1) { 510 | $245 = _clock() | 0; 511 | __ZN7b2World4StepEfii($world); 512 | HEAP32[($243 + ($i4_038 << 2) | 0) >> 2] = (_clock() | 0) - $245 | 0; 513 | $i4_038 = $i4_038 + 1 | 0; 514 | if (($i4_038 | 0) >= (HEAP32[9656 >> 2] | 0 | 0)) { 515 | break; 516 | } 517 | } 518 | } 519 | __Z7measurePm($result, $243); 520 | $260 = +HEAPF32[($result + 4 | 0) >> 2]; 521 | _printf(3480 | 0 | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[tempInt >> 3] = +HEAPF32[($result | 0) >> 2], HEAPF64[tempInt + 8 >> 3] = $260, tempInt) | 0) | 0; 522 | _llvm_stackrestore($242 | 0); 523 | __ZN7b2WorldD2Ev($world); 524 | $_0 = 0; 525 | STACKTOP = __stackBase__; 526 | return $_0 | 0; 527 | } 528 | function badf() { 529 | var $9 = Math_fround(0); 530 | $9 = (HEAP32[tempDoublePtr>>2]=$8,Math_fround(HEAPF32[tempDoublePtr>>2])); 531 | HEAPF32[$gep23_asptr>>2] = $9; 532 | } 533 | function badf2() { 534 | var $9 = 0; 535 | $9 = (HEAPF32[tempDoublePtr>>2]=$8,HEAP32[tempDoublePtr>>2]|0); 536 | HEAP32[$gep23_asptr>>2] = $9; 537 | } 538 | function fcomp() { 539 | // de-morgan's laws are not valid on floats, due to NaNs >:( 540 | if (!($y < $x)) return 5; 541 | if (!(5 < $x)) return 5; 542 | if (!($y < 5)) return 5; 543 | if (!(($a|0) < ($b|0))) return 5; 544 | if (!(($a|0) < 5)) return 5; 545 | if (!(5 < ($b|0))) return 5; 546 | if (!(5 < 5)) return 5; 547 | } 548 | function conditionalizeMe() { 549 | if ((x > 1) & (x+y+z+w > 12)) { 550 | b(); 551 | } 552 | if ((a() > 1) & (x+y+z+w > 12)) { 553 | b(); 554 | } 555 | if ((x > 1) & (x+y+z+k() > 12)) { 556 | b(); 557 | } 558 | if ((a() > 1) & (x+y+z+k() > 12)) { 559 | b(); 560 | } 561 | if ((x > 1) | (x+y+z+w > 12)) { 562 | b(); 563 | } 564 | if ((a() > 1) | (x+y+z+w > 12)) { 565 | b(); 566 | } 567 | if ((x > 1) | (x+y+z+k() > 12)) { 568 | b(); 569 | } 570 | if ((a() > 1) | (x+y+z+k() > 12)) { 571 | b(); 572 | } 573 | if ((x+y+z+w > 12) | (x > 1)) { 574 | b(); 575 | } 576 | if ((x+y+z+w > 12) | (a() > 1)) { 577 | b(); 578 | } 579 | if ((x+y+z+k() > 12) | (x > 1)) { 580 | b(); 581 | } 582 | if ((x+y+z+k() > 12) | (a() > 1)) { 583 | b(); 584 | } 585 | while ((x > 1) & (x+y+z+w > 12)) { 586 | b(); 587 | } 588 | while ((a() > 1) & (x+y+z+w > 12)) { 589 | b(); 590 | } 591 | while ((x > 1) & (x+y+z+k() > 12)) { 592 | b(); 593 | } 594 | while ((a() > 1) & (x+y+z+k() > 12)) { 595 | b(); 596 | } 597 | if (!($sub$i480 >= Math_fround(+0)) | !($sub4$i483 >= Math_fround(+0))) { 598 | b(); 599 | } 600 | if (!($sub$i480 >= Math_fround(+0)) | !($sub4$i483 >= Math_fround(HEAPF32[x+y|0]))) { 601 | b(); 602 | } 603 | if (x > 10 | (HEAP[20] + 2) > 5) { 604 | b(); 605 | } 606 | print( (((HEAP8[a] + HEAP8[b] + HEAP8[c] + HEAP8[d] + HEAP8[e] + HEAP8[f] | 0) > (a % b % c % d)) ? 1 : $el) | ($cheap > 0) ); // conditional does not always emit boolean 607 | print( (((HEAP8[a] + HEAP8[b] + HEAP8[c] + HEAP8[d] + HEAP8[e] + HEAP8[f] | 0) > (a % b % c % d)) ? 1 : -1) | ($cheap > 0) ); 608 | print( (((HEAP8[a] + HEAP8[b] + HEAP8[c] + HEAP8[d] + HEAP8[e] + HEAP8[f] | 0) > (a % b % c % d)) ? 1 : 0) | ($cheap > 0) ); // this one is safe! 609 | print( (((HEAP8[a] + HEAP8[b] + HEAP8[c] + HEAP8[d] + HEAP8[e] + HEAP8[f] | 0) > (a % b % c % d)) ? -1 : 1) | ($cheap > 0) ); 610 | return ((((Math_imul(i6+1, i7) | 0) + 17 | 0) % 5 | 0 | 0) == 0 | ((((Math_imul(i7+1, i7) | 0) + 11 | 0) >>> 0) % 3 | 0 | 0) == 0 | 0) == 0; 611 | } 612 | function bignum() { 613 | HEAP32[20] = 2779096485 | 0; 614 | if (!(($2814 | 0) >= 0)) return; 615 | } 616 | 617 | -------------------------------------------------------------------------------- /src/cashew/samples/8.js.1_0.js: -------------------------------------------------------------------------------- 1 | function a() { 2 | f((HEAPU8[10202] | 0) + 5 | 0); 3 | f(HEAPU8[10202] | 0 | 0); 4 | f(347 | 0); 5 | f(347 | 12); 6 | f(347 & 12); 7 | HEAP[4096 >> 2] = 5; 8 | HEAP[(4096 & 8191) >> 2] = 5; 9 | whee(12, 13) | 0; 10 | +whee(12, 13); 11 | f((g = t(), g + g | 0) | 0); 12 | f() | 0; 13 | f((h() | 0) + 5 | 0); 14 | f((x + y | 0) + z | 0); 15 | +f(); 16 | f(+(+h() + 5)); 17 | $140 = $p_3_i + (-$mantSize_0_i | 0) | 0; 18 | f(g() | 0 | 0); 19 | f(g() | 0 & -1); 20 | f((g() | 0) >> 2); 21 | $56 = _fcntl() | 0 | 1; 22 | FUNCTION_TABLE_ii[55 & 127]() | 0; 23 | } 24 | 25 | function b($this, $__n) { 26 | $this = $this | 0; 27 | $__n = $__n | 0; 28 | var $4 = 0, $5 = 0, $10 = 0, $13 = 0, $14 = 0, $15 = 0, $23 = 0, $30 = 0, $38 = 0, $40 = 0; 29 | if (($__n | 0) == 0) { 30 | return; 31 | } 32 | $4 = $this; 33 | $5 = HEAP8[$4 & 16777215] | 0; 34 | if (($5 & 1) << 24 >> 24 == 0) { 35 | $14 = 10; 36 | $13 = $5; 37 | } else { 38 | $10 = HEAP32[(($this | 0) & 16777215) >> 2] | 0; 39 | $14 = ($10 & -2) - 1 | 0; 40 | $13 = $10 & 255; 41 | } 42 | $15 = $13 & 255; 43 | if (($15 & 1 | 0) == 0) { 44 | $23 = $15 >>> 1; 45 | } else { 46 | $23 = HEAP32[(($this + 4 | 0) & 16777215) >> 2] | 0; 47 | } 48 | if (($14 - $23 | 0) >>> 0 < $__n >>> 0) { 49 | __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEjjjjjj($this, $14, ($__n - $14 | 0) + $23 | 0, $23, $23); 50 | $30 = HEAP8[$4 & 16777215] | 0; 51 | } else { 52 | $30 = $13; 53 | } 54 | if (($30 & 1) << 24 >> 24 == 0) { 55 | $38 = $this + 1 | 0; 56 | } else { 57 | $38 = HEAP32[(($this + 8 | 0) & 16777215) >> 2] | 0; 58 | } 59 | _memset($38 + $23 | 0 | 0 | 0, 0 | 0 | 0, $__n | 0 | 0, 1 | 0 | 0, 1213141516); 60 | $40 = $23 + $__n | 0; 61 | if (((HEAP8[$4 & 16777215] | 0) & 1) << 24 >> 24 == 0) { 62 | HEAP8[$4 & 16777215] = $40 << 1 & 255; 63 | } else { 64 | HEAP32[(($this + 4 | 0) & 16777215) >> 2] = $40; 65 | } 66 | HEAP8[($38 + $40 | 0) & 16777215] = 0; 67 | HEAP32[$4] = ~(HEAP32[$5] | 0) | 0; 68 | HEAP8[$4] = HEAP32[$5] & 255; 69 | HEAP16[$4] = HEAP32[$5] & 65535; 70 | HEAP32[$4] = HEAP32[$5] ^ -1; 71 | HEAP32[$4] = (HEAP32[$5] | 0) ^ -1 | 0; 72 | h(~~g ^ -1); 73 | return; 74 | } 75 | 76 | function i32_8() { 77 | if ((HEAP8[$4 & 16777215] | 0) << 24 >> 24 == 0) { 78 | print(5); 79 | } 80 | if (HEAP8[$5 & 16777215] << 24 >> 24 == 0) { 81 | print(5); 82 | } 83 | if ((HEAPU8[$6 & 16777215] | 0) << 24 >> 24 == 0) { 84 | print(5); 85 | } 86 | if (HEAPU8[$7 & 16777215] << 24 >> 24 == 0) { 87 | print(5); 88 | } 89 | if (HEAPU8[$8 & 16777215] << 24 >> 16 == 0) { 90 | print(5); 91 | } 92 | if (HEAPU8[$9 & 16777215] << 16 >> 16 == 0) { 93 | print(5); 94 | } 95 | } 96 | 97 | function sign_extension_simplification() { 98 | if ((HEAP8[$4 & 16777215] & 127) << 24 >> 24 == 0) { 99 | print(5); 100 | } 101 | if ((HEAP8[$4 & 16777215] & 128) << 24 >> 24 == 0) { 102 | print(5); 103 | } 104 | if ((HEAP32[$5 & 16777215] & 32767) << 16 >> 16 == 0) { 105 | print(5); 106 | } 107 | if ((HEAP32[$5 & 16777215] & 32768) << 16 >> 16 == 0) { 108 | print(5); 109 | } 110 | } 111 | 112 | function compare_result_simplification() { 113 | f((a > b & 1) + 1 | 0); 114 | f(a > b & 1 | z); 115 | f(a > b & 1 | c > d & 1); 116 | HEAP32[$4] = HEAP32[$5] < HEAP32[$6] & 1; 117 | var x = HEAP32[$5] != HEAP32[$6] & 1; 118 | } 119 | 120 | function tempDoublePtr($45, $14, $28, $42) { 121 | $45 = $45 | 0; 122 | $14 = $14 | 0; 123 | $28 = $28 | 0; 124 | $42 = $42 | 0; 125 | var unelim = 0; 126 | var bad = 0; 127 | var unelim2 = 0; 128 | unelim = (HEAPF32[tempDoublePtr >> 2] = 127.5 * +$14, HEAP32[tempDoublePtr >> 2] | 0); 129 | HEAP32[$45 >> 2] = 0 | (HEAPF32[tempDoublePtr >> 2] = ($14 < $28 ? $14 : $28) - $42, HEAP32[tempDoublePtr >> 2] | 0); 130 | HEAP32[$world + 102916 >> 2] = _malloc(192) | 0; 131 | f((HEAP32[tempDoublePtr >> 2] = HEAP32[$45 >> 2], +HEAPF32[tempDoublePtr >> 2])); 132 | g((HEAPF32[tempDoublePtr >> 2] = HEAPF32[$14 >> 2], HEAP32[tempDoublePtr >> 2] | 0)); 133 | $42 = (HEAP32[tempDoublePtr >> 2] = HEAP32[$42 >> 2] | 0, +HEAPF32[tempDoublePtr >> 2]); 134 | ch($42); 135 | HEAP32[$45 >> 2] = unelim; 136 | moar(); 137 | bad = (HEAPF32[tempDoublePtr >> 2] = 127.5 * +$14, HEAP32[tempDoublePtr >> 2] | 0); 138 | func(); 139 | HEAP32[4] = bad; 140 | HEAP32[5] = bad + 1 | 0; 141 | moar(); 142 | unelim2 = (HEAP32[tempDoublePtr >> 2] = 127 + $14, +HEAPF32[tempDoublePtr >> 2]); 143 | func(); 144 | HEAPF32[4] = unelim2; 145 | barrier(); 146 | $f163 = (HEAP32[tempDoublePtr >> 2] = HEAP32[$f165 >> 2], HEAP32[tempDoublePtr + 4 >> 2] = HEAP32[$f165 + 4 >> 2], +HEAPF64[tempDoublePtr >> 3]); 147 | } 148 | 149 | function boxx($this, $aabb, $xf, $childIndex) { 150 | $this = $this | 0; 151 | $aabb = $aabb | 0; 152 | $xf = $xf | 0; 153 | $childIndex = $childIndex | 0; 154 | var $2 = +0, $4 = +0, $7 = +0, $9 = +0, $13 = +0, $14 = +0, $19 = +0, $20 = +0, $22 = +0, $25 = +0, $28 = +0, $32 = +0, $42 = +0, $45 = 0, $_sroa_06_0_insert_insert$1 = 0, $51 = 0, $_sroa_0_0_insert_insert$1 = 0; 155 | $2 = +HEAPF32[$xf + 12 >> 2]; 156 | $4 = +HEAPF32[$this + 12 >> 2]; 157 | $7 = +HEAPF32[$xf + 8 >> 2]; 158 | $9 = +HEAPF32[$this + 16 >> 2]; 159 | $13 = +HEAPF32[$xf >> 2]; 160 | $14 = $13 + ($2 * $4 - $7 * $9); 161 | $19 = +HEAPF32[$xf + 4 >> 2]; 162 | $20 = $4 * $7 + $2 * $9 + $19; 163 | $22 = +HEAPF32[$this + 20 >> 2]; 164 | $25 = +HEAPF32[$this + 24 >> 2]; 165 | $28 = $13 + ($2 * $22 - $7 * $25); 166 | $32 = $19 + ($7 * $22 + $2 * $25); 167 | $42 = +HEAPF32[$this + 8 >> 2]; 168 | $45 = $aabb; 169 | $_sroa_06_0_insert_insert$1 = (HEAPF32[tempDoublePtr >> 2] = ($20 < $32 ? $20 : $32) - $42, HEAP32[tempDoublePtr >> 2] | 0) | 0; 170 | HEAPF32[$45 >> 2] = ($14 < $28 ? $14 : $28) - $42; 171 | HEAP32[$45 + 4 >> 2] = $_sroa_06_0_insert_insert$1; 172 | $51 = $aabb + 8 | 0; 173 | $_sroa_0_0_insert_insert$1 = (HEAPF32[tempDoublePtr >> 2] = $42 + ($20 > $32 ? $20 : $32), HEAP32[tempDoublePtr >> 2] | 0) | 0; 174 | HEAPF32[$51 >> 2] = $42 + ($14 > $28 ? $14 : $28); 175 | HEAP32[$51 + 4 >> 2] = $_sroa_0_0_insert_insert$1; 176 | return; 177 | } 178 | 179 | function _main($argc, $argv) { 180 | $argc = $argc | 0; 181 | $argv = $argv | 0; 182 | var $def_i21 = 0, $def_i = 0, $world = 0, $bd = 0, $shape = 0, $shape1 = 0, $bd2 = 0, $result = 0, $6 = 0, $WARMUP_0 = 0, $14 = 0, $15 = 0, $17 = 0, $i_09_i_i = 0, $j_08_i_i = 0, $34 = 0, $j_1_i_i = 0, $38 = 0, $46 = 0, $48 = 0, $50 = 0, $54 = 0, $i_05_i_i_i = 0, $56 = 0, $62 = 0, $_lcssa_i_i_i = 0, $87 = 0, $96 = 0, $97 = 0, $98 = 0, $112 = 0, $115 = 0, $116 = 0, $118 = 0, $121 = 0, $126 = 0, $135 = 0, $137 = 0, $174 = 0, $176 = 0, $177 = 0, $178 = 0, $179 = 0, $180 = 0, $181 = 0, $182 = 0, $183 = 0, $185 = 0, $186 = 0, $188 = 0, $189 = 0, $190 = 0, $191 = 0, $192 = 0, $193 = 0, $194 = 0, $195 = 0, $196 = 0, $i_057 = 0, $x_sroa_0_0_load303656 = +0, $x_sroa_1_4_load313755 = +0, $j_052 = 0, $y_sroa_0_0_load283451 = +0, $y_sroa_1_4_load293550 = +0, $y_sroa_0_0_insert_insert$1 = 0, $205 = 0, $208 = 0, $209 = 0, $213 = 0, $223 = 0, $236 = 0, $i3_042 = 0, $241 = 0, $242 = 0, $243 = 0, $i4_038 = 0, $245 = 0, $260 = +0, $_0 = 0, label = 0, __stackBase__ = 0; 183 | __stackBase__ = STACKTOP; 184 | STACKTOP = STACKTOP + 103416 | 0; 185 | $def_i21 = __stackBase__ | 0; 186 | $def_i = __stackBase__ + 32 | 0; 187 | $world = __stackBase__ + 64 | 0; 188 | $bd = __stackBase__ + 103096 | 0; 189 | $shape = __stackBase__ + 103152 | 0; 190 | $shape1 = __stackBase__ + 103200 | 0; 191 | $bd2 = __stackBase__ + 103352 | 0; 192 | $result = __stackBase__ + 103408 | 0; 193 | do { 194 | if (($argc | 0) > 1) { 195 | $6 = (HEAP8[HEAP32[($argv + 4 | 0) >> 2] | 0] | 0) << 24 >> 24; 196 | if (($6 | 0 | 0) == (49 | 0)) { 197 | HEAP32[9656 >> 2] = 35; 198 | $WARMUP_0 = 5; 199 | break; 200 | } else if (($6 | 0 | 0) == (50 | 0)) { 201 | HEAP32[9656 >> 2] = 161; 202 | $WARMUP_0 = 32; 203 | break; 204 | } else if (($6 | 0 | 0) == (51 | 0)) { 205 | label = 43; 206 | break; 207 | } else if (($6 | 0 | 0) == (52 | 0)) { 208 | HEAP32[9656 >> 2] = 2331; 209 | $WARMUP_0 = 320; 210 | break; 211 | } else if (($6 | 0 | 0) == (53 | 0)) { 212 | HEAP32[9656 >> 2] = 5661; 213 | $WARMUP_0 = 640; 214 | break; 215 | } else if (($6 | 0 | 0) == (48 | 0)) { 216 | $_0 = 0; 217 | STACKTOP = __stackBase__; 218 | return $_0 | 0; 219 | } else { 220 | _printf(3512 | 0 | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[tempInt >> 2] = $6 - 48 | 0, tempInt) | 0) | 0; 221 | $_0 = -1; 222 | STACKTOP = __stackBase__; 223 | return $_0 | 0; 224 | } 225 | } else { 226 | label = 43; 227 | } 228 | } while (0); 229 | if ((label | 0) == 43) { 230 | HEAP32[9656 >> 2] = 333; 231 | $WARMUP_0 = 64; 232 | } 233 | $14 = $world | 0; 234 | $15 = $world + 8 | 0; 235 | HEAP32[$15 >> 2] = 128; 236 | HEAP32[($world + 4 | 0) >> 2] = 0; 237 | $17 = _malloc(1024) | 0; 238 | HEAP32[($world | 0) >> 2] = $17; 239 | _memset($17 | 0 | 0, 0 | 0 | 0, (HEAP32[$15 >> 2] | 0) << 3 | 0 | 0); 240 | _memset($world + 12 | 0 | 0 | 0, 0 | 0 | 0, 56 | 0 | 0); 241 | $j_08_i_i = 0; 242 | $i_09_i_i = 1; 243 | while (1) { 244 | if (!(($j_08_i_i | 0) < 14)) { 245 | label = 49; 246 | break; 247 | } 248 | if (($i_09_i_i | 0) > (HEAP32[(9600 + ($j_08_i_i << 2) | 0) >> 2] | 0 | 0)) { 249 | $34 = $j_08_i_i + 1 | 0; 250 | HEAP8[$i_09_i_i + 8952 | 0] = $34 & 255; 251 | $j_1_i_i = $34; 252 | } else { 253 | HEAP8[$i_09_i_i + 8952 | 0] = $j_08_i_i & 255; 254 | $j_1_i_i = $j_08_i_i; 255 | } 256 | $38 = $i_09_i_i + 1 | 0; 257 | if (($38 | 0) < 641) { 258 | $j_08_i_i = $j_1_i_i; 259 | $i_09_i_i = $38; 260 | } else { 261 | break; 262 | } 263 | } 264 | if ((label | 0) == 49) { 265 | ___assert_func(3248 | 0 | 0, 73 | 0, 6448 | 0 | 0, 3360 | 0 | 0); 266 | return 0 | 0; 267 | } 268 | HEAP32[($world + 102468 | 0) >> 2] = 0; 269 | HEAP32[($world + 102472 | 0) >> 2] = 0; 270 | HEAP32[($world + 102476 | 0) >> 2] = 0; 271 | HEAP32[($world + 102864 | 0) >> 2] = 0; 272 | HEAP32[($world + 102872 | 0) >> 2] = -1; 273 | $46 = $world + 102884 | 0; 274 | HEAP32[$46 >> 2] = 16; 275 | HEAP32[($world + 102880 | 0) >> 2] = 0; 276 | $48 = _malloc(576) | 0; 277 | $50 = $world + 102876 | 0; 278 | HEAP32[$50 >> 2] = $48; 279 | _memset($48 | 0 | 0, 0 | 0 | 0, (HEAP32[$46 >> 2] | 0) * 36 & -1 | 0 | 0); 280 | $54 = (HEAP32[$46 >> 2] | 0) - 1 | 0; 281 | if (($54 | 0) > 0) { 282 | $i_05_i_i_i = 0; 283 | while (1) { 284 | $56 = $i_05_i_i_i + 1 | 0; 285 | HEAP32[((HEAP32[$50 >> 2] | 0) + ($i_05_i_i_i * 36 & -1) + 20 | 0) >> 2] = $56; 286 | HEAP32[((HEAP32[$50 >> 2] | 0) + ($i_05_i_i_i * 36 & -1) + 32 | 0) >> 2] = -1; 287 | $62 = (HEAP32[$46 >> 2] | 0) - 1 | 0; 288 | if (($56 | 0) < ($62 | 0)) { 289 | $i_05_i_i_i = $56; 290 | } else { 291 | $_lcssa_i_i_i = $62; 292 | break; 293 | } 294 | } 295 | } else { 296 | $_lcssa_i_i_i = $54; 297 | } 298 | HEAP32[((HEAP32[$50 >> 2] | 0) + ($_lcssa_i_i_i * 36 & -1) + 20 | 0) >> 2] = -1; 299 | HEAP32[((HEAP32[$50 >> 2] | 0) + (((HEAP32[$46 >> 2] | 0) - 1 | 0) * 36 & -1) + 32 | 0) >> 2] = -1; 300 | _memset($world + 102888 | 0 | 0 | 0, 0 | 0 | 0, 16 | 0 | 0); 301 | HEAP32[($world + 102920 | 0) >> 2] = 16; 302 | HEAP32[($world + 102924 | 0) >> 2] = 0; 303 | HEAP32[($world + 102916 | 0) >> 2] = _malloc(192) | 0; 304 | HEAP32[($world + 102908 | 0) >> 2] = 16; 305 | HEAP32[($world + 102912 | 0) >> 2] = 0; 306 | HEAP32[($world + 102904 | 0) >> 2] = _malloc(64) | 0; 307 | HEAP32[($world + 102932 | 0) >> 2] = 0; 308 | HEAP32[($world + 102936 | 0) >> 2] = 0; 309 | HEAP32[($world + 102940 | 0) >> 2] = 104; 310 | HEAP32[($world + 102944 | 0) >> 2] = 96; 311 | $87 = $world + 102948 | 0; 312 | HEAP32[($world + 102980 | 0) >> 2] = 0; 313 | HEAP32[($world + 102984 | 0) >> 2] = 0; 314 | _memset($87 | 0 | 0, 0 | 0 | 0, 20 | 0 | 0); 315 | HEAP8[$world + 102992 | 0] = 1; 316 | HEAP8[$world + 102993 | 0] = 1; 317 | HEAP8[$world + 102994 | 0] = 0; 318 | HEAP8[$world + 102995 | 0] = 1; 319 | $96 = $world + 102976 | 0; 320 | HEAP8[$96] = 1; 321 | $97 = $world + 102968 | 0; 322 | HEAP32[($97 | 0) >> 2] = 0; 323 | HEAP32[($97 + 4 | 0) >> 2] = -1054867456; 324 | $98 = $world + 102868 | 0; 325 | HEAP32[$98 >> 2] = 4; 326 | HEAPF32[($world + 102988 | 0) >> 2] = +0; 327 | HEAP32[$87 >> 2] = $14; 328 | _memset($world + 102996 | 0 | 0 | 0, 0 | 0 | 0, 32 | 0 | 0); 329 | HEAP8[$96] = 0; 330 | HEAP32[($bd + 44 | 0) >> 2] = 0; 331 | _memset($bd + 4 | 0 | 0 | 0, 0 | 0 | 0, 32 | 0 | 0); 332 | HEAP8[$bd + 36 | 0] = 1; 333 | HEAP8[$bd + 37 | 0] = 1; 334 | HEAP8[$bd + 38 | 0] = 0; 335 | HEAP8[$bd + 39 | 0] = 0; 336 | HEAP32[($bd | 0) >> 2] = 0; 337 | HEAP8[$bd + 40 | 0] = 1; 338 | HEAPF32[($bd + 48 | 0) >> 2] = +1; 339 | $112 = __ZN16b2BlockAllocator8AllocateEi($14, 152) | 0; 340 | if (($112 | 0) == 0) { 341 | $116 = 0; 342 | } else { 343 | $115 = $112; 344 | __ZN6b2BodyC2EPK9b2BodyDefP7b2World($115, $bd, $world); 345 | $116 = $115; 346 | } 347 | HEAP32[($116 + 92 | 0) >> 2] = 0; 348 | $118 = $world + 102952 | 0; 349 | HEAP32[($116 + 96 | 0) >> 2] = HEAP32[$118 >> 2] | 0; 350 | $121 = HEAP32[$118 >> 2] | 0; 351 | if (!(($121 | 0) == 0)) { 352 | HEAP32[($121 + 92 | 0) >> 2] = $116; 353 | } 354 | HEAP32[$118 >> 2] = $116; 355 | $126 = $world + 102960 | 0; 356 | HEAP32[$126 >> 2] = (HEAP32[$126 >> 2] | 0) + 1 | 0; 357 | HEAP32[($shape | 0) >> 2] = 8016 | 0; 358 | HEAP32[($shape + 4 | 0) >> 2] = 1; 359 | HEAPF32[($shape + 8 | 0) >> 2] = +.009999999776482582; 360 | _memset($shape + 28 | 0 | 0 | 0, 0 | 0 | 0, 18 | 0 | 0); 361 | $135 = $shape + 12 | 0; 362 | HEAP32[($135 | 0) >> 2] = -1038090240; 363 | HEAP32[($135 + 4 | 0) >> 2] = 0; 364 | $137 = $shape + 20 | 0; 365 | HEAP32[($137 | 0) >> 2] = 1109393408; 366 | HEAP32[($137 + 4 | 0) >> 2] = 0; 367 | HEAP8[$shape + 44 | 0] = 0; 368 | HEAP8[$shape + 45 | 0] = 0; 369 | HEAP16[($def_i + 22 | 0) >> 1] = 1; 370 | HEAP16[($def_i + 24 | 0) >> 1] = -1; 371 | HEAP16[($def_i + 26 | 0) >> 1] = 0; 372 | HEAP32[($def_i + 4 | 0) >> 2] = 0; 373 | HEAPF32[($def_i + 8 | 0) >> 2] = +.20000000298023224; 374 | HEAPF32[($def_i + 12 | 0) >> 2] = +0; 375 | HEAP8[$def_i + 20 | 0] = 0; 376 | HEAP32[($def_i | 0) >> 2] = $shape | 0; 377 | HEAPF32[($def_i + 16 | 0) >> 2] = +0; 378 | __ZN6b2Body13CreateFixtureEPK12b2FixtureDef($116, $def_i); 379 | HEAP32[($shape1 | 0) >> 2] = 7968 | 0; 380 | HEAP32[($shape1 + 4 | 0) >> 2] = 2; 381 | HEAPF32[($shape1 + 8 | 0) >> 2] = +.009999999776482582; 382 | HEAP32[($shape1 + 148 | 0) >> 2] = 4; 383 | HEAPF32[($shape1 + 20 | 0) >> 2] = +-.5; 384 | HEAPF32[($shape1 + 24 | 0) >> 2] = +-.5; 385 | HEAPF32[($shape1 + 28 | 0) >> 2] = +.5; 386 | HEAPF32[($shape1 + 32 | 0) >> 2] = +-.5; 387 | HEAPF32[($shape1 + 36 | 0) >> 2] = +.5; 388 | HEAPF32[($shape1 + 40 | 0) >> 2] = +.5; 389 | HEAPF32[($shape1 + 44 | 0) >> 2] = +-.5; 390 | HEAPF32[($shape1 + 48 | 0) >> 2] = +.5; 391 | HEAPF32[($shape1 + 84 | 0) >> 2] = +0; 392 | HEAPF32[($shape1 + 88 | 0) >> 2] = +-1; 393 | HEAPF32[($shape1 + 92 | 0) >> 2] = +1; 394 | HEAPF32[($shape1 + 96 | 0) >> 2] = +0; 395 | HEAPF32[($shape1 + 100 | 0) >> 2] = +0; 396 | HEAPF32[($shape1 + 104 | 0) >> 2] = +1; 397 | HEAPF32[($shape1 + 108 | 0) >> 2] = +-1; 398 | HEAPF32[($shape1 + 112 | 0) >> 2] = +0; 399 | HEAPF32[($shape1 + 12 | 0) >> 2] = +0; 400 | HEAPF32[($shape1 + 16 | 0) >> 2] = +0; 401 | $174 = $bd2 + 44 | 0; 402 | $176 = $bd2 + 36 | 0; 403 | $177 = $bd2 + 4 | 0; 404 | $178 = $bd2 + 37 | 0; 405 | $179 = $bd2 + 38 | 0; 406 | $180 = $bd2 + 39 | 0; 407 | $181 = $bd2 | 0; 408 | $182 = $bd2 + 40 | 0; 409 | $183 = $bd2 + 48 | 0; 410 | $185 = $bd2 + 4 | 0; 411 | $186 = $shape1 | 0; 412 | $188 = $def_i21 + 22 | 0; 413 | $189 = $def_i21 + 24 | 0; 414 | $190 = $def_i21 + 26 | 0; 415 | $191 = $def_i21 | 0; 416 | $192 = $def_i21 + 4 | 0; 417 | $193 = $def_i21 + 8 | 0; 418 | $194 = $def_i21 + 12 | 0; 419 | $195 = $def_i21 + 16 | 0; 420 | $196 = $def_i21 + 20 | 0; 421 | $x_sroa_1_4_load313755 = +.75; 422 | $x_sroa_0_0_load303656 = +-7; 423 | $i_057 = 0; 424 | L82 : while (1) { 425 | $y_sroa_1_4_load293550 = $x_sroa_1_4_load313755; 426 | $y_sroa_0_0_load283451 = $x_sroa_0_0_load303656; 427 | $j_052 = $i_057; 428 | while (1) { 429 | HEAP32[$174 >> 2] = 0; 430 | _memset($177 | 0 | 0, 0 | 0 | 0, 32 | 0 | 0); 431 | HEAP8[$176] = 1; 432 | HEAP8[$178] = 1; 433 | HEAP8[$179] = 0; 434 | HEAP8[$180] = 0; 435 | HEAP8[$182] = 1; 436 | HEAPF32[$183 >> 2] = +1; 437 | HEAP32[$181 >> 2] = 2; 438 | $y_sroa_0_0_insert_insert$1 = (HEAPF32[tempDoublePtr >> 2] = $y_sroa_1_4_load293550, HEAP32[tempDoublePtr >> 2] | 0) | 0; 439 | HEAP32[($185 | 0) >> 2] = 0 | (HEAPF32[tempDoublePtr >> 2] = $y_sroa_0_0_load283451, HEAP32[tempDoublePtr >> 2] | 0); 440 | HEAP32[($185 + 4 | 0) >> 2] = $y_sroa_0_0_insert_insert$1; 441 | if (!(((HEAP32[$98 >> 2] | 0) & 2 | 0) == 0)) { 442 | label = 65; 443 | break L82; 444 | } 445 | $205 = __ZN16b2BlockAllocator8AllocateEi($14, 152) | 0; 446 | if (($205 | 0) == 0) { 447 | $209 = 0; 448 | } else { 449 | $208 = $205; 450 | __ZN6b2BodyC2EPK9b2BodyDefP7b2World($208, $bd2, $world); 451 | $209 = $208; 452 | } 453 | HEAP32[($209 + 92 | 0) >> 2] = 0; 454 | HEAP32[($209 + 96 | 0) >> 2] = HEAP32[$118 >> 2] | 0; 455 | $213 = HEAP32[$118 >> 2] | 0; 456 | if (!(($213 | 0) == 0)) { 457 | HEAP32[($213 + 92 | 0) >> 2] = $209; 458 | } 459 | HEAP32[$118 >> 2] = $209; 460 | HEAP32[$126 >> 2] = (HEAP32[$126 >> 2] | 0) + 1 | 0; 461 | HEAP16[$188 >> 1] = 1; 462 | HEAP16[$189 >> 1] = -1; 463 | HEAP16[$190 >> 1] = 0; 464 | HEAP32[$192 >> 2] = 0; 465 | HEAPF32[$193 >> 2] = +.20000000298023224; 466 | HEAPF32[$194 >> 2] = +0; 467 | HEAP8[$196] = 0; 468 | HEAP32[$191 >> 2] = $186; 469 | HEAPF32[$195 >> 2] = +5; 470 | __ZN6b2Body13CreateFixtureEPK12b2FixtureDef($209, $def_i21); 471 | $223 = $j_052 + 1 | 0; 472 | if (($223 | 0) < 40) { 473 | $y_sroa_1_4_load293550 = $y_sroa_1_4_load293550 + +0; 474 | $y_sroa_0_0_load283451 = $y_sroa_0_0_load283451 + 1.125; 475 | $j_052 = $223; 476 | } else { 477 | break; 478 | } 479 | } 480 | $236 = $i_057 + 1 | 0; 481 | if (($236 | 0) < 40) { 482 | $x_sroa_1_4_load313755 = $x_sroa_1_4_load313755 + +1; 483 | $x_sroa_0_0_load303656 = $x_sroa_0_0_load303656 + +.5625; 484 | $i_057 = $236; 485 | } else { 486 | $i3_042 = 0; 487 | break; 488 | } 489 | } 490 | if ((label | 0) == 65) { 491 | ___assert_func(112 | 0 | 0, 109 | 0, 5328 | 0 | 0, 2520 | 0 | 0); 492 | return 0 | 0; 493 | } 494 | while (1) { 495 | __ZN7b2World4StepEfii($world); 496 | $i3_042 = $i3_042 + 1 | 0; 497 | if (($i3_042 | 0) >= ($WARMUP_0 | 0)) { 498 | break; 499 | } 500 | } 501 | $241 = HEAP32[9656 >> 2] | 0; 502 | $242 = _llvm_stacksave() | 0; 503 | $243 = STACKTOP; 504 | STACKTOP = STACKTOP + ($241 * 4 & -1) | 0; 505 | STACKTOP = STACKTOP + 7 >> 3 << 3; 506 | if (($241 | 0) > 0) { 507 | $i4_038 = 0; 508 | while (1) { 509 | $245 = _clock() | 0; 510 | __ZN7b2World4StepEfii($world); 511 | HEAP32[($243 + ($i4_038 << 2) | 0) >> 2] = (_clock() | 0) - $245 | 0; 512 | $i4_038 = $i4_038 + 1 | 0; 513 | if (($i4_038 | 0) >= (HEAP32[9656 >> 2] | 0 | 0)) { 514 | break; 515 | } 516 | } 517 | } 518 | __Z7measurePm($result, $243); 519 | $260 = +HEAPF32[($result + 4 | 0) >> 2]; 520 | _printf(3480 | 0 | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[tempInt >> 3] = +HEAPF32[($result | 0) >> 2], HEAPF64[tempInt + 8 >> 3] = $260, tempInt) | 0) | 0; 521 | _llvm_stackrestore($242 | 0); 522 | __ZN7b2WorldD2Ev($world); 523 | $_0 = 0; 524 | STACKTOP = __stackBase__; 525 | return $_0 | 0; 526 | } 527 | 528 | function badf() { 529 | var $9 = Math_fround(0); 530 | $9 = (HEAP32[tempDoublePtr >> 2] = $8, Math_fround(HEAPF32[tempDoublePtr >> 2])); 531 | HEAPF32[$gep23_asptr >> 2] = $9; 532 | } 533 | 534 | function badf2() { 535 | var $9 = 0; 536 | $9 = (HEAPF32[tempDoublePtr >> 2] = $8, HEAP32[tempDoublePtr >> 2] | 0); 537 | HEAP32[$gep23_asptr >> 2] = $9; 538 | } 539 | 540 | function fcomp() { 541 | if (!($y < $x)) return 5; 542 | if (!(5 < $x)) return 5; 543 | if (!($y < 5)) return 5; 544 | if (!(($a | 0) < ($b | 0))) return 5; 545 | if (!(($a | 0) < 5)) return 5; 546 | if (!(5 < ($b | 0))) return 5; 547 | if (!(5 < 5)) return 5; 548 | } 549 | 550 | function conditionalizeMe() { 551 | if (x > 1 & x + y + z + w > 12) { 552 | b(); 553 | } 554 | if (a() > 1 & x + y + z + w > 12) { 555 | b(); 556 | } 557 | if (x > 1 & x + y + z + k() > 12) { 558 | b(); 559 | } 560 | if (a() > 1 & x + y + z + k() > 12) { 561 | b(); 562 | } 563 | if (x > 1 | x + y + z + w > 12) { 564 | b(); 565 | } 566 | if (a() > 1 | x + y + z + w > 12) { 567 | b(); 568 | } 569 | if (x > 1 | x + y + z + k() > 12) { 570 | b(); 571 | } 572 | if (a() > 1 | x + y + z + k() > 12) { 573 | b(); 574 | } 575 | if (x + y + z + w > 12 | x > 1) { 576 | b(); 577 | } 578 | if (x + y + z + w > 12 | a() > 1) { 579 | b(); 580 | } 581 | if (x + y + z + k() > 12 | x > 1) { 582 | b(); 583 | } 584 | if (x + y + z + k() > 12 | a() > 1) { 585 | b(); 586 | } 587 | while (x > 1 & x + y + z + w > 12) { 588 | b(); 589 | } 590 | while (a() > 1 & x + y + z + w > 12) { 591 | b(); 592 | } 593 | while (x > 1 & x + y + z + k() > 12) { 594 | b(); 595 | } 596 | while (a() > 1 & x + y + z + k() > 12) { 597 | b(); 598 | } 599 | if (!($sub$i480 >= Math_fround(+0)) | !($sub4$i483 >= Math_fround(+0))) { 600 | b(); 601 | } 602 | if (!($sub$i480 >= Math_fround(+0)) | !($sub4$i483 >= Math_fround(HEAPF32[x + y | 0]))) { 603 | b(); 604 | } 605 | if (x > 10 | HEAP[20] + 2 > 5) { 606 | b(); 607 | } 608 | print(((HEAP8[a] + HEAP8[b] + HEAP8[c] + HEAP8[d] + HEAP8[e] + HEAP8[f] | 0) > a % b % c % d ? 1 : $el) | $cheap > 0); 609 | print(((HEAP8[a] + HEAP8[b] + HEAP8[c] + HEAP8[d] + HEAP8[e] + HEAP8[f] | 0) > a % b % c % d ? 1 : -1) | $cheap > 0); 610 | print(((HEAP8[a] + HEAP8[b] + HEAP8[c] + HEAP8[d] + HEAP8[e] + HEAP8[f] | 0) > a % b % c % d ? 1 : 0) | $cheap > 0); 611 | print(((HEAP8[a] + HEAP8[b] + HEAP8[c] + HEAP8[d] + HEAP8[e] + HEAP8[f] | 0) > a % b % c % d ? -1 : 1) | $cheap > 0); 612 | return ((((Math_imul(i6 + 1, i7) | 0) + 17 | 0) % 5 | 0 | 0) == 0 | ((((Math_imul(i7 + 1, i7) | 0) + 11 | 0) >>> 0) % 3 | 0 | 0) == 0 | 0) == 0; 613 | } 614 | 615 | function bignum() { 616 | HEAP32[20] = 2779096485 | 0; 617 | if (!(($2814 | 0) >= 0)) return; 618 | } 619 | 620 | -------------------------------------------------------------------------------- /src/cashew/samples/9.js: -------------------------------------------------------------------------------- 1 | function asm(x, y) { 2 | x = +x; 3 | y = y | 0; 4 | var int1 = 0, int2 = 0; // do not mix the types! 5 | var double1 = +0, double2 = +0; 6 | int1 = (x+x)|0; 7 | double1 = d(Math_max(10, Math_min(5, f()))); 8 | int2 = (int1+2)|0; 9 | print(int2); 10 | double2 = double1*5; 11 | return double2; 12 | } 13 | function _doit($x, $y$0, $y$1) { 14 | $x = $x | 0; 15 | $y$0 = $y$0 | 0; 16 | $y$1 = $y$1 | 0; 17 | var __stackBase__ = 0; 18 | __stackBase__ = STACKTOP; 19 | _printf(__str | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[(tempInt & 16777215) >> 2] = $y$0, HEAP32[(tempInt + 4 & 16777215) >> 2] = $y$1, tempInt)); 20 | STACKTOP = __stackBase__; 21 | return 0 | 0; 22 | } 23 | function stackRestore(top) { 24 | top = top|0; 25 | STACKTOP = top; 26 | } 27 | function switchey(x, y) { 28 | x = +x; 29 | y = y | 0; 30 | var int1 = 0, int2 = 0; // do not mix the types! 31 | var double1 = +0, double2 = +0; 32 | switch(x|0) { 33 | case 0: 34 | int1 = (x+x)|0; 35 | double1 = d(Math_max(10, Math_min(5, f()))); 36 | int2 = (int1+2)|0; 37 | print(int2); 38 | double2 = double1*5; 39 | return double2; 40 | case -10: { 41 | x = +20; 42 | return x; 43 | } 44 | case 1: 45 | return 20; 46 | } 47 | } 48 | function switchey2() { 49 | var $rng2 = 0, $count_06 = 0, $i_05 = 0, $2 = +0, $3 = +0, $count_1 = 0, $9 = 0, label = 0, __stackBase__ = 0; 50 | __stackBase__ = STACKTOP; 51 | STACKTOP = STACKTOP + 8 | 0; 52 | label = 1; 53 | while (1) switch (label | 0) { 54 | case 1: 55 | $rng2 = __stackBase__ | 0; 56 | __ZN6RandomC1Ev($rng2); 57 | $i_05 = 0; 58 | $count_06 = 0; 59 | label = 2; 60 | break; 61 | case 2: 62 | $2 = +__ZN6Random3getEf(8, +1); 63 | $3 = +__ZN6Random3getEf($rng2, +1); 64 | _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = $2, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = $3, tempInt) | 0); 65 | $count_1 = ($2 != $3 & 1) + $count_06 | 0; 66 | $9 = $i_05 + 1 | 0; 67 | if (($9 | 0) < 100) { 68 | $i_05 = $9; 69 | $count_06 = $count_1; 70 | label = 2; 71 | break; 72 | } else { 73 | label = 3; 74 | break; 75 | } 76 | case 3: 77 | _printf(16, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[CHECK_ALIGN_4(tempInt | 0) >> 2] = $count_1, tempInt) | 0); 78 | STACKTOP = __stackBase__; 79 | return 0; 80 | } 81 | return 0; 82 | } 83 | function iffey() { 84 | var $rng2 = 0, $count_06 = 0, $i_05 = 0, $2 = +0, $3 = +0, $count_1 = 0, $9 = 0, label = 0, __stackBase__ = 0; 85 | __stackBase__ = STACKTOP; 86 | STACKTOP = STACKTOP + 8 | 0; 87 | label = 1; 88 | while (1) { 89 | if (label | 0) { 90 | $rng2 = __stackBase__ | 0; 91 | __ZN6RandomC1Ev($rng2); 92 | $i_05 = 0; 93 | $count_06 = 0; 94 | label = 2; 95 | } else { 96 | $2 = +__ZN6Random3getEf(8, +1); 97 | $3 = +__ZN6Random3getEf($rng2, +1); 98 | _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = $2, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = $3, tempInt) | 0); 99 | $count_1 = ($2 != $3 & 1) + $count_06 | 0; 100 | $9 = $i_05 + 1 | 0; 101 | if (($9 | 0) < 100) { 102 | $i_05 = $9; 103 | $count_06 = $count_1; 104 | label = 2; 105 | } else { 106 | label = 3; 107 | return 10; 108 | } 109 | } 110 | } 111 | return 0; 112 | } 113 | function nops() { 114 | var x = 0; 115 | x | 0; 116 | ~x; 117 | f(x); 118 | } 119 | 120 | -------------------------------------------------------------------------------- /src/cashew/samples/9.js.1_0.js: -------------------------------------------------------------------------------- 1 | function asm(x, y) { 2 | x = +x; 3 | y = y | 0; 4 | var int1 = 0, int2 = 0; 5 | var double1 = +0, double2 = +0; 6 | int1 = x + x | 0; 7 | double1 = d(Math_max(10, Math_min(5, f()))); 8 | int2 = int1 + 2 | 0; 9 | print(int2); 10 | double2 = double1 * 5; 11 | return double2; 12 | } 13 | 14 | function _doit($x, $y$0, $y$1) { 15 | $x = $x | 0; 16 | $y$0 = $y$0 | 0; 17 | $y$1 = $y$1 | 0; 18 | var __stackBase__ = 0; 19 | __stackBase__ = STACKTOP; 20 | _printf(__str | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[(tempInt & 16777215) >> 2] = $y$0, HEAP32[(tempInt + 4 & 16777215) >> 2] = $y$1, tempInt)); 21 | STACKTOP = __stackBase__; 22 | return 0 | 0; 23 | } 24 | 25 | function stackRestore(top) { 26 | top = top | 0; 27 | STACKTOP = top; 28 | } 29 | 30 | function switchey(x, y) { 31 | x = +x; 32 | y = y | 0; 33 | var int1 = 0, int2 = 0; 34 | var double1 = +0, double2 = +0; 35 | switch (x | 0) { 36 | case 0: 37 | int1 = x + x | 0; 38 | double1 = d(Math_max(10, Math_min(5, f()))); 39 | int2 = int1 + 2 | 0; 40 | print(int2); 41 | double2 = double1 * 5; 42 | return double2; 43 | case -10: 44 | { 45 | x = +20; 46 | return x; 47 | } 48 | case 1: 49 | return 20; 50 | } 51 | } 52 | 53 | function switchey2() { 54 | var $rng2 = 0, $count_06 = 0, $i_05 = 0, $2 = +0, $3 = +0, $count_1 = 0, $9 = 0, label = 0, __stackBase__ = 0; 55 | __stackBase__ = STACKTOP; 56 | STACKTOP = STACKTOP + 8 | 0; 57 | label = 1; 58 | while (1) switch (label | 0) { 59 | case 1: 60 | $rng2 = __stackBase__ | 0; 61 | __ZN6RandomC1Ev($rng2); 62 | $i_05 = 0; 63 | $count_06 = 0; 64 | label = 2; 65 | break; 66 | case 2: 67 | $2 = +__ZN6Random3getEf(8, +1); 68 | $3 = +__ZN6Random3getEf($rng2, +1); 69 | _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = $2, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = $3, tempInt) | 0); 70 | $count_1 = ($2 != $3 & 1) + $count_06 | 0; 71 | $9 = $i_05 + 1 | 0; 72 | if (($9 | 0) < 100) { 73 | $i_05 = $9; 74 | $count_06 = $count_1; 75 | label = 2; 76 | break; 77 | } else { 78 | label = 3; 79 | break; 80 | } 81 | case 3: 82 | _printf(16, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[CHECK_ALIGN_4(tempInt | 0) >> 2] = $count_1, tempInt) | 0); 83 | STACKTOP = __stackBase__; 84 | return 0; 85 | } 86 | return 0; 87 | } 88 | 89 | function iffey() { 90 | var $rng2 = 0, $count_06 = 0, $i_05 = 0, $2 = +0, $3 = +0, $count_1 = 0, $9 = 0, label = 0, __stackBase__ = 0; 91 | __stackBase__ = STACKTOP; 92 | STACKTOP = STACKTOP + 8 | 0; 93 | label = 1; 94 | while (1) { 95 | if (label | 0) { 96 | $rng2 = __stackBase__ | 0; 97 | __ZN6RandomC1Ev($rng2); 98 | $i_05 = 0; 99 | $count_06 = 0; 100 | label = 2; 101 | } else { 102 | $2 = +__ZN6Random3getEf(8, +1); 103 | $3 = +__ZN6Random3getEf($rng2, +1); 104 | _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = $2, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = $3, tempInt) | 0); 105 | $count_1 = ($2 != $3 & 1) + $count_06 | 0; 106 | $9 = $i_05 + 1 | 0; 107 | if (($9 | 0) < 100) { 108 | $i_05 = $9; 109 | $count_06 = $count_1; 110 | label = 2; 111 | } else { 112 | label = 3; 113 | return 10; 114 | } 115 | } 116 | } 117 | return 0; 118 | } 119 | 120 | function nops() { 121 | var x = 0; 122 | x | 0; 123 | ~x; 124 | f(x); 125 | } 126 | 127 | -------------------------------------------------------------------------------- /src/cashew/simple_ast.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "simple_ast.h" 3 | 4 | // Ref methods 5 | 6 | Ref& Ref::operator[](unsigned x) { 7 | return (*get())[x]; 8 | } 9 | 10 | Ref& Ref::operator[](IString x) { 11 | return (*get())[x]; 12 | } 13 | 14 | bool Ref::operator==(const char *str) { 15 | return get()->isString() && !strcmp(get()->str.str, str); 16 | } 17 | 18 | bool Ref::operator!=(const char *str) { 19 | return get()->isString() ? !!strcmp(get()->str.str, str) : true; 20 | } 21 | 22 | bool Ref::operator==(const IString &str) { 23 | return get()->isString() && get()->str == str; 24 | } 25 | 26 | bool Ref::operator!=(const IString &str) { 27 | return get()->isString() && get()->str != str; 28 | } 29 | 30 | bool Ref::operator==(Ref other) { 31 | return **this == *other; 32 | } 33 | 34 | bool Ref::operator!() { 35 | return !get() || get()->isNull(); 36 | } 37 | 38 | // Arena 39 | 40 | Arena arena; 41 | 42 | Ref Arena::alloc() { 43 | if (chunks.size() == 0 || index == CHUNK_SIZE) { 44 | chunks.push_back(new Value[CHUNK_SIZE]); 45 | index = 0; 46 | } 47 | return &chunks.back()[index++]; 48 | } 49 | 50 | // dump 51 | 52 | void dump(const char *str, Ref node, bool pretty) { 53 | std::cerr << str << ": "; 54 | if (!!node) node->stringify(std::cerr, pretty); 55 | else std::cerr << "(nullptr)"; 56 | std::cerr << std::endl; 57 | } 58 | 59 | // AST traversals 60 | 61 | // Traversals 62 | 63 | struct TraverseInfo { 64 | TraverseInfo() {} 65 | TraverseInfo(Ref node) : node(node), index(0) {} 66 | Ref node; 67 | int index; 68 | }; 69 | 70 | template 71 | struct StackedStack { // a stack, on the stack 72 | T stackStorage[init]; 73 | T* storage; 74 | int used, available; // used amount, available amount 75 | bool alloced; 76 | 77 | StackedStack() : used(0), available(init), alloced(false) { 78 | storage = stackStorage; 79 | } 80 | ~StackedStack() { 81 | if (alloced) free(storage); 82 | } 83 | 84 | int size() { return used; } 85 | 86 | void push_back(const T& t) { 87 | assert(used <= available); 88 | if (used == available) { 89 | available *= 2; 90 | if (!alloced) { 91 | T* old = storage; 92 | storage = (T*)malloc(sizeof(T)*available); 93 | memcpy(storage, old, sizeof(T)*used); 94 | alloced = true; 95 | } else { 96 | T *newStorage = (T*)realloc(storage, sizeof(T)*available); 97 | assert(newStorage); 98 | storage = newStorage; 99 | } 100 | } 101 | assert(used < available); 102 | assert(storage); 103 | storage[used++] = t; 104 | } 105 | 106 | T& back() { 107 | assert(used > 0); 108 | return storage[used-1]; 109 | } 110 | 111 | void pop_back() { 112 | assert(used > 0); 113 | used--; 114 | } 115 | }; 116 | 117 | #define visitable(node) (node->isArray() && node->size() > 0) 118 | 119 | #define TRAV_STACK 40 120 | 121 | // Traverse, calling visit before the children 122 | void traversePre(Ref node, std::function visit) { 123 | if (!visitable(node)) return; 124 | visit(node); 125 | StackedStack stack; 126 | stack.push_back(TraverseInfo(node)); 127 | while (stack.size() > 0) { 128 | TraverseInfo& top = stack.back(); 129 | if (top.index < (int)top.node->size()) { 130 | Ref sub = top.node[top.index]; 131 | top.index++; 132 | if (visitable(sub)) { 133 | visit(sub); 134 | stack.push_back(TraverseInfo(sub)); 135 | } 136 | } else { 137 | stack.pop_back(); 138 | } 139 | } 140 | } 141 | 142 | // Traverse, calling visitPre before the children and visitPost after 143 | void traversePrePost(Ref node, std::function visitPre, std::function visitPost) { 144 | if (!visitable(node)) return; 145 | visitPre(node); 146 | StackedStack stack; 147 | stack.push_back(TraverseInfo(node)); 148 | while (stack.size() > 0) { 149 | TraverseInfo& top = stack.back(); 150 | if (top.index < (int)top.node->size()) { 151 | Ref sub = top.node[top.index]; 152 | top.index++; 153 | if (visitable(sub)) { 154 | visitPre(sub); 155 | stack.push_back(TraverseInfo(sub)); 156 | } 157 | } else { 158 | visitPost(top.node); 159 | stack.pop_back(); 160 | } 161 | } 162 | } 163 | 164 | // Traverse, calling visitPre before the children and visitPost after. If pre returns false, do not traverse children 165 | void traversePrePostConditional(Ref node, std::function visitPre, std::function visitPost) { 166 | if (!visitable(node)) return; 167 | if (!visitPre(node)) return; 168 | StackedStack stack; 169 | stack.push_back(TraverseInfo(node)); 170 | while (stack.size() > 0) { 171 | TraverseInfo& top = stack.back(); 172 | if (top.index < (int)top.node->size()) { 173 | Ref sub = top.node[top.index]; 174 | top.index++; 175 | if (visitable(sub)) { 176 | if (visitPre(sub)) { 177 | stack.push_back(TraverseInfo(sub)); 178 | } 179 | } 180 | } else { 181 | visitPost(top.node); 182 | stack.pop_back(); 183 | } 184 | } 185 | } 186 | 187 | // Traverses all the top-level functions in the document 188 | void traverseFunctions(Ref ast, std::function visit) { 189 | if (!ast || ast->size() == 0) return; 190 | if (ast[0] == TOPLEVEL) { 191 | Ref stats = ast[1]; 192 | for (size_t i = 0; i < stats->size(); i++) { 193 | Ref curr = stats[i]; 194 | if (curr[0] == DEFUN) visit(curr); 195 | } 196 | } else if (ast[0] == DEFUN) { 197 | visit(ast); 198 | } 199 | } 200 | 201 | // ValueBuilder 202 | 203 | IStringSet ValueBuilder::statable("assign call binary unary-prefix if name num conditional dot new sub seq string object array"); 204 | 205 | -------------------------------------------------------------------------------- /src/cashew/snprintf.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Visual Studio does not support C99, so emulate snprintf support for it manually. 4 | 5 | #ifdef _MSC_VER 6 | 7 | #define snprintf c99_snprintf 8 | 9 | inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap) 10 | { 11 | int count = -1; 12 | 13 | if (size != 0) 14 | count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); 15 | if (count == -1) 16 | count = _vscprintf(format, ap); 17 | 18 | return count; 19 | } 20 | 21 | inline int c99_snprintf(char* str, size_t size, const char* format, ...) 22 | { 23 | int count; 24 | va_list ap; 25 | 26 | va_start(ap, format); 27 | count = c99_vsnprintf(str, size, format, ap); 28 | va_end(ap); 29 | 30 | return count; 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /src/cashew/test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "simple_ast.h" 3 | 4 | int main(int argc, char **argv) { 5 | // Read input file 6 | FILE *f = fopen(argv[1], "r"); 7 | assert(f); 8 | fseek(f, 0, SEEK_END); 9 | int size = ftell(f); 10 | char *src = new char[size+1]; 11 | rewind(f); 12 | int num = fread(src, 1, size, f); 13 | assert(num == size); 14 | fclose(f); 15 | src[size] = 0; 16 | 17 | cashew::Parser builder; 18 | Ref ast = builder.parseToplevel(src); 19 | 20 | if (argc == 2) { 21 | ast->stringify(std::cout, true); 22 | std::cout << "\n"; 23 | } else { 24 | JSPrinter jser(argv[2][0] == '1', argv[3][0] == '1', ast); 25 | jser.printAst(); 26 | std::cout << jser.buffer << "\n"; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/cashew/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | # -*- Mode: python -*- 3 | 4 | import os, sys, difflib 5 | from subprocess import Popen, PIPE, STDOUT 6 | 7 | if not os.path.exists('a.out') or os.stat('a.out').st_mtime < os.stat('parser.h').st_mtime: 8 | print 'building' 9 | try: 10 | os.unlink('a.out') 11 | except: 12 | print '(no existing file)' 13 | proc = Popen(['sh', './build.sh'], stdout=PIPE) 14 | proc.communicate() 15 | assert proc.returncode == 0, 'failed to build' 16 | 17 | print 'testing' 18 | 19 | for i in os.listdir('samples'): 20 | if i.endswith('.js') and i.count('.') == 1: 21 | for extra in [[], ['1', '0']]: 22 | command = ['./a.out', os.path.join('samples', i)] + extra 23 | print ' '.join(command) 24 | out, err = Popen(command, stdout=PIPE).communicate() 25 | out = out.replace('\n\n', '\n') 26 | filename = os.path.join('samples', i + ('.' if extra else '') + '_'.join(extra) + ('.js' if extra else '.txt')) 27 | try: 28 | expected = open(filename).read() 29 | except: 30 | print 'no expected output for:\n', out, filename 31 | raise 32 | expected = expected.replace('\n\n', '\n') 33 | #print out 34 | #print '^v' 35 | #print expected 36 | assert out == expected, ''.join([a.rstrip()+'\n' for a in difflib.unified_diff(expected.split('\n'), out.split('\n'), fromfile='expected', tofile='actual')]) 37 | 38 | print 'ok.' 39 | 40 | -------------------------------------------------------------------------------- /src/load-wasm-worker.js: -------------------------------------------------------------------------------- 1 | 2 | // src/load-wasm-worker.js: this file is concatenated at the end of the 3 | // Emscripten-compiled unpack.cpp into jslib/load-wasm-worker.js. 4 | 5 | // This file implements a worker that responds to a single initial message 6 | // containing a url to fetch and unpack and the name of the global callback 7 | // function to pass the resulting asm.js module when the decoded script is 8 | // executed. The worker responds by sending a Blob containing the decoded utf8 9 | // chars. 10 | 11 | function mallocArrayCopy(src) { 12 | var L = src.byteLength; 13 | var dst = _malloc(L); 14 | HEAP8.set(new Uint8Array(src), dst); 15 | return dst; 16 | } 17 | 18 | function mallocStringCopy(src) { 19 | var L = src.length; 20 | var dst = _malloc(L + 1); 21 | for (var i = 0; i < L; i++) 22 | HEAP8[dst + i] = src.charCodeAt(i); 23 | HEAP8[dst + L] = 0; 24 | return dst; 25 | } 26 | 27 | function unpack(inBytes, callbackName) { 28 | var packedPtr = mallocArrayCopy(inBytes); 29 | if (!_asmjs_has_magic_number(packedPtr)) 30 | throw "File does not appear to be packed asm.js"; 31 | var callbackNamePtr = mallocStringCopy(callbackName); 32 | var unpackedSize = _asmjs_unpacked_size(packedPtr, callbackNamePtr); 33 | var unpackedPtr = _malloc(unpackedSize); 34 | _asmjs_unpack(packedPtr, callbackNamePtr, unpackedSize, unpackedPtr); 35 | return HEAP8.subarray(unpackedPtr, unpackedPtr + unpackedSize); 36 | } 37 | 38 | onmessage = function(e) { 39 | var url = e.data.url; 40 | var callbackName = e.data.callbackName; 41 | function doUnpack(data) { 42 | try { 43 | var bef = Date.now(); 44 | var utf8 = unpack(data, callbackName); 45 | var aft = Date.now(); 46 | if (ENVIRONMENT_IS_WEB) console.log("unpack of " + url + " took " + (aft - bef) + "ms"); 47 | postMessage({ callbackName: callbackName, data: new Blob([utf8]) }); 48 | } catch (e) { 49 | postMessage("failed to unpack " + url + ": " + e); 50 | } 51 | } 52 | if (typeof XMLHttpRequest !== 'undefined') { 53 | var xhr = new XMLHttpRequest(); 54 | xhr.open("GET", url, true); 55 | xhr.responseType = 'arraybuffer'; 56 | xhr.onerror = function (e) { 57 | postMessage('Loading ' + url + ' failed'); 58 | } 59 | xhr.onload = function (e) { 60 | if (xhr.status !== 200) { 61 | postMessage("failed to download " + url + " with status: " + xhr.statusText); 62 | } else { 63 | doUnpack(xhr.response); 64 | } 65 | } 66 | xhr.send(null); 67 | } else { 68 | doUnpack(Module['readBinary'](url)); 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /src/shared.h: -------------------------------------------------------------------------------- 1 | // vim: set ts=2 sw=2 tw=99 et: 2 | 3 | #ifndef shared_h_ 4 | #define shared_h_ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace asmjs { 11 | 12 | // ================================================================================================= 13 | // Magic serialization constants 14 | 15 | static const uint32_t MagicNumber = 0x6d736177; 16 | 17 | enum class Stmt : uint8_t 18 | { 19 | SetLoc, 20 | SetGlo, 21 | I32Store8, 22 | I32StoreOff8, 23 | I32Store16, 24 | I32StoreOff16, 25 | I32Store32, 26 | I32StoreOff32, 27 | F32Store, 28 | F32StoreOff, 29 | F64Store, 30 | F64StoreOff, 31 | CallInt, 32 | CallInd, 33 | CallImp, 34 | Ret, 35 | Block, 36 | IfThen, 37 | IfElse, 38 | While, 39 | Do, 40 | Label, 41 | Break, 42 | BreakLabel, 43 | Continue, 44 | ContinueLabel, 45 | Switch, 46 | 47 | Bad 48 | }; 49 | 50 | enum class StmtWithImm : uint8_t 51 | { 52 | SetLoc, 53 | SetGlo, 54 | Reseved1, 55 | Reseved2, 56 | 57 | Bad 58 | }; 59 | 60 | enum class SwitchCase : uint8_t 61 | { 62 | Case0, 63 | Case1, 64 | CaseN, 65 | Default0, 66 | Default1, 67 | DefaultN 68 | }; 69 | 70 | enum class I32 : uint8_t 71 | { 72 | LitPool, 73 | LitImm, 74 | GetLoc, 75 | GetGlo, 76 | SetLoc, 77 | SetGlo, 78 | SLoad8, 79 | SLoadOff8, 80 | ULoad8, 81 | ULoadOff8, 82 | SLoad16, 83 | SLoadOff16, 84 | ULoad16, 85 | ULoadOff16, 86 | Load32, 87 | LoadOff32, 88 | Store8, 89 | StoreOff8, 90 | Store16, 91 | StoreOff16, 92 | Store32, 93 | StoreOff32, 94 | CallInt, 95 | CallInd, 96 | CallImp, 97 | Cond, 98 | Comma, 99 | FromF32, 100 | FromF64, 101 | Neg, 102 | Add, 103 | Sub, 104 | Mul, 105 | SDiv, 106 | UDiv, 107 | SMod, 108 | UMod, 109 | BitNot, 110 | BitOr, 111 | BitAnd, 112 | BitXor, 113 | Lsh, 114 | ArithRsh, 115 | LogicRsh, 116 | Clz, 117 | LogicNot, 118 | EqI32, 119 | EqF32, 120 | EqF64, 121 | NEqI32, 122 | NEqF32, 123 | NEqF64, 124 | SLeThI32, 125 | ULeThI32, 126 | LeThF32, 127 | LeThF64, 128 | SLeEqI32, 129 | ULeEqI32, 130 | LeEqF32, 131 | LeEqF64, 132 | SGrThI32, 133 | UGrThI32, 134 | GrThF32, 135 | GrThF64, 136 | SGrEqI32, 137 | UGrEqI32, 138 | GrEqF32, 139 | GrEqF64, 140 | SMin, 141 | UMin, 142 | SMax, 143 | UMax, 144 | Abs, 145 | 146 | Bad 147 | }; 148 | 149 | enum class I32WithImm : uint8_t 150 | { 151 | LitPool, 152 | LitImm, 153 | GetLoc, 154 | Reserved, 155 | 156 | Bad 157 | }; 158 | 159 | enum class F32 : uint8_t 160 | { 161 | LitPool, 162 | LitImm, 163 | GetLoc, 164 | GetGlo, 165 | SetLoc, 166 | SetGlo, 167 | Load, 168 | LoadOff, 169 | Store, 170 | StoreOff, 171 | CallInt, 172 | CallInd, 173 | Cond, 174 | Comma, 175 | FromS32, 176 | FromU32, 177 | FromF64, 178 | Neg, 179 | Add, 180 | Sub, 181 | Mul, 182 | Div, 183 | Abs, 184 | Ceil, 185 | Floor, 186 | Sqrt, 187 | 188 | Bad 189 | }; 190 | 191 | enum class F32WithImm : uint8_t 192 | { 193 | LitPool, 194 | GetLoc, 195 | Reserved0, 196 | Reserved1, 197 | 198 | Bad 199 | }; 200 | 201 | enum class F64 : uint8_t 202 | { 203 | LitPool, 204 | LitImm, 205 | GetLoc, 206 | GetGlo, 207 | SetLoc, 208 | SetGlo, 209 | Load, 210 | LoadOff, 211 | Store, 212 | StoreOff, 213 | CallInt, 214 | CallInd, 215 | CallImp, 216 | Cond, 217 | Comma, 218 | FromS32, 219 | FromU32, 220 | FromF32, 221 | Neg, 222 | Add, 223 | Sub, 224 | Mul, 225 | Div, 226 | Mod, 227 | Min, 228 | Max, 229 | Abs, 230 | Ceil, 231 | Floor, 232 | Sqrt, 233 | Cos, 234 | Sin, 235 | Tan, 236 | ACos, 237 | ASin, 238 | ATan, 239 | ATan2, 240 | Exp, 241 | Ln, 242 | Pow, 243 | 244 | Bad 245 | }; 246 | 247 | enum class F64WithImm : uint8_t 248 | { 249 | LitPool, 250 | GetLoc, 251 | Reserved0, 252 | Reserved1, 253 | 254 | Bad 255 | }; 256 | 257 | enum class Void : uint8_t 258 | { 259 | CallInt, 260 | CallInd, 261 | CallImp, 262 | 263 | Bad 264 | }; 265 | 266 | enum class Type : uint8_t 267 | { 268 | I32, 269 | F32, 270 | F64 271 | }; 272 | 273 | enum class VarTypes : uint8_t 274 | { 275 | I32 = 0x1, 276 | F32 = 0x2, 277 | F64 = 0x4, 278 | }; 279 | 280 | inline VarTypes operator|(VarTypes lhs, VarTypes rhs) { return VarTypes(uint8_t(lhs) | uint8_t(rhs)); } 281 | inline bool operator&(VarTypes lhs, VarTypes rhs) { return bool(uint8_t(lhs) & uint8_t(rhs)); } 282 | 283 | enum class VarTypesWithImm : uint8_t 284 | { 285 | OnlyI32, 286 | Reserved0, 287 | Reserved1, 288 | Reserved2 289 | }; 290 | 291 | enum class RType : uint8_t 292 | { 293 | I32 = uint8_t(Type::I32), 294 | F32 = uint8_t(Type::F32), 295 | F64 = uint8_t(Type::F64), 296 | Void 297 | }; 298 | 299 | inline RType 300 | to_rtype(Type t) 301 | { 302 | return RType(t); 303 | } 304 | 305 | 306 | // HACK: Workaround for unconstrained unions (C++11) support unavailable in MSVC++ 307 | // We have a union that used to contain an Expr, but this is invalid pre-C++11 since 308 | // Expr has constructors. 309 | class Expr; 310 | 311 | struct ExprPOD 312 | { 313 | RType type_; 314 | uint8_t raw_code_; 315 | 316 | operator Expr () const; 317 | }; 318 | 319 | 320 | class Expr 321 | { 322 | friend struct ExprPOD; 323 | 324 | RType type_; 325 | union U { 326 | I32 i32_; 327 | F32 f32_; 328 | F64 f64_; 329 | Void v_; 330 | uint8_t raw_; 331 | } u; 332 | 333 | static_assert(sizeof(U) == sizeof(uint8_t), "Exact overlay of raw_"); 334 | 335 | public: 336 | Expr() : type_(RType(-1)), u{} {} 337 | static Expr Bad() { return Expr(); } 338 | Expr(I32 i32) : type_(RType::I32) { assert(i32 < I32::Bad); u.i32_ = i32; } 339 | Expr(F32 f32) : type_(RType::F32) { assert(f32 < F32::Bad); u.f32_ = f32; } 340 | Expr(F64 f64) : type_(RType::F64) { assert(f64 < F64::Bad); u.f64_ = f64; } 341 | Expr(Void v) : type_(RType::Void) { assert(v < Void::Bad); u.v_ = v; } 342 | 343 | bool is_bad() const { return type_ == RType(-1); } 344 | RType type() const { assert(!is_bad()); return type_; } 345 | I32 i32() const { assert(type_ == RType::I32); return u.i32_; } 346 | F32 f32() const { assert(type_ == RType::F32); return u.f32_; } 347 | F64 f64() const { assert(type_ == RType::F64); return u.f64_; } 348 | uint8_t raw_code() const { assert(!is_bad()); return u.raw_; } 349 | 350 | bool operator==(Expr rhs) const { return type_ == rhs.type_ && u.raw_ == rhs.u.raw_; } 351 | bool operator!=(Expr rhs) const { return !(*this == rhs); } 352 | 353 | operator ExprPOD () const { 354 | ExprPOD result; 355 | result.type_ = type_; 356 | result.raw_code_ = u.raw_; 357 | return result; 358 | } 359 | }; 360 | 361 | inline ExprPOD::operator Expr () const { 362 | Expr result; 363 | result.type_ = type_; 364 | result.u.raw_ = raw_code_; 365 | return result; 366 | } 367 | 368 | static const uint8_t HasImmFlag = 0x80; 369 | static_assert(uint8_t(I32::Bad) <= HasImmFlag, "MSB reserved to distinguish I32 from I32WithImm"); 370 | static_assert(uint8_t(F32::Bad) <= HasImmFlag, "MSB reserved to distinguish F32 from F32WithImm"); 371 | static_assert(uint8_t(F64::Bad) <= HasImmFlag, "MSB reserved to distinguish F64 from F64WithImm"); 372 | 373 | static const unsigned OpWithImmBits = 2; 374 | static const uint32_t OpWithImmLimit = 1 << OpWithImmBits; 375 | static_assert(uint8_t(I32WithImm::Bad) <= OpWithImmLimit, "I32WithImm op fits"); 376 | static_assert(uint8_t(F32WithImm::Bad) <= OpWithImmLimit, "F32WithImm op fits"); 377 | static_assert(uint8_t(F64WithImm::Bad) <= OpWithImmLimit, "F64WithImm op fits"); 378 | 379 | static const unsigned ImmBits = 5; 380 | static const uint32_t ImmLimit = 1 << ImmBits; 381 | static_assert(1 + OpWithImmBits + ImmBits == 8, "Bits of immediate op should add up to a byte"); 382 | 383 | static inline uint8_t 384 | PackOpWithImm(uint8_t op, uint8_t imm) 385 | { 386 | assert(op < OpWithImmLimit); 387 | assert(imm < ImmLimit); 388 | return HasImmFlag | (uint8_t(op) << ImmBits) | imm; 389 | } 390 | 391 | template 392 | static inline void 393 | UnpackOpWithImm(uint8_t byte, TWithImm* op, uint8_t *imm) 394 | { 395 | assert(byte & HasImmFlag); 396 | *op = TWithImm((byte >> ImmBits) & (OpWithImmLimit - 1)); 397 | *imm = byte & (ImmLimit - 1); 398 | } 399 | 400 | class ExprWithImm 401 | { 402 | Type type_; 403 | union U { 404 | I32WithImm i32_; 405 | F32WithImm f32_; 406 | F64WithImm f64_; 407 | uint8_t raw_; 408 | } u; 409 | 410 | static_assert(sizeof(U) == sizeof(uint8_t), "Exact overlay of raw_"); 411 | 412 | public: 413 | ExprWithImm() : type_(Type(-1)) {} 414 | ExprWithImm(I32WithImm i32) : type_(Type::I32) { assert(i32 < I32WithImm::Bad); u.i32_ = i32; } 415 | ExprWithImm(F32WithImm f32) : type_(Type::F32) { assert(f32 < F32WithImm::Bad); u.f32_ = f32; } 416 | ExprWithImm(F64WithImm f64) : type_(Type::F64) { assert(f64 < F64WithImm::Bad); u.f64_ = f64; } 417 | 418 | bool is_bad() const { return type_ == Type(-1); } 419 | Type type() const { return type_; } 420 | I32WithImm i32() const { assert(type_ == Type::I32); return u.i32_; } 421 | F32WithImm f32() const { assert(type_ == Type::F32); return u.f32_; } 422 | F64WithImm f64() const { assert(type_ == Type::F64); return u.f64_; } 423 | uint8_t raw_code() const { assert(!is_bad()); return u.raw_; } 424 | }; 425 | 426 | enum class ExportFormat : uint8_t 427 | { 428 | Default, 429 | Record 430 | }; 431 | 432 | // ================================================================================================= 433 | // Utilities 434 | 435 | template 436 | T inline 437 | unreachable() 438 | { 439 | assert(false && "unreachable"); 440 | return *(T*)nullptr; 441 | } 442 | 443 | template <> 444 | void inline 445 | unreachable() 446 | { 447 | assert(false && "unreachable"); 448 | } 449 | 450 | template 451 | T inline 452 | type_switch(Type type, T i32, T f32, T f64) 453 | { 454 | switch (type) { 455 | case Type::I32: return i32; 456 | case Type::F32: return f32; 457 | case Type::F64: return f64; 458 | } 459 | return unreachable(); 460 | } 461 | 462 | inline Expr 463 | type_switch(RType type, I32 i32, F32 f32, F64 f64, Void v) 464 | { 465 | switch (type) { 466 | case RType::I32: return i32; 467 | case RType::F32: return f32; 468 | case RType::F64: return f64; 469 | case RType::Void: return v; 470 | } 471 | return unreachable(); 472 | } 473 | 474 | template 475 | inline T 476 | type_switch(RType type, T i32, T f32, T f64, T v) 477 | { 478 | switch (type) { 479 | case RType::I32: return i32; 480 | case RType::F32: return f32; 481 | case RType::F64: return f64; 482 | case RType::Void: return v; 483 | } 484 | return unreachable(); 485 | } 486 | 487 | inline Expr 488 | type_switch(Type type, I32 i32, F32 f32, F64 f64) 489 | { 490 | switch (type) { 491 | case Type::I32: return i32; 492 | case Type::F32: return f32; 493 | case Type::F64: return f64; 494 | } 495 | return unreachable(); 496 | } 497 | 498 | enum Signedness { Signed, Unsigned }; 499 | 500 | template 501 | inline Expr 502 | signedness_switch(Signedness si, T s32, T u32) 503 | { 504 | switch (si) { 505 | case Signed: return s32; 506 | case Unsigned: return u32; 507 | } 508 | return unreachable(); 509 | } 510 | 511 | struct Signature 512 | { 513 | RType ret; 514 | std::vector args; 515 | 516 | Signature() {} 517 | Signature(RType ret) : ret(ret) {} 518 | Signature(RType ret, uint32_t num_args) : ret(ret), args(num_args) {} 519 | Signature(RType ret, std::vector&& args) : ret(ret), args(move(args)) {} 520 | 521 | bool operator==(const Signature& rhs) const { return ret == rhs.ret && args == rhs.args; } 522 | bool operator!=(const Signature& rhs) const { return !(*this == rhs); } 523 | 524 | struct Hash { 525 | bool operator()(const Signature &sig) const { 526 | static_assert(sizeof(Type) == 1 && sizeof(RType) == 1, "Shift more"); 527 | uint32_t h = uint8_t(sig.ret); 528 | for (Type t : sig.args) 529 | h = ((h << 2) | uint8_t(t)) ^ (h >> 30); 530 | return h; 531 | } 532 | }; 533 | }; 534 | 535 | // ================================================================================================= 536 | 537 | class In 538 | { 539 | const uint8_t* cur_; 540 | 541 | template T u8() { return T(*cur_++); } 542 | 543 | public: 544 | In(const uint8_t* beg) : cur_(beg) {} 545 | 546 | template T fixed_width(); 547 | Stmt stmt() { return u8(); } 548 | SwitchCase switch_case() { return u8(); } 549 | template inline bool code(T*, TWithImm*, uint8_t*); 550 | Void void_expr() { return u8(); } 551 | ExportFormat export_format() { return u8(); } 552 | Type type() { return u8(); } 553 | RType rtype() { return u8(); } 554 | inline uint32_t imm_u32(); 555 | inline int32_t imm_s32(); 556 | char single_char() { return *cur_++; } 557 | 558 | inline bool if_i32_lit(const std::vector& i32s, uint32_t* u32); 559 | inline bool is_next_node_block(); 560 | }; 561 | 562 | template <> 563 | uint32_t inline 564 | In::fixed_width() 565 | { 566 | uint32_t u32 = cur_[0] | cur_[1] << 8 | cur_[2] << 16 | cur_[3] << 24; 567 | cur_ += 4; 568 | return u32; 569 | } 570 | 571 | template <> 572 | float inline 573 | In::fixed_width() 574 | { 575 | union { 576 | uint8_t arr[4]; 577 | float f; 578 | } u = { { cur_[0], cur_[1], cur_[2], cur_[3] } }; 579 | cur_ += 4; 580 | return u.f; 581 | } 582 | 583 | template <> 584 | double inline 585 | In::fixed_width() 586 | { 587 | union { 588 | uint8_t arr[8]; 589 | double d; 590 | } u = { { cur_[0], cur_[1], cur_[2], cur_[3], cur_[4], cur_[5], cur_[6], cur_[7] } }; 591 | cur_ += 8; 592 | return u.d; 593 | } 594 | 595 | template 596 | bool 597 | In::code(T* t, TWithImm* t_with_imm, uint8_t* imm) 598 | { 599 | uint8_t byte = *cur_++; 600 | if (!(byte & HasImmFlag)) { 601 | *t = T(byte); 602 | return true; 603 | } 604 | 605 | UnpackOpWithImm(byte, t_with_imm, imm); 606 | return false; 607 | } 608 | 609 | uint32_t inline 610 | In::imm_u32() 611 | { 612 | uint32_t u32 = *cur_++; 613 | if (u32 < 0x80) 614 | return u32; 615 | 616 | u32 &= 0x7f; 617 | 618 | for (unsigned shift = 7; true; shift += 7) { 619 | uint32_t b = *cur_++; 620 | if (b < 0x80) 621 | return u32 | (b << shift); 622 | u32 |= (b & 0x7f) << shift; 623 | } 624 | } 625 | 626 | int32_t inline 627 | In::imm_s32() 628 | { 629 | uint32_t u32 = *cur_++; 630 | if (u32 < 0x80) 631 | return int32_t(u32) << (32-7) >> (32-7); 632 | 633 | u32 &= 0x7f; 634 | 635 | for (unsigned shift = 7; true; shift += 7) { 636 | uint32_t b = *cur_++; 637 | if (b < 0x80) { 638 | u32 |= b << shift; 639 | int sign_extend = (32-7) - shift; 640 | if (sign_extend > 0) 641 | return int32_t(u32) << sign_extend >> sign_extend; 642 | return int32_t(u32); 643 | } 644 | u32 |= (b & 0x7f) << shift; 645 | } 646 | } 647 | 648 | bool inline 649 | In::if_i32_lit(const std::vector& i32s, uint32_t* u32) 650 | { 651 | uint8_t byte = *cur_; 652 | 653 | if (byte & HasImmFlag) { 654 | I32WithImm i32_with_imm; 655 | uint8_t imm; 656 | UnpackOpWithImm(byte, &i32_with_imm, &imm); 657 | 658 | if (i32_with_imm == I32WithImm::LitImm) { 659 | cur_++; 660 | *u32 = imm; 661 | return true; 662 | } 663 | 664 | if (i32_with_imm == I32WithImm::LitPool) { 665 | cur_++; 666 | *u32 = i32s[imm]; 667 | return true; 668 | } 669 | 670 | return false; 671 | } 672 | 673 | if (I32(byte) == I32::LitImm) { 674 | cur_++; 675 | *u32 = imm_u32(); 676 | return true; 677 | } 678 | 679 | if (I32(byte) == I32::LitPool) { 680 | cur_++; 681 | *u32 = i32s[imm_u32()]; 682 | return true; 683 | } 684 | 685 | return false; 686 | } 687 | 688 | bool inline 689 | In::is_next_node_block() 690 | { 691 | static_assert(uint32_t(Stmt::Block) < 0x80, 692 | "We can fetch the code in a single byte"); 693 | return Stmt(*cur_) == Stmt::Block; 694 | } 695 | 696 | } // namespace asmjs 697 | #endif // shared_h_ 698 | -------------------------------------------------------------------------------- /src/unpack-asmjs.cpp: -------------------------------------------------------------------------------- 1 | // vim: set ts=2 sw=2 tw=99 et: 2 | 3 | #include "unpack.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | int 12 | main(int argc, char** argv) 13 | try 14 | { 15 | if (argc < 3 || argc > 4) { 16 | cerr << "Usage: unpack-asmjs in.wasm out.js [name]" << endl; 17 | return -1; 18 | } 19 | 20 | const char* in_file_name = argv[1]; 21 | const char* out_file_name = argv[2]; 22 | const char* name = argc > 3 ? argv[3] : nullptr; 23 | 24 | // Read in packed .asm file bytes. 25 | vector in_bytes; 26 | ifstream in_stream(in_file_name, ios::binary | ios::ate); 27 | in_stream.exceptions(ios::failbit | ios::badbit); 28 | in_bytes.resize(in_stream.tellg()); 29 | in_stream.seekg(0); 30 | in_stream.read((char*)in_bytes.data(), in_bytes.size()); 31 | in_stream.close(); 32 | 33 | if (!asmjs::has_magic_number(in_bytes.data())) { 34 | cerr << in_file_name << " isn't a packed asm.js file" << endl; 35 | return -1; 36 | } 37 | 38 | // Unpack .asm file into utf8 chars. 39 | uint32_t unpacked_size = asmjs::unpacked_size(in_bytes.data(), name); 40 | vector out_bytes(unpacked_size); 41 | asmjs::unpack(in_bytes.data(), name, out_bytes.size(), out_bytes.data()); 42 | 43 | // Write the utf8 chars out to a .js file. 44 | ofstream out_stream(out_file_name, ios::binary); 45 | out_stream.exceptions(ios::failbit | ios::badbit); 46 | out_stream.write((char*)out_bytes.data(), out_bytes.size()); 47 | out_stream.close(); 48 | 49 | return 0; 50 | } 51 | catch (const ios::failure& err) 52 | { 53 | cerr << "Failed with iostream error: " << err.what() << endl; 54 | return -1; 55 | } 56 | catch(const runtime_error& err) 57 | { 58 | cerr << "Failed with runtime error: " << err.what() << endl; 59 | return -1; 60 | } 61 | -------------------------------------------------------------------------------- /src/unpack.h: -------------------------------------------------------------------------------- 1 | #ifndef unpack_h_ 2 | #define unpack_h_ 3 | 4 | #include 5 | #include 6 | 7 | namespace asmjs { 8 | 9 | #ifdef CHECKED_OUTPUT_SIZE 10 | 11 | uint32_t calculate_unpacked_size(const uint8_t* packed); 12 | 13 | #else 14 | 15 | bool has_magic_number(const uint8_t* packed); 16 | uint32_t unpacked_size(const uint8_t* packed, const char* callback_name); 17 | void unpack(const uint8_t* packed, const char* cb_name, uint32_t unpacked_size, uint8_t* unpacked); 18 | 19 | #endif 20 | 21 | } // namespace asmjs 22 | #endif // unpack_h_ 23 | -------------------------------------------------------------------------------- /test/a01.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | function $w(k,l,m){ 32 | k=k|0;l=+l;m=j(m); 33 | } 34 | function $x(){ 35 | } 36 | function $y(){ 37 | } 38 | return {one:$w,two:$x}; 39 | } 40 | -------------------------------------------------------------------------------- /test/a02.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | function $w(k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,_,aa,ab){ 32 | k=+k;l=+l;m=+m;n=+n;o=+o;p=+p;q=+q;r=+r;s=+s;t=+t;u=+u;v=+v;w=+w;x=+x;y=+y;z=+z;A=+A;B=+B;C=+C;D=+D;E=+E;F=+F;G=+G;H=+H;I=+I;J=+J;K=+K;L=L|0;M=M|0;N=+N;O=+O;P=+P;Q=+Q;R=+R;S=+S;T=+T;U=+U;V=+V;W=+W;X=+X;Y=+Y;Z=+Z;_=+_;aa=+aa;ab=+ab; 33 | } 34 | function $x(){ 35 | } 36 | function $y(){ 37 | } 38 | function $z(){ 39 | } 40 | function $A(){ 41 | } 42 | function $B(){ 43 | } 44 | function $C(){ 45 | } 46 | function $D(){ 47 | } 48 | function $E(){ 49 | } 50 | function $F(){ 51 | } 52 | function $G(){ 53 | } 54 | function $H(){ 55 | } 56 | function $I(){ 57 | } 58 | function $J(){ 59 | } 60 | function $K(){ 61 | } 62 | function $L(){ 63 | } 64 | function $M(){ 65 | } 66 | function $N(){ 67 | } 68 | function $O(){ 69 | } 70 | function $P(){ 71 | } 72 | function $Q(){ 73 | } 74 | function $R(){ 75 | } 76 | function $S(){ 77 | } 78 | function $T(){ 79 | } 80 | function $U(){ 81 | } 82 | function $V(){ 83 | } 84 | function $W(){ 85 | } 86 | function $X(){ 87 | } 88 | function $Y(){ 89 | } 90 | function $Z(){ 91 | } 92 | function $_(){ 93 | } 94 | function $$(){ 95 | } 96 | function $0(){ 97 | } 98 | function $1(){ 99 | } 100 | function $2(){ 101 | } 102 | function $3(){ 103 | } 104 | function $4(){ 105 | } 106 | function $5(){ 107 | } 108 | function $6(){ 109 | } 110 | function $7(){ 111 | } 112 | function $8(){ 113 | } 114 | function $9(){ 115 | } 116 | function $aa(){ 117 | } 118 | function $ab(){ 119 | } 120 | function $ac(){ 121 | } 122 | function $ad(){ 123 | } 124 | return {one:$X,two:$0}; 125 | } 126 | -------------------------------------------------------------------------------- /test/a03.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | function $w(k,l){ 32 | k=k|0;l=+l; 33 | var m=0,n=j(0),o=0.; 34 | } 35 | function $x(k){ 36 | k=+k; 37 | var l=0,m=j(0),n=0.; 38 | } 39 | return $w; 40 | } 41 | -------------------------------------------------------------------------------- /test/a04.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | function $w(k,l){ 32 | k=k|0;l=+l; 33 | var m=0,n=j(0); 34 | k=0; 35 | k=1; 36 | k=2; 37 | k=3; 38 | k=4; 39 | k=5; 40 | k=(e[0]|0,e[1]|0,e[2]|0,e[3]|0,e[4]|0,e[5]|0,e[6]|0,e[7]|0,e[8]|0,e[9]|0,e[10]|0,e[11]|0,e[12]|0,e[13]|0,e[14]|0,e[15]|0,e[16]|0,e[17]|0,e[18]|0,e[19]|0,e[20]|0,e[21]|0,e[22]|0,e[23]|0,e[24]|0,e[25]|0); 41 | k=(e[26]|0,e[27]|0,e[28]|0,e[29]|0,e[30]|0,e[31]|0,e[32]|0,e[33]|0,e[34]|0,e[35]|0,e[36]|0,e[37]|0,e[38]|0,e[39]|0,e[40]|0,e[41]|0,e[42]|0,e[43]|0,e[44]|0,e[45]|0,e[46]|0,e[47]|0,e[48]|0,e[49]|0,e[50]|0); 42 | k=(e[51]|0,e[52]|0,e[53]|0,e[54]|0,e[55]|0,e[56]|0,e[57]|0,e[58]|0,e[59]|0,e[60]|0,e[61]|0,e[62]|0,e[63]|0,e[64]|0,e[65]|0,e[66]|0); 43 | k=2147483646; 44 | k=2147483647; 45 | k=-2147483648; 46 | k=-2; 47 | k=-1; 48 | k=-127; 49 | k=-128; 50 | k=-129; 51 | k=-130; 52 | k=-2147483646; 53 | k=-2147483647; 54 | k=-2147483648; 55 | n=j(0); 56 | n=j(1); 57 | n=j(-1); 58 | n=j(123456); 59 | n=j(-12345); 60 | } 61 | return $w; 62 | } 63 | -------------------------------------------------------------------------------- /test/a05.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | function $w(){ 32 | var k=j(0),l=0.; 33 | l=0.; 34 | l=1.; 35 | l=3.1; 36 | l=3.12345; 37 | l=0.12345; 38 | l=1.e+09; 39 | l=1.23e+09; 40 | l=0.0001; 41 | l=0.0001234; 42 | l=0.000123456; 43 | k=j(0); 44 | k=j(0.1); 45 | k=j(0.1245); 46 | k=j(1e+09); 47 | k=j(0.001); 48 | k=j(0.00123456); 49 | } 50 | return $w; 51 | } 52 | -------------------------------------------------------------------------------- /test/a06.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | function $w(k,l){ 32 | k=k|0;l=+l; 33 | var m=0,n=j(0),o=0.; 34 | k=1+2+3|0; 35 | m=k; 36 | o=1.1+l-3.2; 37 | n=j(j(1.1)+n); 38 | n=j(g[0]); 39 | o=+g[0]; 40 | g[0]=j(1.1)+n; 41 | n=j(n-j(1.1)); 42 | g[0]=n-j(1.1); 43 | m=k+3+m|m+k; 44 | m=i(m,3); 45 | m=i(3,m); 46 | o=3.*o+l; 47 | o=(3.+o)*l; 48 | m=i(3,m)+3|0; 49 | m=i(3+m|0,3); 50 | n=j(j(1.3)*n); 51 | g[0]=j(1.3)*n; 52 | m=k=k+1|0; 53 | l=l+l+l; 54 | l=l+(l+l); 55 | l=l+l+l-l+l+l-l; 56 | l=l+l+l-(l+l+l)-l; 57 | l=o+o*o+o+3.*o*(3.2+o*4.)*4.3; 58 | k=m&k^m|k; 59 | k=m&(k^(m|k)); 60 | k=m|k^m&k; 61 | k=((m|k)^m)&k; 62 | l=l/o*l%o; 63 | l=l/3.+o*o%1.+l%o; 64 | l=l/(3.+o*o)%1.+l%o; 65 | l=l/(3.+o*o%1.+l)%o; 66 | l=l/(o*(l%o)); 67 | n=j(n/n); 68 | g[0]=n/j(1.1); 69 | n=j(+n/+n); 70 | g[0]=j(+n/+n); 71 | n=(1,2,j(1.1)); 72 | n=j(m|0); 73 | g[0]=j(m|0); 74 | n=j(m>>>0); 75 | g[0]=j(m>>>0); 76 | k=k+m>>m+k>>>k+m<<2; 77 | k=k+(m>>m+k)>>>k+m<<2; 78 | k=((k>>>0)/(m>>>0)|0)+((k&m|0)%(k|0)|0)|0; 79 | k=((k|k)>>>0)/(k>>k>>>0)|0; 80 | k=((k|k)>>>0)%(k>>k>>>0)|0; 81 | k=(3/(m>>>0)|0)+((k|0)%40|0)|0; 82 | k=3/3|0; 83 | k=(k|0)/3|0; 84 | k=(k>>>0)/3|0; 85 | k=3/(k|0)|0; 86 | k=3/(k>>>0)|0; 87 | k=3%3|0; 88 | k=(k|0)%3|0; 89 | k=(k>>>0)%3|0; 90 | k=3%(k|0)|0; 91 | k=3%(k>>>0)|0; 92 | k=k|(k+1|k); 93 | k=k&(k+1^k); 94 | k=k>>(k+1<>>0>>0; 104 | k=l>o; 105 | k=n>n; 106 | k=(k|0)>(m|0); 107 | k=k>>>0>m>>>0; 108 | k=l<=o; 109 | k=n<=n; 110 | k=(k|0)<=(m|0); 111 | k=k>>>0<=m>>>0; 112 | k=l>=o; 113 | k=n>=n; 114 | k=(k|0)>=(m|0); 115 | k=k>>>0>=m>>>0; 116 | k=(l==l|0)==1; 117 | k=1==(l==1.|0); 118 | k=(k<<2|0)==(k>>>2|0); 119 | l=+(k|0); 120 | l=+(k>>>0); 121 | l=+1; 122 | k=-1; 123 | k=-(k+1|0)|0; 124 | l=-l; 125 | l=-1.; 126 | l=-(l+1.); 127 | n=j(-n); 128 | g[0]=-n; 129 | k=~k; 130 | k=~1; 131 | k=~(k+1); 132 | k=-~-!~-k|0; 133 | k=~((-!~-k|0)+4); 134 | k=~i(-!~-k|0,4); 135 | l=-+(~(k+1)|0); 136 | k=!k; 137 | k=!((k|0)<(m|0)); 138 | k=!~!(k>>>0>>0); 139 | k=(-~-!~-k|0,1==(l==1.|0),k>>(k+1<>0]|0,-4-(a[0]|0)|0,a[0]=1,3+(a[0]=1)|0,a[k>>0]=1,4+(a[k>>0]=1)|0); 35 | k=(b[0]|0,2+(b[0]|0)|0,b[k>>0]|0,-4-(b[0]|0)|0); 36 | k=(c[0]|0,2+(c[0]|0)|0,c[k>>1]|0,-4-(c[0]|0)|0,c[0]=1,3+(c[0]=1)|0,c[k>>1]=1,4+(c[k>>1]=1)|0); 37 | k=(d[0]|0,2+(d[0]|0)|0,d[k>>1]|0,-4-(d[0]|0)|0); 38 | k=(e[0]|0,2+(e[0]|0)|0,e[k>>2]|0,-4-(e[0]|0)|0,e[0]=1,3+(e[0]=1)|0,e[k>>2]=1,4+(e[k>>2]=1)|0); 39 | k=(e[0]|0,2+(e[0]|0)|0,e[k>>2]|0,-4-(e[0]|0)|0); 40 | l=(+g[0],2.+ +g[0],+g[k>>2],-4.1+ +g[0],g[0]=j(1),j(j(3)+(g[0]=j(1))),g[k>>2]=j(1.4),j(j(4.4)+(g[k>>2]=j(1)))); 41 | m=(+h[0],2.1+ +h[0],+h[k>>3],-4.9+ +h[0]); 42 | a[k+1>>0]=1; 43 | k=a[k+4>>0]|0; 44 | k=b[k+1000>>0]|0; 45 | c[k+42>>1]=1; 46 | k=c[k+40>>1]|0; 47 | k=d[k+100>>1]|0; 48 | e[k+4>>2]=1; 49 | k=e[k+8>>2]|0; 50 | g[k+12>>2]=j(1); 51 | l=j(g[k+48>>2]); 52 | h[k+100>>3]=1.; 53 | m=+h[k+100>>3]; 54 | k=e[k+40+20>>2]|0; 55 | k=e[k-40+20>>2]|0; 56 | k=e[40+k+20>>2]|0; 57 | k=e[40-k+20>>2]|0; 58 | k=e[i(40,k)+20>>2]|0; 59 | k=e[(40>>0)+20>>2]|0; 60 | k=e[(e[k>>2]|0)+20>>2]|0; 61 | m=$l(+g[0]); 62 | m=$m(+g[0]); 63 | m=$n(+g[0]); 64 | m=$o(+g[0]); 65 | a[0]=(k,($x()|0)+1|0); 66 | k=4+(a[0]=(k,($x()|0)+1|0))|0; 67 | a[0]=k+1; 68 | c[0]=k+1; 69 | e[0]=k+1; 70 | h[0]=h[0]; 71 | h[0]=+g[0]; 72 | g[0]=j(+h[0]); 73 | g[0]=g[0]; 74 | k=a[100000000>>0]|0; 75 | k=b[100000000>>0]|0; 76 | k=c[100000000>>1]|0; 77 | k=d[100000000>>1]|0; 78 | k=e[100000000>>2]|0; 79 | l=j(g[100000000>>2]); 80 | m=+h[100000000>>3]; 81 | a[100000000>>0]=2; 82 | c[100000000>>1]=3; 83 | e[100000000>>2]=5; 84 | g[100000000>>2]=j(6); 85 | h[100000000>>3]=7.; 86 | } 87 | function $x(){ 88 | return 1; 89 | } 90 | return $w; 91 | } 92 | -------------------------------------------------------------------------------- /test/a12.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | function $w(k,l,m){ 32 | k=k|0;l=+l;m=j(m); 33 | var n=0.; 34 | k=i((k,3),k); 35 | k=i(k,(k,3)); 36 | k=i(k,k); 37 | k=i(1,2); 38 | l=($d(l),$d(h[0])); 39 | l=($e(l),$d(h[0])); 40 | l=($f(l),$d(h[0])); 41 | l=($g(l),$d(h[0])); 42 | l=($h(l),$d(h[0])); 43 | l=($i(l),$d(h[0])); 44 | l=($k(l),$d(h[0])); 45 | l=($l(l),$l(h[0])); 46 | m=(j($l(m)),j($l(g[0]))); 47 | l=($m(l),$m(h[0])); 48 | m=(j($m(m)),j($m(g[0]))); 49 | l=($n(l),$n(h[0])); 50 | m=(j($n(m)),j($n(g[0]))); 51 | l=($o(l),$o(h[0])); 52 | k=($o(k|0),$o(a[0]|0)); 53 | m=(j($o(m)),j($o(g[0]))); 54 | l=($r(l,l),$r(h[0],h[0])); 55 | l=($s(l,l),$s(h[0],h[0])); 56 | n=($t(k),$d(h[0])); 57 | l=(l=$p(1.,l),l=$p(1.,l,h[0])); 58 | k=($p(1,k|0),k=$p(1,k+1|0,a[0]|0)); 59 | l=($q(1.,l),l=$q(1.,l,h[0])); 60 | k=($q(1,k|0),k=$q(1,k+1|0,a[0]|0)); 61 | n=+(i(1,2)|0); 62 | k=~~$h(1.); 63 | n=$s(+g[0],h[0]); 64 | n=$p(+g[0],h[0]); 65 | n=$h(+g[0]); 66 | n=$h(h[0]); 67 | } 68 | return $w; 69 | } 70 | -------------------------------------------------------------------------------- /test/a13.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | var $w=$b.one; 32 | var $x=$b.two; 33 | var $y=$b.three; 34 | function $z(k,l){ 35 | k=k|0;l=+l; 36 | $w(); 37 | +$w(k|0); 38 | $w(l)|0; 39 | $x(); 40 | k=($y(),+$y(1),$y(1,2,3),$y()|0); 41 | } 42 | function $A(){ 43 | } 44 | function $B(){ 45 | } 46 | return $z; 47 | } 48 | -------------------------------------------------------------------------------- /test/a14.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | var $w=$b.one; 32 | var $x=$b.two; 33 | var $y=$b.three; 34 | function $z(){ 35 | } 36 | function $A(k){ 37 | k=k|0; 38 | return 1.; 39 | } 40 | function $B(k,l){ 41 | k=k|0;l=+l; 42 | $H[k&3](); 43 | l=(+$I[k&0](k),l+ +$I[k&0](k),l-+$I[k&0](k)); 44 | k=($J[k&1](k,l)|0,k+($J[k&1](k,l)|0)|0); 45 | $H[k+1&3](); 46 | $H[(k|1)&3](); 47 | $H[($J[k&1](k,l)|0)&3](); 48 | $H[a[k>>0]&3](); 49 | return 1; 50 | } 51 | function $C(){ 52 | } 53 | function $D(k,l){ 54 | k=k|0;l=+l; 55 | return 2; 56 | } 57 | function $E(){ 58 | return 1.; 59 | } 60 | function $F(k){ 61 | k=j(k); 62 | j($K[0&3](k)); 63 | return j(1.1); 64 | } 65 | function $G(k){ 66 | k=j(k); 67 | return j(2); 68 | } 69 | var $H=[$z,$C,$z,$z]; 70 | var $I=[$A]; 71 | var $J=[$B,$D]; 72 | var $K=[$F,$G,$F,$G]; 73 | return $z; 74 | } 75 | -------------------------------------------------------------------------------- /test/a15.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | var $w=$b.wee; 32 | var $x=$b.aboo; 33 | var $y=0; 34 | var $z=0; 35 | var $A=j(0); 36 | var $B=0.; 37 | var $C=0.; 38 | var $D=$b.foo|0; 39 | var $E=$b.bar|0; 40 | var $F=j($b.foopy); 41 | var $G=+$b.baz; 42 | var $H=+$b.quux; 43 | function $I(){ 44 | $D=1; 45 | $E=$D+2|0; 46 | $G=1.; 47 | $A=j(1); 48 | $B=$G+2.; 49 | $F=j($A+j(2.2)); 50 | $y=1+$z+$D+$E|0; 51 | $G=1.1+$C+$G+$H; 52 | $w($y|0,$z|0)|0; 53 | $x($z|0,$B); 54 | +$w($D|0,$C); 55 | $w(); 56 | +$J(); 57 | $I(); 58 | } 59 | function $J(){ 60 | return 1.; 61 | } 62 | return $I; 63 | } 64 | -------------------------------------------------------------------------------- /test/a16.js: -------------------------------------------------------------------------------- 1 | function asmModule($a,$b,$c){'use asm'; 2 | var a=new $a.Int8Array($c); 3 | var b=new $a.Uint8Array($c); 4 | var c=new $a.Int16Array($c); 5 | var d=new $a.Uint16Array($c); 6 | var e=new $a.Int32Array($c); 7 | var f=new $a.Uint32Array($c); 8 | var g=new $a.Float32Array($c); 9 | var h=new $a.Float64Array($c); 10 | var i=$a.Math.imul; 11 | var j=$a.Math.fround; 12 | var $d=$a.Math.acos; 13 | var $e=$a.Math.asin; 14 | var $f=$a.Math.atan; 15 | var $g=$a.Math.cos; 16 | var $h=$a.Math.sin; 17 | var $i=$a.Math.tan; 18 | var $j=$a.Math.exp; 19 | var $k=$a.Math.log; 20 | var $l=$a.Math.ceil; 21 | var $m=$a.Math.floor; 22 | var $n=$a.Math.sqrt; 23 | var $o=$a.Math.abs; 24 | var $p=$a.Math.min; 25 | var $q=$a.Math.max; 26 | var $r=$a.Math.atan2; 27 | var $s=$a.Math.pow; 28 | var $t=$a.Math.clz32; 29 | var $u=$a.NaN; 30 | var $v=$a.Infinity; 31 | function $w(){ 32 | var k=0.; 33 | k=$u; 34 | k=$v; 35 | k=$u+1.1; 36 | k=$u+$v; 37 | } 38 | return {one:$w}; 39 | } 40 | -------------------------------------------------------------------------------- /vs/.gitignore: -------------------------------------------------------------------------------- 1 | Debug 2 | Release 3 | *.suo 4 | *.sdf 5 | *.opensdf 6 | *.user 7 | *.filters -------------------------------------------------------------------------------- /vs/pack-asmjs.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {16CCFC5C-02DF-4825-97BE-2E575D22B014} 15 | Win32Proj 16 | vs 17 | pack-asmjs 18 | 19 | 20 | 21 | Application 22 | true 23 | v120 24 | Unicode 25 | 26 | 27 | Application 28 | false 29 | v120 30 | true 31 | Unicode 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | true 45 | ..\tools 46 | $(Configuration)\$(ProjectName)\ 47 | 48 | 49 | false 50 | ..\tools 51 | $(Configuration)\$(ProjectName)\ 52 | 53 | 54 | 55 | 56 | 57 | Level3 58 | Disabled 59 | CHECKED_OUTPUT_SIZE;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 60 | MultiThreadedDebugDLL 61 | 62 | 63 | Console 64 | true 65 | 16777216 66 | 67 | 68 | 69 | 70 | Level3 71 | 72 | 73 | MaxSpeed 74 | true 75 | true 76 | CHECKED_OUTPUT_SIZE;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 77 | MultiThreadedDLL 78 | 79 | 80 | Console 81 | true 82 | true 83 | true 84 | 16777216 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /vs/polyfill-prototype-1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pack-asmjs", "pack-asmjs.vcxproj", "{16CCFC5C-02DF-4825-97BE-2E575D22B014}" 7 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unpack-asmjs", "unpack-asmjs.vcxproj", "{16CCFC5C-02DF-4825-97BE-2E575D22B015}" 8 | EndProject 9 | Global 10 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 11 | Debug|Win32 = Debug|Win32 12 | Release|Win32 = Release|Win32 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {16CCFC5C-02DF-4825-97BE-2E575D22B014}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {16CCFC5C-02DF-4825-97BE-2E575D22B014}.Debug|Win32.Build.0 = Debug|Win32 17 | {16CCFC5C-02DF-4825-97BE-2E575D22B014}.Release|Win32.ActiveCfg = Release|Win32 18 | {16CCFC5C-02DF-4825-97BE-2E575D22B014}.Release|Win32.Build.0 = Release|Win32 19 | {16CCFC5C-02DF-4825-97BE-2E575D22B015}.Debug|Win32.ActiveCfg = Debug|Win32 20 | {16CCFC5C-02DF-4825-97BE-2E575D22B015}.Debug|Win32.Build.0 = Debug|Win32 21 | {16CCFC5C-02DF-4825-97BE-2E575D22B015}.Release|Win32.ActiveCfg = Release|Win32 22 | {16CCFC5C-02DF-4825-97BE-2E575D22B015}.Release|Win32.Build.0 = Release|Win32 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /vs/unpack-asmjs.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {16CCFC5C-02DF-4825-97BE-2E575D22B015} 15 | Win32Proj 16 | vs 17 | unpack-asmjs 18 | 19 | 20 | 21 | Application 22 | true 23 | v120 24 | Unicode 25 | 26 | 27 | Application 28 | false 29 | v120 30 | true 31 | Unicode 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | true 45 | ..\tools 46 | $(Configuration)\$(ProjectName)\ 47 | 48 | 49 | false 50 | ..\tools 51 | $(Configuration)\$(ProjectName)\ 52 | 53 | 54 | 55 | 56 | 57 | Level3 58 | Disabled 59 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 60 | MultiThreadedDebugDLL 61 | 62 | 63 | Console 64 | true 65 | 66 | 67 | 68 | 69 | Level3 70 | 71 | 72 | MaxSpeed 73 | true 74 | true 75 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 76 | MultiThreadedDLL 77 | 78 | 79 | Console 80 | true 81 | true 82 | true 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | --------------------------------------------------------------------------------