Skip to content

Instantly share code, notes, and snippets.

@kripken
kripken / 1.js
Created February 27, 2017 04:53
Possible APIs for getting two locals and adding them in binaryen.js
var left = module.getLocal(0, Binaryen.Int32);
var right = module.getLocal(1, Binaryen.Int32);
var add = module.binary(Binaryen.AddInt32, left, right);
; Function Attrs: inlinehint norecurse nounwind
define internal fastcc void @_ZN4core3ptr14write_volatile17h89fe80f6e705ad15E(%E*, %E* noalias nocapture readonly dereferenceable(256)) unnamed_addr #2 personality i32 (...)* bitcast (i32 (i8*)* @rust_eh_personality to i32 (...)*) {
entry-block:
%src.sroa.0.sroa.0.0.src.sroa.0.0..sroa_cast.sroa_idx = getelementptr inbounds %E, %E* %1, i32 0, i32 0, i32 0
%src.sroa.0.sroa.0.0.copyload = load i64, i64* %src.sroa.0.sroa.0.0.src.sroa.0.0..sroa_cast.sroa_idx, align 8
%src.sroa.0.sroa.2.0.src.sroa.0.0..sroa_cast.sroa_idx34 = getelementptr inbounds %E, %E* %1, i32 0, i32 0, i32 1
%src.sroa.0.sroa.2.0.copyload = load i64, i64* %src.sroa.0.sroa.2.0.src.sroa.0.0..sroa_cast.sroa_idx34, align 8
%src.sroa.0.sroa.3.0.src.sroa.0.0..sroa_cast.sroa_idx35 = getelementptr inbounds %E, %E* %1, i32 0, i32 0, i32 2
%src.sroa.0.sroa.3.0.copyload = load i64, i64* %src.sroa.0.sroa.3.0.src.sroa.0.0..sroa_cast.sroa_idx35, align 8
$ EMCC_DEBUG=1 ./emcc -s VERBOSE=1 tests/hello_libcxx.cpp
DEBUG:root:PYTHON not defined in /home/alon/.emscripten, using "/usr/bin/python"
DEBUG:root:Cache: PID 4282 acquiring multiprocess file lock to Emscripten cache
DEBUG:root:Cache: done
DEBUG:root:Cache: PID 4282 released multiprocess file lock to Emscripten cache
DEBUG:root:check tells us to use asm.js backend
WARNING:root:invocation: ./emcc -s VERBOSE=1 tests/hello_libcxx.cpp (in /home/alon/Dev/emscripten)
DEBUG:root:Checking JS engine ['nodejs']
INFO:root:(Emscripten: Running sanity checks)
DEBUG:root:compiling to bitcode
$ EMCC_DEBUG=1 ./emcc tests/hello_world.cpp -s VERBOSE=1
DEBUG:root:PYTHON not defined in /home/alon/.emscripten, using "/usr/bin/python"
DEBUG:root:Cache: PID 31471 acquiring multiprocess file lock to Emscripten cache
DEBUG:root:Cache: done
DEBUG:root:Cache: PID 31471 released multiprocess file lock to Emscripten cache
DEBUG:root:check tells us to use asm.js backend
WARNING:root:invocation: ./emcc tests/hello_world.cpp -s VERBOSE=1 (in /media/alon/2f9a30d7-6124-42d9-87c5-3c80cb70ec54/home/alon/Dev/emscripten)
DEBUG:root:Checking JS engine ['/home/alon/Downloads/node-v4.2.6-linux-x64/bin/node']
INFO:root:(Emscripten: Running sanity checks)
DEBUG:root:compiling to bitcode
@kripken
kripken / SAB.now
Last active December 7, 2017 13:38 — forked from mbebenita/SAB.now
<html>
<body>
<script>
function sum(array) {
var num = 0;
for (var i = 0, l = array.length; i < l; i++) num += array[i];
return num;
}
(module
(type $0 (func (param i32 i32 i32) (result i32)))
(type $1 (func (param i32) (result i32)))
(type $2 (func (param i32)))
(type $3 (func (result i32)))
(type $4 (func (param i32 i32) (result i32)))
(type $5 (func))
(type $6 (func (param i32 i32)))
(type $7 (func (param i32 i32 i32 i32) (result i32)))
(import "env" "DYNAMICTOP_PTR" (global $import$0 i32))
(module
(type $0 (func (param i32 i32 i32) (result i32)))
(type $1 (func (param i32) (result i32)))
(type $2 (func (result i32)))
(type $3 (func (param i32 i32) (result i32)))
(type $4 (func))
(import "env" "___syscall146" (func $import$0 (param i32 i32) (result i32)))
(import "env" "memory" (memory $0 256 256))
(import "env" "table" (table 6 6 anyfunc))
(elem (i32.const 0) $4 $4 $4 $1)
(module
(type $0 (func (param i32 i32 i32) (result i32)))
(type $1 (func (param i32) (result i32)))
(type $2 (func (result i32)))
(type $3 (func (param i32 i32) (result i32)))
(type $4 (func))
(import "env" "___syscall146" (func $import$0 (param i32 i32) (result i32)))
(import "env" "memory" (memory $0 256 256))
(import "env" "table" (table 6 6 anyfunc))
(elem (i32.const 0) $1 $1 $1 $5)
function makeAtomicOps(ofType) {
function makeRMW(opName) {
return function(bytes, offset, ptr, value) {
return Module['_BinaryenAtomicRMW'](module, Module[opName], bytes, offset, ptr, value, ofType);
};
}
return {
'rmw': {
'add': makeRMW('AtomicRMWAdd'),
'sub': makeRMW('AtomicRMWSub'),
diff --git a/tools/shared.py b/tools/shared.py
index a591325..60a1853 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1854,49 +1854,50 @@ class Building(object):
# LLVM optimizations
# @param opt A list of LLVM optimization parameters
@staticmethod
def llvm_opt(filename, opts, out=None):
inputs = filename