]> git.proxmox.com Git - rustc.git/blame - src/binaryen/scripts/spidermonkify.py
New upstream version 1.25.0+dfsg1
[rustc.git] / src / binaryen / scripts / spidermonkify.py
CommitLineData
abe05a73
XL
1#! /usr/bin/env python
2
3# Copyright 2016 WebAssembly Community Group participants
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17'''
18A bunch of hackish fixups for testing of SpiderMonkey support. We should
19get rid of these ASAP.
20
21This is meant to be run using BINARYEN_SCRIPTS in emcc, and not standalone.
22'''
23
24import os
25import subprocess
26import sys
27
28import emscripten
29
30binaryen_root = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
31
32js_target = sys.argv[1]
33wast_target = sys.argv[2]
34
35wasm_target = wast_target[:-5] + '.wasm'
36
37# convert to binary using spidermonkey
38'''
39using something like
40mozjs -e 'os.file.writeTypedArrayToFile("moz.wasm",
41new Uint8Array(wasmTextToBinary(os.file.readFile("a.out.wast"))))'
42investigate with
43>>> map(chr, map(ord, open('moz.wasm').read()))
44or
45python -c "print str(map(chr,map(ord,
46 open('a.out.wasm').read()))).replace(',', '\n')"
47'''
48subprocess.check_call(
49 emscripten.shared.SPIDERMONKEY_ENGINE +
50 ['-e', 'os.file.writeTypedArrayToFile("' + wasm_target +
51 '", new Uint8Array(wasmTextToBinary(os.file.readFile("' +
52 wast_target + '"))))'])