summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jsifier.js4
-rw-r--r--src/library_fs.js7
-rw-r--r--src/shell.js13
-rw-r--r--tests/cases/switch64_ta2.ll55
-rw-r--r--tools/test-js-optimizer-regs-output.js16
-rw-r--r--tools/test-js-optimizer-regs.js2
6 files changed, 82 insertions, 15 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 49f2c564..1f53b1a2 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1148,6 +1148,10 @@ function JSify(data, functionsOnly, givenFunctions) {
if (VERBOSE && useIfs && item.switchLabels.length >= 6) {
warn('not optimizing llvm switch into js switch because range of values is ' + range + ', density is ' + range/item.switchLabels.length);
}
+ if (!useIfs && isIllegalType(item.type)) {
+ useIfs = true;
+ if (VERBOSE) warn('not optimizing llvm switch because illegal type ' + item.type);
+ }
var phiSets = calcPhiSets(item);
// Consolidate checks that go to the same label. This is important because it makes the relooper simpler and faster.
diff --git a/src/library_fs.js b/src/library_fs.js
index 4a150d80..8bf0a83a 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -807,6 +807,13 @@ mergeInto(LibraryManager.library, {
if (stream.stream_ops.open) {
stream.stream_ops.open(stream);
}
+ if (Module['logReadFiles'] && !(flags & {{{ cDefine('O_WRONLY')}}})) {
+ if (!FS.readFiles) FS.readFiles = {};
+ if (!(path in FS.readFiles)) {
+ FS.readFiles[path] = 1;
+ Module['printErr']('read file: ' + path);
+ }
+ }
return stream;
},
close: function(stream) {
diff --git a/src/shell.js b/src/shell.js
index f91aa96a..7bfbe781 100644
--- a/src/shell.js
+++ b/src/shell.js
@@ -104,25 +104,26 @@ else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
Module['arguments'] = arguments;
}
- if (ENVIRONMENT_IS_WEB) {
+ if (typeof console !== 'undefined') {
Module['print'] = function(x) {
console.log(x);
};
-
Module['printErr'] = function(x) {
console.log(x);
};
-
- this['{{{ EXPORT_NAME }}}'] = Module;
- } else if (ENVIRONMENT_IS_WORKER) {
- // We can do very little here...
+ } else {
+ // Probably a worker, and without console.log. We can do very little here...
var TRY_USE_DUMP = false;
Module['print'] = (TRY_USE_DUMP && (typeof(dump) !== "undefined") ? (function(x) {
dump(x);
}) : (function(x) {
// self.postMessage(x); // enable this if you want stdout to be sent as messages
}));
+ }
+ if (ENVIRONMENT_IS_WEB) {
+ this['{{{ EXPORT_NAME }}}'] = Module;
+ } else {
Module['load'] = importScripts;
}
}
diff --git a/tests/cases/switch64_ta2.ll b/tests/cases/switch64_ta2.ll
new file mode 100644
index 00000000..e56ccfba
--- /dev/null
+++ b/tests/cases/switch64_ta2.ll
@@ -0,0 +1,55 @@
+@.str = private constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1]
+
+define linkonce_odr i32 @main() align 2 {
+ %333 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0]
+ %444 = zext i32 %333 to i64
+ %199 = trunc i8 1 to i1 ; [#uses=1]
+ switch i64 %444, label %label999 [
+ i64 1000, label %label9950
+ i64 1001, label %label9951
+ i64 1002, label %label9952
+ i64 1003, label %label9953
+ i64 1004, label %label9954
+ i64 1005, label %label9955
+ i64 1006, label %label9956
+ i64 1007, label %label9957
+ i64 1008, label %label9958
+ i64 1009, label %label9959
+ ] ; switch should ignore all code after it in the block
+ ; No predecessors!
+ %a472 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ %a473 = extractvalue { i8*, i32 } %a472, 0
+ %a474 = extractvalue { i8*, i32 } %a472, 1
+ br label %label999
+
+label9950:
+ %333b = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0]
+ br label %label999
+
+label9951:
+ br label %label999
+label9952:
+ br label %label999
+label9953:
+ br label %label999
+label9954:
+ br label %label999
+label9955:
+ br label %label999
+label9956:
+ br label %label999
+label9957:
+ br label %label999
+label9958:
+ br label %label999
+label9959:
+ br label %label999
+
+label999: ; preds = %555
+ ret i32 0
+}
+
+declare i32 @printf(i8*)
+declare i32 @__gxx_personality_v0(...)
+
diff --git a/tools/test-js-optimizer-regs-output.js b/tools/test-js-optimizer-regs-output.js
index 149ca984..6f67bcec 100644
--- a/tools/test-js-optimizer-regs-output.js
+++ b/tools/test-js-optimizer-regs-output.js
@@ -175,19 +175,19 @@ function fcntl_open() {
return null;
}
function ex() {
- var r1, r2;
- r1 = STACKTOP;
+ var __stackBase__ = STACKTOP;
STACKTOP += 4;
- r2 = r1;
- r1 = _puts(STRING_TABLE._str17 | 0);
- r1 = r2 | 0;
- r2 = 0;
+ var $e1 = __stackBase__;
+ var $puts = _puts(STRING_TABLE._str17 | 0);
+ var $x41 = $e1 | 0;
+ var $i_04 = 0;
while (1) {
- r1 = _printf(STRING_TABLE.__str15 | 0, (tempInt = STACKTOP, STACKTOP += 4, HEAP32[tempInt >> 2] = r2, tempInt));
+ var $i_04;
+ var $call1 = _printf(STRING_TABLE.__str15 | 0, (tempInt = STACKTOP, STACKTOP += 4, HEAP32[tempInt >> 2] = $i_04, tempInt));
((function() {
try {
__THREW__ = false;
- return __Z5magici(r2);
+ return __Z5magici($i_04);
} catch (e) {
if (typeof e != "number") throw e;
if (ABORT) throw e;
diff --git a/tools/test-js-optimizer-regs.js b/tools/test-js-optimizer-regs.js
index 00303786..bc0ebb5a 100644
--- a/tools/test-js-optimizer-regs.js
+++ b/tools/test-js-optimizer-regs.js
@@ -190,7 +190,7 @@ function ex() {
while (1) {
var $i_04;
var $call1 = _printf(STRING_TABLE.__str15 | 0, (tempInt = STACKTOP, STACKTOP += 4, HEAP32[tempInt >> 2] = $i_04, tempInt));
- ((function() {
+ ((function() { // prevents registerize, looks like inline asm
try {
__THREW__ = false;
return __Z5magici($i_04);