1
commit a61ef3dbbaf7333ad67fca29c0aad5bcc99b653a
2
Author: Alon Zakai <alonzakai@gmail.com>
3
Date: Wed Mar 6 18:18:03 2013 -0800
5
handle new vars in asm code, such as the loop vars from memset/memcpy loops
7
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
8
index f2dc516..65059e8 100644
9
--- a/tools/js-optimizer.js
10
+++ b/tools/js-optimizer.js
11
@@ -1321,7 +1321,7 @@ function normalizeAsm(func) {
14
if (!(name in data.vars)) {
15
- assert(value[0] == 'num' || (value[0] == 'unary-prefix' && value[2][0] == 'num')); // must be valid coercion no-op
16
+ if (!(value[0] == 'num' || (value[0] == 'unary-prefix' && value[2][0] == 'num'))) break outer; // must be valid coercion no-op
17
data.vars[name] = detectAsmCoercion(value);
18
v.length = 1; // make an un-assigning var
20
@@ -1331,6 +1331,7 @@ function normalizeAsm(func) {
23
// finally, look for other var definitions and collect them
25
while (i < stats.length) {
26
traverse(stats[i], function(node, type) {
28
@@ -1340,6 +1341,7 @@ function normalizeAsm(func) {
30
if (!(name in data.vars)) {
31
data.vars[name] = detectAsmCoercion(value);
32
+ extra.push(['var', [[name]]]); // add a 'var' for normal JS
35
unVarify(node[1], node);
36
@@ -1353,6 +1355,7 @@ function normalizeAsm(func) {
40
+ if (extra.length > 0) stats.splice.apply(stats, [0, 0].concat(extra));
41
//printErr('normalized \n\n' + astToSrc(func) + '\n\nwith: ' + JSON.stringify(data));
44
diff --git a/tools/test-js-optimizer-asm-regs-output.js b/tools/test-js-optimizer-asm-regs-output.js
45
index 99bccd2..f84b8d5 100644
46
--- a/tools/test-js-optimizer-asm-regs-output.js
47
+++ b/tools/test-js-optimizer-asm-regs-output.js
48
@@ -9,6 +9,18 @@ function asm(d1, i2) {
52
+function asm2(d1, i2) {
55
+ var i3 = 0, d4 = +0;
58
+ d1 = d(Math_max(10, Math_min(5, f())));
64
function _doit(i1, i2, i3) {
67
diff --git a/tools/test-js-optimizer-asm-regs.js b/tools/test-js-optimizer-asm-regs.js
68
index 0afced2..fbaa7c4 100644
69
--- a/tools/test-js-optimizer-asm-regs.js
70
+++ b/tools/test-js-optimizer-asm-regs.js
71
@@ -10,6 +10,19 @@ function asm(x, y) {
75
+function asm2(x, y) {
78
+ var int1 = 0, int2 = 0; // do not mix the types!
79
+ var double1 = +0, double2 = +0;
82
+ double1 = d(Math.max(10, Math_min(5, f())));
85
+ double2 = double1*5;
88
function _doit($x, $y$0, $y$1) {
91
@@ -41,5 +54,5 @@ function retf() {
93
// missing final return, need it as a float
95
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "_doit", "rett", "ret2t", "retf"]
96
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "asm2", "_doit", "rett", "ret2t", "retf"]